mirror of
https://github.com/eliasstepanik/ark-ac-server-tools.git
synced 2026-01-12 10:58:28 +00:00
270 lines
5.9 KiB
Bash
Executable File
270 lines
5.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# ARK: survival evolved manager
|
|
#
|
|
# Original author: LeXaT
|
|
# Maintainer: FezVrasta, Sispheor
|
|
|
|
# Check the user is not currently running this script as root
|
|
if [ "$(id -u)" == "0" ]; then
|
|
echo "This script must NOT be run as root" 1>&2
|
|
exit 1
|
|
fi
|
|
|
|
#---------------------
|
|
# Variables
|
|
#---------------------
|
|
|
|
# Global variables
|
|
source /etc/arkmanager/arkmanager.cfg
|
|
|
|
# Local variables
|
|
info=""
|
|
thejob=""
|
|
instver=""
|
|
bnumber=""
|
|
timestamp=$( date +%T )
|
|
GREEN="\\033[1;32m"
|
|
RED="\\033[1;31m"
|
|
NORMAL="\\033[0;39m"
|
|
|
|
#---------------------
|
|
# functions
|
|
#---------------------
|
|
function testfunction(){
|
|
if [ -z $servermail ]; then
|
|
echo "mail ok"
|
|
fi
|
|
|
|
}
|
|
|
|
#
|
|
# Check if a new version is available but not apply it
|
|
#
|
|
function checkForUpdate(){
|
|
if isUpdateNeeded; then
|
|
echo "Current version:" $instver
|
|
echo "Available version:" $bnumber
|
|
echo "Your server needs to be restarted in order to receive the latest update."
|
|
echo "Run \"arkmanager update\" to do so"
|
|
else
|
|
echo "No update available"
|
|
fi
|
|
}
|
|
|
|
#
|
|
# Set the new current version in a file
|
|
#
|
|
function setCurrentVersion(){
|
|
cd $arkserverroot
|
|
echo $bnumber > arkversion
|
|
}
|
|
|
|
#
|
|
# Check if the server need to be updated
|
|
# Return 0 if update is needed, else return 1
|
|
#
|
|
function isUpdateNeeded(){
|
|
getCurrentVersion
|
|
getAvailableVersion
|
|
if [ "$bnumber" -eq "$instver" ]; then
|
|
return 1 # no update needed
|
|
else
|
|
return 0 # update needed
|
|
fi
|
|
|
|
}
|
|
|
|
#
|
|
# Return the current version number
|
|
#
|
|
function getCurrentVersion(){
|
|
cd $arkserverroot
|
|
touch arkversion # If the file doesn't exist
|
|
instver=`cat "arkversion"`
|
|
return $instver
|
|
|
|
}
|
|
|
|
#
|
|
# Get the current available server version on steamdb
|
|
#
|
|
function getAvailableVersion(){
|
|
bnumber=`$steamcmdroot/$steamcmdexec +login anonymous +app_info_print "$appid" +quit | grep -EA 5 "^\s+\"public\"$" | grep -E "^\s+\"buildid\"\s+" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -f3 | sed 's/^ //' | cut -c9-14`
|
|
return $bnumber
|
|
}
|
|
|
|
#
|
|
# Check id the server process is alive
|
|
#
|
|
function isTheServerRunning(){
|
|
SERVICE="ShooterGameServer"
|
|
ps aux | grep -v grep | grep $SERVICE > /dev/null
|
|
result=$?
|
|
return $result
|
|
}
|
|
|
|
#
|
|
# Check if the server is up and visible in steam server list
|
|
# If the server is listenning on his port return 0, else return 1
|
|
#
|
|
function isTheServerUp(){
|
|
PORT="7779"
|
|
lsof -i |grep $PORT > /dev/null
|
|
result=$?
|
|
return $result
|
|
}
|
|
|
|
|
|
#
|
|
# start function
|
|
#
|
|
doStart() {
|
|
if isTheServerRunning; then
|
|
echo "The server is already running"
|
|
else
|
|
arkserveropts="TheIsland?SessionName=$sessioname?QueryPort=$arkqueryport?Port=$arkserverport?ServerPassword=$arkserverpass?ServerAdminPassword=$arkserverapass?listen"
|
|
thejob="$arkserverroot/$arkserverexec $arkserveropts"
|
|
screen -dmS "$servicename" $thejob
|
|
echo "$timestamp: start" >> "$logdir/arkserver.log"
|
|
tail -n 1 "$logdir/arkserver.log"
|
|
fi
|
|
}
|
|
|
|
#
|
|
# stop the ARK server
|
|
#
|
|
doStop() {
|
|
if isTheServerRunning; then
|
|
screen -X -S "$servicename" -X stuff "^C"
|
|
sleep 30
|
|
echo "$timestamp: stop" >> "$logdir/arkserver.log"
|
|
tail -n 1 "$logdir/arkserver.log"
|
|
else
|
|
echo "The server is already stopped"
|
|
fi
|
|
}
|
|
|
|
#
|
|
# install of ARK server
|
|
#
|
|
doInstall() {
|
|
if [ ! -d "$arkserverroot" ]; then
|
|
mkdir $arkserverroot
|
|
fi
|
|
cd $steamcmdroot
|
|
# install the server
|
|
./$steamcmdexec +login anonymous +force_install_dir "$arkserverroot" +app_update $appid validate +quit
|
|
# the current version should be the last version. We set our version
|
|
getAvailableVersion
|
|
setCurrentVersion
|
|
}
|
|
|
|
#
|
|
# Stop the server, update it and then start it back.
|
|
#
|
|
doUpdate() {
|
|
cd $arkserverroot
|
|
|
|
if isUpdateNeeded; then
|
|
# check if the server was alive before the update so we can launch it back after the update
|
|
serverWasAlive=0
|
|
if isTheServerRunning ;then
|
|
serverWasAlive=1
|
|
fi
|
|
doStop
|
|
cd $steamcmdroot
|
|
./$steamcmdexec +login anonymous +force_install_dir "$arkserverroot" +app_update $appid +quit
|
|
cd $logdir
|
|
echo "$bnumber" > "$arkserverroot/arkversion"
|
|
cd $steamcmdroot
|
|
echo "$timestamp: update to $bnumber complete" >> "$logdir/update.log"
|
|
tail -n 1 "$logdir/arkserver.log"
|
|
|
|
# we restart the server only if it was started before the update
|
|
if [ $serverWasAlive -eq 1 ]; then
|
|
doStart
|
|
fi
|
|
# send mail to admin
|
|
#if [ -z $servermail ]; then
|
|
# mail -a $logdir/update.log -s "Update-Log" $servermail < /dev/null
|
|
#fi
|
|
else
|
|
echo "No update available"
|
|
echo "$timestamp: No update needed." >> "$logdir/update.log"
|
|
tail -n 1 "$logdir/update.log"
|
|
fi;
|
|
}
|
|
|
|
#
|
|
# Broadcast message to server
|
|
#
|
|
doInfo() {
|
|
if [ ! -z $1 ]; then
|
|
info=$1
|
|
fi
|
|
screen -S "$servicename" -p 0 -X stuff "broadcast $info $(printf \\r)"
|
|
}
|
|
|
|
#
|
|
# Print the status of the server (running? online? version?)
|
|
#
|
|
printStatus(){
|
|
if isTheServerRunning ;then
|
|
echo -e "$NORMAL" "Server running:" "$GREEN" "Yes"
|
|
else
|
|
echo -e "$NORMAL" "Server running:" "$RED" "No"
|
|
fi
|
|
|
|
if isTheServerUp ;then
|
|
echo -e "$NORMAL" "Server online:" "$GREEN" " Yes"
|
|
else
|
|
echo -e "$NORMAL" "Server online:" "$RED" " No"
|
|
fi
|
|
getCurrentVersion
|
|
echo -e "$NORMAL" "Server version:" "$GREEN" $instver
|
|
|
|
}
|
|
|
|
#---------------------
|
|
# Main program
|
|
#---------------------
|
|
case "$1" in
|
|
start)
|
|
doStart
|
|
;;
|
|
stop)
|
|
doStop
|
|
;;
|
|
restart)
|
|
doStop
|
|
echo "$timestamp: stop" >> "$logdir/arkserver.log"
|
|
tail -n 1 "$logdir/arkserver.log"
|
|
sleep 10
|
|
doStart
|
|
echo "$timestamp: start" >> "$logdir/arkserver.log"
|
|
tail -n 1 "$logdir/arkserver.log"
|
|
echo "$timestamp: restart" >> "$logdir/arkserver.log"
|
|
tail -n 1 "$logdir/arkserver.log"
|
|
;;
|
|
install)
|
|
doInstall
|
|
;;
|
|
update)
|
|
doUpdate
|
|
#testfunction
|
|
;;
|
|
checkupdate)
|
|
checkForUpdate
|
|
;;
|
|
broadcast)
|
|
doInfo $2
|
|
;;
|
|
status)
|
|
printStatus
|
|
;;
|
|
*)
|
|
echo "use arkmanager <start|stop|restart|install|update|broadcast|status>"
|
|
;;
|
|
esac
|