#!/usr/bin/env bash source /files/dz-common # Workshop. This file will store metadata about what mods are installed. WORKSHOP_CFG="${SERVER_FILES}/workshop.cfg" if [ ! -f "${WORKSHOP_CFG}" ] then touch "${WORKSHOP_CFG}" fi # An array to store Workshop items. Each element contains the mod's ID, name, and state (active or not). declare -a workshopID workshopfolder="${SERVER_FILES}/steamapps/workshop/content/${release_client_appid}" workshoplist="" # Functions # Usage usage(){ echo -e " ${red}Bad option or arguments! ${yellow}${*}${default} Usage: ${green}$(basename $0)${yellow} option [ arg1 [ arg2 ] ] Options and arguments: add id - Add a DayZ Workshop item by id. Added items become active by default i|install - Install the DayZ server files l|list - List Workshop items and their details g|login - Login to Steam. m|modupdate - Update the mod files r|remove id - Remove all files and directories of a Workshop item by id s|status - Shows the server's status: Running, uptime, mods, parameters, mod parameter, etc. u|update - Update the server files ${default}" exit 1 } # Ensures all is installed and ready before allowing operations that depends on things being ready. # Installs the initial server config file from its template. # Handles the importing of changes to that template. # Installs the initial Battleye RCON config. loadconfig(){ # check_install # Handle the initial server configuration file if [ ! -f ${SERVER_CFG_DST} ] then echo "Creating initial server configuration file" cp "${SERVER_CFG_SRC}" "${SERVER_CFG_DST}" fi # battleye config and rconpassword setup # The server creates a new file from this file, which it then uses. # Let's make sure to delete it first BE_SERVER_FILE="${SERVER_FILES}/battleye/beserver_x64.cfg" ALT_BE_SERVER_FILE=$(find ${SERVER_FILES}/battleye -name "beserver_x64_active*") if [ ! -f "${BE_SERVER_FILE}" ] && [ ! -f "${ALT_BE_SERVER_FILE}" ] then passwd=$(openssl rand -base64 8 | tr -dc 'A-Za-z0-9') if [ "${passwd}" == "" ] then passwd=$(< /dev/urandom tr -dc 'A-Za-z0-9' | head -c10) fi if [ "${passwd}" == "" ] then printf "[ ${red}FAIL${default} ] Could not generate a passwort for RCON!\nOpen the Battleye config with 'dayzserver rcon'." exit 1 else cat > "${BE_SERVER_FILE}" < ~/py3rcon.config.json } # Handle the Steam login information. login(){ loadconfig if [ -f "${STEAM_LOGIN}" ] then if prompt_yn "The steam login is already set. Reset it?" then rm -f "${STEAM_LOGIN}" else echo "Not reset." exit 0 fi fi if [ ! -f "${STEAM_LOGIN}" ] then echo "Setting up Steam credentials" echo -n "Steam Username (anonymous): " read steamlogin if [[ "${steamlogin}" = "" ]] then echo "Steam login set to 'anonymous'" steamlogin="anonymous" fi echo "steamlogin=${steamlogin}" > "${STEAM_LOGIN}" ${STEAMCMD} +force_install_dir ${SERVER_FILES} +login "${steamlogin}" +quit fi } # "Perform" the Steam login. This just sources the file with the Steam login name. dologin(){ loadconfig if [ -f "${STEAM_LOGIN}" ] then source "${STEAM_LOGIN}" else echo "No cached Steam credentials. Please configure this now: " login fi } # Perform the installation of the server files. install(){ loadconfig if [ ! -f "${SERVER_INSTALL_FILE}" ] || [[ ${1} = "force" ]] then printf "[ ${yellow}DayZ${default} ] Downloading DayZ Server-Files!\n" dologin ${STEAMCMD} +force_install_dir ${SERVER_FILES} +login "${steamlogin}" +app_update "${release_server_appid}" validate +quit else printf "[ ${lightblue}DayZ${default} ] The server is already installed.\n" fi } # Update the server files. update(){ dologin appmanifestfile=${SERVER_FILES}/steamapps/appmanifest_"${release_server_appid}".acf printf "[ ... ] Checking for update:" # 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" fi # check for new build availablebuild=$(${STEAMCMD} +login "${steamlogin}" +app_info_update 1 +app_info_print "${release_server_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:\n" printf "\r[ ${red}FAIL${default} ] Checking for update:: Not returning version info\n" exit else printf "\r[ ${green}OK${default} ] Checking for update:" fi # compare builds if [ "${currentbuild}" != "${availablebuild}" ] || [[ ${1} = "force" ]] then printf "\r[ ${green}OK${default} ] Checking for update:: 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/${release_server_appid}/\n" printf "\nApplying update" # run update dologin ${STEAMCMD} +force_install_dir ${SERVER_FILES} +login "${steamlogin}" +app_update "${release_server_appid}" validate +quit modupdate else printf "\r[ ${green}OK${default} ] Checking for update:: 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/${release_server_appid}/\n\n" fi } # Update mods modupdate(){ echo "Updating mods..." dologin # echo ${STEAMCMD} +force_install_dir ${SERVER_FILES} +login "${steamlogin}" ${workshoplist} +quit ${STEAMCMD} +force_install_dir ${SERVER_FILES} +login "${steamlogin}" ${workshoplist} +quit # Updated files come in with mixed cases. Fix that. echo -ne "\nFixing file names..." find "${workshopfolder}" -depth -exec rename -f 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \; echo "done" echo } # List mods list(){ mapfile -t workshopID < "${WORKSHOP_CFG}" workshoplist="" for i in "${workshopID[@]}" do ID=$(echo ${i} | cut -d: -f1) workshoplist+=" +workshop_download_item "${release_client_appid}" "${ID} done if [[ "${workshopID[@]}" = "" ]] then return fi X=1 spaces=" " echo -e "\n ID Name URL Size" echo "------------------------------------------------------------------------------------------------------------------------" for i in "${workshopID[@]}" do ID=$(echo ${i} | cut -d: -f1) NAME=$(echo ${i} | cut -d: -f2) # ACTIVE=$(echo ${i} | cut -d: -f3) SIZE=$(du -sh ${SERVER_FILES}/steamapps/workshop/content/221100/${ID} | awk '{print $1}') # if [[ ${ACTIVE} = "1" ]] # then C="${green}" # else # C="${red}" # fi printf "${C}%.3d %s %.23s %s https://steamcommunity.com/sharedfiles/filedetails/?id=%s %s${default}\n" ${X} ${ID} "${NAME}" "${spaces:${#NAME}+1}" ${ID} ${SIZE} X=$((X+1)) done } # Display the status of everything status(){ INSTALLED="${NO}" LOGGED_IN="${NO}" RUNNING="${NO}" # DayZ Server files installation if [ -f "${SERVER_INSTALL_FILE}" ] then INSTALLED="${YES}" fi # Logged into Steam if [ -f "${STEAM_LOGIN}" ] then LOGGED_IN="${YES}" if grep -q anonymous "${STEAM_LOGIN}" then ANONYMOUS="${yellow}(as anonymous)${default}" else ANONYMOUS="${green}(not anonymous)${default}" fi fi echo -ne " Logged in to Steam: ${LOGGED_IN} ${ANONYMOUS} Server files installed: ${INSTALLED}" if [[ "${INSTALLED}" = "${NO}" ]] then echo echo exit 0 fi # Mods echo -ne " Mods: " MODS=$(list) if [[ ${MODS} == "" ]] then echo -n "none" fi echo -e "${MODS}" } # Capture the first argument and shift it off so we can pass $@ to every function C=${1} shift || { usage } case "${C}" in add) add "${@}" ;; i|install) install "${@}" ;; l|list) list "${@}" ;; login) login "${@}" ;; m|modupdate) modupdate "${@}" ;; r|remove) remove "${@}" ;; s|status) status "${@}" ;; u|update) update "${@}" ;; *) usage "$*" ;; esac