root/other-projects/expeditee-release-kits/process_incoming.sh @ 31174

Revision 30424, 4.3 KB (checked in by ak19, 3 years ago)

Dr Bainbridge improved the code so that the script always gets the latest rke.out filename of today to process (and it processes both that and the associated uploaded binary).

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
13origdir=`pwd`
14
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
17bindir=`dirname "$0"` #dirname "$(readlink -f "$0")"
18pushd $bindir
19
20# http://stackoverflow.com/questions/1401482/yyyy-mm-dd-format-date-in-shell-script
21date=`date +%Y-%m-%d`
22
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
26# the file pattern looks for rke-currentdate-<OS>.out files
27#incoming_file=$1
28incoming_file=`ls -rt rke-*$date*.out 2>/dev/null | tail -n 1`
29#echo "Incoming file: $incoming_file" >> out.txt
30
31# http://stackoverflow.com/questions/21620406/how-do-i-pause-my-shell-script-for-1-second-before-continuing
32#sleep 2m
33
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.
37rke_suffix=("-linux64" "-linux" "-windows" "-mac-MountainLion")
38os_substr=("-linux64" "-linux" "-windows" "-MountainLion")
39#bin_suffix=("-linux64" "-linux" "-windows.exe" "-MacOS-intel-MountainLion.dmg")
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
43rke_file_pattern=
44if [[ $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
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*"
87        break
88    fi
89    done
90   
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
95   
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
103    if [[ $file != *"$date"* ]] || [[ $file != *"$os_str"* ]]; then
104        echo "$file"       
105        rm -rf $file
106    fi
107    done
108    shopt -u nullglob
109fi
110
111
112# clean up ._Expeditee-1-YYYY-MM-DD-MacOS-intel-MountainLion.dmg temp files
113#ls -la "._Expeditee*dmg"
114rm -rf "._Expeditee*dmg"
115
116popd
Note: See TracBrowser for help on using the browser.