mirror of
https://ceregatti.org/git/daniel/dayzdockerserver.git
synced 2025-05-06 22:31:18 +00:00
155 lines
3.5 KiB
Bash
Executable file
155 lines
3.5 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
set -eEa
|
|
|
|
# If you want/need the server and rcon ports to be different, set them here.
|
|
# The steam query port is set in serverDZ.cfg.
|
|
|
|
# Server port
|
|
port=2302
|
|
rcon_port=2303
|
|
|
|
# Don't change anything else.
|
|
|
|
# Colors
|
|
default="\e[0m"
|
|
red="\e[31m"
|
|
green="\e[32m"
|
|
yellow="\e[93m"
|
|
lightblue="\e[94m"
|
|
blue="\e[34m"
|
|
magenta="\e[35m"
|
|
cyan="\e[36m"
|
|
|
|
# DayZ release server Steam app ID.
|
|
# Presumably once the Linux server is released, the binaries will come from this ID.
|
|
# But more importantly, if we have a release-compatible binary, the base files must be installed from this id.
|
|
release_server_appid=223350
|
|
# Without a release binary, we must use the experimental server app id for everything.
|
|
#release_server_appid=1042420
|
|
|
|
# DayZ release client SteamID. This is for mods, as only the release client has them.
|
|
release_client_appid=221100
|
|
|
|
# Main container base directories
|
|
CFG_SRC_FILES="/files"
|
|
SERVER_FILES="/serverfiles"
|
|
|
|
# Server configuration file
|
|
SERVER_CFG_FILE="serverDZ.cfg"
|
|
SERVER_CFG_DST="${SERVER_FILES}/${SERVER_CFG_FILE}"
|
|
SERVER_CFG_SRC="${CFG_SRC_FILES}/${SERVER_CFG_FILE}"
|
|
|
|
# Used to check if dayZ is installed
|
|
SERVER_INSTALL_FILE="${SERVER_FILES}/DayZServer"
|
|
|
|
# Steam files
|
|
STEAM_LOGIN="${HOME}/steamlogin"
|
|
STEAMCMD=steamcmd
|
|
|
|
# Workshop. This file will store metadata about what mods are installed.
|
|
WORKSHOP_CFG="${HOME}/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}"
|
|
|
|
# Other stuff
|
|
YES="${green}yes${default}"
|
|
NO="${red}no${default}"
|
|
|
|
# Functions
|
|
|
|
checkInstall(){
|
|
# See if this mod id exists in files/mods, and offer to install other server side files if an install.sh is found
|
|
if [ -f /files/mods/${1}/${2}.sh ]
|
|
then
|
|
echo "An ${2}.sh was found for mod id ${1}. Running..."
|
|
/files/mods/${1}/${2}.sh
|
|
fi
|
|
# A generic map install script. Presumes a git repo as the source
|
|
if [ -f /files/mods/${1}/install.env ]
|
|
then
|
|
echo "An ${2}.env was found for mod id ${1}. Performing ${2}..."
|
|
source /files/mods/${1}/install.env
|
|
/files/mods/install.sh ${1} ${2}
|
|
fi
|
|
}
|
|
|
|
# Convenience function
|
|
prompt_yn(){
|
|
echo -n "${1} (y|N) " >&2
|
|
read -s -n 1 a
|
|
a=$(echo ${a} | tr A-Z a-z)
|
|
echo
|
|
if [[ "${a}" = "y" ]]
|
|
then
|
|
return 0
|
|
else
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
check_install(){
|
|
if [ ! -f "${SERVER_INSTALL_FILE}" ]
|
|
then
|
|
echo
|
|
echo -e "The DayZ server files are not installed. Run '${green}docker-compose run --rm main dayzserver install${default}'"
|
|
echo
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Assemble the workshop variables
|
|
get_mods(){
|
|
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
|
|
}
|
|
|
|
get_mod_id_by_index(){
|
|
# If we were passed a valid mod id, just return it
|
|
if [[ -d "${workshopdir}/${1}" ]]
|
|
then
|
|
echo ${1}
|
|
return
|
|
fi
|
|
X=1
|
|
# Loop over mod list
|
|
for i in "${workshopID[@]}"
|
|
do
|
|
ID=$(echo ${i} | cut -d: -f1)
|
|
if [[ ${X} = ${1} ]]
|
|
then
|
|
echo ${ID}
|
|
return
|
|
fi
|
|
X=$((X+1))
|
|
done
|
|
}
|
|
|
|
# Get mod name by ID or index
|
|
get_mod_name(){
|
|
# Check for an ID
|
|
if [ -d "${workshopfolder}/${1}" ]
|
|
then
|
|
ID=${1}
|
|
else
|
|
ID=$(get_mod_id_by_index ${1})
|
|
fi
|
|
if ! [ -d "${workshopfolder}/${ID}" ]
|
|
then
|
|
echo "Mod ID ${1} doesn't exist" >&2
|
|
exit 1
|
|
fi
|
|
NAME=$(grep name ${workshopfolder}/${ID}/meta.cpp | cut -d '"' -f2 | sed -r 's/\s+//g')
|
|
echo ${NAME}
|
|
}
|