2014-08-11 12:02:16 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2014-08-11 13:41:37 +02:00
|
|
|
function usage() {
|
|
|
|
cat <<HEREDOC
|
|
|
|
usage: $0 [-t <turn>] [-g <game>] [-f <file>] command [args]
|
|
|
|
commands:
|
|
|
|
build -- pull and rebuild the code
|
|
|
|
version -- print the current build number
|
|
|
|
setup -- create base directory and config files
|
|
|
|
run -- run a turn
|
|
|
|
send [id ...] -- send reports to one or more factions, or to all ids in <file>
|
|
|
|
HEREDOC
|
|
|
|
exit 1
|
2014-08-11 12:02:16 +02:00
|
|
|
}
|
|
|
|
|
2014-08-11 13:41:37 +02:00
|
|
|
function abort() {
|
|
|
|
echo $1
|
|
|
|
[ -z $2 ] && exit -1
|
|
|
|
exit $2 # otherwise
|
2014-08-11 12:02:16 +02:00
|
|
|
}
|
|
|
|
|
2014-08-11 13:41:37 +02:00
|
|
|
function build() {
|
|
|
|
assert_dir $SOURCE
|
|
|
|
cd $SOURCE
|
2016-10-16 11:58:42 +02:00
|
|
|
rm -rf crypto tolua
|
2015-02-01 08:21:07 +01:00
|
|
|
git fetch || abort "failed to update source. do you have local changes?"
|
2014-12-21 13:41:21 +01:00
|
|
|
[ -z $1 ] || git checkout $1
|
2017-02-26 13:12:47 +01:00
|
|
|
git pull -q
|
2015-02-01 08:21:07 +01:00
|
|
|
git submodule update
|
2017-02-26 13:10:23 +01:00
|
|
|
s/build > /dev/null || abort "build failed."
|
2014-08-11 13:41:37 +02:00
|
|
|
}
|
2014-08-11 12:02:16 +02:00
|
|
|
|
2014-08-11 13:41:37 +02:00
|
|
|
function assert_file() {
|
|
|
|
[ -e $1 ] || abort "missing file: $1"
|
|
|
|
}
|
2014-08-11 12:02:16 +02:00
|
|
|
|
2014-08-11 13:41:37 +02:00
|
|
|
function assert_files() {
|
|
|
|
while [ ! -z $1 ] ; do
|
|
|
|
assert_file $1
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
}
|
2014-08-11 12:02:16 +02:00
|
|
|
|
2014-08-11 13:41:37 +02:00
|
|
|
function assert_dir() {
|
|
|
|
[ -d $1 ] || abort "missing directory: $1"
|
|
|
|
}
|
2014-08-11 12:02:16 +02:00
|
|
|
|
2014-08-11 13:41:37 +02:00
|
|
|
function setup() {
|
|
|
|
assert_dir $SOURCE
|
|
|
|
assert_dir $LIVE
|
2014-08-11 12:02:16 +02:00
|
|
|
mkdir -p $TESTROOT
|
2014-08-11 13:41:37 +02:00
|
|
|
assert_dir $TESTROOT
|
2014-08-11 12:02:16 +02:00
|
|
|
cd $TESTROOT
|
|
|
|
|
|
|
|
cat >| eressea.ini <<HEREDOC
|
|
|
|
[lua]
|
|
|
|
dbname = preview.db
|
|
|
|
install = $SOURCE
|
|
|
|
paths = $SOURCE/lunit:$SOURCE/git/scripts
|
2014-08-11 13:41:37 +02:00
|
|
|
rules = e$game
|
2014-08-11 12:02:16 +02:00
|
|
|
HEREDOC
|
2014-08-11 13:41:37 +02:00
|
|
|
}
|
2014-08-11 12:02:16 +02:00
|
|
|
|
2014-08-11 13:41:37 +02:00
|
|
|
function run() {
|
|
|
|
echo "testing turn $turn of game $game"
|
|
|
|
assert_dir $TESTROOT
|
|
|
|
cd $TESTROOT
|
2014-12-14 07:01:22 +01:00
|
|
|
[ ! -e execute.lock ] || abort "lockfile prevents running game $game"
|
2014-08-11 12:02:16 +02:00
|
|
|
[ -d data ] || mkdir data
|
2014-08-11 13:41:37 +02:00
|
|
|
assert_dir data
|
|
|
|
assert_files $LIVE/orders.$turn $LIVE/data/$turn.dat
|
2014-08-11 12:02:16 +02:00
|
|
|
cp $LIVE/eressea.db preview.db
|
2014-08-11 13:41:37 +02:00
|
|
|
ln -f $LIVE/orders.$turn
|
|
|
|
ln -f $LIVE/data/$turn.dat data/
|
2014-08-11 12:02:16 +02:00
|
|
|
rm -rf reports
|
|
|
|
mkdir -p reports
|
|
|
|
|
2016-01-17 16:10:29 +01:00
|
|
|
SUPP="$SOURCE/share/debian-7_8.supp"
|
2015-07-19 20:05:38 +02:00
|
|
|
SERVER="$SOURCE/Debug/eressea/eressea"
|
2014-12-12 11:13:25 +01:00
|
|
|
VALGRIND=$(which valgrind)
|
|
|
|
if [ ! -z $VALGRIND ]; then
|
2017-02-26 13:12:47 +01:00
|
|
|
SERVER="$VALGRIND --quiet --suppressions=$SUPP --error-exitcode=1 --leak-check=no $SERVER"
|
2014-12-12 11:13:25 +01:00
|
|
|
fi
|
2017-02-05 14:48:43 +01:00
|
|
|
$SERVER -v$verbose -t$turn $SOURCE/scripts/run-turn.lua
|
2014-08-11 13:41:37 +02:00
|
|
|
let turn=$turn+1
|
|
|
|
[ -e data/$turn.dat ] || abort "no data file created"
|
|
|
|
}
|
|
|
|
|
|
|
|
function send() {
|
|
|
|
zip="$turn-$1.zip"
|
2014-08-16 18:23:44 +02:00
|
|
|
zip -q -u $zip $turn-$1.?r
|
2014-08-11 13:41:37 +02:00
|
|
|
email=$(grep "faction=$1:" reports.txt | cut -d: -f2 | sed 's/email=//')
|
2014-08-21 19:50:03 +02:00
|
|
|
echo "sending reports to $1 / $email"
|
2014-09-02 09:26:59 +02:00
|
|
|
info=/dev/null
|
|
|
|
[ -e ../email.txt ] && info=../email.txt
|
|
|
|
cat $info | mutt -F $ERESSEA/etc/muttrc -s "Testauswertung Spiel $game Partei $1" -a $zip -- $email
|
2014-08-11 13:41:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
game=0
|
|
|
|
turn=0
|
|
|
|
verbose=1
|
|
|
|
factions="testers.txt"
|
|
|
|
while getopts :g:t:f:v: o; do
|
|
|
|
case "${o}" in
|
|
|
|
f)
|
|
|
|
factions=${OPTARG}
|
|
|
|
;;
|
|
|
|
v)
|
|
|
|
verbose=${OPTARG}
|
|
|
|
;;
|
|
|
|
g)
|
|
|
|
game=${OPTARG}
|
|
|
|
;;
|
|
|
|
t)
|
|
|
|
turn=${OPTARG}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
|
2014-09-21 16:55:28 +02:00
|
|
|
[ -z $ERESSEA ] && ERESSEA=$HOME/eressea
|
|
|
|
[ -d $ERESSEA ] || abort "invalid or missing env variable ERESSEA ($ERESSEA)"
|
2014-08-11 13:41:37 +02:00
|
|
|
[ -z $1 ] && usage
|
|
|
|
[ -z $SOURCE ] && SOURCE=$ERESSEA/git
|
|
|
|
[ -d $SOURCE ] || abort "missing source directory: $SOURCE"
|
|
|
|
[ -d LIVE ] || LIVE=$ERESSEA/game-$game
|
|
|
|
[ -d TESTROOT ] || TESTROOT=$LIVE/test
|
|
|
|
|
|
|
|
while [ ! -z $1 ]; do
|
|
|
|
case "$1" in
|
|
|
|
"build")
|
2014-08-22 07:44:52 +02:00
|
|
|
shift
|
|
|
|
build $*
|
2014-08-11 13:41:37 +02:00
|
|
|
;;
|
|
|
|
"setup")
|
|
|
|
setup
|
|
|
|
;;
|
|
|
|
"run")
|
|
|
|
if [ $turn -eq 0 ]; then
|
2015-06-17 07:50:35 +02:00
|
|
|
[ -f $LIVE/turn ] || abort "missing turn file in $LIVE, and no turn specified"
|
2014-08-11 13:41:37 +02:00
|
|
|
let turn=$(cat $LIVE/turn)-1
|
|
|
|
fi
|
|
|
|
run
|
|
|
|
;;
|
|
|
|
"send")
|
|
|
|
shift
|
2014-08-16 18:23:44 +02:00
|
|
|
sent=0
|
|
|
|
cd $TESTROOT/reports
|
2014-08-16 18:57:06 +02:00
|
|
|
if [ $turn -eq 0 ]; then
|
|
|
|
[ -f $TESTROOT/turn ] || abort "missing turn file, and no turn specified"
|
|
|
|
let turn=$(cat $TESTROOT/turn)
|
|
|
|
fi
|
2014-12-14 06:57:45 +01:00
|
|
|
[ -f reports.txt ] || abort "missing reports.txt for game $game"
|
2014-08-11 13:41:37 +02:00
|
|
|
for faction in $* ; do
|
|
|
|
send $faction
|
2014-08-16 18:23:44 +02:00
|
|
|
sent=1
|
2014-08-11 13:41:37 +02:00
|
|
|
done
|
2014-08-16 18:23:44 +02:00
|
|
|
if [ $sent -eq 0 ]; then
|
2014-08-21 19:50:03 +02:00
|
|
|
if [ -e ../$factions ]; then
|
2017-02-26 13:08:50 +01:00
|
|
|
for faction in $(grep -v -E '^#' ../$factions) ; do
|
2014-08-16 18:23:44 +02:00
|
|
|
send $faction
|
|
|
|
done
|
|
|
|
fi
|
2014-08-11 13:41:37 +02:00
|
|
|
fi
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|