#!/bin/bash
PATH=/bin:/usr/bin:/sbin:/usr/sbin
# Hier anpassen
#
DATE=$(date +%Y-%m-%d_%H-%M-%S);
LOGNAME="LIFE"
LOG="${DATE}_${LOGNAME}"
logPath=/home/steam/steamcmd/arma3/life/log
serverConfigDir=/home/steam/steamcmd/arma3/life/serverconfig
homePath=/home/steam/steamcmd/arma3/life
missionPath=/home/steam/steamcmd/arma3/life/mpmissions
lifePath=/home/steam/steamcmd/arma3/life/@life_server/addons
safeMissionPath=/home/steam/steamcmd/arma3/life/safe/mission
safeLifePath=/home/steam/steamcmd/arma3/life/safe/life
safeConfigPath=/home/steam/steamcmd/arma3/life/safe/config
uploadPath=/home/steam/steamcmd/arma3/life/upload
# networkConfig=$serverConfigDir/basic.cfg
serverConfig=$serverConfigDir/server.cfg
profileName=life
DIR=/home/steam/steamcmd/arma3/life
servermods=@marma
mods=@extDB2\;@life_server
BE=$DIR/battleye
DAEMON=arma3lifeserver
NAME=arma3lifeserver
PARAMS="-cfg=$networkConfig -config=$serverConfig -name=$profileName -servermod=$servermods -mod=$mods -bepath=$BE -world=empty -port=2302 -noSound -loadMissionToMemory -enableHT -autoinit"
DESC="ArmA 3 Lifeserver"
#
# Ab hier nichts mehr ändern
case "$1" in
start)
 echo "Starte: $DESC"
 if [ -e $DIR ];
 then
 cd $DIR
 ./$DAEMON $PARAMS
 else echo "Verzeichnis $DIR nicht gefunden!"
 fi
 ;;
startLoad)
 echo "Wechsle Missionsdatei und starte: $DESC"
 cd $missionPath
 mv Altis_Life.Altis.pbo $safeMissionPath
 cd $safeMissionPath
 mv Altis_Life.Altis.pbo ${DATE}-Altis_Life.Altis.pbo
 cd $lifePath
 mv life_server.pbo $safeLifePath
 cd $safeLifePath
 mv life_server.pbo ${DATE}-life_server.pbo
 cd $homePath
 mv serverconfig $safeConfigPath
 cd $safeConfigPath
 mv serverconfig ${DATE}-serverconfig
 cd $uploadPath
 cp Altis_Life.Altis.pbo $missionPath
 cp life_server.pbo $lifePath
 cp -r serverconfig $homePath
 if [ -e $DIR ];
 then
 cd $DIR
 ./$DAEMON $PARAMS >$logPath/${LOG}.rpt 2>&1
 else echo "Verzeichnis $DIR nicht gefunden!"
 fi
 ;;
stop)
 if [[ `pidof $NAME` > "0" ]]
 then
 echo -n "Stoppe: $DESC"
 kill `pidof $NAME |awk -F . '{print $1}'|awk '{print $1}'`
 echo " ... fertig."
 else
 echo "Kein $DESC gefunden"
 fi
 ;;
restart)
 if [[ `pidof $NAME` > "0" ]]
 then
 echo -n "Stoppe: $DESC"
 kill `pidof $NAME |awk -F . '{print $1}'|awk '{print $1}'`
 echo " ... fertig."
 else
 echo "Kein $DESC gefunden"
 fi
 echo -n "Starte: $DESC"
 cd $DIR
 ./$DAEMON $PARAMS
 echo " ... fertig."
 ;;
restartLoad)
 if [[ `pidof $NAME` > "0" ]]
 then
 echo -n "Stoppe: $DESC"
 kill `pidof $NAME |awk -F . '{print $1}'|awk '{print $1}'`
 echo " ... fertig."
 else
 echo "Kein $DESC gefunden"
 fi
 echo -n "Wechsle Missionsdatei und starte: $DESC"
 cd $missionPath
 mv Altis_Life.Altis.pbo $safeMissionPath
 cd $safeMissionPath
 mv Altis_Life.Altis.pbo ${DATE}-Altis_Life.Altis.pbo
 cd $lifePath
 mv life_server.pbo $safeLifePath
 cd $safeLifePath
 mv life_server.pbo ${DATE}-life_server.pbo
 cd $homePath
 mv serverconfig $safeConfigPath
 cd $safeConfigPath
 mv serverconfig ${DATE}-serverconfig
 cd $uploadPath
 cp Altis_Life.Altis.pbo $missionPath
 cp life_server.pbo $lifePath
 cp -r serverconfig $homePath
 cd $DIR
 ./$DAEMON $PARAMS >$logPath/${LOG}.rpt 2>&1
 echo " ... fertig."
 ;;
status)
 if [[ `pidof $NAME` > "0" ]]
 then
 echo "$DESC ist ONLINE"
 else
 echo "$DESC ist OFFLINE"
 fi
 ;;
crash)
 if [[ `pidof $NAME` > "0" ]]
 then
 echo "Server läuft"
 else
 echo "Server nicht gefunden, neustarten ..."
 cd $DIR
 ./$DAEMON $PARAMS
 fi
 ;;
*)
 echo "Benutzung: $0 {start|startLoad|stop|status|restart|restartLoad|crash}"
 exit 1
 ;;
esac
exit 0
