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

Last change on this file since 30407 was 30407, checked in by ak19, 6 years ago

Script for clearing old binaries and logs from the machine where they finally get uploaded to.

File size: 3.4 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 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
12incoming_file=$1
13
14# http://stackoverflow.com/questions/1401482/yyyy-mm-dd-format-date-in-shell-script
15date=`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.
20bin_suffix=("-linux64" "-linux" "-windows.exe" "-MacOS-intel-MountainLion.dmg")
21rke_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
26rke_file_pattern=
27if [[ $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
60fi
61
62# binaries start with "Expeditee-1-"
63bin_file_pattern=
64if [[ $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
90fi
91
92# clean up ._Expeditee-1-YYYY-MM-DD-MacOS-intel-MountainLion.dmg temp files
93#ls -la "._Expeditee*dmg"
94rm -rf "._Expeditee*dmg"
Note: See TracBrowser for help on using the repository browser.