only bring in as many sdl things as are strictly necessary
[tangerine.git] / scripts / nightly-update
blobbc7ce2822a75bff8e8580c2f296925fdeaceb0b9
1 #!/bin/bash
3 ##############################################################################
4 # Moves nightly build files from the uploads directory to the download
5 # directory. Checks the integrity of files before moving, so incomplete or
6 # broken files are not available for download.
8 #-- Configuration & Setup ----------------------------------------------------
9 ROOT=/home/groups/a/ar/aros
10 SRC=$ROOT/uploads/nightly
11 DST=$ROOT/htdocs/downloads/nightly
12 LOCK=$SRC.lock
14 umask 0002
16 #-- Support Functions --------------------------------------------------------
17 function md5check()
19 # Description:
20 # Checks the MD5 sum of the given file. Will return failure if the MD5 sum
21 # is incorrect, the file is missing, or the MD5 sum file is missing.
23 # The MD5 sum must be stored in a separate file with the same name as the
24 # file to be tested, with ".md5" appended. Eg., if the file is "foo.txt",
25 # then the MD5 sum must be stored in "foo.txt.md5". The format of the file
26 # is that of the output from the GNU md5sum command.
28 # Inputs:
29 # $1 - path of file to check.
31 # Outputs:
32 # $? - 0 if file is OK, !0 if FAILED.
34 local oldpwd="$PWD"
35 cd "$(dirname $1)"
36 md5sum -c "$(basename $1).md5" >/dev/null 2>&1; rc=$?
37 cd "$oldpwd"
39 return $rc
42 #-- Acquire Lock -------------------------------------------------------------
43 lockfile -r 0 "$LOCK"
44 if [[ $? != 0 ]]; then
45 echo Could not acquire lock. Aborting...
46 exit 1
49 #-- Process Pending Files ----------------------------------------------------
50 cd "$SRC"
52 OLDIFS=$IFS; IFS=";"
53 for file in $(find . -type f -not -name "*.md5" -printf "%p;"); do
54 if [ ! -z "$file" ]; then
55 md5check "$file"
56 if [ $? = 0 ]; then
57 echo "> $file"
59 dst="$DST/$(dirname $file)"
60 mkdir -p "$dst"
62 if [ "${file:${#file}-4:4}" = ".xml" ]; then
63 cl="$(basename ${file:0:${#file}-4})"
64 xsltproc -o $dst/$cl.php --stringparam date ${cl:5:8} --stringparam module ${cl:24} $ROOT/scripts/cl2html.xslt "$file"
66 if [ $? = 0 ]; then
67 rm "$file"
68 rm "$file.md5"
70 else
71 mv -f "$file" $dst
72 mv -f "$file.md5" $dst
74 else
75 echo "! $file"
78 done
79 IFS=$OLDIFS
81 #-- Prune Downloads Directory ------------------------------------------------
82 cd "$DST"
84 count=$(($(ls -1 | wc -l) - 1))
85 for directory in *; do
86 if [[ $count -gt 0 ]]; then
87 rm -rf "$directory"
88 count=$((count - 1))
90 done
92 #-- Release Lock -------------------------------------------------------------
93 rm -f "$LOCK"