source: other-projects/expeditee-release-kits/process_incoming.sh@ 30410

Last change on this file since 30410 was 30410, checked in by ak19, 8 years ago

Finally got the upload of the binary to turn up.

File size: 3.9 KB
Line 
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'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.
12
13
14# http://stackoverflow.com/questions/1401482/yyyy-mm-dd-format-date-in-shell-script
15date=`date +%Y-%m-%d`
16
17# code from Puka
18# the file uploaded is the one with the latest timestamp
19# ls -rt lists files by time, then get the last one
20#incoming_file=$1
21incoming_file=`ls -rt *$date* 2>/dev/null | tail -n 1`
22#echo "Hello world. Incoming file: $incoming_file" >> out.txt
23
24# arrays
25# make sure -linux64 comes before linux, because we'll be matching against these
26# strings, so need the longest strings to be matched first.
27rke_suffix=("-linux64" "-linux" "-windows" "-mac-MountainLion")
28os_substr=("-linux64" "-linux" "-windows" "-MountainLion")
29#bin_suffix=("-linux64" "-linux" "-windows.exe" "-MacOS-intel-MountainLion.dmg")
30
31# http://stackoverflow.com/questions/2172352/in-bash-how-can-i-check-if-a-string-begins-with-some-value
32# http://stackoverflow.com/questions/229551/string-contains-in-bash
33rke_file_pattern=
34if [[ $incoming_file == "rke-"* ]] ; then
35 for suffix in ${rke_suffix[@]}; do
36 if [[ $incoming_file == *"$suffix"* ]]; then
37 rke_file_pattern="rke-*${suffix}.out"
38 break
39 fi
40 done
41
42 # ONE WAY:
43 #echo "found $rke_file_pattern"
44 # -f to make it silent: will also be silent if there's nothing to rm
45 #rm -f $rke_file_pattern
46
47 # OR:
48 # get rid of all files of the pattern that are not of the current date
49 # http://stackoverflow.com/questions/10981439/reading-filenames-into-an-array
50
51 # setting for fileglobbing:
52 # for using wildcards to get matching files on filesystem into array
53 # "The nullglob option causes the array to be empty if there are no matched."
54 # http://stackoverflow.com/questions/10981439/reading-filenames-into-an-array
55 # See shopt command at http://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html
56 shopt -s nullglob
57
58 files=($rke_file_pattern)
59 for file in ${files[@]}; do
60 # set nullglob earlier, so won't be here if there's no file that matched
61 if [[ $file != "rke-$date${suffix}.out" ]]; then
62 rm -rf $file
63 fi
64 done
65
66 shopt -u nullglob
67
68 # We now know the OS for the binary associated with the rke log
69 # that's being uploaded too. Delete all bins for this OS except
70 # any with the current date.
71
72 bin_file_pattern=
73 # binaries start with "Expeditee-1-"
74 for os_str in ${os_substr[@]}; do
75 if [[ $incoming_file == *"$os_str"* ]]; then
76 bin_file_pattern="Expeditee-1-*$os_str*"
77 break
78 fi
79 done
80
81 # ONE WAY:
82 #echo "found $bin_file_pattern"
83 # -f to make it silent: will also be silent if there's nothing to rm
84 #rm -rf $bin_file_pattern
85
86 # OR:
87 # get rid of all files of the pattern that are not of the current date
88 # http://stackoverflow.com/questions/10981439/reading-filenames-into-an-array
89 shopt -s nullglob
90 files=($bin_file_pattern)
91 for file in ${files[@]}; do
92 # set nullglob earlier, so won't be here if there's no file that matched
93 if [[ $file != *"$date"* ]] || [[ $file != *"$os_str"* ]]; then
94 echo "$file"
95 rm -rf $file
96 fi
97 done
98 shopt -u nullglob
99fi
100
101
102# clean up ._Expeditee-1-YYYY-MM-DD-MacOS-intel-MountainLion.dmg temp files
103#ls -la "._Expeditee*dmg"
104rm -rf "._Expeditee*dmg"
Note: See TracBrowser for help on using the repository browser.