mirror of
https://ceregatti.org/git/daniel/dayzdockerserver.git
synced 2025-05-06 22:31:18 +00:00

Logging into to Steam, accounting for Steam Guard. These credentials persist throughout the lifetime of the docker volume storing the data. Adding/removing/managing workshop items. The goal is to also manage the "=mod=" parameter. Listing the auto-generated RCON password. Backing up. Further refine the original dayzserver script. In docker, a lot of the other stuff wasn't necessary so a lot is just being removed. Install steamcmd into the container in Dockerfile and adjust paths. Vastly updated docs!
192 lines
6.3 KiB
Bash
Executable file
192 lines
6.3 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
appid=1042420
|
|
dayz_id=221100
|
|
|
|
default="\e[0m"
|
|
red="\e[31m"
|
|
green="\e[32m"
|
|
yellow="\e[33m"
|
|
lightyellow="\e[93m"
|
|
blue="\e[34m"
|
|
lightblue="\e[94m"
|
|
magenta="\e[35m"
|
|
cyan="\e[36m"
|
|
|
|
STEAMCMD=/steamcmd/steamcmd.sh
|
|
|
|
fn_loadconfig_dayz(){
|
|
source /files/default.cfg
|
|
# Handle adding the server cfg file
|
|
if [ ! -f ${HOME}/serverfiles/serverDZ.cfg ]
|
|
then
|
|
echo "Creating initial serverDZ.cfg"
|
|
cp /files/serverDZ.cfg "${HOME}/serverfiles/serverDZ.cfg"
|
|
elif diff -q /files/default.cfg "${HOME}/serverfiles/serverDZ.cfg" > /dev/null
|
|
then
|
|
echo "Updating serverDZ.cfg"
|
|
cp /files/serverDZ.cfg "${HOME}/serverfiles/serverDZ.cfg"
|
|
fi
|
|
}
|
|
|
|
fn_create_beconfig(){
|
|
if [ -d "${HOME}/serverfiles/battleye" ] && [ ! -f "${HOME}/serverfiles/battleye/beserver_x64.cfg" ]
|
|
then
|
|
echo -n "Creating Battle Eye RCON file "
|
|
fn_do_rcon
|
|
elif diff -q /files/beserver_x64.cfg "${HOME}/serverfiles/battleye/beserver_x64.cfg" > /dev/null
|
|
then
|
|
echo -n "Updating Battle Eye RCON file "
|
|
fn_do_rcon
|
|
fi
|
|
}
|
|
|
|
fn_do_rcon(){
|
|
cp /files/beserver_x64.cfg "${HOME}/serverfiles/battleye/beserver_x64.cfg"
|
|
# Set a random RCON password, unless one's set in the environment
|
|
if grep -v RCON_PASSWORD /files/beserver_x64.cfg
|
|
then
|
|
RCON_PASSWORD=$(< /dev/urandom tr -dc 'A-Za-z0-9' | head -c10)
|
|
echo -e "using random RCON password ${yellow}${RCON_PASSWORD}"
|
|
sed -i "${HOME}/serverfiles/battleye/beserver_x64.cfg" -e "s/RCON_PASSWORD/${RCON_PASSWORD}/"
|
|
else
|
|
echo "using the RCON_PASSWORD already set in files/beserver_x64.cfg."
|
|
fi
|
|
}
|
|
|
|
fn_start_dayz(){
|
|
fn_loadconfig_dayz
|
|
fn_workshop_mods
|
|
printf "[ ${green}DayZ${default} ] Starting server...\n"
|
|
cd ${HOME}/serverfiles
|
|
./DayZServer $dayzparameter "$workshop" || (
|
|
echo
|
|
echo -e "${yellow}========================================== error.log =========================================="
|
|
find /home/user -name error.log -exec cat {} \; -exec rm -f {} \;
|
|
echo
|
|
echo -e "${yellow}========================================== script*.log ========================================"
|
|
find /home/user -name "script*.log" -exec cat {} \; -exec rm -f {} \;
|
|
echo
|
|
echo -e "${yellow}========================================== *.RPT =============================================="
|
|
find /home/user -name "*.RPT" -exec cat {} \; -exec rm -f {} \;
|
|
echo
|
|
echo -e "${yellow}========================================== End crash log ======================================"
|
|
)
|
|
}
|
|
|
|
fn_steamlogin_dayz(){
|
|
source /files/steamlogin
|
|
}
|
|
|
|
fn_install_dayz(){
|
|
if [ ! -f "${HOME}/serverfiles/DayZServer" ]; then
|
|
mkdir ${HOME}/serverfiles &> /dev/null
|
|
mkdir ${HOME}/serverprofile &> /dev/null
|
|
printf "[ ${yellow}DayZ${default} ] Downloading DayZ Server-Files!\n"
|
|
fn_steamlogin_dayz
|
|
fn_runvalidate_dayz
|
|
else
|
|
printf "[ ${lightblue}DayZ${default} ] The Server is already installed.\n"
|
|
fi
|
|
}
|
|
|
|
fn_runupdate_dayz(){
|
|
fn_loadconfig_dayz
|
|
${STEAMCMD} +force_install_dir ${HOME}/serverfiles +login "${steamlogin}" +app_update "${appid}" +quit
|
|
}
|
|
|
|
fn_update_dayz(){
|
|
fn_steamlogin_dayz
|
|
fn_loadconfig_dayz
|
|
appmanifestfile=${HOME}/serverfiles/steamapps/appmanifest_"${appid}".acf
|
|
printf "[ ... ] Checking for update: SteamCMD"
|
|
# gets currentbuild
|
|
currentbuild=$(grep buildid "${appmanifestfile}" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d \ -f3)
|
|
# Removes appinfo.vdf as a fix for not always getting up to date version info from SteamCMD
|
|
if [ -f "${HOME}/Steam/appcache/appinfo.vdf" ]; then
|
|
rm -f "${HOME}/Steam/appcache/appinfo.vdf"
|
|
sleep 1
|
|
fi
|
|
# check for new build
|
|
availablebuild=$(${STEAMCMD} +login "${steamlogin}" +app_info_update 1 +app_info_print "${appid}" +app_info_print "${appid}" +quit | sed -n '/branch/,$p' | grep -m 1 buildid | tr -cd '[:digit:]')
|
|
if [ -z "${availablebuild}" ]; then
|
|
printf "\r[ ${red}FAIL${default} ] Checking for update: SteamCMD\n"
|
|
printf "\r[ ${red}FAIL${default} ] Checking for update: SteamCMD: Not returning version info\n"
|
|
exit
|
|
else
|
|
printf "\r[ ${green}OK${default} ] Checking for update: SteamCMD"
|
|
fi
|
|
# compare builds
|
|
if [ "${currentbuild}" != "${availablebuild}" ]; then
|
|
printf "\r[ ${green}OK${default} ] Checking for update: SteamCMD: Update available\n"
|
|
printf "Update available:\n"
|
|
printf "\tCurrent build: ${red}${currentbuild}${default}\n"
|
|
printf "\tAvailable build: ${green}${availablebuild}${default}\n"
|
|
printf "\thttps://steamdb.info/app/${appid}/\n"
|
|
printf "\nApplying update"
|
|
# run update
|
|
fn_runupdate_dayz
|
|
fn_workshop_mods
|
|
else
|
|
printf "\r[ ${green}OK${default} ] Checking for update: SteamCMD: No update available\n"
|
|
printf "\nNo update available:\n"
|
|
printf "\tCurrent version: ${green}${currentbuild}${default}\n"
|
|
printf "\tAvailable version: ${green}${availablebuild}${default}\n"
|
|
printf "\thttps://steamdb.info/app/${appid}/\n\n"
|
|
fi
|
|
}
|
|
|
|
fn_runvalidate_dayz(){
|
|
fn_loadconfig_dayz
|
|
${STEAMCMD} +force_install_dir ${HOME}/serverfiles +login "${steamlogin}" +app_update "${appid}" validate +quit
|
|
}
|
|
|
|
fn_workshop_mods(){
|
|
fn_steamlogin_dayz
|
|
fn_loadconfig_dayz
|
|
declare -a workshopID
|
|
workshopfolder="${HOME}/serverfiles/steamapps/workshop/content/221100"
|
|
workshoplist=""
|
|
if [ ! -f /files/workshop.cfg ]
|
|
then
|
|
echo "No workshop mods..."
|
|
return
|
|
else
|
|
echo "Syncing workshop mods..."
|
|
fi
|
|
mapfile -t -s 1 workshopID < /files/workshop.cfg
|
|
# gather mods
|
|
for i in "${workshopID[@]}"
|
|
do
|
|
if [[ $i =~ ^[0-9] ]] && [ $(expr length $i) -gt 7 ]; then
|
|
workshoplist+=" +workshop_download_item "${dayz_id}" "$i""
|
|
fi
|
|
done
|
|
# download mods
|
|
${STEAMCMD} +force_install_dir ${HOME}/serverfiles +login "${steamlogin}" ${workshoplist} +quit
|
|
# link mods
|
|
for i in "${workshopID[@]}"
|
|
do
|
|
if [[ $i =~ ^[0-9] ]] && [ $(expr length $i) -gt 7 ] && [ -d "${workshopfolder}/$i" ]; then
|
|
modname=$(cut -d '"' -f 2 <<< $(grep name ${workshopfolder}/$i/meta.cpp))
|
|
if [ ! -d "${HOME}/serverfiles/@${modname}" ]; then
|
|
ln -s ${workshopfolder}/$i "${HOME}/serverfiles/@${modname}" &> /dev/null
|
|
fi
|
|
find "${workshopfolder}/$i" -depth -exec rename -f 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \;
|
|
fi
|
|
done
|
|
if ls ${HOME}/serverfiles/@* 1> /dev/null 2>&1; then
|
|
printf "\n[ ${green}DayZ${default} ] Copy Key Files from Mods...\n"
|
|
cp -vu ${HOME}/serverfiles/@*/keys/* "${HOME}/serverfiles/keys/" > /dev/null 2>&1
|
|
fi
|
|
}
|
|
|
|
# Make sure we don't start collecting core files
|
|
ulimit -c 0
|
|
|
|
if [[ ${1} = "start" ]]
|
|
then
|
|
fn_install_dayz
|
|
fn_create_beconfig
|
|
fn_start_dayz
|
|
fi
|