|
#!/bin/bash |
|
|
|
set -e |
|
|
|
workshop_id=221100 |
|
mp_mission_version=DZ_125 |
|
expansion_mp_mission_version=master |
|
port=2301 |
|
|
|
declare -A server_types |
|
server_types[stable]="223350" |
|
server_types[experimental]="1042420" |
|
|
|
|
|
declare -A client_types |
|
client_types[stable]="221100" |
|
client_types[experimental]="1024020" |
|
|
|
# a named list of mods to install |
|
|
|
# shellcheck disable=SC1091 |
|
source "${PWD}/config.sh" |
|
|
|
|
|
client_id="${client_types[${SERVER_MODE}]}" |
|
server_id="${server_types[${SERVER_MODE}]}" |
|
|
|
join() { |
|
output=$1 |
|
sep="${2:-;}" # can be of any length |
|
|
|
list=$(printf "${sep}%s" "${output[@]}") |
|
echo "${list:${#sep}};" |
|
} |
|
|
|
helper_confirm() { |
|
read -r -p "${1:-Are you sure? [y/N]} " response |
|
case "$response" in |
|
[yY][eE][sS] | [yY]) |
|
true |
|
;; |
|
*) |
|
false |
|
;; |
|
esac |
|
} |
|
|
|
helper_run_steamcmd() { |
|
echo " |
|
Running SteamCMD with the following arguments: |
|
${*} |
|
" |
|
|
|
steamcmd \ |
|
@NoPromptForPassword 1 \ |
|
+force_install_dir "${PWD}" \ |
|
+login "${STEAMCMD_USERNAME}" "${STEAMCMD_PASSWORD}" \ |
|
"$@" |
|
} |
|
|
|
helper_run_steam() { |
|
echo " |
|
Running Steam with the following arguments: |
|
${*} |
|
" |
|
|
|
steam -applaunch \ |
|
"${client_id}" \ |
|
"$@" |
|
} |
|
|
|
helper_run_server() { |
|
echo " |
|
Running DayZ Server with the following arguments: |
|
${*} |
|
" |
|
|
|
./DayZServer \ |
|
"$@" |
|
} |
|
|
|
arg_requires() { |
|
arg=$1 |
|
mesage=$2 |
|
|
|
if [ -z "${arg}" ]; then |
|
echo "[MissingArgError] ${mesage}" |
|
exit 1 |
|
fi |
|
} |
|
|
|
# print the keys of the MOD_LIST and join with ; |
|
data_get_mod_clientlaunch_args() { |
|
output=() |
|
# loop over the keys |
|
for mod_id in "${!MOD_LIST[@]}"; do |
|
# a mod path is stored here so join it with the mod_name |
|
# mod_name="${MOD_LIST[${mod_id}]}" |
|
# mod_path="$PWD/mods/${mod_name}" |
|
output+=("${mod_id}") |
|
done |
|
|
|
sep=';' # can be of any length |
|
list=$(printf "${sep}%s" "${output[@]}") |
|
echo "${list:${#sep}};" |
|
|
|
} |
|
|
|
data_get_mod_serverlaunch_args() { |
|
output="" |
|
for mod_id in "${!MOD_LIST[@]}"; do |
|
mod_name="${MOD_LIST[${mod_id}]}" |
|
output+="mods/${mod_name}';'" |
|
done |
|
|
|
echo "${output}" |
|
} |
|
|
|
data_get_mod_serverinstall_args() { |
|
output=() |
|
|
|
for mod_id in "${!MOD_LIST[@]}"; do |
|
mod_name="${MOD_LIST[${mod_id}]}" |
|
output+=("+workshop_download_item ${workshop_id} ${mod_id} validate") |
|
done |
|
|
|
sep=' ' # can be of any length |
|
list=$(printf "${sep}%s" "${output[@]}") |
|
echo "${list:${#sep}};" |
|
|
|
} |
|
|
|
data_get_here_ip() { |
|
ip -o route get to 8.8.8.8 | sed -n 's/.*src \([0-9.]\+\).*/\1/p' |
|
} |
|
|
|
cmd_install() { |
|
|
|
helper_run_steamcmd \ |
|
+app_update "${server_id}" \ |
|
$(data_get_mod_serverinstall_args) \ |
|
+quit |
|
|
|
|
|
mkdir -p "${PWD}/mods" |
|
mkdir -p "${PWD}/keys" |
|
|
|
# remove all keys except dayz.bikey |
|
find "${PWD}/keys" -type f ! -name "dayz.bikey" -delete |
|
|
|
# remove all mod folders |
|
find "${PWD}/mods" -mindepth 1 -delete |
|
|
|
|
|
for mod_id in "${!MOD_LIST[@]}"; do |
|
mod_name="${MOD_LIST[${mod_id}]}" |
|
mod_source_path="${PWD}/steamapps/workshop/content/${workshop_id}/${mod_id}/" |
|
mod_target_path="${PWD}/mods/${mod_name}" |
|
|
|
|
|
# create symlink to mod |
|
cp -r \ |
|
"${mod_source_path}" \ |
|
"${mod_target_path}" |
|
|
|
find "${mod_target_path}" -depth -execdir bash -c 'mv $0 ${0,,}' {} \; |
|
|
|
# copy any .bikey file to the keys directory |
|
find "${mod_target_path}" \ |
|
-type f -name "*.bikey" \ |
|
-exec cp {} "${PWD}/keys" \; |
|
done |
|
} |
|
|
|
cmd_reset_mission() { |
|
here_dir="${PWD}" |
|
mpmission_dir="${here_dir}/mpmissions" |
|
|
|
rm -rf "${mpmission_dir}" |
|
mkdir -p "${mpmission_dir}" |
|
|
|
mission_download_tmp=$(mktemp -d) |
|
wget https://github.com/BohemiaInteractive/DayZ-Central-Economy/archive/refs/tags/${mp_mission_version}.zip \ |
|
-O "${mission_download_tmp}/DayZ-Central-Economy.zip" |
|
cd "${mission_download_tmp}" |
|
bsdtar --strip-components=1 -xvf \ |
|
./DayZ-Central-Economy.zip \ |
|
-C "${mpmission_dir}" |
|
|
|
rm ./DayZ-Central-Economy.zip |
|
|
|
expansion_download_tmp=$(mktemp -d) |
|
cd "${expansion_download_tmp}" |
|
|
|
# download as filename: DayZ-Expansion-Missions.zip |
|
wget https://github.com/ExpansionModTeam/DayZ-Expansion-Missions/archive/refs/heads/master.zip |
|
|
|
# unzip as directory named: DayZ-Expansion-Missions |
|
bsdtar --strip-components=1 -xvf ./master.zip |
|
rm ./master.zip |
|
mv ./Template/Chernarus/expansion_ce "${mpmission_dir}" |
|
mv ./Template/Chernarus/expansion "${mpmission_dir}" |
|
|
|
# move all the README* files in the root only |
|
# do not recurse into subdirectories |
|
# prefix them with "expansion_" to avoid conflicts |
|
find . \ |
|
-maxdepth 1 -type f \ |
|
-name "README*" \ |
|
-exec mv {} "${mpmission_dir}/expansion_$(basename {})" \; |
|
|
|
cd "$here_dir" |
|
|
|
rm -rf "${mission_download_tmp}" |
|
rm -rf "${expansion_download_tmp}" |
|
|
|
} |
|
|
|
|
|
echo "Dayz Server Manager" |
|
echo "PWD: ${PWD}" |
|
echo "Mods: ${MOD_LIST[*]}" |
|
echo "Server Mode: ${SERVER_MODE}" |
|
echo " " |
|
|
|
case "$1" in |
|
install) |
|
helper_confirm "Are you sure you want to install the server?" || exit 1 |
|
cmd_install |
|
;; |
|
start) |
|
helper_run_server \ |
|
-config=serverDZ.cfg \ |
|
-port=2301 \ |
|
-BEpath=battleye \ |
|
-profiles=profiles \ |
|
"'-mod=$(data_get_mod_serverlaunch_args)'" \ |
|
-dologs \ |
|
-adminlog \ |
|
-netlog \ |
|
-freezecheck |
|
;; |
|
|
|
reset-mission) |
|
helper_confirm "Are you sure you want to reset the mission?" || exit 1 |
|
cmd_reset_mission |
|
;; |
|
|
|
client) |
|
helper_run_steam \ |
|
-name "DayZ Admin" \ |
|
-nolauncher \ |
|
-nosplash \ |
|
-port="${port}" \ |
|
-connect="$(data_get_here_ip)" \ |
|
"'-mod=$(data_get_mod_clientlaunch_args)'" |
|
;; |
|
mods) |
|
data_get_modlist |
|
;; |
|
*) |
|
echo "Usage: $0 {install|start|reset-mission|client}" |
|
exit 1 |
|
;; |
|
esac |