forked from opensciencegrid/release-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release-common.sh
158 lines (140 loc) · 3.81 KB
/
release-common.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash
die () {
echo "$@" 1>&2
exit 1
}
usage () {
echo "usage: $script_name [options] <VERSION 1> [<VERSION 2>...<VERSION N>]"
echo "Options:"
echo -e "\t-d REVISION, --data REVISION\tSpecify the REVISION of the data-only release"
echo -e "\t-n, --dry-run\t\t\tPrint the commands that would be run"
echo -e "\t-h, --help\t\t\tPrint this message"
}
print_header () {
echo -e "\033[1;33m$1\033[0m"
}
osg_release () {
osgversion=$1
sed -r 's/\.[0-9]+$//' <<< $osgversion
}
osg_dvers () {
osgversion=$1
branch=$(osg_release $osgversion)
if [[ $branch == '3.3' || $branch == '3.4' || $branch == 'upcoming' ]]; then
echo el6 el7
fi
}
is_rel_ver () {
grep -E '^3\.[3-4]+\.[0-9]+$' <<< $1 > /dev/null 2>&1
echo $?
}
run_cmd () {
# Runs command(s) (accepting pipes and redirection!) and appends the command
# string to a rescue file if successful. Prints cmd to stdout if user
# specifies -d/--dry-run. Expects double quoted string (be sure to escape
# chars that you don't want evaluated by bash when being echoed to the rescue
# file e.g. '\$1' or '\"')
cmd=$1
if [[ $DRY_RUN -eq 1 ]]; then
echo "$cmd"
echo "$cmd" >> $rescue_file
else
grep -F "$cmd" $rescue_file > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
eval $cmd
if [[ $? -eq 0 ]]; then
echo "$cmd" >> $rescue_file
else
exit 1
fi
fi
fi
}
check_file_transfer_rc () {
# Exit script if files fail to copy over so we can use the rescue file
# mechanism to resend the files
if [ $1 -ne 0 ]; then
echo -e "\033[1;31mFailed to copy release notes to AFS. Re-run $script_name\033[0m"
exit 1
fi
}
detect_rescue_file () {
rescue_file=`pwd`/$script_name.rescue
[ -e $rescue_file ] && print_header "Found rescue file, picking up after the last successful command...\n" \
|| touch $rescue_file
}
cleanup_on_success () {
rm $rescue_file
}
pkg_dist () {
osgversion=$1
dver=$2
if [[ $osgversion == 'upcoming' ]]; then
echo "osgup.$dver"
else
branch=$(osg_release $osgversion)
echo "osg$(sed 's/\.//' <<< $branch).$dver"
fi
}
pkgs_to_release () {
branch=$1
dver=$2
awk "/^RPMs.*osg-$branch-$dver-testing/ {flag=1;next} /^[[:space:]]*$/ { flag=0 } flag { print }" release-list
}
########
# MAIN #
########
DRY_RUN=0
DATA=0
versions=()
script_name=$(basename $0)
if [ $# -lt 1 ]; then
usage
die
fi
while [ $# -ne 0 ];
do
case $1 in
-h|--help)
usage
die
;;
-n|--dry-run)
DRY_RUN=1
shift
;;
-d|--data)
shift
DATA=$1
if ! [[ $DATA =~ ^[2-9]$ ]]; then
die "Unexpected revision number: $DATA"
fi
shift
;;
-*)
usage
die "unknown option: $1"
;;
*)
if [[ $(is_rel_ver $1) -eq '0' || $1 == 'upcoming' ]]; then
versions+=($1)
shift
else
usage
die "unknown parameter: $1"
fi
esac
done
# Get the OSG version to associate with the upcoming release
grep 'upcoming' <<< ${versions[@]} > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
# get the latest version provided
upcoming_version=$(echo ${versions[@]} | tr ' ' '\n' | grep -v upcoming | sort -V | tail -n1)
has_upcoming_version=$(is_rel_ver $upcoming_version)
# user has only specified upcoming
while [ $has_upcoming_version != 0 ]; do
echo "What release version should upcoming be associated with?"
read upcoming_version
has_upcoming_version=$(is_rel_ver $upcoming_version)
done
fi