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

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

Fix (from Puka) for the upload destination machine to work out the incoming nightly file's name when the file is uploaded.

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