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.
|
---|
5 | # When any binary or its log *.out file is being uploaded via secure shell, this script
|
---|
6 | # will be called. The invocation of this script should go into .ssh/authorizedkeys.
|
---|
7 | # Then this script will delete all other files in this folder that have the same naming
|
---|
8 | # pattern as the uploaded binary/log file, excepting any existing file with the current
|
---|
9 | # date in its name (in case this turns out to be the uploaded file itself).
|
---|
10 |
|
---|
11 |
|
---|
12 | incoming_file=$1
|
---|
13 |
|
---|
14 | # http://stackoverflow.com/questions/1401482/yyyy-mm-dd-format-date-in-shell-script
|
---|
15 | date=`date +%Y-%m-%d`
|
---|
16 |
|
---|
17 | # arrays
|
---|
18 | # make sure -linux64 comes before linux, because we'll be matching against these
|
---|
19 | # strings, so need the longest strings to be matched first.
|
---|
20 | bin_suffix=("-linux64" "-linux" "-windows.exe" "-MacOS-intel-MountainLion.dmg")
|
---|
21 | rke_suffix=("-linux64" "-linux" "-windows" "-mac-MountainLion")
|
---|
22 |
|
---|
23 |
|
---|
24 | # http://stackoverflow.com/questions/2172352/in-bash-how-can-i-check-if-a-string-begins-with-some-value
|
---|
25 | # http://stackoverflow.com/questions/229551/string-contains-in-bash
|
---|
26 | rke_file_pattern=
|
---|
27 | if [[ $incoming_file == "rke-"* ]] ; then
|
---|
28 | for suffix in ${rke_suffix[@]}; do
|
---|
29 | if [[ $incoming_file == *"$suffix"* ]]; then
|
---|
30 | rke_file_pattern="rke-*${suffix}.out"
|
---|
31 | break
|
---|
32 | fi
|
---|
33 | done
|
---|
34 |
|
---|
35 | # ONE WAY:
|
---|
36 | #echo "found $rke_file_pattern"
|
---|
37 | # -f to make it silent: will also be silent if there's nothing to rm
|
---|
38 | #rm -f $rke_file_pattern
|
---|
39 |
|
---|
40 | # OR:
|
---|
41 | # get rid of all files of the pattern that are not of the current date
|
---|
42 | # http://stackoverflow.com/questions/10981439/reading-filenames-into-an-array
|
---|
43 |
|
---|
44 | # setting for fileglobbing:
|
---|
45 | # for using wildcards to get matching files on filesystem into array
|
---|
46 | # "The nullglob option causes the array to be empty if there are no matched."
|
---|
47 | # http://stackoverflow.com/questions/10981439/reading-filenames-into-an-array
|
---|
48 | # See shopt command at http://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html
|
---|
49 | shopt -s nullglob
|
---|
50 |
|
---|
51 | files=($rke_file_pattern)
|
---|
52 | for file in ${files[@]}; do
|
---|
53 | # set nullglob earlier, so won't be here if there's no file that matched
|
---|
54 | if [[ $file != "rke-$date${suffix}.out" ]]; then
|
---|
55 | rm -rf $file
|
---|
56 | fi
|
---|
57 | done
|
---|
58 |
|
---|
59 | shopt -u nullglob
|
---|
60 | fi
|
---|
61 |
|
---|
62 | # binaries start with "Expeditee-1-"
|
---|
63 | bin_file_pattern=
|
---|
64 | if [[ $incoming_file == "Expeditee-"* ]] ; then
|
---|
65 | for suffix in ${bin_suffix[@]}; do
|
---|
66 | if [[ $incoming_file == *"$suffix" ]]; then
|
---|
67 | bin_file_pattern="Expeditee-1-*$suffix"
|
---|
68 | break
|
---|
69 | fi
|
---|
70 | done
|
---|
71 |
|
---|
72 | # ONE WAY:
|
---|
73 | #echo "found $bin_file_pattern"
|
---|
74 | # -f to make it silent: will also be silent if there's nothing to rm
|
---|
75 | #rm -rf $bin_file_pattern
|
---|
76 |
|
---|
77 | # OR:
|
---|
78 | # get rid of all files of the pattern that are not of the current date
|
---|
79 | # http://stackoverflow.com/questions/10981439/reading-filenames-into-an-array
|
---|
80 | shopt -s nullglob
|
---|
81 | files=($bin_file_pattern)
|
---|
82 | for file in ${files[@]}; do
|
---|
83 | # set nullglob earlier, so won't be here if there's no file that matched
|
---|
84 | if [[ $file != "Expeditee-1-$date$suffix" ]]; then
|
---|
85 | echo "$file"
|
---|
86 | rm -rf $file
|
---|
87 | fi
|
---|
88 | done
|
---|
89 | shopt -u nullglob
|
---|
90 | fi
|
---|
91 |
|
---|
92 | # clean up ._Expeditee-1-YYYY-MM-DD-MacOS-intel-MountainLion.dmg temp files
|
---|
93 | #ls -la "._Expeditee*dmg"
|
---|
94 | rm -rf "._Expeditee*dmg"
|
---|