forked from github/server
111 lines
2.3 KiB
Bash
Executable File
111 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
ROOT=$(pwd)
|
|
while [ ! -d $ROOT/.git ]; do
|
|
ROOT=$(dirname $ROOT)
|
|
if [ "/" = "$ROOT" ]; then
|
|
echo "could not find root, are you in the git repository?"
|
|
exit
|
|
fi
|
|
done
|
|
ERESSEA=$(dirname $ROOT)
|
|
|
|
function abort() {
|
|
echo $1
|
|
[ -z $2 ] && exit -1
|
|
exit $2 # otherwise
|
|
}
|
|
|
|
function usage() {
|
|
cat <<USAGE
|
|
Usage: $u [-hfn] [-d DIR] [-g <game>] [-r <rules>] [-s DIR]
|
|
-h print this message
|
|
-f force overwrite of existing game
|
|
-g game id
|
|
-n create new eressea.ini file
|
|
-r name of ruleset
|
|
-s server installation directory
|
|
-d override directory name
|
|
USAGE
|
|
}
|
|
|
|
game=0
|
|
force=0
|
|
src=server
|
|
edit=1
|
|
while getopts :d:g:r:s:hfn o; do
|
|
case "${o}" in
|
|
h) usage ; exit 0 ;;
|
|
s) src=${OPTARG} ;;
|
|
d) dir=${OPTARG} ;;
|
|
f) force=1 ;;
|
|
n) edit=0 ;;
|
|
g) game=${OPTARG} ;;
|
|
r) rules=${OPTARG} ;;
|
|
*) echo "not implemented ${o} ${OPTARG}" ;;
|
|
esac
|
|
done
|
|
|
|
[ $game -gt 0 ] || abort "must use a positive integer for game id"
|
|
[ -z $SOURCE ] && SOURCE=$ERESSEA/$src
|
|
[ -d $SOURCE ] || abort "invalid source directory $SOURCE"
|
|
[ -z $rules ] && rules=e$game
|
|
[ -z $dir ] && dir=game-$game
|
|
[ -z $TOOLS ] && TOOLS=$SOURCE/build-x86_64-gcc-Debug
|
|
[ -e $TOOLS ] || TOOLS=$SOURCE/bin
|
|
[ -z $INIFILE ] && INIFILE=$TOOLS/inifile
|
|
[ -e $INIFILE ] || INIFILE=$TOOLS/iniparser/inifile
|
|
|
|
[ -e $SOURCE/conf/$rules/config.xml ] || abort "cannot find conf/$rules/config.xml"
|
|
|
|
cd $ERESSEA
|
|
if [ -d $dir ] ; then
|
|
[ $force -eq 1 ] || abort "$dir directory exists. Use -f to force"
|
|
fi
|
|
mkdir -p $dir
|
|
cd $dir || abort "could not chdir to game-$game"
|
|
mkdir -p data reports
|
|
|
|
function ini_sec() {
|
|
if [ $edit -eq 1 ]; then
|
|
$INIFILE eressea.ini add $1
|
|
else
|
|
echo "[$1]" >> eressea.ini
|
|
fi
|
|
}
|
|
function ini_add() {
|
|
if [ $edit -eq 1 ]; then
|
|
$INIFILE eressea.ini add $1:$2 $3
|
|
else
|
|
echo "$2 = $3" >> eressea.ini
|
|
fi
|
|
}
|
|
function ini_start() {
|
|
if [ -e eressea.ini ]; then
|
|
if [ ! -e $INIFILE ] && [ $edit -eq 1 ]; then
|
|
abort "missing editor for eressea.ini. use -n to create new file."
|
|
fi
|
|
rm -f eressea.ini
|
|
edit=0
|
|
else
|
|
edit=0
|
|
fi
|
|
touch eressea.ini
|
|
}
|
|
|
|
ini_start
|
|
ini_sec game
|
|
ini_add game locales de,en
|
|
ini_add id $game
|
|
ini_sec lua
|
|
ini_add lua install $SOURCE
|
|
ini_add lua paths $SOURCE/scripts:$SOURCE/lunit
|
|
ini_add lua rules $rules
|
|
|
|
echo 0 > turn
|
|
touch newfactions
|
|
ln -sf $SOURCE/bin/eressea
|
|
ln -sf $SOURCE/scripts/run-turn.lua
|
|
ln -sf $SOURCE/scripts/reports.lua
|
|
ln -sf $SOURCE/scripts/config.lua
|