diff --git a/.travis.yml b/.travis.yml index a6b898c6c..325d573ad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ addons: - libxml2-dev - valgrind - cppcheck + - shellcheck os: - linux notifications: diff --git a/process/Makefile b/process/Makefile new file mode 100644 index 000000000..8edfed0b8 --- /dev/null +++ b/process/Makefile @@ -0,0 +1,6 @@ +SCRIPTS=compress.sh send-bz2-report send-zip-report create-orders \ +run-turn sendreports.sh +IGNORE=sendreport.sh + +shellcheck: $(SCRIPTS) + shellcheck $(SCRIPTS) diff --git a/process/compress.sh b/process/compress.sh index 116b3d061..4c0147978 100755 --- a/process/compress.sh +++ b/process/compress.sh @@ -1,24 +1,25 @@ #!/bin/bash -if [ -z $ERESSEA ]; then +if [ -z "$ERESSEA" ]; then echo "You need to define the \$ERESSEA environment variable to run $0" exit -2 fi -GAME=$ERESSEA/game-$1 -GAME_NAME=$(grep -w name $GAME/eressea.ini | sed 's/.*=\s*//') +GAME="$ERESSEA/game-$1" +GAME_NAME=$(grep -w name "$GAME/eressea.ini" | sed 's/.*=\s*//') TURN=$2 -if [ -z $TURN ] +if [ -z "$TURN" ] then - TURN=`cat $GAME/turn` + TURN=$(cat "$GAME/turn") fi -if [ ! -d $GAME/reports ]; then +if [ ! -d "$GAME/reports" ]; then echo "cannot find reports directory in $GAME" exit -1 fi -cd $GAME/reports -$ERESSEA/server/bin/compress.py $TURN "$GAME_NAME" -cd - +cd "$GAME/reports" || exit +"$ERESSEA/server/bin/compress.py" "$TURN" "$GAME_NAME" +cd - || exit + diff --git a/process/create-orders b/process/create-orders index b0ca292f4..7016741ac 100755 --- a/process/create-orders +++ b/process/create-orders @@ -3,26 +3,25 @@ GAME=$1 TURN=$2 -if [ ! -d $ERESSEA/game-$GAME ] ; then +if [ ! -d "$ERESSEA/game-$GAME" ] ; then echo "No such game: $GAME" exit 1 fi -cd $ERESSEA/game-$GAME +cd "$ERESSEA/game-$GAME" || exit -if [ -d orders.dir.$TURN ]; then +if [ -d "orders.dir.$TURN" ]; then echo "orders.dir.$TURN already exists" else - mv orders.dir orders.dir.$TURN + mv orders.dir "orders.dir.$TURN" mkdir -p orders.dir fi -ls -1rt orders.dir.$TURN/turn-* | xargs cat > orders.$TURN +ls -1rt "orders.dir.$TURN/turn-*" | xargs cat > "orders.$TURN" lockfile -r3 -l120 orders.queue.lock if [ -e orders.queue ] ; then - mv orders.queue orders.dir.$TURN/orders.queue + mv orders.queue "orders.dir.$TURN/orders.queue" fi rm -f orders.queue.lock -fi diff --git a/process/run-turn b/process/run-turn index c0d0d6a40..9fa6a325c 100755 --- a/process/run-turn +++ b/process/run-turn @@ -1,17 +1,17 @@ #!/bin/sh -GAME=$1 -TURN=$2 +GAME="$1" +TURN="$2" -if [ ! -d $ERESSEA/game-$GAME ] ; then +if [ ! -d "$ERESSEA/game-$GAME" ] ; then echo "No such game: $GAME" exit 1 fi -cd $ERESSEA/game-$GAME +cd "$ERESSEA/game-$GAME" || exit echo "running turn $TURN, game $GAME" -$ERESSEA/server/bin/eressea -v3 -t $TURN run-turn.lua +"$ERESSEA/server/bin/eressea" -v3 -t "$TURN" run-turn.lua mkdir -p log -ln -f eressea.log log/eressea.log.$TURN +ln -f eressea.log "log/eressea.log.$TURN" diff --git a/process/send-bz2-report b/process/send-bz2-report index 2282a9f24..c9fb87840 100755 --- a/process/send-bz2-report +++ b/process/send-bz2-report @@ -1,13 +1,12 @@ #!/bin/bash -if [ -z $ERESSEA ]; then - ERESSEA=`echo $PWD |sed -e 's/\/game.*//'` +if [ -z "$ERESSEA" ]; then + ERESSEA=$(echo "$PWD" |sed -e 's/\/game.*//') echo "Assuming that ERESSEA=$ERESSEA" fi if [ ! -f reports.txt ]; then echo "need to run $0 from the report direcory" exit -2 fi -source $HOME/bin/functions.sh TEMPLATE=report-mail.txt if [ "$1" == "-Lde" ] @@ -26,4 +25,6 @@ addr=$1 subj=$2 shift 2 -cat $ERESSEA/server/etc/$TEMPLATE | mutt -F $ERESSEA/etc/muttrc -s "$subj" -a $* -- $addr +mutt -F "$ERESSEA/etc/muttrc" -s "$subj" -a "$@" -- "$addr" \ + < "$ERESSEA/server/etc/$TEMPLATE" + diff --git a/process/send-zip-report b/process/send-zip-report index 6ea2ea8e7..89f742b82 100755 --- a/process/send-zip-report +++ b/process/send-zip-report @@ -1,6 +1,7 @@ #!/bin/bash -if [ -z $ERESSEA ]; then - ERESSEA=`echo $PWD |sed -e 's/\/game.*//'` + +if [ -z "$ERESSEA" ]; then + ERESSEA=$(echo "$PWD" |sed -e 's/\/game.*//') echo "Assuming that ERESSEA=$ERESSEA" fi if [ ! -f reports.txt ]; then @@ -9,7 +10,7 @@ if [ ! -f reports.txt ]; then fi PWD=$(pwd) -GAME=$(dirname $PWD) +GAME=$(dirname "$PWD") TEMPLATE=report-mail.txt if [ "$1" == "-Lde" ] @@ -24,13 +25,13 @@ then shift fi -if [ -e $GAME/$TEMPLATE ]; then -TEMPLATE=$GAME/$TEMPLATE +if [ -e "$GAME/$TEMPLATE" ]; then +TEMPLATE="$GAME/$TEMPLATE" else -TEMPLATE=$ERESSEA/server/etc/$TEMPLATE +TEMPLATE="$ERESSEA/server/etc/$TEMPLATE" fi -if [ ! -e $TEMPLATE ]; then +if [ ! -e "$TEMPLATE" ]; then echo "no such email template: $TEMPLATE" exit -3 fi @@ -42,8 +43,7 @@ done addr=$1 subject=$2 shift 2 -mutt -F $ERESSEA/etc/muttrc -s "$subject" -a $* -- $addr < $TEMPLATE -if [ $? -ne 0 ] ; then - echo "Sending failed for email/report: $2/$3" -fi +mutt -F "$ERESSEA/etc/muttrc" -s "$subject" -a "$@" -- "$addr" \ + < "$TEMPLATE" || echo "Sending failed for email/report: $2/$3" + diff --git a/process/sendreports.sh b/process/sendreports.sh index c2bfa741c..d1adba943 100755 --- a/process/sendreports.sh +++ b/process/sendreports.sh @@ -3,30 +3,23 @@ ## ## Prepare the report -if [ -z $ERESSEA ]; then +if [ -z "$ERESSEA" ]; then echo "You have to define the \$ERESSEA environment variable to run $0" exit -2 fi -source $HOME/bin/functions.sh -if [ ! -z $1 ]; then - GAME=$ERESSEA/game-$1 +if [ ! -z "$1" ]; then + GAME="$ERESSEA/game-$1" else GAME=$ERESSEA fi -cd $GAME/reports || abort "could not chdir to reports directory" +cd "$GAME/reports" || exit for REPORT in *.sh do echo -n "Sending " - basename $REPORT .sh - bash $REPORT + basename "$REPORT" .sh + bash "$REPORT" done -cd - - -if [ -e $GAME/ages.sh ]; then - cd $GAME - ./ages.sh - cd - -fi +cd - || exit diff --git a/s/travis-build b/s/travis-build index 4c5237fdf..2da3ed7b5 100755 --- a/s/travis-build +++ b/s/travis-build @@ -26,4 +26,6 @@ cppcheck --version cppcheck --quiet --error-exitcode=1 src s/runtests -V integration_tests +cd ../process +make