import to github
Signed-off-by: Ava Affine <ava@sunnypup.io>
This commit is contained in:
commit
8c91778fe1
7 changed files with 638 additions and 0 deletions
71
common.sh
Normal file
71
common.sh
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
#!/bin/bash
|
||||
|
||||
RED='\033[1;31m'
|
||||
GRN='\033[1;32m'
|
||||
YEL='\033[1;33m'
|
||||
BLU='\033[1;34m'
|
||||
WHT='\033[1;37m'
|
||||
MGT='\033[1;95m'
|
||||
CYA='\033[1;96m'
|
||||
END='\033[0m'
|
||||
|
||||
function section() {
|
||||
echo ""
|
||||
log "***** Section: ${MGT}$1${END} *****";
|
||||
echo ""
|
||||
}
|
||||
|
||||
function log() { >&2 printf "${WHT}#${END} $1\n"; }
|
||||
|
||||
function error() { >&2 printf "${WHT}#${END} ${RED}$1${END}\n"; }
|
||||
|
||||
# takes a function and many inputs, runs function on each input in parallel
|
||||
# inputs should be stored deliniated by newlines in $2
|
||||
# if $3 exists it will be a stub for logging filename
|
||||
function parallel_invoke_and_wait() {
|
||||
local procedure=$1
|
||||
local pids=()
|
||||
local rets=()
|
||||
|
||||
if [[ ! $1 ]]; then
|
||||
log "failed to invoke null procedure"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ ! $2 ]]; then
|
||||
log "failed to invoke procedure on 0 inputs"
|
||||
return 1
|
||||
fi
|
||||
|
||||
IFS=$'\n'
|
||||
for input in $2; do
|
||||
log "invoking procedure with input $input"
|
||||
if [[ $3 ]]; then
|
||||
$procedure $input &>${3}${input}.log &
|
||||
else
|
||||
$procedure $input &
|
||||
fi
|
||||
pids+=("$input/$!")
|
||||
done
|
||||
|
||||
cf="true"
|
||||
for pid in ${pids[*]}; do
|
||||
local p=$(basename $pid)
|
||||
local input=$(dirname $pid)
|
||||
wait $p
|
||||
local code=$?
|
||||
log "procedure with input $input returned $code"
|
||||
if [[ $3 && ! $code == 0 ]]; then # needs to catch code==2, etc
|
||||
log "tail of related logs..."
|
||||
tail ${3}${input}.log
|
||||
log "see more in ${3}${input}.log"
|
||||
cf="false"
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ $cf == "false" ]]; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue