dayzdockerserver/files/bin/dz-common
Daniel Ceregatti 887374587d There are no mpmissions in the server container when it starts for the first time. Ensure Chernarus is copied over as a default when this is detected, as the server is expected to start successfully. Presumes a default config where the map hasn't been changed.
Make development work by setting an environment variable.
Set the web container to restart instead of not, should the express server crash.
Copy XML files that are merged when the server  starts only when the mpmissions directory exists.
Refactor XML functions for better naming.
Handle display of lists when no mods are installed.
Add support for adding mpmissions for Deer Isle and mpmissions in general via mod integrations.
Add support for Red Falcon Watercraft XML files. WIP.
Add a deer isle DayZ bicycle spawn file.
2023-09-07 12:08:12 -07:00

168 lines
4 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. USE ONE OR THE OTHER!!
# 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,
# even if the server binary and accompanying shared object don't come from it.
#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
# Server container profile directory
SERVER_PROFILE="/profiles"
# Common container base directories
FILES="/files"
SERVER_FILES="/serverfiles"
# Used to check if dayZ is installed
SERVER_INSTALL_FILE="${SERVER_FILES}/DayZServer"
# Steam files
STEAM_LOGIN="${HOME}/steamlogin"
STEAMCMD=steamcmd
# Other stuff
YES="${green}yes${default}"
NO="${red}no${default}"
# 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
}
# List mods
list(){
X=1
C="${green}"
spaces=" "
FIRST=1
for link in $(ls -d ${SERVER_FILES}/@* 2> /dev/null | sort)
do
if [[ ${FIRST} = 1 ]]
then
echo
echo -e " ID Name URL Size"
echo "------------------------------------------------------------------------------------------------------------------------"
FIRST=0
fi
ID=$(readlink ${link} | awk -F/ '{print $NF}')
MODNAME=$(get_mod_name ${ID})
SIZE=$(du -sh "${WORKSHOP_DIR}/${ID}" | awk '{print $1}')
printf "${C}%.3d %s %.30s %s https://steamcommunity.com/sharedfiles/filedetails/?id=%s %s${default}\n" ${X} ${ID} "${MODNAME}" "${spaces:${#MODNAME}+1}" ${ID} ${SIZE}
X=$((X+1))
done
echo
}
# Get mod name by ID or index
get_mod_name(){
# Check for an ID
if ! [ -d "${WORKSHOP_DIR}/${1}" ]
then
echo "Mod ID ${1} doesn't exist" >&2
exit 1
fi
NAME=$(grep name ${WORKSHOP_DIR}/${1}/meta.cpp | cut -d '"' -f2 | tr -cd [:alnum:])
echo -n ${NAME}
}
get_mod_id(){
# If we were passed a valid mod id, just return it
if [ -d "${WORKSHOP_DIR}/${1}" ]
then
echo -n ${1}
return
fi
# If we have a second argument, we want to iterate over active server mods
DIR=${SERVER_FILES}
ARG="-d"
if [[ ${2} = "0" ]]
then
ARG="-tdr"
DIR=${SERVER_PROFILE}
fi
# echo "DIR: ${DIR}, ARG: ${ARG}" >&2
X=1
# Loop over mods
for link in $(ls ${ARG} ${DIR}/@* 2> /dev/null)
do
ID=$(readlink ${link} | awk -F/ '{print $NF}')
if [[ ${X} = ${1} ]]
then
echo -n ${ID}
return
fi
X=$((X+1))
done
}
get_mods(){
workshoplist=""
for link in $(ls -d ${SERVER_FILES}/@* 2> /dev/null | sort)
do
ID=$(readlink ${link} | awk -F/ '{print $NF}')
MODNAME=$(get_mod_name ${ID})
workshoplist+=" +workshop_download_item "${release_client_appid}" "${ID}
done
get_mod_command_line
}
get_mod_command_line(){
mod_command_line=""
for link in $(ls -tdr ${SERVER_PROFILE}/@* 2> /dev/null)
do
ID=$(readlink ${link} | awk -F/ '{print $NF}')
MODNAME=$(get_mod_name ${ID})
mod_command_line+="@${MODNAME};"
done
if [[ ${mod_command_line} != "" ]]
then
mod_command_line='-mod='${mod_command_line::-1}
fi
}
# Copy mod keys
copy_keys(){
if [[ ${1} = 1 ]]
then
echo -n "Copying key file(s): "
find ${WORKSHOP_DIR}/${2} -name "*.bikey" -exec cp -v {} "${SERVER_FILES}/keys/" \;
else
echo -n "Removing key file(s): "
find ${WORKSHOP_DIR}/${2} -name "*.bikey" -execdir rm -vf "${SERVER_FILES}/keys/{}" \;
fi
}