-
Notifications
You must be signed in to change notification settings - Fork 21
/
post
executable file
·189 lines (171 loc) · 6.05 KB
/
post
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
#!/bin/bash
#*****************************************************************
#
# Organization: Lawrence Livermore National Lab (LLNL)
# Directorate: Computation
# Department: Computing Applications and Research
# Division: S&T Global Security
# Matrix: Atmospheric, Earth and Energy Division
# Program: PCMDI
# Project: Earth Systems Grid
# First Author: Gavin M. Bell ([email protected])
#
# Description:
#
# Simple script for pushing files from the repsitory to the website
# for general consumption. The motivation here was to not have
# people pummel our source code repository getting these files, which
# is slow and not what a repo is for. Web servers are made exactly
# for this task, so put the necessary files on one, right? :-)
#
# This file reads a manifest file by default postlist.manif
#
# The format of the manifest file is pseudo "ini" like. You can
# specifiy the destination directory extending from the esg_dist_url
# value by putting that value on a single line in []s. files must be
# listed with either absolute path or directory relative to the
# execution of the "post" script. There may be a second value after the
# file location that determines where this particular entry is put on
# the server (after the esg_dist_url value). If no destination
# directory value is set the default is esg_node set at the top of the
# script.
#
# NOTE: Because we use rsync -c files will not be pushed if they have
# not changed since the last push! :-) Pretty damn sweet!
#
# Ex:
# -----
#
# #lines starting with "#" are ignored :-)
# /path/file1
#
# [server_dir]
#
# path/file2
# path/file3 other_server_dir
# ../path/file4
#
# [another_path/foo]
#
# path/file4
#
# -----
# file1 will go to ${esg_dist_url}/esg_node (the default server dir)
# file2 will go to ${esg_dist_url}/server_dir
# file3 will to go ${esg_dist_url}/other_server_dir
# file4 will go to ${esg_dist_url}/server_dir
# file5 will go to ${esg_dist_url}/another_path/foo
#
#
#Misc:
# the sed pattern for how we write our version with git and branch is...
# sed 's/script_version="v[0-9]\+\.[0-9]\+\.[0-9]\+\(-[0-9]\+-g[0-9a-z]\+\)\?\(-[a-zA-Z].*\)\?"$//'
# (may come in handy and this took me too long to get right to just dash it weh so, to raahtid!
#*****************************************************************
#uses: egrep, rsync (and thus ssh)
__on_mac=$(uname -a | grep -q Darwin && echo 1 || echo 0)
__md5sum_() {
((__on_mac)) && md5 $@ | sed -n 's/MD5 (\([^)]*\))[ ]*=[ ]*\(.*\)/\2 \1/p' || md5sum $@
}
devel=${devel:-0}
verbose=${verbose:-0}
debug=${debug:-0}
noop=${noop:-0}
while [ -n "$1" ]; do
case $1 in
--devel)
devel=1
;;
--verbose)
verbose=1
;;
--debug)
debug=1
;;
--noop | --dry-run)
noop=1
;;
*)
printf "\n ERROR: unknown switch \"$1\" \n\n" && exit 1
;;
esac
shift
done
#-----
# double check
my_current_branch=$(git status | sed -n '1 s/.*On branch[ ]*\(.*$\)/\1/p')
if echo $my_current_branch | grep devel >& /dev/null; then
#I am on a devel branch...
#Make sure that devel is turned on
if ((devel != 1)); then
read -t 5 -p "You are on branch [${my_current_branch}] and attempting to post to main distribution location, okay? [y/N]: " answer
[ -z "${answer}" ] && answer="n"
answer=$(echo ${answer} | tr 'A-Z' 'a-z')
if [ "$answer" != "y" ]; then
echo
echo "NOTE: use the \"--devel\" flag or export devel=1 in order to post to development area."
echo
exit 1
fi
fi
fi
#-----
((devel)) && echo "Pushing to development area..."
((verbose)) && echo "Verbose is ON"
((noop)) && echo "Noop is ON"
manifest_file=${manifest_file:-$0.manif}
esg_dist_url="rainbow.llnl.gov:/pcmdi_web/dist$( ((devel == 1)) && echo "/devel" || echo "")"
current_dir=${current_dir:="esgf-installer"}
xfer_user=${xfer_user:-""}
[ -n "${xfer_user}" ] && xfer_user+="@" && echo "[${xfer_user}${esg_dist_url}]"
fail=0
good=0
total=0
script_version=$(git describe)-${my_current_branch}
script_release=$(git tag | sed -ne 's/\(v[0-9]*\.[0-9]*\.[0-9]*\)-\([a-zA-Z0-9_-]*\)-release.*$/\1 \2/p' | sort -n -k1,1 | awk '{print $2}' | tail -n 1)
while read file dest_dir; do
#skip comment lines (#) and blank lines...
if [ -n "$(echo $file | grep ^#)" ] || [ -z "$file" ]; then
continue
fi
t=$(echo $file | egrep "[[](.*)[]]" | awk '{print substr($1,2,length($1)-2)}')
if [ -n "$t" ]; then
current_dir=$t
continue
fi
if [ ! -e $file ]; then
echo -n "x"
((verbose)) && echo " [FAIL] No Such File $file"
((++total))
((++fail))
continue
fi
dest_dir=${dest_dir:-"${current_dir}"}
#echo "[$file] >> [$dest_dir]"
tmp_file=${file}_${RANDOM}
((verbose)) && echo -n "pushing $file ---> ${xfer_user}${esg_dist_url}/${dest_dir} " || echo -n "*"
#NOTE: I am sure there is a cleaner way to do this two step replacement that does not require two tmp files!!!
# In a cross platform way (unix will take "-i" alone, apple wants "-i ''") :-(
((debug)) && echo "sed 's#\(script_version=\)"\(.*\)".*$#\1"'${script_version}'"#' ${file} > ${tmp_file}_"
sed 's#\(script_version=\)"\(.*\)".*$#\1"'${script_version}'"#' ${file} > ${tmp_file}_
((debug)) && echo "sed 's#\(script_release=\)"\(.*\)".*$#\1"'${script_release}'"#' ${tmp_file}_ > ${tmp_file}"
sed 's#\(script_release=\)"\(.*\)".*$#\1"'${script_release}'"#' ${tmp_file}_ > ${tmp_file}
((!noop)) && __md5sum_ ${tmp_file} | sed -n 's/_[0-9]*//p' > ${file}.md5
((!noop)) && rsync -c ${file}.md5 ${xfer_user}${esg_dist_url}/${dest_dir}/${file##*/}.md5 >& /dev/null
echo -n "-"
((!noop)) && rsync -c ${tmp_file} ${xfer_user}${esg_dist_url}/${dest_dir}/${file##*/} >& /dev/null
if [ $? != 0 ]; then
((verbose)) && echo "[FAIL]"
((++fail))
else
((verbose)) && echo "[OK]"
((++good))
fi
((++total))
rm ${tmp_file}{,_}
done < $manifest_file
echo
echo total=${total} good=${good} fail=${fail}
echo "done."
unset __on_mac
exit 0