[30407] | 1 | #!/bin/bash
|
---|
| 2 |
|
---|
| 3 | # This script is for use on the machine where the nightly Expeditee binaries are to be
|
---|
| 4 | # uploaded. Put this script in the same folder as the uploads are meant to go.
|
---|
[30410] | 5 | # When any binary's log *.out file is being uploaded via secure shell (which is fast),
|
---|
| 6 | # this script's called. The invocation of this script should go into .ssh/authorizedkeys.
|
---|
| 7 | # Then this script will delete all other log and binary files in this folder for the same
|
---|
| 8 | # os-release that are not of the current date (in case it's the uploaded file itself).
|
---|
| 9 | # The code didn't work if the binary was processed independent of the log file, since the
|
---|
| 10 | # bin's filename (and hence target os) could not be determined as it was still being
|
---|
| 11 | # uploaded.
|
---|
[30407] | 12 |
|
---|
[30424] | 13 | origdir=`pwd`
|
---|
[30407] | 14 |
|
---|
[30424] | 15 | # default binary directory to where this script lives, then go there
|
---|
| 16 | # http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
|
---|
| 17 | bindir=`dirname "$0"` #dirname "$(readlink -f "$0")"
|
---|
| 18 | pushd $bindir
|
---|
| 19 |
|
---|
[30410] | 20 | # http://stackoverflow.com/questions/1401482/yyyy-mm-dd-format-date-in-shell-script
|
---|
[30407] | 21 | date=`date +%Y-%m-%d`
|
---|
| 22 |
|
---|
[30408] | 23 | # code from Puka
|
---|
| 24 | # the file uploaded is the one with the latest timestamp
|
---|
| 25 | # ls -rt lists files by time, then get the last one
|
---|
[30424] | 26 | # the file pattern looks for rke-currentdate-<OS>.out files
|
---|
[30408] | 27 | #incoming_file=$1
|
---|
[30424] | 28 | incoming_file=`ls -rt rke-*$date*.out 2>/dev/null | tail -n 1`
|
---|
| 29 | #echo "Incoming file: $incoming_file" >> out.txt
|
---|
[30408] | 30 |
|
---|
[30424] | 31 | # http://stackoverflow.com/questions/21620406/how-do-i-pause-my-shell-script-for-1-second-before-continuing
|
---|
| 32 | #sleep 2m
|
---|
| 33 |
|
---|
[30407] | 34 | # arrays
|
---|
| 35 | # make sure -linux64 comes before linux, because we'll be matching against these
|
---|
| 36 | # strings, so need the longest strings to be matched first.
|
---|
| 37 | rke_suffix=("-linux64" "-linux" "-windows" "-mac-MountainLion")
|
---|
[30410] | 38 | os_substr=("-linux64" "-linux" "-windows" "-MountainLion")
|
---|
| 39 | #bin_suffix=("-linux64" "-linux" "-windows.exe" "-MacOS-intel-MountainLion.dmg")
|
---|
[30407] | 40 |
|
---|
| 41 | # http://stackoverflow.com/questions/2172352/in-bash-how-can-i-check-if-a-string-begins-with-some-value
|
---|
| 42 | # http://stackoverflow.com/questions/229551/string-contains-in-bash
|
---|
| 43 | rke_file_pattern=
|
---|
| 44 | if [[ $incoming_file == "rke-"* ]] ; then
|
---|
| 45 | for suffix in ${rke_suffix[@]}; do
|
---|
| 46 | if [[ $incoming_file == *"$suffix"* ]]; then
|
---|
| 47 | rke_file_pattern="rke-*${suffix}.out"
|
---|
| 48 | break
|
---|
| 49 | fi
|
---|
| 50 | done
|
---|
| 51 |
|
---|
| 52 | # ONE WAY:
|
---|
| 53 | #echo "found $rke_file_pattern"
|
---|
| 54 | # -f to make it silent: will also be silent if there's nothing to rm
|
---|
| 55 | #rm -f $rke_file_pattern
|
---|
| 56 |
|
---|
| 57 | # OR:
|
---|
| 58 | # get rid of all files of the pattern that are not of the current date
|
---|
| 59 | # http://stackoverflow.com/questions/10981439/reading-filenames-into-an-array
|
---|
| 60 |
|
---|
| 61 | # setting for fileglobbing:
|
---|
| 62 | # for using wildcards to get matching files on filesystem into array
|
---|
| 63 | # "The nullglob option causes the array to be empty if there are no matched."
|
---|
| 64 | # http://stackoverflow.com/questions/10981439/reading-filenames-into-an-array
|
---|
| 65 | # See shopt command at http://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html
|
---|
| 66 | shopt -s nullglob
|
---|
| 67 |
|
---|
| 68 | files=($rke_file_pattern)
|
---|
| 69 | for file in ${files[@]}; do
|
---|
| 70 | # set nullglob earlier, so won't be here if there's no file that matched
|
---|
| 71 | if [[ $file != "rke-$date${suffix}.out" ]]; then
|
---|
| 72 | rm -rf $file
|
---|
| 73 | fi
|
---|
| 74 | done
|
---|
| 75 |
|
---|
| 76 | shopt -u nullglob
|
---|
| 77 |
|
---|
[30410] | 78 | # We now know the OS for the binary associated with the rke log
|
---|
| 79 | # that's being uploaded too. Delete all bins for this OS except
|
---|
| 80 | # any with the current date.
|
---|
| 81 |
|
---|
| 82 | bin_file_pattern=
|
---|
| 83 | # binaries start with "Expeditee-1-"
|
---|
| 84 | for os_str in ${os_substr[@]}; do
|
---|
| 85 | if [[ $incoming_file == *"$os_str"* ]]; then
|
---|
| 86 | bin_file_pattern="Expeditee-1-*$os_str*"
|
---|
[30407] | 87 | break
|
---|
| 88 | fi
|
---|
| 89 | done
|
---|
[30410] | 90 |
|
---|
[30407] | 91 | # ONE WAY:
|
---|
| 92 | #echo "found $bin_file_pattern"
|
---|
| 93 | # -f to make it silent: will also be silent if there's nothing to rm
|
---|
| 94 | #rm -rf $bin_file_pattern
|
---|
[30410] | 95 |
|
---|
[30407] | 96 | # OR:
|
---|
| 97 | # get rid of all files of the pattern that are not of the current date
|
---|
| 98 | # http://stackoverflow.com/questions/10981439/reading-filenames-into-an-array
|
---|
| 99 | shopt -s nullglob
|
---|
| 100 | files=($bin_file_pattern)
|
---|
| 101 | for file in ${files[@]}; do
|
---|
| 102 | # set nullglob earlier, so won't be here if there's no file that matched
|
---|
[30410] | 103 | if [[ $file != *"$date"* ]] || [[ $file != *"$os_str"* ]]; then
|
---|
| 104 | echo "$file"
|
---|
[30407] | 105 | rm -rf $file
|
---|
| 106 | fi
|
---|
| 107 | done
|
---|
| 108 | shopt -u nullglob
|
---|
| 109 | fi
|
---|
| 110 |
|
---|
[30410] | 111 |
|
---|
[30407] | 112 | # clean up ._Expeditee-1-YYYY-MM-DD-MacOS-intel-MountainLion.dmg temp files
|
---|
| 113 | #ls -la "._Expeditee*dmg"
|
---|
| 114 | rm -rf "._Expeditee*dmg"
|
---|
[30424] | 115 |
|
---|
| 116 | popd
|
---|