From 99dbe745e3ff20ec4f0dfae77bfd71c4a7439f0e Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Wed, 21 Feb 2024 22:12:17 -0500 Subject: [PATCH 1/9] Added countdown function --- scripts/helper_functions.sh | 55 +++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index d35970cfa..8cd26be3f 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -202,3 +202,58 @@ shutdown_server() { fi return "$return_val" } + +# Given an amount of time in minutes and a message prefix +# Will skip countdown if no players are in the server, Will only check the mtime if there are players in the server +# Returns 0 on success +# Returns 1 if mtime is empty +# Returns 2 if mtime is not an integer +countdown_message() { + local mtime="$1" + local message_prefix="$2" + local return_val=0 + + # Only do countdown if there are players + if [ "$(get_player_count)" -gt 0 ]; then + if [[ "${mtime}" =~ ^[0-9]+$ ]]; then + for ((i = "${mtime}" ; i > 0 ; i--)); do + case "$i" in + 1 ) + broadcast_command "${message_prefix}_in_${i}_minute" + sleep 30s + broadcast_command "${message_prefix}_in_30_seconds" + sleep 20s + broadcast_command "${message_prefix}_in_10_seconds" + sleep 10s + ;; + 2 ) + ;& + 3 ) + ;& + 10 ) + ;& + 15 ) + ;& + "$mtime" ) + broadcast_command "${message_prefix}_in_${i}_minutes" + ;& + * ) + sleep 1m + # Checking for players every minute + # Checking after sleep since it is ran in the beginning of the function + if [ "$(get_player_count)" -eq 0 ]; then + break + fi + ;; + esac + done + # If there are players but mtime is empty + elif [ -z "${mtime}" ]; then + return_val=1 + # If there are players but mtime is not an integer + else + return_val=2 + fi + fi + return "$return_val" +} From 79ddad0fc10a6d42dbfcc542bf313553d8848936 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Wed, 21 Feb 2024 22:57:08 -0500 Subject: [PATCH 2/9] Updated auto reboot --- scripts/auto_reboot.sh | 49 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index 1698b2cf7..0f97b0439 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -2,31 +2,30 @@ # shellcheck source=scripts/helper_functions.sh source "/home/steam/server/helper_functions.sh" -if [ "${RCON_ENABLED,,}" != true ]; then - LogWarn "Unable to reboot. RCON is required." - exit 0 -fi +if [ "${RCON_ENABLED,,}" = true ]; then + if [ "${AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE,,}" != true ]; then + players_count=$(get_player_count) -if [ -z "${AUTO_REBOOT_WARN_MINUTES}" ]; then - LogError "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is empty." - exit 0 -fi + if [ "$players_count" -gt 0 ]; then + LogWarn "There are ${players_count} players online. Skipping auto reboot." + exit 0 + fi + fi -if [ "${AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE,,}" != true ]; then - players_count=$(get_player_count) - if [ "$players_count" -gt 0 ]; then - LogWarn "There are ${players_count} players online. Skipping auto reboot." - exit 0 - fi -fi - -if [[ "${AUTO_REBOOT_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then - for ((i = "${AUTO_REBOOT_WARN_MINUTES}" ; i > 0 ; i--)); do - broadcast_command "The Server will reboot in ${i} minutes" - sleep "1m" - done - shutdown_server - exit 0 + case "$(countdown_message "${AUTO_REBOOT_WARN_MINUTES}" "The_Server_will_reboot"; echo $?)" in + 0 ) + shutdown_server + ;; + 1 ) + LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is empty" + exit 1 + ;; + 2 ) + LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}" + exit 1 + ;; + esac +else + LogWarn "Unable to reboot. RCON is required." + exit 1 fi - -LogError "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}" \ No newline at end of file From 00f8e283eb785278ac7cc887ad97a62386f88435 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Wed, 21 Feb 2024 23:02:29 -0500 Subject: [PATCH 3/9] Fixed spacing --- scripts/update.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/update.sh b/scripts/update.sh index 0eaf94a98..1b519f021 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -26,10 +26,10 @@ if [ "${RCON_ENABLED,,}" = false ]; then fi if [ "$(get_player_count)" -gt 0 ]; then - LogAction "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." - DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" - broadcast_command "The Serverwill update in ${AUTO_UPDATE_WARN_MINUTES} minutes" - sleep "${AUTO_UPDATE_WARN_MINUTES}m" + LogAction "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." + DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" + broadcast_command "The Serverwill update in ${AUTO_UPDATE_WARN_MINUTES} minutes" + sleep "${AUTO_UPDATE_WARN_MINUTES}m" fi rm /palworld/steamapps/appmanifest_2394010.acf From a2281c4dcfa2af98fddb96dfc2e04b127f850795 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Wed, 21 Feb 2024 23:12:32 -0500 Subject: [PATCH 4/9] Updated update.sh --- scripts/update.sh | 57 ++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/scripts/update.sh b/scripts/update.sh index 1b519f021..c6cb3017b 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -6,32 +6,39 @@ source "/home/steam/server/helper_functions.sh" # shellcheck source=scripts/helper_install.sh source "/home/steam/server/helper_install.sh" -UpdateRequired -updateRequired=$? -# Check if Update was actually required -if [ "$updateRequired" != 0 ]; then - exit 0 -fi +# Check if Update is actually required +if UpdateRequired; then + if [ "${UPDATE_ON_BOOT,,}" != true ]; then + LogWarn "An update is available however, UPDATE_ON_BOOT needs to be enabled for auto updating" + DiscordMessage "An update is available however, UPDATE_ON_BOOT needs to be enabled for auto updating" "warn" + exit 1 + fi -if [ "${UPDATE_ON_BOOT}" = false ]; then - LogWarn "An update is available however, UPDATE_ON_BOOT needs to be enabled for auto updating" - DiscordMessage "An update is available however, UPDATE_ON_BOOT needs to be enabled for auto updating" "warn" - exit 1 -fi + if [ "${RCON_ENABLED,,}" != true ]; then + LogWarn "An update is available however auto updating without rcon is not supported" + DiscordMessage "An update is available however auto updating without rcon is not supported" "warn" + exit 1 + fi -if [ "${RCON_ENABLED,,}" = false ]; then - LogWarn "An update is available however auto updating without rcon is not supported" - DiscordMessage "An update is available however auto updating without rcon is not supported" "warn" - exit 1 -fi + if [[ "${AUTO_UPDATE_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then + DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" + fi -if [ "$(get_player_count)" -gt 0 ]; then - LogAction "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." - DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" - broadcast_command "The Serverwill update in ${AUTO_UPDATE_WARN_MINUTES} minutes" - sleep "${AUTO_UPDATE_WARN_MINUTES}m" -fi + case "$(countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server_will_update"; echo $?)" in + 0 ) + LogAction "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." + rm /palworld/steamapps/appmanifest_2394010.acf -rm /palworld/steamapps/appmanifest_2394010.acf -backup -RCON "shutdown 1" \ No newline at end of file + backup + shutdown_server + ;; + 1 ) + LogWarn "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is empty." + exit 1 + ;; + 2 ) + LogWarn "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is not an integer: ${AUTO_UPDATE_WARN_MINUTES}" + exit 1 + ;; + esac +fi From 1c0ef7c63e30a6930837a9682179fa2d2f2d4b58 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Wed, 21 Feb 2024 23:24:06 -0500 Subject: [PATCH 5/9] Minimize changes --- scripts/auto_reboot.sh | 47 ++++++++++++++--------------- scripts/update.sh | 68 ++++++++++++++++++++++-------------------- 2 files changed, 59 insertions(+), 56 deletions(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index 0f97b0439..fa6ad54ed 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -2,30 +2,29 @@ # shellcheck source=scripts/helper_functions.sh source "/home/steam/server/helper_functions.sh" -if [ "${RCON_ENABLED,,}" = true ]; then - if [ "${AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE,,}" != true ]; then - players_count=$(get_player_count) - - if [ "$players_count" -gt 0 ]; then - LogWarn "There are ${players_count} players online. Skipping auto reboot." - exit 0 - fi - fi - - case "$(countdown_message "${AUTO_REBOOT_WARN_MINUTES}" "The_Server_will_reboot"; echo $?)" in - 0 ) - shutdown_server - ;; - 1 ) - LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is empty" - exit 1 - ;; - 2 ) - LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}" - exit 1 - ;; - esac -else +if [ "${RCON_ENABLED,,}" != true ]; then LogWarn "Unable to reboot. RCON is required." exit 1 fi + +if [ "${AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE,,}" != true ]; then + players_count=$(get_player_count) + if [ "$players_count" -gt 0 ]; then + LogWarn "There are ${players_count} players online. Skipping auto reboot." + exit 0 + fi +fi + +case "$(countdown_message "${AUTO_REBOOT_WARN_MINUTES}" "The_Server_will_reboot"; echo $?)" in + 0 ) + shutdown_server + ;; + 1 ) + LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is empty" + exit 1 + ;; + 2 ) + LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}" + exit 1 + ;; +esac diff --git a/scripts/update.sh b/scripts/update.sh index c6cb3017b..6d6e74c22 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -6,39 +6,43 @@ source "/home/steam/server/helper_functions.sh" # shellcheck source=scripts/helper_install.sh source "/home/steam/server/helper_install.sh" -# Check if Update is actually required -if UpdateRequired; then - if [ "${UPDATE_ON_BOOT,,}" != true ]; then - LogWarn "An update is available however, UPDATE_ON_BOOT needs to be enabled for auto updating" - DiscordMessage "An update is available however, UPDATE_ON_BOOT needs to be enabled for auto updating" "warn" - exit 1 - fi - - if [ "${RCON_ENABLED,,}" != true ]; then - LogWarn "An update is available however auto updating without rcon is not supported" - DiscordMessage "An update is available however auto updating without rcon is not supported" "warn" - exit 1 - fi +UpdateRequired +updateRequired=$? +# Check if Update was actually required +if [ "$updateRequired" != 0 ]; then + exit 0 +fi - if [[ "${AUTO_UPDATE_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then - DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" - fi +if [ "${UPDATE_ON_BOOT,,}" != true ]; then + LogWarn "An update is available however, UPDATE_ON_BOOT needs to be enabled for auto updating" + DiscordMessage "An update is available however, UPDATE_ON_BOOT needs to be enabled for auto updating" "warn" + exit 1 +fi - case "$(countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server_will_update"; echo $?)" in - 0 ) - LogAction "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." - rm /palworld/steamapps/appmanifest_2394010.acf +if [ "${RCON_ENABLED,,}" != true ]; then + LogWarn "An update is available however auto updating without rcon is not supported" + DiscordMessage "An update is available however auto updating without rcon is not supported" "warn" + exit 1 +fi - backup - shutdown_server - ;; - 1 ) - LogWarn "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is empty." - exit 1 - ;; - 2 ) - LogWarn "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is not an integer: ${AUTO_UPDATE_WARN_MINUTES}" - exit 1 - ;; - esac +if [[ "${AUTO_UPDATE_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then + DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" fi + +case "$(countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server_will_update"; echo $?)" in + 0 ) + LogAction "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." + rm /palworld/steamapps/appmanifest_2394010.acf + + backup + shutdown_server + ;; + 1 ) + LogWarn "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is empty." + exit 1 + ;; + 2 ) + LogWarn "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is not an integer: ${AUTO_UPDATE_WARN_MINUTES}" + exit 1 + ;; +esac From bc90d2b0601ab1a1c2c413d7a0b7a1b58c15b593 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Wed, 21 Feb 2024 23:25:43 -0500 Subject: [PATCH 6/9] Undid space changes --- scripts/auto_reboot.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index fa6ad54ed..fdae308d9 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -8,11 +8,11 @@ if [ "${RCON_ENABLED,,}" != true ]; then fi if [ "${AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE,,}" != true ]; then - players_count=$(get_player_count) - if [ "$players_count" -gt 0 ]; then - LogWarn "There are ${players_count} players online. Skipping auto reboot." - exit 0 - fi + players_count=$(get_player_count) + if [ "$players_count" -gt 0 ]; then + LogWarn "There are ${players_count} players online. Skipping auto reboot." + exit 0 + fi fi case "$(countdown_message "${AUTO_REBOOT_WARN_MINUTES}" "The_Server_will_reboot"; echo $?)" in From 5731c6eba90dc2961e7b07d9bb13276e838497de Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Wed, 21 Feb 2024 23:28:22 -0500 Subject: [PATCH 7/9] Make case more readable --- scripts/auto_reboot.sh | 4 +++- scripts/update.sh | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index fdae308d9..d78fc7fb8 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -15,7 +15,9 @@ if [ "${AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE,,}" != true ]; then fi fi -case "$(countdown_message "${AUTO_REBOOT_WARN_MINUTES}" "The_Server_will_reboot"; echo $?)" in +countdown_message "${AUTO_REBOOT_WARN_MINUTES}" "The_Server_will_reboot" +countdown_exit_code=$? +case "${countdown_exit_code}" in 0 ) shutdown_server ;; diff --git a/scripts/update.sh b/scripts/update.sh index 6d6e74c22..9de445bc2 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -29,7 +29,9 @@ if [[ "${AUTO_UPDATE_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" fi -case "$(countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server_will_update"; echo $?)" in +countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server_will_update" +countdown_exit_code=$? +case "${countdown_exit_code}" in 0 ) LogAction "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." rm /palworld/steamapps/appmanifest_2394010.acf From cb3906b5ec01ab2343ecc555b965099621802f57 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Thu, 22 Feb 2024 02:34:09 -0500 Subject: [PATCH 8/9] Removed underscores --- scripts/auto_reboot.sh | 2 +- scripts/helper_functions.sh | 8 ++++---- scripts/update.sh | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index d78fc7fb8..ac8a0cd2f 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -15,7 +15,7 @@ if [ "${AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE,,}" != true ]; then fi fi -countdown_message "${AUTO_REBOOT_WARN_MINUTES}" "The_Server_will_reboot" +countdown_message "${AUTO_REBOOT_WARN_MINUTES}" "Server will reboot" countdown_exit_code=$? case "${countdown_exit_code}" in 0 ) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 8cd26be3f..7d4b8aad7 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -219,11 +219,11 @@ countdown_message() { for ((i = "${mtime}" ; i > 0 ; i--)); do case "$i" in 1 ) - broadcast_command "${message_prefix}_in_${i}_minute" + broadcast_command "${message_prefix} in ${i} minute" sleep 30s - broadcast_command "${message_prefix}_in_30_seconds" + broadcast_command "${message_prefix} in 30 seconds" sleep 20s - broadcast_command "${message_prefix}_in_10_seconds" + broadcast_command "${message_prefix} in 10 seconds" sleep 10s ;; 2 ) @@ -235,7 +235,7 @@ countdown_message() { 15 ) ;& "$mtime" ) - broadcast_command "${message_prefix}_in_${i}_minutes" + broadcast_command "${message_prefix} in ${i} minutes" ;& * ) sleep 1m diff --git a/scripts/update.sh b/scripts/update.sh index 9de445bc2..c0b033872 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -29,7 +29,7 @@ if [[ "${AUTO_UPDATE_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" fi -countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server_will_update" +countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server will update" countdown_exit_code=$? case "${countdown_exit_code}" in 0 ) From 6e0ad974b996e0d920edf989284863a2af1b3f86 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Thu, 22 Feb 2024 08:12:06 -0500 Subject: [PATCH 9/9] Resolves #427 --- scripts/helper_functions.sh | 3 +-- scripts/player_logging.sh | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 769a174bb..8e5f36a03 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -85,8 +85,7 @@ get_players_list() { return_val=1 fi - # tail -n +2 removes the header "name,playeruid,steamid" - RCON "ShowPlayers" | tail -n +2 + RCON "ShowPlayers" return "$return_val" } diff --git a/scripts/player_logging.sh b/scripts/player_logging.sh index a3a0ea2c8..371229300 100644 --- a/scripts/player_logging.sh +++ b/scripts/player_logging.sh @@ -18,7 +18,7 @@ while true; do if [ "${#server_pids[@]}" -ne 0 ]; then # Player IDs are usally 9 or 10 digits however when a player joins for the first time for a given boot their ID is temporary 00000000 (8x zeros) while loading # Player ID is also 00000000 (8x zeros) when in character creation - mapfile -t new_player_list < <( get_players_list | sed '/,00000000,[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/d' ) + mapfile -t new_player_list < <( get_players_list | tail -n +2 | sed '/,00000000,[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/d' ) # See players whose states have changed mapfile -t players_change_list < <( printf '%s\n' "${old_player_list[@]}" "${new_player_list[@]}" | sort | uniq -u )