Index: scripts/etc/7dtd.conf
===================================================================
--- scripts/etc/7dtd.conf	(revision 505)
+++ scripts/etc/7dtd.conf	(revision 1)
@@ -1,33 +1,15 @@
 #!/bin/sh
 
-#   Copyright 2016 Christian 'Alloc' Illy
-#
-#   Licensed under the Apache License, Version 2.0 (the "License");
-#   you may not use this file except in compliance with the License.
-#   You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-#   Unless required by applicable law or agreed to in writing, software
-#   distributed under the License is distributed on an "AS IS" BASIS,
-#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#   See the License for the specific language governing permissions and
-#   limitations under the License.
+# Root directory where steamcmd should be placed
+export STEAMCMD_ROOT=/home/sdtd/steamcmd
+export STEAM_USER=
+export STEAM_PASS=
 
+# Root directory of the engine
+export SDTD_ROOT=/home/sdtd/7dtd
+export SDTD_SERVERCONFIG=$SDTD_ROOT/../serverconfig.xml
 
-# Root of the 7dtd folders, containing e.g. the "engine", "instances" folders
-export SDTD_BASE=/home/sdtd
-
-# How many seconds should stopping wait for the instance to shutdown
-export STOP_WAIT=5
-
-# Backup options
+# Root directory for backups
 export SDTD_BACKUP_ROOT=/home/sdtd/backup
-export SDTD_BACKUP_SAVEWORLD=true
-export SDTD_BACKUP_MIN_BACKUPS_KEEP=
-export SDTD_BACKUP_MAX_BACKUPS=
-export SDTD_BACKUP_MAX_STORAGE=
-export SDTD_BACKUP_MAX_AGE=
-export SDTD_BACKUP_COMPRESS=none
 
 # User account and group to run the server
@@ -35,8 +17,59 @@
 export SDTD_GROUP=sdtd
 
+# World to load
+export SDTD_WORLD=Navezgane
+
+# Name of savegame to load
+export SDTD_SAVE=a7
+
+# Base port to use for networking
+# Note that baseport (UDP) and base+1 up to base+3 (each TCP) will be used
+export SDTD_PORT=25000
+
+# Set this to a reasonable value to get notified if the engine uses up too much RAM
+# Value in mebibytes (MiB)
+# For a server only used for 7dtd this should be ~500 MiB lower than the machines total RAM
+export MEM_NOTIFY_MAX_RAM=2500
+
+# If limit exceeded notify someone by email?
+export MEM_NOTIFY_MAIL=no
+
+# If limit exceeded notify someone by XMPP (aka Jabber)?
+export MEM_NOTIFY_XMPP=yes
+
+# XMPP user to use for sending
+export XMPP_USER=
+# XMPP server for sending
+export XMPP_SERVER=
+# XMPP account password
+export XMPP_PASSWORD=
+# Receiver of message
+export XMPP_TARGET=
+
+# Mail from field
+export MAIL_FROM=
+# Mail receiver
+export MAIL_TO=
+# Subject of mail
+export MAIL_SUBJECT=7dtd memory usage
+# SMTP server to use for sending
+export MAIL_SMTP=
+# SMTP user (not used if empty)
+export MAIL_USER=
+# SMTP password (not used if empty)
+export MAIL_PASS=
+
 # Paths to binaries. Use "which BINARYNAME" to find the path of a single binary
+export CP=/bin/cp
 export RSYNC=/usr/bin/rsync
