source: other-projects/nightly-tasks/crons-and-scripts/do-snapshots-and-latest.sh@ 29996

Last change on this file since 29996 was 29996, checked in by ak19, 9 years ago

Finished implementing two of Kathy's excellent requests. 1. That when all caveat bins/src for GS2 have been generated for a day, these all get transferred into the nzdl release-snapshots area as 'stables'. And the same for GS3. 2. A new subfolder inside caveat-emptor called 'latest', which the caveat page links to. This page should provide a link to the last successfully caveat generated binary or src version. That way, even if all binaries and src versions fail to generate for the last 5 days or more, and the links to the previous caveat days don't provide any downloads, the new 'latest' link would still provide something to download for each src or binary version, even if it is very old.

  • Property svn:executable set to *
File size: 7.9 KB
Line 
1#!/bin/bash
2
3# This script is called each time a nightly GS file (binary or otherwise) gets uploaded to puka
4# to the caveat-emptor folder. This script is called from
5# nzdl@puka:[522]~/.ssh$ less authorized_keys
6
7
8######### GLOBAL VARS #########
9
10# http://stackoverflow.com/questions/1401482/yyyy-mm-dd-format-date-in-shell-script
11# we want . as separator to produce: yyyy.mm.dd
12
13today=`date +%Y.%m.%d`
14
15# http://askubuntu.com/questions/367136/how-do-i-read-a-variable-from-a-file
16
17gs2version=`cat /greenstone/greenstone.org/base/next-release.txt`
18gs3version=`cat /greenstone/greenstone.org/base/next-release-greenstone3.txt`
19
20# static array of string literals representing the caveat file suffixes we're interested in
21
22suffixes=("linux" "linux-x64" "Lion-MacOS-intel.dmg" "MacOS-intel.dmg" "windows.exe" "source-component.tar.gz" "source-component.zip" "source-distribution.tar.gz" "source-distribution.zip")
23
24gs2_bin_prefix=Greenstone-$gs2version-candidate-$today-
25gs3_bin_prefix=Greenstone-$gs3version-candidate-$today-
26
27#echo "Date is $today"
28#echo "gs2ver is $gs2version"
29#echo "gs3ver is $gs3version"
30#echo "gs2_bin_prefix is $gs2_bin_prefix"
31#echo "gs3_bin_prefix is $gs3_bin_prefix"
32
33caveat_dir=/greenstone/greenstone.org/base/caveat-emptor/
34snapshots_dir=/greenstone/greenstone.org/base/release-snapshots/
35latest_dir=${caveat_dir}latest/
36
37###############################
38
39# Function that checks whether all of today's binaries for a gs_version (GS2 or GS3) are
40# present in the caveat folder
41# If so, it copies those bins over into the release-snapshots folder under new names
42
43# Non-ambiguous string concatenation: ${varname}string-literal
44# stackoverflow.com/questions/4181703/how-can-i-concatenate-string-variables-in-bash
45
46function snapshots_for_gs_version () {
47
48 # Local vs global variables in functions
49 # http://www.tldp.org/LDP/abs/html/localvar.html
50
51 local gs_version=$1
52
53 #check if we've found all gs_version nightly binaries
54 local foundallbins=true
55
56 for suffix in ${suffixes[@]}; do
57 local file=$caveat_dir
58 if [ "$gs_version" == "2" ]; then
59 file=$file$gs2_bin_prefix$suffix
60 else
61 file=$file$gs3_bin_prefix$suffix
62 fi
63
64 if [ ! -f $file ]; then
65 echo "File does not exist: $file"
66 foundallbins=false
67 #else
68 #echo "File exists: $file"
69 fi
70 done
71
72 echo ""
73
74 if [ "$foundallbins" == "true" ]; then
75 echo "All gs$gs_version binaries for $today generated"
76 echo ""
77
78 # delete the old stables
79 echo "Deleting ${snapshots_dir}Greenstone-${gs_version}s*"
80 rm ${snapshots_dir}Greenstone-${gs_version}s*
81 echo ""
82
83 # copy the gs2 binaries to release-snapshots folder
84 # under the new name Greenstone-${gs_version}sDATE-suffix, where gs_version = 2|3
85 # Use hardlinking instead of copy to save space
86
87 for suffix in ${suffixes[@]}; do
88 local file=$caveat_dir
89 if [ "$gs_version" == "2" ]; then
90 file=$file$gs2_bin_prefix$suffix
91 else
92 file=$file$gs3_bin_prefix$suffix
93 fi
94 local newfile=${snapshots_dir}Greenstone-${gs_version}s${today}-$suffix
95
96 # http://askubuntu.com/questions/108771/what-is-the-difference-between-a-hard-link-and-a-symbolic-link
97 # Q & A: The difference between hard and soft links at http://linuxgazette.tuwien.ac.at/105/pitcher.html
98 echo "Hardlinking file $file as $newfile"
99 ln $file $newfile
100
101 done
102
103 else
104 echo "Not all gs${gs_version} binaries for $today have been generated. (foundallbins: $foundallbins)"
105 fi
106
107 echo ""
108
109
110 # cdrom components only for GS2
111
112 if [ "$gs_version" == "2" ]; then
113
114 echo "GS2 CD ROM components"
115 echo ""
116
117 cd_suffixes=("linux" "linux-x64" "Lion-mac" "mac" "full-windows" "windows")
118 cdfile_src=cdrom-components-${gs2version}-candidate-${today}-
119
120 local foundallcds=true
121
122 for suffix in ${cd_suffixes[@]}; do
123
124 local file=${caveat_dir}$cdfile_src${suffix}.tar.gz
125
126 if [ ! -f $file ]; then
127 foundallcds=false
128 echo "Could not find cdrom component $file"
129 fi
130 done
131
132 # if all cdrom components present, then copy across under new names
133 if [ "$foundallcds" == "true" ]; then
134
135 # delete the old cdrom components from release-snapshots
136 echo "Deleting ${snapshots_dir}cdrom-components-2s*"
137 rm ${snapshots_dir}cdrom-components-2s*
138 echo ""
139
140 # copy across the new cdrom components
141 # use hardlinking instead of copying to save space
142
143 for suffix in ${cd_suffixes[@]}; do
144
145 local srcfile=${caveat_dir}$cdfile_src${suffix}.tar.gz
146 local destfile=${snapshots_dir}cdrom-components-2s${today}-${suffix}.tar.gz
147 echo "Hardlinking $srcfile as $destfile"
148 ln $srcfile $destfile
149 done
150 fi
151
152 echo ""
153 fi
154
155
156}
157
158# Inspect the most recently added file in the caveat folder and iff it's a GS binary or src file,
159# create a hardlink for it under the appropriate name in the 'latest' subfolder
160# and delete the earlier variant of the same in 'latest'.
161# In time may have to start including the GS documented examples archive files generated overnight.
162#
163# General: http://stackoverflow.com/questions/3601515/how-to-check-if-a-variable-is-set-in-bash
164
165function make_latest () {
166
167 echo ""
168 #echo "In MAKE_LATEST"
169
170 # find the latest file in caveat, since this script is called upon each upload to puka's caveat
171 # http://stackoverflow.com/questions/5885934/bash-function-to-find-newest-file-matching-pattern
172 # http://mywiki.wooledge.org/BashFAQ/003
173 unset -v latest
174 for file in "${caveat_dir}"*; do
175 [[ -f $file ]] && [[ $file -nt $latest ]] && latest=$file
176 done
177
178 # latest will not be undef, because this script is only ever called upon a legitimate
179 # file upload into puka's caveat-emptor location
180 # E.g. for testing, latest=Greenstone-3.07-candidate-2015.06.26-linux
181 echo "Latest file in caveat is: $latest"
182
183 # Iff this is a GS binary/src file that we want to maintain in the caveat/latest folder,
184 # then remove the older version of the same file from caveat/latest folder, if any,
185 # and hardlink the latest file into caveat/latest
186
187 # Check whether the latest file ends with the binary/src suffix
188 # https://viewsby.wordpress.com/2013/09/06/bash-string-ends-with/
189 # single or double square brackets for testing conditions, [] vs [[]]
190 # http://stackoverflow.com/questions/669452/is-preferable-over-in-bash-scripts
191 # Need double brackets below, [[]], for string expansion with wildcard
192
193 for suffix in ${suffixes[@]}; do
194 if [[ "$latest" == *"$suffix" ]]; then
195 echo "Found that suffix matched: $suffix"
196
197 # splits the filename $latest by hyphens, -, and then gets the 2nd substring
198 # in this case the GS2 or GS3 full version number
199 # http://stackoverflow.com/questions/428109/extract-substring-in-bash
200 local matchfile=`echo $latest| cut -d'-' -f 2`
201 echo "Found gs version prefix: $matchfile"
202
203 matchfile=${latest_dir}Greenstone-${matchfile}-candidate-*-${suffix}
204
205 # remove the matching file from the caveat/latest folder
206 # we don't know it's date, so we substituted that portion with a * as wildcard
207 # E.g. matchfile=<caveat>/latest/Greenstone-2.87-candidate-*-source-component.tar.gz
208
209 echo "Removing $matchfile"
210 rm $matchfile
211
212 # make a hardlink of the $latest file into the caveat_latest folder
213 ln ${caveat_dir}$latest ${latest_dir}$latest
214 #else
215 #echo "$latest did not match $suffix"
216 fi
217 done
218
219 echo ""
220}
221
222####################
223
224# the 'main'
225
226# This script is called upon each upload to puka's caveat-emptor by
227# the file nzdl@puka:[522]~/.ssh/authorized_keys
228
229# Check if conditions are true to create snapshots out of today's GS2 bins, these conditions
230# being that all src and bins of GS2 have been generated for today.
231# And if so, hardlink these src and bin files into the release-snapshots dir.
232# Repeat for GS3.
233# Finally, for each uploaded file that is a Greenstone src or binary file in caveat
234# hardlink it into the caveat/latest folder to keep a copy of the most-recent version of that
235# bin/file that was successfully generated.
236
237snapshots_for_gs_version "2"
238snapshots_for_gs_version "3"
239make_latest
Note: See TracBrowser for help on using the repository browser.