forked from opensciencegrid/tarball-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload-tarballs-to-oasis
executable file
·208 lines (178 loc) · 6.41 KB
/
upload-tarballs-to-oasis
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/bash
TARBALL_CLIENT_DIR=/p/vdt/public/html/tarball-client
REMOTE_LOGIN=ouser.mis
REMOTE_HOST=oasis-login.opensciencegrid.org
REMOTE_PATH_BASE=/stage/oasis/mis
FINAL_LOCATION_BASE=/cvmfs/oasis.opensciencegrid.org/mis
# OASIS_CERTIFICATES_DEFAULT must match what's in OASIS_CERTIFICATES in
# /etc/cvmfs/config.d/oasis.opensciencegrid.org.conf in the cvmfs-config-osg
# package
OASIS_CERTIFICATES_DEFAULT=/cvmfs/oasis.opensciencegrid.org/mis/certificates
OASIS_VODATA=/cvmfs/oasis.opensciencegrid.org/mis/vodata
main() {
[[ -n $1 ]] || die_with_usage # No version specified
local version=$1
local major_version=${version%.*}
local release
if [[ -z $2 ]]; then
message "Release not specified; assuming release is '1'"
release=1
else
release=$2
fi
# The dir each tarball will be extracted into in the staging area
local remote_dir=$REMOTE_PATH_BASE/osg-wn-client/$major_version/$version-$release
# The path in the filesystem files will be accessible from on client machines
local final_dir=$FINAL_LOCATION_BASE/osg-wn-client/$major_version/$version-$release
local current_symlink=$REMOTE_PATH_BASE/osg-wn-client/$major_version/current
foreach_dver_arch $major_version \
die_if_tarball_missing $version $release \$dver \$arch
die_if_remote_dir_exists $remote_dir # Don't want to clobber anything
do_remotely mkdir -p $remote_dir
foreach_dver_arch $major_version \
transfer_and_extract_tarball_or_die $version $release \$dver \$arch $remote_dir
foreach_dver_arch $major_version \
run_post_unpack_steps \$dver \$arch $remote_dir $final_dir
echo
message "All steps successful."
message "Verify the contents of $remote_dir are as expected."
message "If this was the newest tarball for the $major_version major version,"
message "then update the 'current' symlink by running:"
message $'\t'"ln -snf '$version-$release' '$current_symlink'"
message "Then, run 'osg-batch-update'."
echo
message "Opening an interactive shell to $REMOTE_HOST via 'ssh'."
ssh $REMOTE_LOGIN@$REMOTE_HOST
}
message() {
echo $'\t'"$*"
}
die_with_usage() {
message "Usage: $0 <VERSION> [<RELEASE>]"
exit 2
}
local_tarball_path() {
local version=$1
local release=$2
local dver=$3
local arch=$4
local major_version=${version%.*}
echo $TARBALL_CLIENT_DIR/$major_version/$arch/osg-wn-client-$version-$release.$dver.$arch.tar.gz
}
do_remotely () {
ssh $REMOTE_LOGIN@$REMOTE_HOST "$@"
}
transfer_and_extract_tarball_or_die() {
local version=$1
local release=$2
local dver=$3
local arch=$4
local remote_dir=$5
local remote_subdir=$remote_dir/$dver-$arch
local tarball=$(local_tarball_path "$version" "$release" "$dver" "$arch")
local ret
local tries=0
local max_tries=5
while true; do
message "Transferring $(basename $tarball)"
< "$tarball" do_remotely tar -xz -C "$remote_dir"
ret=$?
if [[ $ret -ne 0 ]]; then
message "Error uploading $tarball"
if [[ $tries < $max_tries ]]; then
let tries+=1
local timeout=$((tries*30))
message "Sleeping for $timeout seconds and retrying"
sleep $timeout
else
message "Exceeded max retries, exiting.."
exit 1
fi
else
message "$(basename $tarball) uploaded after $tries retries"
break
fi
done
# Everything in the tarball is in the 'osg-wn-client' directory
# That's redundant here, so have the dver and arch in the directory
# name instead.
do_remotely mv "$remote_dir/osg-wn-client" "$remote_subdir"
}
run_post_unpack_steps() {
local dver=$1
local arch=$2
local remote_dir=$3
local remote_subdir=$remote_dir/$dver-$arch
local final_dir=$4
local final_subdir=$final_dir/$dver-$arch
message "Running post-unpack steps in $remote_subdir"
do_remotely "(cd '$remote_subdir'; ./osg/osg-post-install . --final-osg-location='$final_subdir')"
local ret=$?
if [[ $ret -ne 0 ]]; then
message "Unable to run osg-post-install for $dver $arch"
exit 1
fi
# $(OASIS_CERTIFICATES:-...) is CVMFS syntax, not bash, and must be
# quoted AND escaped to survive evaluation
do_remotely ln -s '\$\(OASIS_CERTIFICATES:-'"$OASIS_CERTIFICATES_DEFAULT"'\)' "$remote_subdir"/etc/grid-security/certificates
do_remotely "(
[[ -f $OASIS_VODATA/vomses ]] && \
rm -f '$remote_subdir'/etc/vomses && \
ln -s '$OASIS_VODATA'/vomses '$remote_subdir'/etc/vomses
)"
if [[ $? -ne 0 ]]; then
message "Unable to symlink vomses file for $dver $arch"
exit 1
fi
do_remotely "(
[[ -d $OASIS_VODATA/grid-security/vomsdir ]] && \
rm -rf '$remote_subdir'/etc/grid-security/vomsdir && \
ln -s '$OASIS_VODATA'/grid-security/vomsdir '$remote_subdir'/etc/grid-security/vomsdir
)"
if [[ $? -ne 0 ]]; then
message "Unable to symlink vomsdir dir for $dver $arch"
exit 1
fi
# Make all files and directories world-accessible (or osg-oasis-update will complain).
do_remotely find "$remote_subdir" '\!' '-perm' '/o=r' '-exec' 'chmod a+r' '{}' '\;'
do_remotely find "$remote_subdir" '-type' 'd' '\!' '-perm' '/o=x' '-exec' 'chmod a+x' '{}' '\;'
}
die_if_tarball_missing() {
local tarball=$(local_tarball_path "$1" "$2" "$3" "$4")
if [[ ! -e $tarball ]]; then
message $tarball not found
exit 1
fi
}
die_if_remote_dir_exists() {
local remote_dir=$1
local result=$(do_remotely 'test -d '$remote_dir' && echo exists')
if [[ $result == exists ]]; then
message "$remote_dir already exists. Not overwriting it."
exit 1
fi
}
foreach_dver_arch() {
local major_version="$1"; shift
local dver
local arch
local dver_arch
local dver_arches=()
local ret
local all_ret=0
case $major_version in
3.4) dver_arches=({el6,el7}.x86_64);;
3.5) dver_arches=({el7,el8}.x86_64);;
3.6) dver_arches=({el7,el8,el9}.x86_64);;
23) dver_arches=({el8,el9}.x86_64);;
esac
for dver_arch in ${dver_arches[@]}; do
dver=${dver_arch%.*}
arch=${dver_arch#*.}
eval "$@"
ret=$?
all_ret=$(( all_ret || ret ))
done
return $all_ret
}
main "$@"