-export XMLSTARLET=/usr/bin/xmlstarlet
-export PKILL=/usr/bin/pkill
-export SSD=/usr/local/lib/7dtd/start-stop-daemon/start-stop-daemon
-export EDITOR=/usr/bin/editor
+export DU=/usr/bin/du
+export FREE=/usr/bin/free
+export AWK=/usr/bin/awk
+export PIDOF=/bin/pidof
+export WINE=/usr/bin/wine
+
+if [ -e $SDTD_SERVERCONFIG ]; then
+	export SDTD_TELNET_ENABLED=`xmllint --xpath "string(/ServerSettings/property[@name='TelnetEnabled']/@value)" $SDTD_SERVERCONFIG`
+	export SDTD_TELNET_PORT=`xmllint --xpath "string(/ServerSettings/property[@name='TelnetPort']/@value)" $SDTD_SERVERCONFIG`
+	export SDTD_TELNET_PASSWORD=`xmllint --xpath "string(/ServerSettings/property[@name='TelnetPassword']/@value)" $SDTD_SERVERCONFIG`
+fi
Index: scripts/etc/init.d/7dtd.sh
===================================================================
--- scripts/etc/init.d/7dtd.sh	(revision 505)
+++ scripts/etc/init.d/7dtd.sh	(revision 1)
@@ -13,28 +13,68 @@
 ### END INIT INFO
 
-#   Copyright 2016 Christian 'Alloc' Illy
-#
-#   Licensed under the Apache License, Version 2.0 (the "License");
-#   you may not use this file except in compliance with the License.
-#   You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-#   Unless required by applicable law or agreed to in writing, software
-#   distributed under the License is distributed on an "AS IS" BASIS,
-#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#   See the License for the specific language governing permissions and
-#   limitations under the License.
+. /etc/7dtd.conf
 
+NAME="7DtD"
+SCREENREF="sdtd"
+BINARYPATH=$SDTD_ROOT
+USER=$SDTD_USER
+RUNTIME=$WINE
+BINARYNAME=7DaysToDie.exe
+PIDFILE="7dtd-server.pid"
+
+OPTS="-quit -batchmode -nographics -configfile=../serverconfig.xml -dedicated"
+
+cd "$BINARYPATH"
 
 case "$1" in
     start)
-    	/usr/local/bin/7dtd.sh start "!"
+        echo -n "Starting the $NAME server... "
+        if [ ! `pgrep Xvfb` ]; then
+        	su -c "/usr/bin/Xvfb :1 -screen 0 640x480x16" sdtd &
+        	sleep 3
+        fi
+	if [ -e "$BINARYNAME" ]; then
+	    if [ `pgrep $BINARYNAME` ]; then
+	        echo "Already running!"
+	    else
+	    	export DISPLAY=localhost:1.0
+                start-stop-daemon --start --pidfile $SDTD_ROOT/$PIDFILE --background --make-pidfile --chuid $USER --user $USER --chdir $BINARYPATH --exec "/usr/bin/screen" -- -D -m -S $SCREENREF $RUNTIME $BINARYPATH/$BINARYNAME $OPTS
+                sleep 1
+            fi
+        else
+            echo "Could not find binary, aborting!"
+            exit 5
+        fi
+        if [ `pgrep -F $SDTD_ROOT/$PIDFILE` ]; then
+            echo "Done!"
+        else
+            echo "Failed!"
+            rm -f $SDTD_ROOT/$PIDFILE
+        fi
     ;;
     stop)
-    	/usr/local/bin/7dtd.sh kill "!"
+    	start-stop-daemon --status --pidfile $SDTD_ROOT/$PIDFILE
+        if [ $? -eq 0 ]; then
+            echo -n "Stopping the $NAME server... "
+            if [ "$SDTD_TELNET_ENABLED" = "true" ] && [ -n "$SDTD_TELNET_PASSWORD" ]; then
+                echo "$SDTD_TELNET_PASSWORD\nshutdown" | nc -q 2 127.0.0.1 $SDTD_TELNET_PORT
+                sleep 5
+            else
+                echo "Telnet not enabled or no password set. No graceful shutdown!"
+            fi
+            start-stop-daemon --stop --pidfile $SDTD_ROOT/$PIDFILE
+            rm $SDTD_ROOT/$PIDFILE
+            echo "Done!"
+        else
+            echo "$NAME not running"
+        fi
     ;;
     status)
