Initial
This commit is contained in:
170
files/bin/dz-common
Normal file
170
files/bin/dz-common
Normal file
@@ -0,0 +1,170 @@
|
||||
#!/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. Set these in the .env file for the container.
|
||||
if [[ ${SERVER_PORT} = "" ]]
|
||||
then
|
||||
export SERVER_PORT=2302
|
||||
fi
|
||||
|
||||
if [[ ${RCON_PORT} = "" ]]
|
||||
then
|
||||
export RCON_PORT=2303
|
||||
fi
|
||||
|
||||
export port=${SERVER_PORT}
|
||||
export rcon_port=${RCON_PORT}
|
||||
|
||||
# Don't change anything else.
|
||||
|
||||
# Colors
|
||||
export default="\e[0m"
|
||||
export red="\e[31m"
|
||||
export green="\e[32m"
|
||||
export yellow="\e[93m"
|
||||
export lightblue="\e[94m"
|
||||
export blue="\e[34m"
|
||||
export magenta="\e[35m"
|
||||
export cyan="\e[36m"
|
||||
|
||||
# DayZ release server Steam app ID.
|
||||
# Now that the Linux server is released, the binaries will come from this ID.
|
||||
export release_server_appid=223350
|
||||
|
||||
# Leaving the experimental server appid here to allow for the use of the experimental server.
|
||||
#export release_server_appid=1042420
|
||||
|
||||
# DayZ release client SteamID. This is for mods, as only the release client has them.
|
||||
export release_client_appid=221100
|
||||
|
||||
# Server container profile directory
|
||||
export SERVER_PROFILE="/profiles"
|
||||
|
||||
# Common container base directories
|
||||
export FILES="/files"
|
||||
export SERVER_FILES="/serverfiles"
|
||||
|
||||
# Used to check if dayZ is installed
|
||||
export SERVER_INSTALL_FILE="${SERVER_FILES}/DayZServer"
|
||||
|
||||
# Steam files
|
||||
export STEAM_LOGIN="${HOME}/steamlogin"
|
||||
export STEAMCMD=steamcmd
|
||||
|
||||
# Other stuff
|
||||
export YES="${green}yes${default}"
|
||||
export 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}}" ${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:]")
|
||||
if [[ ${NAME} = "" ]]
|
||||
then
|
||||
echo "Could not get metadata. See above. Exiting..."
|
||||
exit 1
|
||||
fi
|
||||
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
|
||||
}
|
||||
38
files/bin/map.sh
Normal file
38
files/bin/map.sh
Normal file
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eE
|
||||
|
||||
TERM="map"
|
||||
if [[ ${1} =~ ^[0-9]+$ ]]
|
||||
then
|
||||
TERM="mod id"
|
||||
fi
|
||||
|
||||
if [ -f "/files/mods/${1}/map.env" ]
|
||||
then
|
||||
source "/files/mods/${1}/map.env"
|
||||
else
|
||||
echo "map.env not found for ${TERM} ${1}..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ${2} = "uninstall" ]]
|
||||
then
|
||||
echo "Backing up, as uninstalling will remove the ${MAP} mpmissions directory"
|
||||
dz backup
|
||||
rm -rf "${SERVER_FILES}/mpmissions/${MPDIR}"
|
||||
elif [[ ${2} = "update" ]] || [[ ${2} = "install" ]]
|
||||
then
|
||||
cd /tmp
|
||||
if [ -d "${DIR}" ]
|
||||
then
|
||||
pushd "${DIR}" > /dev/null
|
||||
git pull
|
||||
popd > /dev/null
|
||||
else
|
||||
git clone "${REPO}"
|
||||
fi
|
||||
rm -rf ${SERVER_FILES}/mpmissions/${MPDIR:?}
|
||||
pushd "${DIR}" > /dev/null
|
||||
find . -name "${MPDIR}" -exec cp -a {} "${SERVER_FILES}/mpmissions" \;
|
||||
fi
|
||||
71
files/bin/xml.sh
Normal file
71
files/bin/xml.sh
Normal file
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# A generic script that retrieves XML files from mods, either upstream in remote endpoints, or
|
||||
# locally from the downloaded mod directory, or from project files.
|
||||
|
||||
set -eE
|
||||
|
||||
ID=${1}
|
||||
|
||||
if ! [ -f ${FILES}/mods/${ID}/xml.env ]
|
||||
then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
source ${FILES}/mods/${ID}/xml.env
|
||||
|
||||
# Iterate over the file names we can handle
|
||||
for i in cfgeventgroups.xml cfgenvironment.xml cfgeventspawns.xml cfggameplay.json cfgspawnabletypes.xml cfgweather.xml events.xml init.c types.xml
|
||||
do
|
||||
FILE=$(echo ${i} | cut -d. -f1)
|
||||
TYPE=$(echo ${i} | cut -d. -f2)
|
||||
UP=${FILE^^}
|
||||
VAL=${!UP}
|
||||
DIR="${WORKSHOP_DIR}/${ID}"
|
||||
OUT="${DIR}/${i}"
|
||||
if echo ${VAL} | grep -qE "^http"
|
||||
then
|
||||
echo
|
||||
echo "${i} is a URL, downloading to ${OUT}"
|
||||
curl -so ${OUT} ${VAL}
|
||||
elif echo ${VAL} | grep -qE "^local"
|
||||
then
|
||||
echo
|
||||
echo "${i} comes from mod integration, copying to ${OUT}"
|
||||
echo -n " "
|
||||
cp -v "${FILES}/mods/${ID}/${i}" "${OUT}"
|
||||
elif echo ${VAL} | grep -qE "^\./"
|
||||
then
|
||||
echo
|
||||
echo "${FILE} comes from the mod as ${VAL}, copying to ${OUT}"
|
||||
echo -n " "
|
||||
cp -v "${DIR}/${VAL}" "${OUT}"
|
||||
fi
|
||||
if [ -f ${OUT} ]
|
||||
then
|
||||
if [[ ${TYPE} = "xml" ]]
|
||||
then
|
||||
xmllint --noout ${OUT} 2> /dev/null && (
|
||||
echo -e " ${green}${OUT} passes XML lint test!${default}"
|
||||
) || (
|
||||
echo -e " ${yellow}${OUT} does not pass XML lint test!${default}"
|
||||
)
|
||||
# TODO - validate against schema - https://github.com/rvost/DayZ-Central-Economy-Schema/tree/master
|
||||
elif [ "${TYPE}" == "json" ]
|
||||
then
|
||||
jq -e . ${OUT} > /dev/null || (
|
||||
echo -e " ${yellow}${OUT} does not pass JSON lint test!${default}"
|
||||
) && (
|
||||
echo -e " ${green}${OUT} passes JSON lint test!${default}"
|
||||
)
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -f "${FILES}/mods/${ID}/start.sh" ]
|
||||
then
|
||||
echo
|
||||
echo "Copy ${FILES}/mods/${ID}/start.sh -> ${DIR}/start.sh"
|
||||
cp "${FILES}/mods/${ID}/start.sh" "${DIR}/start.sh"
|
||||
echo
|
||||
fi
|
||||
Reference in New Issue
Block a user