Compare commits

..

14 Commits

Author SHA1 Message Date
d64f62977b asdf 2023-11-29 07:33:12 -06:00
1205108c34 adsf 2023-11-29 07:17:48 -06:00
fcc86b3760 asdf 2023-11-29 07:13:33 -06:00
0ebab689b7 asdf 2023-11-29 07:13:11 -06:00
95e5ff889b asdf 2023-11-29 07:12:53 -06:00
65e4aa16a0 asdf 2023-11-29 07:11:56 -06:00
dfe20d9fed asdf 2023-11-29 06:58:07 -06:00
a9a87303c2 asdf 2023-11-29 06:52:36 -06:00
7dec690284 asdf 2023-11-29 06:50:02 -06:00
b25a761c6a asdf 2023-11-29 06:48:46 -06:00
29cd2e3ec0 asdf 2023-11-29 06:45:55 -06:00
0fe8c31b72 asdf 2023-11-29 06:30:19 -06:00
bb3ac16365 asdf 2023-11-29 05:35:07 -06:00
4d3b0104f4 asdf 2023-11-26 09:27:29 -06:00
7 changed files with 94 additions and 63 deletions

View File

@@ -33,18 +33,16 @@ export TAKISTAN_MOD_ID=2563233742
################### GLOBAL VARS ############################## ################### GLOBAL VARS ##############################
################### GLOBAL ALIASES ########################### ################### GLOBAL ALIASES ###########################
# note: OLD? MAYBE NEEDED?
###########alias do_sync='rsync -rvltDhu --delete --partial --progress'
unalias rsync 2>/dev/null ||: unalias rsync 2>/dev/null ||:
alias do_sync='rsync -avhu --progress --delete --partial --links' alias do_sync='rsync -avhu --progress --delete --partial --links'
################### GLOBAL ALIASES ########################### ################### GLOBAL ALIASES ###########################
################### GLOBAL FUNCTIONS ######################### ################### GLOBAL FUNCTIONS #########################
msg() { msg() {
printf '\n[*] %s\n\n' "$*" printf '>>>>>[MESSAGE]: %s\n' "$*"
} }
errmsg() { errmsg() {
>&2 printf '\n[Error]: %s\n\n' "$*" >&2 printf '>>>>>>[ERROR]: %s\n' "$*"
} }
die() { die() {
errmsg "$*" errmsg "$*"
@@ -52,7 +50,7 @@ die() {
} }
debug() { debug() {
if [ "$DEBUG" ] ; then if [ "$DEBUG" ] ; then
>&2 printf '>>>>>>>>>DEBUG: %s\n' "$*" >&2 printf '>>>>>>DEBUG: %s\n' "$*"
fi fi
} }
isempty() { isempty() {
@@ -87,7 +85,9 @@ isempty() {
} }
mount_dayz_network_drive() { mount_dayz_network_drive() {
if ! is_network_drive_mounted ; then if ! is_network_drive_mounted ; then
if [ ! -d /mnt/dayz ] ; then
sudo mkdir -p /mnt/dayz sudo mkdir -p /mnt/dayz
fi
if [ -e /proc/version ] ; then if [ -e /proc/version ] ; then
read -r ver < /proc/version read -r ver < /proc/version
case $ver in case $ver in

View File

@@ -10,3 +10,5 @@ msg() {
-H "Content-Type:application/json" \ -H "Content-Type:application/json" \
--data "{\"content\": $message}" --data "{\"content\": $message}"
} }
msg "$@"

View File

@@ -18,7 +18,24 @@
# =================================================== # ===================================================
echo "Starting, attempting to load globals.sh" echo "Starting, attempting to load globals.sh"
GLOBALS_FILE="$PWD/lib/globals.sh" # if we are called externally by one of the servers,
# the command will be "~/dayz-servers/modserver_update.sh"
# we need to change from $PWD to accomodate for that
export WORKING_DIR=$PWD
if [ ! -d "$WORKING_DIR"/lib ] ; then
export WORKING_DIR="$HOME/dayz-servers"
if [ ! -d "$WORKING_DIR"/lib ] ; then
>&2 echo "Could not find lib. Exiting"
exit 1
fi
fi
# grab fresh copy of all helper scripts / libraries
if [ -d "$WORKING_DIR/lib" ] ; then
cp -f "$WORKING_DIR/lib"/* .
fi
GLOBALS_FILE="$WORKING_DIR/globals.sh"
if [ -e "$GLOBALS_FILE" ] ; then if [ -e "$GLOBALS_FILE" ] ; then
chmod +x "$GLOBALS_FILE" chmod +x "$GLOBALS_FILE"
. "$GLOBALS_FILE" . "$GLOBALS_FILE"
@@ -31,7 +48,7 @@ fi
# 02. Local script variables # 02. Local script variables
# =================================================== # ===================================================
export STEAMCMD_USER=steam export STEAMCMD_USER=steam
export MODLISTS="$PWD/modlists" export MODLISTS="$WORKING_DIR/modlists"
export LOCAL_STOCK="$HOME/stock" export LOCAL_STOCK="$HOME/stock"
export LOCAL_STOCK_GAME="$LOCAL_STOCK/DayZ" export LOCAL_STOCK_GAME="$LOCAL_STOCK/DayZ"
@@ -75,14 +92,14 @@ check() {
die "Remote server already locked?" die "Remote server already locked?"
fi fi
msg "Health checks passed successfully." msg "(MODSERVER): Health checks passed successfully."
} }
# =================================================== # ===================================================
# 05. Begin functions # 05. Begin functions
# =================================================== # ===================================================
update_server() { update_server() {
msg "============== UPDATING DAYZ SERVER =================" msg "(MODSERVER): STARTING UPDATING DAYZ SERVER"
steamcmd -tcp \ steamcmd -tcp \
+force_install_dir "$LOCAL_STOCK_SERVER" \ +force_install_dir "$LOCAL_STOCK_SERVER" \
+@sSteamCmdForcePlatformType windows \ +@sSteamCmdForcePlatformType windows \
@@ -93,11 +110,11 @@ update_server() {
is_network_drive_mounted && is_network_drive_mounted &&
do_sync "$LOCAL_STOCK_SERVER"/ "$REMOTE_STOCK_SERVER" do_sync "$LOCAL_STOCK_SERVER"/ "$REMOTE_STOCK_SERVER"
msg "============ DONE UPDATING SERVER =====================" msg "(MODSERVER): FINISHED UPDATING DAYZ SERVER"
} }
update_game() { update_game() {
msg "========== UPDATING DAYZ GAME ================" msg "(MODSERVER): STARTING UPDATING DAYZ GAME"
steamcmd -tcp \ steamcmd -tcp \
+force_install_dir "$LOCAL_STOCK_GAME" \ +force_install_dir "$LOCAL_STOCK_GAME" \
+@sSteamCmdForcePlatformType windows \ +@sSteamCmdForcePlatformType windows \
@@ -108,12 +125,12 @@ update_game() {
is_network_drive_mounted && is_network_drive_mounted &&
do_sync "$LOCAL_STOCK_GAME"/ "$REMOTE_STOCK_GAME" do_sync "$LOCAL_STOCK_GAME"/ "$REMOTE_STOCK_GAME"
msg "============= DONE UPDATING GAME ===================" msg "(MODSERVER): FINISHED UPDATING DAYZ GAME"
} }
# args: $1 = server_modlist.txt to update # args: $1 = server_modlist.txt to update
update_mods_for_server() { update_mods_for_server() {
msg "======= UPDATING MODS FOR MAP: $1 ========" msg "(MODSERVER): UPDATING MODS FOR MAP: $1"
mods_file="$MODLISTS/$1" mods_file="$MODLISTS/$1"
map_name=${1%.txt} map_name=${1%.txt}
@@ -165,12 +182,11 @@ update_mods_for_server() {
die "Problem downloading mods for $map_name" die "Problem downloading mods for $map_name"
fi fi
msg "------------ RENAMING MODS -------------" msg "(MODSERVER): RENAMING MODS"
mods_to_copy="$LOCAL_MODS/mods_to_copy"
rm -rf "$mods_to_copy" 2>/dev/null ||: # blank map's mods.txt
mkdir -p "$mods_to_copy" :> "$remote_map_mod_dir/mods.txt"
:> "$mods_to_copy/mods.txt"
while read -r mod ; do while read -r mod ; do
# skip comments, blank lines # skip comments, blank lines
case "$mod" in case "$mod" in
@@ -182,29 +198,27 @@ update_mods_for_server() {
if [ ! -d "$LOCAL_MODS/steamapps/workshop/content/$DAYZ_GAME_ID/$mod_id" ] ; then if [ ! -d "$LOCAL_MODS/steamapps/workshop/content/$DAYZ_GAME_ID/$mod_id" ] ; then
die "$LOCAL_MODS/steamapps/workshop/content/$DAYZ_GAME_ID/$mod_id does not exist" die "$LOCAL_MODS/steamapps/workshop/content/$DAYZ_GAME_ID/$mod_id does not exist"
fi fi
cp -raf "$LOCAL_MODS/steamapps/workshop/content/$DAYZ_GAME_ID/$mod_id" "$mods_to_copy/@${mod_name}" do_sync "$LOCAL_MODS/steamapps/workshop/content/$DAYZ_GAME_ID/$mod_id"/ "$remote_map_mod_dir/@${mod_name}"
printf '@%s\n' "$mod_name" >> "$mods_to_copy/mods.txt" printf '@%s\n' "$mod_name" >> "$remote_map_mod_dir/mods.txt"
msg "(MODSERVER): Finished syncing: $mod_name"
esac esac
done < "$mods_file" done < "$mods_file"
msg "----------- SYNCING MODS -------------"
do_sync "$mods_to_copy"/ "$remote_map_mod_dir"
rm -f "$tempfile" 2>/dev/null ||: rm -f "$tempfile" 2>/dev/null ||:
unset tempfile mod map_name mods_file mods_to_copy mod_name mod_id remote_map_mod_dir unset tempfile mod map_name mods_file mod_name mod_id remote_map_mod_dir
msg "======= DONE UPDATING MODS FOR: $1 ========" msg "(MODSERVER): FINISHED UPDATING MODS FOR MAP: $1"
} }
update_stock_maps() { update_stock_maps() {
msg "----------- UPDATING MAPS -------------" msg "(MODSERVER): UPDATING MAPS"
msg "Copying Stock Chernarus" msg "(MODSERVER): Copying Stock Chernarus"
do_sync \ do_sync \
"$LOCAL_STOCK_SERVER/mpmissions/$CHERNARUS_MAP_NAME"/ \ "$LOCAL_STOCK_SERVER/mpmissions/$CHERNARUS_MAP_NAME"/ \
"$REMOTE_MAPS/$CHERNARUS_MAP_NAME" "$REMOTE_MAPS/$CHERNARUS_MAP_NAME"
msg "Updating Namalsk Survival" msg "(MODSERVER): Updating Namalsk Survival"
steamcmd \ steamcmd \
-tcp \ -tcp \
+force_install_dir "$LOCAL_MODS" \ +force_install_dir "$LOCAL_MODS" \
@@ -226,7 +240,7 @@ update_stock_maps() {
die "failed to copy Namalsk map files" die "failed to copy Namalsk map files"
fi fi
msg "Updating Namalsk Island" msg "(MODSERVER): Updating Namalsk Island"
steamcmd \ steamcmd \
-tcp \ -tcp \
+force_install_dir "$LOCAL_MODS" \ +force_install_dir "$LOCAL_MODS" \
@@ -244,7 +258,7 @@ update_stock_maps() {
####################TODO: # msg "Updating Optimized Namalsk Server PBOs" ####################TODO: # msg "Updating Optimized Namalsk Server PBOs"
msg "Updating TakistanPlus" msg "(MODSERVER): Updating TakistanPlus"
steamcmd \ steamcmd \
-tcp \ -tcp \
+force_install_dir "$LOCAL_MODS" \ +force_install_dir "$LOCAL_MODS" \
@@ -278,7 +292,7 @@ main() {
for server in $(ls "$MODLISTS" | xargs) ; do for server in $(ls "$MODLISTS" | xargs) ; do
if [ ! -f "$MODLISTS/$server" ] ; then if [ ! -f "$MODLISTS/$server" ] ; then
msg "Could not find modlist for: $MODLISTS/$server" msg "(MODSERVER): Could not find modlist for: $MODLISTS/$server"
continue continue
fi fi
update_mods_for_server "$server" update_mods_for_server "$server"

View File

@@ -1,4 +1,6 @@
#!/bin/sh #!/bin/sh
chmod -x globals.sh chmod -x globals.sh 2>/dev/null ||:
chmod -x lib/globals.sh 2>/dev/null ||:
git stash
git pull git pull

View File

@@ -45,14 +45,6 @@ export STOCK_SERVER_CACHE="$CACHE/stock_server"
export MOD_CACHE="$CACHE/mods" export MOD_CACHE="$CACHE/mods"
export SERVERS="$LOCAL_DAYZ_FILES/servers" export SERVERS="$LOCAL_DAYZ_FILES/servers"
# (4 hours, in seconds)
################################# export RESTART_INTERVAL=$((60 * 60 * 4))
# (10 minutes)
# export RESTART_INTERVAL=$((10 * 60))
export RESTART_INTERVAL=$((1 * 60))
# =================================================== # ===================================================
# 03. Mount network drive # 03. Mount network drive
# =================================================== # ===================================================
@@ -222,7 +214,8 @@ EOF
cmd.exe /C temp.bat cmd.exe /C temp.bat
rm -f temp.bat modstring 2>/dev/null ||: rm -f temp.bat modstring 2>/dev/null ||:
msg '%s - Server started.\n' "$(date)" msg "Server started: $(date)"
msg "RESTART_INTERVAL: $RESTART_INTERVAL"
count=0 count=0
while [ "$count" -lt "$RESTART_INTERVAL" ] ; do while [ "$count" -lt "$RESTART_INTERVAL" ] ; do
@@ -242,7 +235,15 @@ EOF
# =================================================== # ===================================================
# 07. Main loop # 07. Main loop
# =================================================== # ===================================================
main() { main() {
NUMBER_OF_STARTS=0
while true ; do
NUMBER_OF_STARTS=$((NUMBER_OF_STARTS + 1))
msg "Server is preparing to start..."
msg "NUMBER OF STARTS: $NUMBER_OF_STARTS"
cd "$ORIGINAL_DIR" || die "Can no longer cd to $ORIGINAL_DIR" cd "$ORIGINAL_DIR" || die "Can no longer cd to $ORIGINAL_DIR"
if [ -e ./SERVER.ENV ] ; then if [ -e ./SERVER.ENV ] ; then
@@ -263,6 +264,11 @@ main() {
die "Could not find ./serverDZ.cfg" die "Could not find ./serverDZ.cfg"
fi fi
# trigger update for remote server game/map/mod files
# for this, the current machine needs to have ssh-copy-id done
# or else will ask for password
ssh steam@dayz-modserver 'sh /home/steam/dayz-servers/modserver_update.sh'
# sync remote server stock and mod files into local cache # sync remote server stock and mod files into local cache
refresh_local_cache || die "Failed to refresh local cache." refresh_local_cache || die "Failed to refresh local cache."
@@ -271,6 +277,7 @@ main() {
# START THE SERVER - RUN ServerDZ.EXE # START THE SERVER - RUN ServerDZ.EXE
start_server "$@" start_server "$@"
done
} }
main "$@" || exit 1 main "$@" || exit 1

View File

@@ -8,3 +8,9 @@ export SERVER_PORT=2302
# number of threads to allocate # number of threads to allocate
export SERVER_CPU=10 export SERVER_CPU=10
# (4 hours, in seconds)
################################# export RESTART_INTERVAL=$((60 * 60 * 4))
# (5 minutes)
export RESTART_INTERVAL=$((5 * 60))