This commit is contained in:
2023-11-25 02:11:45 -06:00
parent c901a10a6a
commit da9412b1af
5 changed files with 226 additions and 84 deletions

View File

@@ -14,6 +14,7 @@
# export CACHE="$MAIN/cache"
# export MOD_CACHE="$CACHE/mods"
# ORIGINAL_DIR="$PWD"
# export RESTART_INTERVAL=$((60 * 60 * 4 + 3))
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
# Helper functions
@@ -59,31 +60,31 @@
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
# Environment Setup
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
init() {
mkdir -p "$SERVER_HOME" "$MOD_CACHE/$MAP_FOLDER_NAME"
:>"$SERVER_HOME/.modstring"
}
# init() {
# mkdir -p "$SERVER_HOME" "$MOD_CACHE/$MAP_FOLDER_NAME"
# :>"$SERVER_HOME/.modstring"
# }
setup_environment() {
msg "Copying stock server data"
# setup_environment() {
# msg "Copying stock server data"
# list of all stock folders
for folder in addons battleye bliss docs dta keys ; do
do_sync "$STOCK_SERVER_DATA/$folder"/ "$SERVER_HOME/$folder" || die "Failed to copy stock: $folder"
done
# # list of all stock folders
# for folder in addons battleye bliss docs dta keys ; do
# do_sync "$STOCK_SERVER_DATA/$folder"/ "$SERVER_HOME/$folder" || die "Failed to copy stock: $folder"
# done
# list of all stock files
for file in ban.txt dayz.gproj dayzsetting.xml whitelist.txt \
DayZServer_x64.exe steam_api64.dll steamclient64.dll tier0_s64.dll vstdlib_s64.dll ; do
cp -f "$STOCK_SERVER_DATA/$file" "$SERVER_HOME/$file" || die "Failed to copy stock: $file"
done
# # list of all stock files
# for file in ban.txt dayz.gproj dayzsetting.xml whitelist.txt \
# DayZServer_x64.exe steam_api64.dll steamclient64.dll tier0_s64.dll vstdlib_s64.dll ; do
# cp -f "$STOCK_SERVER_DATA/$file" "$SERVER_HOME/$file" || die "Failed to copy stock: $file"
# done
msg "Copying mod files"
do_sync "$DAYZ_FILES/mods/$MAP_FOLDER_NAME"/ "$MOD_CACHE/$MAP_FOLDER_NAME" || die "Failed to copy mod files"
# msg "Copying mod files"
# do_sync "$DAYZ_FILES/mods/$MAP_FOLDER_NAME"/ "$MOD_CACHE/$MAP_FOLDER_NAME" || die "Failed to copy mod files"
msg "Copying DZSA executable"
cp -f "$DAYZ_FILES/software/DZSALModServer.exe" "$SERVER_HOME/"
}
# # msg "Copying DZSA executable"
# # cp -f "$DAYZ_FILES/software/DZSALModServer.exe" "$SERVER_HOME/"
# }
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
# Load Mods
@@ -130,16 +131,16 @@ load_mods() {
printf '%s\n' "$_modstring" > .modstring
}
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
# Load Map
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
load_stock_map_data() {
mkdir -p "$SERVER_HOME/mpmissions/$MAP_FOLDER_NAME"
do_sync --exclude='*storage_1*' \
"$DAYZ_FILES/stock/maps/$MAP_FOLDER_NAME"/ \
"$SERVER_HOME/mpmissions/$MAP_FOLDER_NAME" || \
die "Failed to copy stock map data"
}
# # -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
# # Load Map
# # -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
# load_stock_map_data() {
# mkdir -p "$SERVER_HOME/mpmissions/$MAP_FOLDER_NAME"
# do_sync --exclude='*storage_1*' \
# "$DAYZ_FILES/stock/maps/$MAP_FOLDER_NAME"/ \
# "$SERVER_HOME/mpmissions/$MAP_FOLDER_NAME" || \
# die "Failed to copy stock map data"
# }
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
# Types Patching
@@ -324,13 +325,13 @@ load_configs() {
# Main
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
main() {
init
cd "$SERVER_HOME" || die "Could not cd to '$SERVER_HOME'"
# init
# cd "$SERVER_HOME" || die "Could not cd to '$SERVER_HOME'"
check || die "Failed check"
# check || die "Failed check"
msg "Setting up environment"
setup_environment || die "Could not set up environment."
# msg "Setting up environment"
# setup_environment || die "Could not set up environment."
msg "Loading mods"
load_mods || die "Could not load mods"
@@ -357,9 +358,12 @@ cat > temp.bat <<EOF
:start
start "DayZ Server" /min DZSALModServer.exe -config=serverDZ.cfg -port="$SERVER_PORT" -profiles=Profilesfolder -mod="$mod_string" -cpuCount="$SERVER_CPU" -dologs -adminlog -netlog -freezecheck
EOF
# start the server
cmd.exe /C temp.bat
printf '\n**** Sleeping for: %s *****\n\n' "$RESTART_INTERVAL"
count=0
while [ "$count" -lt "$RESTART_INTERVAL" ] ; do
sleep 60
@@ -379,22 +383,21 @@ EOF
msg "SERVER IS RESTARTING"
}
ORIGINAL_DIR="$PWD"
# while msg 'Starting loop' ; do
# cd "$ORIGINAL_DIR" || die "Can no longer cd to $ORIGINAL_DIR"
while msg 'Starting loop' ; do
cd "$ORIGINAL_DIR" || die "Can no longer cd to $ORIGINAL_DIR"
# if [ -e ./SERVER.ENV ] ; then
# . ./SERVER.ENV
# else
# die "Could not source ./SERVER.ENV"
# fi
if [ -e ./SERVER.ENV ] ; then
. ./SERVER.ENV
else
die "Could not source ./SERVER.ENV"
fi
# if [ -f ./serverDZ.cfg ] ; then
# cp -f ./serverDZ.cfg "$SERVER_HOME"/
# else
# die "Could not find ./serverDZ.cfg"
# fi
if [ -f ./serverDZ.cfg ] ; then
cp -f ./serverDZ.cfg "$SERVER_HOME"/
else
die "Could not find ./serverDZ.cfg"
fi
# main "$@"
# done
main "$@"
done

View File

@@ -133,6 +133,7 @@ is_network_drive_mounted() {
exit 1
fi
}
# =====================================================================================
islocked_remote_server() {
if [ -e "$REMOTE_SERVER_LOCKFILE" ] ; then
msg "Server is not currently locked!"
@@ -141,5 +142,17 @@ islocked_remote_server() {
return 1
fi
}
lock_remote_server() {
msg "Locking remote server."
if ! echo 'locked' | tee "$REMOTE_SERVER_LOCKFILE" ; then
die "Could not create: $REMOTE_SERVER_LOCKFILE"
fi
}
unlock_remote_server() {
msg "Unlocking remote server."
rm -f "$REMOTE_SERVER_LOCKFILE" || die "Could not remove: $REMOTE_SERVER_LOCKFILE"
}
# =====================================================================================
################### GLOBAL FUNCTIONS #########################

View File

@@ -1,10 +1,17 @@
#!/bin/sh
#
# shellcheck disable=1090,2034,2011
#
# "should check code directly not $?"
# 01. "should check code directly not $?"
# shellcheck disable=2181
# ---------------------------------------------------
#
# 02. "can't follow . import"
# shellcheck disable=1090,1091
#
# 03. "possible misspelling"
# shellcheck disable=2153
#
# 04. "use find .. over ls"
# shellcheck disable=2011
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
# ===================================================
# 01. Attempt to load global DayZ values
@@ -263,20 +270,6 @@ update_stock_maps() {
fi
}
# =====================================================================================
lock_remote_server() {
msg "Locking remote server."
if ! echo 'locked' | tee "$REMOTE_SERVER_LOCKFILE" ; then
die "Could not create: $REMOTE_SERVER_LOCKFILE"
fi
}
unlock_remote_server() {
msg "Unlocking remote server."
rm -f "$REMOTE_SERVER_LOCKFILE" || die "Could not remove: $REMOTE_SERVER_LOCKFILE"
}
# =====================================================================================
main() {
check || die "Failed to pass health checks"

View File

@@ -1,17 +1,18 @@
#!/usr/bin/env bash
#!/bin/sh -x
#
# 01. "should check code directly not $?"
# shellcheck disable=2181
#
# 02. "can't follow . import"
# shellcheck disable=1090
# shellcheck disable=1090,1091
#
# 03. "possible misspelling"
# shellcheck disable=2153
#
# 04. "use find .. over ls"
# shellcheck disable=2011
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
##################### CHANGE ME #################################
export SERVER_NAME="XXXXXXXXXX"
##################### CHANGE ME #################################
# ===================================================
# 01. Attempt to load global DayZ values
# ===================================================
@@ -36,19 +37,21 @@ fi
# ^--/servers
# ^--/cache
#
export MAIN="/mnt/c/DAYZ"
export CACHE="$MAIN/cache"
export ORIGINAL_DIR="$PWD"
export LOCAL_DAYZ_FILES="/mnt/c/DAYZ"
export CACHE="$LOCAL_DAYZ_FILES/cache"
export STOCK_SERVER_CACHE="$CACHE/stock_server"
export MOD_CACHE="$CACHE/mods"
export SERVERS="$MAIN/servers"
export SERVER_HOME="$SERVERS/$SERVER_NAME"
export SERVERS="$LOCAL_DAYZ_FILES/servers"
# (4 hours, in seconds)
export RESTART_INTERVAL=$((60 * 60 * 4 + 3))
# ===================================================
# 03. init and checks
# ===================================================
check() {
if [ ! -d "$MAIN" ] ; then
die "dir: $MAIN does not exist"
if [ ! -d "$LOCAL_DAYZ_FILES" ] ; then
die "dir: $LOCAL_DAYZ_FILES does not exist"
fi
if [ ! -d "$SERVER_HOME" ] ; then
die "dir: $SERVER_HOME does not exist"
@@ -57,16 +60,141 @@ check() {
msg "Health checks completed successfully."
}
init() {
init_server() {
mkdir -p "$SERVER_HOME" "$CACHE" "$MOD_CACHE" "$STOCK_SERVER_CACHE"
:>"$SERVER_HOME/.modstring"
check || die "Failed check()"
mkdir -p "$CACHE" "$MOD_CACHE"
msg "Completed intialization. Using server restart time of $RESTART_INTERVAL seconds."
}
# ===================================================
main() {
# ===================================================
# 04. Load stock files
# ===================================================
# load_stock_map_data() {
# mkdir -p "$SERVER_HOME/mpmissions/$MAP_FOLDER_NAME"
# do_sync --exclude='*storage_1*' \
# "$DAYZ_FILES/stock/maps/$MAP_FOLDER_NAME"/ \
# "$SERVER_HOME/mpmissions/$MAP_FOLDER_NAME" || \
# die "Failed to copy stock map data"
# }
refresh_local_cache() {
msg "Refreshing local stock server cache"
if ! islocked_remote_server ; then
load_stock_map_data
do_sync "$REMOTE_STOCK_SERVER"/ "$STOCK_SERVER_CACHE"
unlock_remote_server
else
msg "Remote server is locked, sleeping..."
while islocked_remote_server ; do
sleep 15
echo 'Sleeping...'
done
lock_remote_server
do_sync "$REMOTE_STOCK_SERVER"/ "$STOCK_SERVER_CACHE"
unlock_remote_server
fi
msg "Stock server data copied into local server cache!"
# -------------------------------------
msg "Refreshing local mods cache"
if ! islocked_remote_server ; then
lock_remote_server
do_sync "$REMOTE_MODS"/ "$MOD_CACHE"
unlock_remote_server
else
msg "Remote server is locked, sleeping..."
while islocked_remote_server ; do
sleep 15
echo 'Sleeping...'
done
lock_remote_server
do_sync "$REMOTE_MODS"/ "$MOD_CACHE"
unlock_remote_server
fi
msg "Mods data copied into local mod cache!"
}
setup_environment() {
msg "Copying stock server data from local cache into $SERVER_HOME"
# list of all stock server folders
for folder in addons battleye bliss docs dta keys ; do
do_sync "$STOCK_SERVER_CACHE/$folder"/ "$SERVER_HOME/$folder" || die "Failed to copy stock: $folder"
done
# list of all stock server files
for file in ban.txt dayz.gproj dayzsetting.xml whitelist.txt \
DayZServer_x64.exe steam_api64.dll steamclient64.dll \
tier0_s64.dll vstdlib_s64.dll ; do
cp -fv "$STOCK_SERVER_CACHE/$file" "$SERVER_HOME/$file" || die "Failed to copy stock: $file"
done
msg "Copying mod files from local cache into $SERVER_HOME"
do_sync "$MOD_CACHE/$MAP_FOLDER_NAME"/ "$SERVER_HOME/mods" || die "Failed to copy mods to $SERVER_HOME"
# ~~~~~~~~~~~~~~~~~~~~~~~~~~ TODO: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# msg "Copying DZSA executable"
# cp -f "$DAYZ_FILES/software/DZSALModServer.exe" "$SERVER_HOME/"
# ~~~~~~~~~~~~~~~~~~~~~~~~~~ TODO: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
# ===================================================
# 05. Start function
# ===================================================
start_server() {
check || die "Failed check()"
# wait until dayz-modserver lockfile is released on the NAS
if islocked_remote_server ; then
msg "Remote file server is currently locked"
msg "Sleeping until is no longer locked..."
while islocked_remote_server ; do
echo "Sleeping..."
sleep 10
done
msg "Server unlocked! Continuing..."
fi
cd "$SERVER_HOME" || die "Could not cd to '$SERVER_HOME'"
msg "Setting up environment"
setup_environment || die "Could not set up environment."
}
# ===================================================
# 06. Main loop
# ===================================================
main() {
cd "$ORIGINAL_DIR" || die "Can no longer cd to $ORIGINAL_DIR"
if [ -e ./SERVER.ENV ] ; then
. ./SERVER.ENV
else
die "Could not source ./SERVER.ENV"
fi
# this must be here and not up top as we must load it from the SERVER.ENV
export SERVER_HOME="$SERVERS/$SERVER_NAME"
# create directories in $SERVER_HOME
# blank the modstring
init_server
if [ -e ./serverDZ.cfg ] ; then
cp -f ./serverDZ.cfg "$SERVER_HOME"/ || die "Failed to copy ./serverDZ into $SERVER_HOME"
else
die "Could not find ./serverDZ.cfg"
fi
# sync remote server stock and mod files into local cache
refresh_local_cache || die "Failed to refresh local cache."
# load stock server, map, mod files into $SERVER_HOME
setup_environment || die "Failed to setup environment."
start_server "$@"
}
main "$@" || exit 1

View File

@@ -0,0 +1,5 @@
#!/bin/sh
export SERVER_NAME="Mitch - Chernarus Test v0.0"
export MAP_FOLDER_NAME="$CHERNARUS_MAP_NAME"