-    	/usr/local/bin/7dtd.sh instances
+    	start-stop-daemon --status --pidfile $SDTD_ROOT/$PIDFILE
+        if [ $? -eq 0 ]; then
+            echo "$NAME server is running"
+        else
+            echo "$NAME server not running"
+        fi
     ;;
     *)
Index: scripts/home/sdtd/.screenrc
===================================================================
--- scripts/home/sdtd/.screenrc	(revision 1)
+++ scripts/home/sdtd/.screenrc	(revision 1)
@@ -0,0 +1,3 @@
+multiuser on
+acladd root
+
Index: scripts/usr/local/bin/7dtd-backup.sh
===================================================================
--- scripts/usr/local/bin/7dtd-backup.sh	(revision 1)
+++ scripts/usr/local/bin/7dtd-backup.sh	(revision 1)
@@ -0,0 +1,23 @@
+#!/bin/bash
+. /etc/7dtd.conf
+
+DT=`date "+%Y-%m-%d_%H-%M"`
+NewBackup=$SDTD_BACKUP_ROOT/$DT
+
+# Check for backup folder existence
+if [ -e $SDTD_BACKUP_ROOT ]; then
+	# Exists, copy(link) latest backup
+	unset -v LatestBackup
+	for file in "$SDTD_BACKUP_ROOT"/*; do
+		[[ $file -nt $LatestBackup ]] && LatestBackup=$file
+	done
+	$CP -al $LatestBackup $NewBackup
+else
+	# Create new backup dir
+	mkdir $SDTD_BACKUP_ROOT
+fi
+
+$RSYNC -a --delete --numeric-ids --delete-excluded $SDTD_ROOT/Data/Worlds/./ $NewBackup
+touch $NewBackup
+
+#echo "Backup folder disk usage: `$DU -sh $SDTD_BACKUP_ROOT`"
Index: scripts/usr/local/bin/7dtd-check_mem.sh
===================================================================
--- scripts/usr/local/bin/7dtd-check_mem.sh	(revision 1)
+++ scripts/usr/local/bin/7dtd-check_mem.sh	(revision 1)
@@ -0,0 +1,36 @@
+#!/bin/bash
+. /etc/7dtd.conf
+
+if [[ "$MEM_NOTIFY_XMPP" = "no" ]]; then
+	if [[ "$MEM_NOTIFY_MAIL" = "no" ]]; then
+		exit
+	fi
+fi
+
+PID=`$PIDOF 7DaysToDie.exe`
+
+if [[ -z "$PID" ]]; then
+	exit 0
+fi
+
+USED_CUR_MB=`$FREE -m | $AWK '/buffers\/cache/{print $3;}'`
+#USED_CUR_MB=`cat /proc/$PID/status | $AWK '/VmRSS/{print int($2/1024);}'`
+TELNETPORT=$(($SDTD_PORT + 3))
+#USED_CHUNKS=`echo -e "cc" | nc -q 3 127.0.0.1 $TELNETPORT | grep -a Mem | awk '/Chunk/{print $3;}'`
+
+if [ "$USED_CUR_MB" -gt "$MEM_NOTIFY_MAX_RAM" ]
+then
+	MESSAGE="7dtd: $USED_CUR_MB MiB of memory used! Chunk memory: $USED_CHUNKS"
+	if [[ "$MEM_NOTIFY_XMPP" = "yes" ]]; then
+		echo $MESSAGE | sendxmpp -u $XMPP_USER -p $XMPP_PASSWORD -j $XMPP_SERVER -t $XMPP_TARGET
+	fi
+	if [[ "$MEM_NOTIFY_MAIL" = "yes" ]]; then
+		if [[ -n "$MAIL_USER" ]]; then
+			userparam="-xu $MAIL_USER"
+		fi
+		if [[ -n "$MAIL_PASS" ]]; then
+			passparam="-xp $MAIL_PASS"
+		fi
+		sendEmail -q -f $MAIL_FROM -t $MAIL_TO -u "$MAIL_SUBJECT" -m "$MESSAGE" -s $MAIL_SMTP $userparam $passparam
+	fi
+fi
Index: scripts/usr/local/bin/7dtd-kill.sh
===================================================================
--- scripts/usr/local/bin/7dtd-kill.sh	(revision 1)
+++ scripts/usr/local/bin/7dtd-kill.sh	(revision 1)
@@ -0,0 +1,2 @@
+#!/bin/bash
+/etc/init.d/7dtd.sh stop
Index: scripts/usr/local/bin/7dtd-start.sh
===================================================================
--- scripts/usr/local/bin/7dtd-start.sh	(revision 1)
+++ scripts/usr/local/bin/7dtd-start.sh	(revision 1)
@@ -0,0 +1,2 @@
+#!/bin/bash
+/etc/init.d/7dtd.sh start
Index: scripts/usr/local/bin/7dtd-update.sh
===================================================================
--- scripts/usr/local/bin/7dtd-update.sh	(revision 1)
+++ scripts/usr/local/bin/7dtd-update.sh	(revision 1)
@@ -0,0 +1,21 @@
+#!/bin/bash
+. /etc/7dtd.conf
+
+if [ ! -e $STEAMCMD_ROOT ]; then
+	mkdir $STEAMCMD_ROOT
+	cd /tmp
+	wget http://media.steampowered.com/installer/steamcmd_linux.tar.gz
+	tar -xvzf steamcmd_linux.tar.gz -C $STEAMCMD_ROOT
+	cd $STEAMCMD_ROOT
+	./steamcmd.sh +quit
+fi
+
+cd $STEAMCMD_ROOT
+
+./steamcmd.sh +@sSteamCmdForcePlatformType windows +login $STEAM_USER $STEAM_PASS +force_install_dir $SDTD_ROOT +app_update 251570 validate +quit
+chown $SDTD_USER.$SDTD_GROUP -R $SDTD_ROOT
+
+cp $SDTD_ROOT/Install/32bit/7DaysToDie.exe $SDTD_ROOT/
+cp $SDTD_ROOT/Install/32bit/mono.dll $SDTD_ROOT/7DaysToDie_Data/Mono/
+cp $SDTD_ROOT/Install/32bit/SteamworksManaged.dll $SDTD_ROOT/7DaysToDie_Data/Managed/
+cp $SDTD_ROOT/../msvcr100.dll $SDTD_ROOT/
Index: scripts/usr/local/bin/7dtd.sh
===================================================================
--- scripts/usr/local/bin/7dtd.sh	(revision 505)
+++ 	(revision )
@@ -1,50 +1,0 @@
-#!/bin/bash
-
-#   Copyright 2016 Christian 'Alloc' Illy
-#
-#   Licensed under the Apache License, Version 2.0 (the "License");
-#   you may not use this file except in compliance with the License.
-#   You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-#   Unless required by applicable law or agreed to in writing, software
-#   distributed under the License is distributed on an "AS IS" BASIS,
-#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#   See the License for the specific language governing permissions and
-#   limitations under the License.
-
-
-. /usr/local/lib/7dtd/common.sh
-checkRootLoadConf
-
-if [ -z $1 ]; then
-	genericHelp
-else
-	CMD=$(camelcasePrep "$1")
-	shift
-	
-	if [ "$CMD" = "Help" ]; then
-		if [ -z $1 ]; then
-			genericHelp
-		else
-			HELPCMD=$(camelcasePrep "$1")
-			if [ "$(type -t sdtdCommand${HELPCMD}Help)" = "function" ]; then
-				sdtdCommand${HELPCMD}Help
-			else
-				echo "Command \"$1\" does not exist!"
-				exit 1
-			fi
-		fi
-	else
-		if [ "$(type -t sdtdCommand${CMD})" = "function" ]; then
-			sdtdCommand${CMD} "$@"
-		else
-			echo "Command \"$CMD\" does not exist!"
-			exit 1
-		fi
-	fi
-fi
-
-exit 0
-
