From 019fe45b207c6fab906b897719d071e00b9b3fd6 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Wed, 14 Feb 2024 12:57:22 -0500 Subject: [PATCH 01/49] Fixed spacing --- scripts/update.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update.sh b/scripts/update.sh index f9b6528ce..d06176af6 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -46,7 +46,7 @@ if [ "$CURRENT_MANIFEST" != "$TARGET_MANIFEST" ]; then if [ "$(get_player_count)" -gt 0 ]; then if [ -n "${DISCORD_WEBHOOK_URL}" ]; then - /home/steam/server/discord.sh "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" "info" & + /home/steam/server/discord.sh "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" "info" & fi rcon-cli -c /home/steam/server/rcon.yaml "broadcast Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes" sleep "${AUTO_UPDATE_WARN_MINUTES}m" From 9d6b1068ba46a97d126fcc717050392171be6b77 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Wed, 14 Feb 2024 12:59:41 -0500 Subject: [PATCH 02/49] Added countdown loop --- scripts/update.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/update.sh b/scripts/update.sh index d06176af6..a02306006 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -48,8 +48,10 @@ if [ "$CURRENT_MANIFEST" != "$TARGET_MANIFEST" ]; then if [ -n "${DISCORD_WEBHOOK_URL}" ]; then /home/steam/server/discord.sh "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" "info" & fi - rcon-cli -c /home/steam/server/rcon.yaml "broadcast Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes" - sleep "${AUTO_UPDATE_WARN_MINUTES}m" + for ((i = "${AUTO_UPDATE_WARN_MINUTES}" ; i > 0 ; i--)); do + rcon-cli -c /home/steam/server/rcon.yaml "broadcast Server_will_update_in_${i}_Minutes" + sleep "1m" + done fi backup rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" From fd1a2de88ce2fbca691979a365a9dc9acd2e2715 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Wed, 14 Feb 2024 13:07:09 -0500 Subject: [PATCH 03/49] Added validation for AUTO_UPDATE_WARN_MINUTES --- scripts/update.sh | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/scripts/update.sh b/scripts/update.sh index a02306006..f6472f65d 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -41,20 +41,27 @@ if [ "$CURRENT_MANIFEST" != "$TARGET_MANIFEST" ]; then fi exit 0 fi - echo "New Build was found. Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." - rm /palworld/steamapps/appmanifest_2394010.acf - if [ "$(get_player_count)" -gt 0 ]; then - if [ -n "${DISCORD_WEBHOOK_URL}" ]; then - /home/steam/server/discord.sh "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" "info" & + if [ -z "${AUTO_UPDATE_WARN_MINUTES}" ]; then + echo "Unable to auto update, AUTO_UPDATE_WARN_MINUTES is empty." + elif [[ "${AUTO_UPDATE_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then + echo "New Build was found. Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." + rm /palworld/steamapps/appmanifest_2394010.acf + + if [ "$(get_player_count)" -gt 0 ]; then + if [ -n "${DISCORD_WEBHOOK_URL}" ]; then + /home/steam/server/discord.sh "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" "info" & + fi + for ((i = "${AUTO_UPDATE_WARN_MINUTES}" ; i > 0 ; i--)); do + rcon-cli -c /home/steam/server/rcon.yaml "broadcast Server_will_update_in_${i}_Minutes" + sleep "1m" + done fi - for ((i = "${AUTO_UPDATE_WARN_MINUTES}" ; i > 0 ; i--)); do - rcon-cli -c /home/steam/server/rcon.yaml "broadcast Server_will_update_in_${i}_Minutes" - sleep "1m" - done + backup + rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" + else + echo "Unable to auto update, AUTO_UPDATE_WARN_MINUTES is not an integer: ${AUTO_UPDATE_WARN_MINUTES}" fi - backup - rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" else echo "The Server is up to date!" fi \ No newline at end of file From 595f0a3649256d84720a1393ae2269be8bf2a8e0 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Thu, 15 Feb 2024 22:47:16 -0500 Subject: [PATCH 04/49] Moved countdown to helper function and added seconds --- scripts/auto_reboot.sh | 6 +----- scripts/helper_functions.sh | 37 ++++++++++++++++++++++++++++++++++++- scripts/update.sh | 5 +---- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index 313df8b4c..65aa4a703 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -15,11 +15,7 @@ if [ "${RCON_ENABLED,,}" = true ]; then if [ -z "${AUTO_REBOOT_WARN_MINUTES}" ]; then echo "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is empty." elif [[ "${AUTO_REBOOT_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then - for ((i = "${AUTO_REBOOT_WARN_MINUTES}" ; i > 0 ; i--)); do - rcon-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_reboot_in_${i}_Minutes" - sleep "1m" - done - + countdown_message "${AUTO_REBOOT_WARN_MINUTES}" "The_Server_will_reboot_in" rcon-cli -c /home/steam/server/rcon.yaml save rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" else diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 606655d9a..70807141c 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -77,4 +77,39 @@ get_player_count() { fi player_list=$(rcon-cli -c /home/steam/server/rcon.yaml "ShowPlayers") echo -n "${player_list}" | wc -l -} \ No newline at end of file +} + +# Given an amount of time in minutes and a message prefix +countdown_message() { + mtime="$1" + message_prefix="$2" + + for ((i = "${mtime}" ; i > 0 ; i--)); do + if [ "$i" -eq 1 ]; then + rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_${i}_minutue" + sleep 30s + rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_30_seconds" + sleep 20s + rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_10_seconds" + sleep 10s + else + case "$i" in + "$mtime" ) + ;& + 15 ) + ;& + 10 ) + ;& + 5 ) + ;& + 2 ) + rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_${i}_minutues" + ;& + * ) + sleep 1m + ;; + esac + fi + done + +} diff --git a/scripts/update.sh b/scripts/update.sh index f6472f65d..3268bbb41 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -52,10 +52,7 @@ if [ "$CURRENT_MANIFEST" != "$TARGET_MANIFEST" ]; then if [ -n "${DISCORD_WEBHOOK_URL}" ]; then /home/steam/server/discord.sh "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" "info" & fi - for ((i = "${AUTO_UPDATE_WARN_MINUTES}" ; i > 0 ; i--)); do - rcon-cli -c /home/steam/server/rcon.yaml "broadcast Server_will_update_in_${i}_Minutes" - sleep "1m" - done + countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server_will_update_in" fi backup rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" From ed56e0f63a2357b398cd6707b03aff31fca01c16 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Thu, 15 Feb 2024 22:48:38 -0500 Subject: [PATCH 05/49] Removed/Added extra lines --- scripts/helper_functions.sh | 3 +-- scripts/update.sh | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 70807141c..f4aeb7e32 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -110,6 +110,5 @@ countdown_message() { ;; esac fi - done - + done } diff --git a/scripts/update.sh b/scripts/update.sh index 3268bbb41..a009fb05b 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -61,4 +61,4 @@ if [ "$CURRENT_MANIFEST" != "$TARGET_MANIFEST" ]; then fi else echo "The Server is up to date!" -fi \ No newline at end of file +fi From 98f9c1e7daa2c358c0ca69d248ec1d3943d8a78e Mon Sep 17 00:00:00 2001 From: Carlos Martinez Date: Fri, 16 Feb 2024 12:59:58 -0500 Subject: [PATCH 06/49] Update scripts/helper_functions.sh Co-authored-by: Luatan <74045606+Luatan@users.noreply.github.com> --- scripts/helper_functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index f4aeb7e32..45b752120 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -86,7 +86,7 @@ countdown_message() { for ((i = "${mtime}" ; i > 0 ; i--)); do if [ "$i" -eq 1 ]; then - rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_${i}_minutue" + rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_${i}_minute" sleep 30s rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_30_seconds" sleep 20s From 2d3417962bb2b4e56de3d9dca388209e91e1aada Mon Sep 17 00:00:00 2001 From: Carlos Martinez Date: Fri, 16 Feb 2024 13:00:05 -0500 Subject: [PATCH 07/49] Update scripts/helper_functions.sh Co-authored-by: Luatan <74045606+Luatan@users.noreply.github.com> --- scripts/helper_functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 45b752120..4b569af01 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -103,7 +103,7 @@ countdown_message() { 5 ) ;& 2 ) - rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_${i}_minutues" + rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_${i}_minutes" ;& * ) sleep 1m From 22683fdc61d6bb4c36b497592ff7c141e01245fc Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Fri, 16 Feb 2024 15:23:13 -0500 Subject: [PATCH 08/49] Implemented skip when empty, resolves #393 --- scripts/helper_functions.sh | 3 +++ scripts/update.sh | 9 ++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 4b569af01..d0bc3e9a1 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -85,6 +85,9 @@ countdown_message() { message_prefix="$2" for ((i = "${mtime}" ; i > 0 ; i--)); do + if [ "$(get_player_count)" -eq 0 ]; then + break + fi if [ "$i" -eq 1 ]; then rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_${i}_minute" sleep 30s diff --git a/scripts/update.sh b/scripts/update.sh index a009fb05b..a86122cfd 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -48,12 +48,11 @@ if [ "$CURRENT_MANIFEST" != "$TARGET_MANIFEST" ]; then echo "New Build was found. Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." rm /palworld/steamapps/appmanifest_2394010.acf - if [ "$(get_player_count)" -gt 0 ]; then - if [ -n "${DISCORD_WEBHOOK_URL}" ]; then - /home/steam/server/discord.sh "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" "info" & - fi - countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server_will_update_in" + if [ -n "${DISCORD_WEBHOOK_URL}" ]; then + /home/steam/server/discord.sh "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" "info" & fi + countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server_will_update_in" + backup rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" else From 8bef267189b652bafdf0a0688b54142ff07a1ca5 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Fri, 16 Feb 2024 15:31:55 -0500 Subject: [PATCH 09/49] Moved in_ to countdown message --- 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 65aa4a703..7fda8d5b6 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -15,7 +15,7 @@ if [ "${RCON_ENABLED,,}" = true ]; then if [ -z "${AUTO_REBOOT_WARN_MINUTES}" ]; then echo "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is empty." elif [[ "${AUTO_REBOOT_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then - countdown_message "${AUTO_REBOOT_WARN_MINUTES}" "The_Server_will_reboot_in" + countdown_message "${AUTO_REBOOT_WARN_MINUTES}" "The_Server_will_reboot" rcon-cli -c /home/steam/server/rcon.yaml save rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" else diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index d0bc3e9a1..3d8f5c48b 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -89,11 +89,11 @@ countdown_message() { break fi if [ "$i" -eq 1 ]; then - rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_${i}_minute" + rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_in_${i}_minute" sleep 30s - rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_30_seconds" + rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_in_30_seconds" sleep 20s - rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_10_seconds" + rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_in_10_seconds" sleep 10s else case "$i" in @@ -106,7 +106,7 @@ countdown_message() { 5 ) ;& 2 ) - rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_${i}_minutes" + rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_in_${i}_minutes" ;& * ) sleep 1m diff --git a/scripts/update.sh b/scripts/update.sh index a86122cfd..3cb1514ef 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -51,7 +51,7 @@ if [ "$CURRENT_MANIFEST" != "$TARGET_MANIFEST" ]; then if [ -n "${DISCORD_WEBHOOK_URL}" ]; then /home/steam/server/discord.sh "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" "info" & fi - countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server_will_update_in" + countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server_will_update" backup rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" From 5471fb4a0143505c7975793fdb50a8583fa563fb Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Fri, 16 Feb 2024 15:51:46 -0500 Subject: [PATCH 10/49] Moved integer validation to countdown --- scripts/auto_reboot.sh | 3 +- scripts/helper_functions.sh | 70 ++++++++++++++++++++++--------------- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index 7fda8d5b6..f410e356a 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -14,8 +14,7 @@ if [ "${RCON_ENABLED,,}" = true ]; then if [ -z "${AUTO_REBOOT_WARN_MINUTES}" ]; then echo "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is empty." - elif [[ "${AUTO_REBOOT_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then - countdown_message "${AUTO_REBOOT_WARN_MINUTES}" "The_Server_will_reboot" + elif countdown_message "${AUTO_REBOOT_WARN_MINUTES}" "The_Server_will_reboot"; then rcon-cli -c /home/steam/server/rcon.yaml save rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" else diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 3d8f5c48b..8aff847e4 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -80,38 +80,50 @@ get_player_count() { } # Given an amount of time in minutes and a message prefix +# Returns 0 on success +# If mtime is not an integer and there are players in game then return 1 countdown_message() { mtime="$1" message_prefix="$2" + return_val=0 - for ((i = "${mtime}" ; i > 0 ; i--)); do - if [ "$(get_player_count)" -eq 0 ]; then - break - fi - if [ "$i" -eq 1 ]; then - rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_in_${i}_minute" - sleep 30s - rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_in_30_seconds" - sleep 20s - rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_in_10_seconds" - sleep 10s - else - case "$i" in - "$mtime" ) - ;& - 15 ) - ;& - 10 ) - ;& - 5 ) - ;& - 2 ) - rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_in_${i}_minutes" - ;& - * ) - sleep 1m - ;; - esac + if [[ "${mtime}" =~ ^[0-9]+$ ]]; then + for ((i = "${mtime}" ; i > 0 ; i--)); do + if [ "$(get_player_count)" -eq 0 ]; then + break + fi + if [ "$i" -eq 1 ]; then + rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_in_${i}_minute" + sleep 30s + rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_in_30_seconds" + sleep 20s + rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_in_10_seconds" + sleep 10s + else + case "$i" in + "$mtime" ) + ;& + 15 ) + ;& + 10 ) + ;& + 5 ) + ;& + 2 ) + rcon-cli -c /home/steam/server/rcon.yaml "broadcast ${message_prefix}_in_${i}_minutes" + ;& + * ) + sleep 1m + ;; + esac + fi + done + return 0 + else + # mtime is not an integer so check if there are no players + if [ "$(get_player_count)" -gt 0 ]; then + return_val=1 fi - done + fi + return "$return_val" } From 58a611cb5a520698d4d85ec877d7fc9969504934 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Fri, 16 Feb 2024 15:52:35 -0500 Subject: [PATCH 11/49] Fixed spacing in auto_reboot.sh --- 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 f410e356a..b25618ada 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -4,12 +4,12 @@ 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) + players_count=$(get_player_count) - if [ "$players_count" -gt 0 ]; then - echo "There are ${players_count} players online. Skipping auto reboot." - exit 1 - fi + if [ "$players_count" -gt 0 ]; then + echo "There are ${players_count} players online. Skipping auto reboot." + exit 1 + fi fi if [ -z "${AUTO_REBOOT_WARN_MINUTES}" ]; then From 7e5437952accfb6c526138f90aec74886764e6c0 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Fri, 16 Feb 2024 15:59:36 -0500 Subject: [PATCH 12/49] Update auto_reboot so AUTO_REBOOT_WARN_MINUTES needs to only be valid if players are in the server. --- scripts/auto_reboot.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index b25618ada..98d9ef08b 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -12,11 +12,11 @@ if [ "${RCON_ENABLED,,}" = true ]; then fi fi - if [ -z "${AUTO_REBOOT_WARN_MINUTES}" ]; then - echo "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is empty." - elif countdown_message "${AUTO_REBOOT_WARN_MINUTES}" "The_Server_will_reboot"; then + if countdown_message "${AUTO_REBOOT_WARN_MINUTES}" "The_Server_will_reboot"; then rcon-cli -c /home/steam/server/rcon.yaml save rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" + elif [ -z "${AUTO_REBOOT_WARN_MINUTES}" ]; then + echo "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is empty." else echo "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}" fi From b79edce79c5f3d268952c8ab3044fd9894b13852 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Fri, 16 Feb 2024 16:05:52 -0500 Subject: [PATCH 13/49] Split messages in update --- scripts/update.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/update.sh b/scripts/update.sh index 3cb1514ef..706efc9e8 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -42,10 +42,11 @@ if [ "$CURRENT_MANIFEST" != "$TARGET_MANIFEST" ]; then exit 0 fi + echo "New Build was found." if [ -z "${AUTO_UPDATE_WARN_MINUTES}" ]; then echo "Unable to auto update, AUTO_UPDATE_WARN_MINUTES is empty." elif [[ "${AUTO_UPDATE_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then - echo "New Build was found. Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." + echo "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." rm /palworld/steamapps/appmanifest_2394010.acf if [ -n "${DISCORD_WEBHOOK_URL}" ]; then From 80d4b1c0174322722d8cee1d00ff1ac63d11b8fa Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Fri, 16 Feb 2024 16:11:44 -0500 Subject: [PATCH 14/49] No longer creating update discord message if AUTO_UPDATE_WARN_MINUTES is invalid --- scripts/update.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/update.sh b/scripts/update.sh index 706efc9e8..02b8f381b 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -32,7 +32,7 @@ if [ -z "$TARGET_MANIFEST" ]; then fi exit 1 fi -echo "player count: $(get_player_count)" + if [ "$CURRENT_MANIFEST" != "$TARGET_MANIFEST" ]; then if [ "${RCON_ENABLED,,}" != true ]; then echo "An update is available however auto updating without rcon is not supported" @@ -43,19 +43,19 @@ if [ "$CURRENT_MANIFEST" != "$TARGET_MANIFEST" ]; then fi echo "New Build was found." - if [ -z "${AUTO_UPDATE_WARN_MINUTES}" ]; then - echo "Unable to auto update, AUTO_UPDATE_WARN_MINUTES is empty." - elif [[ "${AUTO_UPDATE_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then - echo "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." - rm /palworld/steamapps/appmanifest_2394010.acf - + if [[ "${AUTO_UPDATE_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then if [ -n "${DISCORD_WEBHOOK_URL}" ]; then /home/steam/server/discord.sh "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" "info" & fi - countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server_will_update" + fi + if countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server_will_update"; then + echo "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." + rm /palworld/steamapps/appmanifest_2394010.acf backup rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" + elif [ -z "${AUTO_UPDATE_WARN_MINUTES}" ]; then + echo "Unable to auto update, AUTO_UPDATE_WARN_MINUTES is empty." else echo "Unable to auto update, AUTO_UPDATE_WARN_MINUTES is not an integer: ${AUTO_UPDATE_WARN_MINUTES}" fi From e73c9f2eaa1579724b6a4386549c403e6db59e85 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Fri, 16 Feb 2024 16:12:45 -0500 Subject: [PATCH 15/49] Updated messages in update.sh --- scripts/update.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/update.sh b/scripts/update.sh index 02b8f381b..8789e2af2 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -42,14 +42,14 @@ if [ "$CURRENT_MANIFEST" != "$TARGET_MANIFEST" ]; then exit 0 fi - echo "New Build was found." + echo "An update is available" if [[ "${AUTO_UPDATE_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then if [ -n "${DISCORD_WEBHOOK_URL}" ]; then /home/steam/server/discord.sh "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" "info" & fi fi if countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server_will_update"; then - echo "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." + echo "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST" rm /palworld/steamapps/appmanifest_2394010.acf backup From 098818ad6defcbdcea38791fa231d212f9598dbe Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Fri, 16 Feb 2024 16:38:06 -0500 Subject: [PATCH 16/49] Updated messages in update and reboot --- scripts/auto_reboot.sh | 4 ++-- scripts/update.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index 98d9ef08b..b4e964937 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -16,9 +16,9 @@ if [ "${RCON_ENABLED,,}" = true ]; then rcon-cli -c /home/steam/server/rcon.yaml save rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" elif [ -z "${AUTO_REBOOT_WARN_MINUTES}" ]; then - echo "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is empty." + echo "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is empty" else - echo "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}" + echo "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}" fi else echo "Unable to reboot. RCON is required." diff --git a/scripts/update.sh b/scripts/update.sh index 8789e2af2..5f6f5d454 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -55,9 +55,9 @@ if [ "$CURRENT_MANIFEST" != "$TARGET_MANIFEST" ]; then backup rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" elif [ -z "${AUTO_UPDATE_WARN_MINUTES}" ]; then - echo "Unable to auto update, AUTO_UPDATE_WARN_MINUTES is empty." + echo "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is empty." else - echo "Unable to auto update, AUTO_UPDATE_WARN_MINUTES is not an integer: ${AUTO_UPDATE_WARN_MINUTES}" + echo "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is not an integer: ${AUTO_UPDATE_WARN_MINUTES}" fi else echo "The Server is up to date!" From 25450e27df78eb4e888cb66281c4936a420f248d Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Fri, 16 Feb 2024 20:45:44 -0500 Subject: [PATCH 17/49] Added save function --- scripts/auto_reboot.sh | 2 +- scripts/backup.sh | 4 +--- scripts/helper_functions.sh | 15 ++++++++++++++- scripts/restore.sh | 2 +- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index 313df8b4c..56604d437 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -20,7 +20,7 @@ if [ "${RCON_ENABLED,,}" = true ]; then sleep "1m" done - rcon-cli -c /home/steam/server/rcon.yaml save + save_server rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" else echo "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}" diff --git a/scripts/backup.sh b/scripts/backup.sh index c82909e5a..f3cc99685 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -4,9 +4,7 @@ if [ -n "${DISCORD_WEBHOOK_URL}" ]; then /home/steam/server/discord.sh "Creating backup..." "in-progress" & fi -if [ "${RCON_ENABLED,,}" = true ]; then - rcon-cli -c /home/steam/server/rcon.yaml save -fi +save_server DATE=$(date +"%Y-%m-%d_%H-%M-%S") FILE_PATH="/palworld/backups/palworld-save-${DATE}.tar.gz" diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 606655d9a..b8e239a12 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -77,4 +77,17 @@ get_player_count() { fi player_list=$(rcon-cli -c /home/steam/server/rcon.yaml "ShowPlayers") echo -n "${player_list}" | wc -l -} \ No newline at end of file +} + +# Saves the server +# Returns 0 if it saves +# Returns 1 if it is not able to save +save_server() { + local return_val=0 + if [ "${RCON_ENABLED,,}" = true ]; then + rcon-cli -c /home/steam/server/rcon.yaml save + else + return_val=1 + fi + return "$return_val" +} diff --git a/scripts/restore.sh b/scripts/restore.sh index 207748fb3..846e95c9c 100644 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -61,7 +61,7 @@ if [ -f "$BACKUP_FILE" ]; then if [ "${RCON_ENABLED}" = true ]; then printf "\e[0;32m*****SHUTDOWN SERVER*****\e[0m\n" - rcon-cli -c /home/steam/server/rcon.yaml save + save_server rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" else echo "RCON is not enabled. Please enable RCON to use this feature. Unable to restore backup." From 5fe4b8da23597ea011b0634221658f0e356398fa Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Fri, 16 Feb 2024 20:49:10 -0500 Subject: [PATCH 18/49] Added shutdown function --- scripts/auto_reboot.sh | 2 +- scripts/helper_functions.sh | 13 +++++++++++++ scripts/restore.sh | 2 +- scripts/update.sh | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index 56604d437..7bc4f9029 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -21,7 +21,7 @@ if [ "${RCON_ENABLED,,}" = true ]; then done save_server - rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" + shutdown_server else echo "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}" fi diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index b8e239a12..c40ba447c 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -91,3 +91,16 @@ save_server() { fi return "$return_val" } + +# Shutdowns the server +# Returns 0 if it is shutdown +# Returns 1 if it is not able to be shutdown +shutdown_server() { + local return_val=0 + if [ "${RCON_ENABLED,,}" = true ]; then + shutdown_server + else + return_val=1 + fi + return "$return_val" +} diff --git a/scripts/restore.sh b/scripts/restore.sh index 846e95c9c..5ab88a25b 100644 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -62,7 +62,7 @@ if [ -f "$BACKUP_FILE" ]; then if [ "${RCON_ENABLED}" = true ]; then printf "\e[0;32m*****SHUTDOWN SERVER*****\e[0m\n" save_server - rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" + shutdown_server else echo "RCON is not enabled. Please enable RCON to use this feature. Unable to restore backup." exit 1 diff --git a/scripts/update.sh b/scripts/update.sh index f9b6528ce..a4a258054 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -52,7 +52,7 @@ if [ "$CURRENT_MANIFEST" != "$TARGET_MANIFEST" ]; then sleep "${AUTO_UPDATE_WARN_MINUTES}m" fi backup - rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" + shutdown_server else echo "The Server is up to date!" fi \ No newline at end of file From fa9735c3ffd81a0b47170a7ab88c7b6b96e6d98c Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Fri, 16 Feb 2024 20:52:09 -0500 Subject: [PATCH 19/49] Added save to shutdown function --- scripts/auto_reboot.sh | 1 - scripts/helper_functions.sh | 9 +++++++-- scripts/restore.sh | 1 - 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index 7bc4f9029..b01b0d381 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -20,7 +20,6 @@ if [ "${RCON_ENABLED,,}" = true ]; then sleep "1m" done - save_server shutdown_server else echo "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}" diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index c40ba447c..a91d9ea20 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -92,13 +92,18 @@ save_server() { return "$return_val" } -# Shutdowns the server +# Saves then shutdowns the server # Returns 0 if it is shutdown # Returns 1 if it is not able to be shutdown shutdown_server() { local return_val=0 if [ "${RCON_ENABLED,,}" = true ]; then - shutdown_server + # Do not shutdown if not able to save + if save_server; then + shutdown_server + else + return_val=1 + fi else return_val=1 fi diff --git a/scripts/restore.sh b/scripts/restore.sh index 5ab88a25b..fa2eca9c9 100644 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -61,7 +61,6 @@ if [ -f "$BACKUP_FILE" ]; then if [ "${RCON_ENABLED}" = true ]; then printf "\e[0;32m*****SHUTDOWN SERVER*****\e[0m\n" - save_server shutdown_server else echo "RCON is not enabled. Please enable RCON to use this feature. Unable to restore backup." From 2c8dbf6a5a908228f4e1350e6810520f7ee96330 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Fri, 16 Feb 2024 20:58:04 -0500 Subject: [PATCH 20/49] Changed mtime, message_prefix, return_val to local vars --- scripts/helper_functions.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 8aff847e4..84be1c677 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -83,9 +83,9 @@ get_player_count() { # Returns 0 on success # If mtime is not an integer and there are players in game then return 1 countdown_message() { - mtime="$1" - message_prefix="$2" - return_val=0 + local mtime="$1" + local message_prefix="$2" + local return_val=0 if [[ "${mtime}" =~ ^[0-9]+$ ]]; then for ((i = "${mtime}" ; i > 0 ; i--)); do From 396a9fb676239bfb2589eeca76709417752c02f0 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 17 Feb 2024 01:05:23 -0500 Subject: [PATCH 21/49] Removed rcon-cli save/shutdown in init.sh --- scripts/init.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/init.sh b/scripts/init.sh index 35ee2253a..2edc42c5a 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -18,10 +18,8 @@ term_handler() { su steam -c "/home/steam/server/discord.sh '${DISCORD_PRE_SHUTDOWN_MESSAGE}' in-progress" & fi - if [ "${RCON_ENABLED,,}" = true ]; then - rcon-cli save - rcon-cli "shutdown 1" - else # Does not save + if ! shutdown_server; then + # If it fails then kill the server kill -SIGTERM "$(pidof PalServer-Linux-Test)" fi From ace7b183f8efd0141fffbc7d6b44e2b9a478652d Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 17 Feb 2024 01:31:37 -0500 Subject: [PATCH 22/49] Fixed shutdown --- scripts/helper_functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index a91d9ea20..c2bbf030a 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -100,7 +100,7 @@ shutdown_server() { if [ "${RCON_ENABLED,,}" = true ]; then # Do not shutdown if not able to save if save_server; then - shutdown_server + rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" else return_val=1 fi From dc66c8ba152df5ee0ec1ef673ad55b428fc13215 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 17 Feb 2024 14:08:41 -0500 Subject: [PATCH 23/49] Merge branch 'main' into update-countdown --- .../configuration/server-settings.md | 4 +- scripts/auto_reboot.sh | 12 +- scripts/backup.sh | 56 ++++---- scripts/compile-settings.sh | 8 +- scripts/discord.sh | 10 +- scripts/helper_functions.sh | 122 +++++++++++++++++- scripts/init.sh | 14 +- scripts/restore.sh | 59 +++++---- scripts/start.sh | 78 +++++------ scripts/update.sh | 40 ++---- 10 files changed, 247 insertions(+), 156 deletions(-) diff --git a/docusaurus/docs/getting-started/configuration/server-settings.md b/docusaurus/docs/getting-started/configuration/server-settings.md index fecd11dfc..c8089a0ab 100644 --- a/docusaurus/docs/getting-started/configuration/server-settings.md +++ b/docusaurus/docs/getting-started/configuration/server-settings.md @@ -39,10 +39,10 @@ It is highly recommended you set the following environment values before startin | BACKUP_ENABLED | Enables automatic backups | true | true/false | | DELETE_OLD_BACKUPS | Delete backups after a certain number of days | false | true/false | | OLD_BACKUP_DAYS | How many days to keep backups | 30 | any positive integer | -| AUTO_UPDATE_CRON_EXPRESSION | Setting affects frequency of automatic updates. | 0 \* \* \* \* | Needs a Cron-Expression - See [Configuring Automatic Updates with Cron](https://palworld-server-docker.loef.dev/guides/automatic-reboots) | +| AUTO_UPDATE_CRON_EXPRESSION | Setting affects frequency of automatic updates. | 0 \* \* \* \* | Needs a Cron-Expression - See [Configuring Automatic Updates with Cron](https://palworld-server-docker.loef.dev/guides/automatic-updates) | | AUTO_UPDATE_ENABLED | Enables automatic updates | false | true/false | | AUTO_UPDATE_WARN_MINUTES | How long to wait to update the server, after the player were informed. | 30 | !0 | -| AUTO_REBOOT_CRON_EXPRESSION | Setting affects frequency of automatic updates. | 0 0 \* \* \* | Needs a Cron-Expression - See [Configuring Automatic Reboots with Cron](https://palworld-server-docker.loef.dev/guides/automatic-updates) | +| AUTO_REBOOT_CRON_EXPRESSION | Setting affects frequency of automatic updates. | 0 0 \* \* \* | Needs a Cron-Expression - See [Configuring Automatic Reboots with Cron](https://palworld-server-docker.loef.dev/guides/automatic-reboots) | | AUTO_REBOOT_ENABLED | Enables automatic reboots | false | true/false | | AUTO_REBOOT_WARN_MINUTES | How long to wait to reboot the server, after the player were informed. | 5 | !0 | | AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE | Restart the Server even if there are players online. | false | true/false | diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index 700df3bcd..fdf4e11b2 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -7,18 +7,20 @@ if [ "${RCON_ENABLED,,}" = true ]; then players_count=$(get_player_count) if [ "$players_count" -gt 0 ]; then - echo "There are ${players_count} players online. Skipping auto reboot." - exit 1 + LogWarn "There are ${players_count} players online. Skipping auto reboot." + exit 0 fi fi if countdown_message "${AUTO_REBOOT_WARN_MINUTES}" "The_Server_will_reboot"; then shutdown_server elif [ -z "${AUTO_REBOOT_WARN_MINUTES}" ]; then - echo "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is empty" + LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is empty" + exit 0 else - echo "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}" + LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}" fi else - echo "Unable to reboot. RCON is required." + LogWarn "Unable to reboot. RCON is required." + exit 1 fi diff --git a/scripts/backup.sh b/scripts/backup.sh index f3cc99685..5cfe83549 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -1,47 +1,41 @@ #!/bin/bash +# shellcheck source=/dev/null +source "/home/steam/server/helper_functions.sh" -if [ -n "${DISCORD_WEBHOOK_URL}" ]; then - /home/steam/server/discord.sh "Creating backup..." "in-progress" & -fi - +DiscordMessage "Creating backup..." "in-progress" save_server DATE=$(date +"%Y-%m-%d_%H-%M-%S") FILE_PATH="/palworld/backups/palworld-save-${DATE}.tar.gz" cd /palworld/Pal/ || exit -echo "Creating backup" +LogAction "Creating backup" tar -zcf "$FILE_PATH" "Saved/" if [ "$(id -u)" -eq 0 ]; then chown steam:steam "$FILE_PATH" fi +LogInfo "Backup created at ${FILE_PATH}" +DiscordMessage "Backup created at ${FILE_PATH}" "success" + +if [ "${DELETE_OLD_BACKUPS,,}" != true ]; then + exit 0 +fi + +if [ -z "${OLD_BACKUP_DAYS}" ]; then + LogWarn "Unable to delete old backups, OLD_BACKUP_DAYS is empty." + DiscordMessage "Unable to delete old backups, OLD_BACKUP_DAYS is empty." "warn" + exit 0 +fi -echo "Backup created at ${FILE_PATH}" -if [ -n "${DISCORD_WEBHOOK_URL}" ]; then - /home/steam/server/discord.sh "Backup created at ${FILE_PATH}" "success" +if [[ "${OLD_BACKUP_DAYS}" =~ ^[0-9]+$ ]]; then + LogAction "Removing Old Backups" + LogInfo "Removing backups older than ${OLD_BACKUP_DAYS} days" + DiscordMessage "Removing backups older than ${OLD_BACKUP_DAYS} days..." "in-progress" + find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -type f -name 'palworld-save-*.tar.gz' -print -delete + DiscordMessage "Removed backups older than ${OLD_BACKUP_DAYS} days" "success" + exit 0 fi -if [ "${DELETE_OLD_BACKUPS,,}" = true ]; then - - if [ -z "${OLD_BACKUP_DAYS}" ]; then - echo "Unable to delete old backups, OLD_BACKUP_DAYS is empty." - if [ -n "${DISCORD_WEBHOOK_URL}" ]; then - /home/steam/server/discord.sh "Unable to delete old backups, OLD_BACKUP_DAYS is empty." "warn" - fi - elif [[ "${OLD_BACKUP_DAYS}" =~ ^[0-9]+$ ]]; then - echo "Removing backups older than ${OLD_BACKUP_DAYS} days" - if [ -n "${DISCORD_WEBHOOK_URL}" ] && [ -n "${DISCORD_PRE_BACKUP_DELETE_MESSAGE}" ]; then - /home/steam/server/discord.sh "Removing backups older than ${OLD_BACKUP_DAYS} days..." "in-progress" & - fi - find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -type f -name 'palworld-save-*.tar.gz' -print -delete - if [ -n "${DISCORD_WEBHOOK_URL}" ]; then - /home/steam/server/discord.sh "Removed backups older than ${OLD_BACKUP_DAYS} days" "success" - fi - else - echo "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" - if [ -n "${DISCORD_WEBHOOK_URL}" ]; then - /home/steam/server/discord.sh "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" "failure" - fi - fi -fi \ No newline at end of file +LogError "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" +DiscordMessage "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" "failure" \ No newline at end of file diff --git a/scripts/compile-settings.sh b/scripts/compile-settings.sh index 4c4f93ce8..d314b42e0 100755 --- a/scripts/compile-settings.sh +++ b/scripts/compile-settings.sh @@ -9,17 +9,17 @@ mkdir -p "$config_dir" || exit # If file exists then check if it is writable if [ -f "$config_file" ]; then if ! isWritable "$config_file"; then - echo "Unable to create $config_file" + LogError "Unable to create $config_file" exit 1 fi # If file does not exist then check if the directory is writable elif ! isWritable "$config_dir"; then # Exiting since the file does not exist and the directory is not writable. - echo "Unable to create $config_file" + LogError "Unable to create $config_file" exit 1 fi -echo "Compiling PalWorldSettings.ini..." +LogAction "Compiling PalWorldSettings.ini" export DIFFICULTY=${DIFFICULTY:-None} export DAYTIME_SPEEDRATE=${DAYTIME_SPEEDRATE:-1.000000} @@ -158,4 +158,4 @@ cat > "$config_file" </dev/null done @@ -43,7 +43,7 @@ fi mapfile -t restore_pids < <(pgrep restore) if [ "${#restore_pids[@]}" -ne 0 ]; then - echo "Waiting for restore to finish" + LogInfo "Waiting for restore to finish" for pid in "${restore_pids[@]}"; do tail --pid="$pid" -f 2>/dev/null done diff --git a/scripts/restore.sh b/scripts/restore.sh index fa2eca9c9..3b432e6ec 100644 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -1,9 +1,11 @@ #!/bin/bash +# shellcheck source=/dev/null +source "/home/steam/server/helper_functions.sh" # Backup file directory path BACKUP_DIRECTORY_PATH="/palworld/backups" -# Resotre path +# Restore path RESTORE_PATH="/palworld/Pal" # Copy the save file before restore temporary path @@ -11,83 +13,83 @@ TMP_SAVE_PATH="/palworld/backups/restore-"$(date +"%Y-%m-%d_%H-%M-%S") # shellcheck disable=SC2317 term_error_handler() { - echo "An error occurred during server shutdown." + LogError "An error occurred during server shutdown." exit 1 } # shellcheck disable=SC2317 restore_error_handler() { - printf "\033[0;31mAn error occurred during restore.\033[0m\n" + LogError "Error occurred during restore." if [ -d "$TMP_SAVE_PATH/Saved" ]; then read -rp "I have a backup before recovery can proceed. Do you want to recovery it? (y/n): " RUN_ANSWER if [[ ${RUN_ANSWER,,} == "y" ]]; then rm -rf "$RESTORE_PATH/Saved" mv "$TMP_SAVE_PATH/Saved" "$RESTORE_PATH" - printf "\e[0;32mRecovery complete.\e[0m\n" + PrintSuccess "Recovery Complete" fi fi - echo "Clean up the temporary directory." + LogInfo "Clean up the temporary directory." rm -rf "$TMP_PATH" "$TMP_SAVE_PATH" exit 1 } if [ "${RCON_ENABLED}" != true ]; then - echo "RCON is not enabled. Please enable RCON to use this feature." + LogWarn "RCON is not enabled. Please enable RCON to use this feature." exit 1 fi # Show up backup list -echo "Backup List:" +LogInfo "Backup List:" mapfile -t BACKUP_FILES < <(find "$BACKUP_DIRECTORY_PATH" -type f -name "*.tar.gz" | sort) select BACKUP_FILE in "${BACKUP_FILES[@]}"; do if [ -n "$BACKUP_FILE" ]; then - echo "Selected backup: $BACKUP_FILE" + LogInfo "Selected backup: $BACKUP_FILE" break else - echo "Invalid selection. Please try again." + LogWarn "Invalid selection. Please try again." fi done if [ -f "$BACKUP_FILE" ]; then - printf "\033[0;31mThis script has been designed to help you restore; however, I am not responsible for any data loss. It is recommended that you create a backup beforehand, and in the event of script failure, be prepared to restore it manually.\033[0m\n" - echo "Do you understand the above and would you like to proceed with this command?" + LogInfo "This script has been designed to help you restore; however, I am not responsible for any data loss. It is recommended that you create a backup beforehand, and in the event of script failure, be prepared to restore it manually." + LogInfo "Do you understand the above and would you like to proceed with this command?" read -rp "When you run it, the server will be stopped and the recovery will proceed. (y/n): " RUN_ANSWER if [[ ${RUN_ANSWER,,} == "y" ]]; then - printf "\e[0;32m*****STARTING PROCESS*****\e[0m\n" + LogAction "Starting Recovery Process" # Shutdown server trap 'term_error_handler' ERR if [ "${RCON_ENABLED}" = true ]; then - printf "\e[0;32m*****SHUTDOWN SERVER*****\e[0m\n" + LogAction "Shutting Down Server" shutdown_server else - echo "RCON is not enabled. Please enable RCON to use this feature. Unable to restore backup." + LogWarn "RCON is not enabled. Please enable RCON to use this feature. Unable to restore backup." exit 1 fi mapfile -t server_pids < <(pgrep PalServer-Linux-Test) if [ "${#server_pids[@]}" -ne 0 ]; then - echo "Waiting for Palworld to exit.." + LogInfo "Waiting for Palworld to exit.." for pid in "${server_pids[@]}"; do tail --pid="$pid" -f 2>/dev/null done fi - printf "\e[0;32mShutdown complete.\e[0m\n" + LogSuccess "Shutdown Complete" trap - ERR trap 'restore_error_handler' ERR - - printf "\e[0;32m*****START RESTORE*****\e[0m\n" + + LogAction "Starting Restore" # Recheck the backup file if [ -f "$BACKUP_FILE" ]; then # Copy the save file before restore if [ -d "$RESTORE_PATH/Saved" ]; then - echo "Saves the current state before the restore proceeds." - echo "$TMP_SAVE_PATH" + LogInfo "Saves the current state before the restore proceeds." + LogInfo "$TMP_SAVE_PATH" mkdir -p "$TMP_SAVE_PATH" if [ "$(id -u)" -eq 0 ]; then chown steam:steam "$TMP_SAVE_PATH" @@ -97,8 +99,7 @@ if [ -f "$BACKUP_FILE" ]; then while [ ! -d "$TMP_SAVE_PATH/Saved" ]; do sleep 1 done - - printf "\e[0;32mSave complete.\e[0m\n" + LogSuccess "Save Complete" fi # Create tmp directory @@ -115,22 +116,20 @@ if [ -f "$BACKUP_FILE" ]; then # Move the backup file to the restore directory \cp -rf -f "$TMP_PATH/Saved/" "$RESTORE_PATH" - - echo "Clean up the temporary directory." + LogInfo "Clean up the temporary directory." rm -rf "$TMP_PATH" "$TMP_SAVE_PATH" - - printf "\e[0;32mRestore complete!!!! Please restart the Docker container\e[0m\n" - + LogSuccess "Restore Complete" + LogInfo "Please restart the container" exit 0 else - echo "The selected backup file does not exist." + LogError "The selected backup file does not exist." exit 1 fi else - echo "Abort the recovery." + LogWarn "Abort the recovery." exit 1 fi else - echo "The selected backup file does not exist." + LogError "The selected backup file does not exist." exit 1 fi \ No newline at end of file diff --git a/scripts/start.sh b/scripts/start.sh index 704e9e879..9a0fa4b08 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -14,23 +14,27 @@ architecture=$(dpkg --print-architecture) # Get host kernel page size kernel_page_size=$(getconf PAGESIZE) -# Check kernel page size for arm64 hosts before running steamcmd +# Check kernel page size for arm64 hosts before running steamcmdac if [ "$architecture" == "arm64" ] && [ "$kernel_page_size" != "4096" ]; then - echo "Only ARM64 hosts with 4k page size is supported." + LogError "Only ARM64 hosts with 4k page size is supported." exit 1 fi -if [ "${UPDATE_ON_BOOT,,}" = true ]; then - printf "\e[0;32m%s\e[0m\n" "*****STARTING INSTALL/UPDATE*****" - - if [ -n "${DISCORD_WEBHOOK_URL}" ] && [ -n "${DISCORD_PRE_UPDATE_BOOT_MESSAGE}" ]; then - /home/steam/server/discord.sh "${DISCORD_PRE_UPDATE_BOOT_MESSAGE}" "in-progress" & - fi - - /home/steam/steamcmd/steamcmd.sh +@sSteamCmdForcePlatformType linux +@sSteamCmdForcePlatformBitness 64 +force_install_dir "/palworld" +login anonymous +app_update 2394010 validate +quit +IsInstalled +ServerInstalled=$? +if [ "$ServerInstalled" == 1 ]; then + LogInfo "Server installation not detected." + LogAction "Starting Installation" + InstallServer +fi - if [ -n "${DISCORD_WEBHOOK_URL}" ] && [ -n "${DISCORD_POST_UPDATE_BOOT_MESSAGE}" ]; then - /home/steam/server/discord.sh "${DISCORD_POST_UPDATE_BOOT_MESSAGE}" "success" +# Update Only If Already Installed +if [ "$ServerInstalled" == 0 ] && [ "${UPDATE_ON_BOOT,,}" == true ]; then + UpdateRequired + IsUpdateRequired=$? + if [ "$IsUpdateRequired" == 0 ]; then + LogAction "Starting Update" + InstallServer fi fi @@ -46,13 +50,17 @@ else STARTCOMMAND=("./PalServer.sh") fi + +#Validate Installation if ! fileExists "${STARTCOMMAND[0]}"; then - echo "Try restarting with UPDATE_ON_BOOT=true" + LogError "Server Not Installed Properly" exit 1 fi + isReadable "${STARTCOMMAND[0]}" || exit isExecutable "${STARTCOMMAND[0]}" || exit +# Prepare Arguments if [ -n "${PORT}" ]; then STARTCOMMAND+=("-port=${PORT}") fi @@ -70,14 +78,12 @@ if [ "${MULTITHREADING,,}" = true ]; then fi if [ "${DISABLE_GENERATE_SETTINGS,,}" = true ]; then - printf "\e[0;32m%s\e[0m\n" "*****CHECKING FOR EXISTING CONFIG*****" - printf "\e[0;32m%s\e[0m\n" "***Env vars will not be applied due to DISABLE_GENERATE_SETTINGS being set to TRUE!***" + LogAction "GENERATING CONFIG" + LogWarn "Env vars will not be applied due to DISABLE_GENERATE_SETTINGS being set to TRUE!" # shellcheck disable=SC2143 if [ ! "$(grep -s '[^[:space:]]' /palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini)" ]; then - - printf "\e[0;32m%s\e[0m\n" "*****GENERATING CONFIG*****" - + LogAction "GENERATING CONFIG" # Server will generate all ini files after first run. if [ "$architecture" == "arm64" ]; then timeout --preserve-status 15s ./PalServer-arm64.sh 1> /dev/null @@ -90,31 +96,30 @@ if [ "${DISABLE_GENERATE_SETTINGS,,}" = true ]; then cp /palworld/DefaultPalWorldSettings.ini /palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini fi else - printf "\e[0;32m%s\e[0m\n" "*****GENERATING CONFIG*****" - printf "\e[0;32m%s\e[0m\n" "***Using Env vars to create PalWorldSettings.ini***" + LogAction "GENERATING CONFIG" + LogInfo "Using Env vars to create PalWorldSettings.ini" /home/steam/server/compile-settings.sh || exit fi -printf "\e[0;32m%s\e[0m\n" "*****GENERATING CRONTAB*****" - +LogAction "GENERATING CRONTAB" rm -f "/home/steam/server/crontab" if [ "${BACKUP_ENABLED,,}" = true ]; then - echo "BACKUP_ENABLED=${BACKUP_ENABLED,,}" - echo "Adding cronjob for auto backups" + LogInfo "BACKUP_ENABLED=${BACKUP_ENABLED,,}" + LogInfo "Adding cronjob for auto backups" echo "$BACKUP_CRON_EXPRESSION bash /usr/local/bin/backup" >> "/home/steam/server/crontab" supercronic -quiet -test "/home/steam/server/crontab" || exit fi if [ "${AUTO_UPDATE_ENABLED,,}" = true ] && [ "${UPDATE_ON_BOOT}" = true ]; then - echo "AUTO_UPDATE_ENABLED=${AUTO_UPDATE_ENABLED,,}" - echo "Adding cronjob for auto updating" + LogInfo "AUTO_UPDATE_ENABLED=${AUTO_UPDATE_ENABLED,,}" + LogInfo "Adding cronjob for auto updating" echo "$AUTO_UPDATE_CRON_EXPRESSION bash /usr/local/bin/update" >> "/home/steam/server/crontab" supercronic -quiet -test "/home/steam/server/crontab" || exit fi if [ "${AUTO_REBOOT_ENABLED,,}" = true ] && [ "${RCON_ENABLED,,}" = true ]; then - echo "AUTO_REBOOT_ENABLED=${AUTO_REBOOT_ENABLED,,}" - echo "Adding cronjob for auto rebooting" + LogInfo "AUTO_REBOOT_ENABLED=${AUTO_REBOOT_ENABLED,,}" + LogInfo "Adding cronjob for auto rebooting" echo "$AUTO_REBOOT_CRON_EXPRESSION bash /home/steam/server/auto_reboot.sh" >> "/home/steam/server/crontab" supercronic -quiet -test "/home/steam/server/crontab" || exit fi @@ -122,9 +127,9 @@ fi if { [ "${AUTO_UPDATE_ENABLED,,}" = true ] && [ "${UPDATE_ON_BOOT,,}" = true ]; } || [ "${BACKUP_ENABLED,,}" = true ] || \ [ "${AUTO_REBOOT_ENABLED,,}" = true ]; then supercronic "/home/steam/server/crontab" & - echo "Cronjobs started" + LogInfo "Cronjobs started" else - echo "No Cronjobs found" + LogInfo "No Cronjobs found" fi # Configure RCON settings @@ -134,16 +139,11 @@ default: password: "${ADMIN_PASSWORD}" EOL -printf "\e[0;32m%s\e[0m\n" "*****STARTING SERVER*****" -if [ -n "${DISCORD_WEBHOOK_URL}" ] && [ -n "${DISCORD_PRE_START_MESSAGE}" ]; then - /home/steam/server/discord.sh "${DISCORD_PRE_START_MESSAGE}" "success" & -fi +LogAction "Starting Server" +DiscordMessage "${DISCORD_PRE_START_MESSAGE}" "success" echo "${STARTCOMMAND[*]}" "${STARTCOMMAND[@]}" -if [ -n "${DISCORD_WEBHOOK_URL}" ] && [ -n "${DISCORD_POST_SHUTDOWN_MESSAGE}" ]; then - /home/steam/server/discord.sh "${DISCORD_POST_SHUTDOWN_MESSAGE}" "failure" -fi - -exit 0 +DiscordMessage "${DISCORD_POST_SHUTDOWN_MESSAGE}" "failure" +exit 0 \ No newline at end of file diff --git a/scripts/update.sh b/scripts/update.sh index d26c545b4..d1254634b 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -2,34 +2,22 @@ # shellcheck source=/dev/null source "/home/steam/server/helper_functions.sh" -if [ "${UPDATE_ON_BOOT}" = false ]; then - echo "Update on Boot needs to be enabled for auto updating" - if [ -n "${DISCORD_WEBHOOK_URL}" ]; then - /home/steam/server/discord.sh "Update on Boot needs to be enabled for auto updating" "warn" - fi - exit 0 +UpdateRequired +updateRequired=$? +# Check if Update was actually required +if [ "$updateRequired" != 0 ]; then + exit 0 fi -temp_file=$(mktemp) -http_code=$(curl https://api.steamcmd.net/v1/info/2394010 --output "$temp_file" --silent --location --write-out "%{http_code}") - -CURRENT_MANIFEST=$(awk '/manifest/{count++} count==2 {print $2; exit}' /palworld/steamapps/appmanifest_2394010.acf) -TARGET_MANIFEST=$(grep -Po '"2394012".*"gid": "\d+"' <"$temp_file" | sed -r 's/.*("[0-9]+")$/\1/') -rm "$temp_file" - -if [ "$http_code" -ne 200 ]; then - echo "There was a problem reaching the Steam api. Unable to check for updates!" - if [ -n "${DISCORD_WEBHOOK_URL}" ]; then - /home/steam/server/discord.sh "There was a problem reaching the Steam api. Unable to check for updates!" "failure" & - 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 [ -z "$TARGET_MANIFEST" ]; then - echo "The server response does not contain the expected BuildID. Unable to check for updates!" - if [ -n "${DISCORD_WEBHOOK_URL}" ]; then - /home/steam/server/discord.sh "Steam servers response does not contain the expected BuildID. Unable to check for updates!" "failure" & - 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 @@ -44,12 +32,10 @@ if [ "$CURRENT_MANIFEST" != "$TARGET_MANIFEST" ]; then echo "An update is available" if [[ "${AUTO_UPDATE_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then - if [ -n "${DISCORD_WEBHOOK_URL}" ]; then - /home/steam/server/discord.sh "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" "info" & - fi + DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" fi if countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server_will_update"; then - echo "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST" + LogAction "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." rm /palworld/steamapps/appmanifest_2394010.acf backup From 53986bde958b40dda5324063cac3133dc24c5c52 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 17 Feb 2024 14:12:39 -0500 Subject: [PATCH 24/49] Removed echo in RCON --- scripts/helper_functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 6a9cfc80f..6e874f4ff 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -131,7 +131,7 @@ DiscordMessage() { # RCON Call RCON() { local args="$1" - echo rcon-cli -c /home/steam/server/rcon.yaml "$args" + rcon-cli -c /home/steam/server/rcon.yaml "$args" } From 043af585fca0658f29d66664315ae8d6a748c440 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 17 Feb 2024 14:14:08 -0500 Subject: [PATCH 25/49] Fixed spacing --- scripts/helper_functions.sh | 102 ++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 6e874f4ff..3ca99c60b 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -93,45 +93,45 @@ export YellowBoldText='\033[1;33m' # Yellow export CyanBoldText='\033[1;36m' # Cyan LogInfo() { - Log "$1" "$WhiteText" + Log "$1" "$WhiteText" } LogWarn() { - Log "$1" "$YellowBoldText" + Log "$1" "$YellowBoldText" } LogError() { - Log "$1" "$RedBoldText" + Log "$1" "$RedBoldText" } LogSuccess() { - Log "$1" "$GreenBoldText" + Log "$1" "$GreenBoldText" } LogAction() { - Log "$1" "$CyanBoldText" "****" "****" + Log "$1" "$CyanBoldText" "****" "****" } Log() { - local message="$1" - local color="$2" - local prefix="$3" - local suffix="$4" - printf "$color%s$RESET$LINE" "$prefix$message$suffix" + local message="$1" + local color="$2" + local prefix="$3" + local suffix="$4" + printf "$color%s$RESET$LINE" "$prefix$message$suffix" } # Send Discord Message # Level is optional variable defaulting to info DiscordMessage() { - local message="$1" - local level="$2" - if [ -n "$level" ]; then - level="info" - fi - if [ -n "${DISCORD_WEBHOOK_URL}" ]; then - /home/steam/server/discord.sh "$message" "$level" & - fi + local message="$1" + local level="$2" + if [ -n "$level" ]; then + level="info" + fi + if [ -n "${DISCORD_WEBHOOK_URL}" ]; then + /home/steam/server/discord.sh "$message" "$level" & + fi } # RCON Call RCON() { - local args="$1" - rcon-cli -c /home/steam/server/rcon.yaml "$args" + local args="$1" + rcon-cli -c /home/steam/server/rcon.yaml "$args" } @@ -139,52 +139,52 @@ RCON() { # Returns 1 if Update NOT Required # Returns 2 if Check Failed UpdateRequired() { -LogAction "Checking for new update" + LogAction "Checking for new update" -temp_file=$(mktemp) -http_code=$(curl https://api.steamcmd.net/v1/info/2394010 --output "$temp_file" --silent --location --write-out "%{http_code}") -TARGET_MANIFEST=$(grep -Po '"2394012".*"gid": "\d+"' <"$temp_file" | sed -r 's/.*("[0-9]+")$/\1/') + temp_file=$(mktemp) + http_code=$(curl https://api.steamcmd.net/v1/info/2394010 --output "$temp_file" --silent --location --write-out "%{http_code}") + TARGET_MANIFEST=$(grep -Po '"2394012".*"gid": "\d+"' <"$temp_file" | sed -r 's/.*("[0-9]+")$/\1/') -CURRENT_MANIFEST=$(awk '/manifest/{count++} count==2 {print $2; exit}' /palworld/steamapps/appmanifest_2394010.acf) -rm "$temp_file" + CURRENT_MANIFEST=$(awk '/manifest/{count++} count==2 {print $2; exit}' /palworld/steamapps/appmanifest_2394010.acf) + rm "$temp_file" -if [ "$http_code" -ne 200 ]; then - LogError "There was a problem reaching the Steam api. Unable to check for updates!" - DiscordMessage "There was a problem reaching the Steam api. Unable to check for updates!" "failure" - return 2 -fi + if [ "$http_code" -ne 200 ]; then + LogError "There was a problem reaching the Steam api. Unable to check for updates!" + DiscordMessage "There was a problem reaching the Steam api. Unable to check for updates!" "failure" + return 2 + fi -if [ -z "$TARGET_MANIFEST" ]; then - LogError "The server response does not contain the expected BuildID. Unable to check for updates!" - DiscordMessage "Steam servers response does not contain the expected BuildID. Unable to check for updates!" "failure" - return 2 -fi + if [ -z "$TARGET_MANIFEST" ]; then + LogError "The server response does not contain the expected BuildID. Unable to check for updates!" + DiscordMessage "Steam servers response does not contain the expected BuildID. Unable to check for updates!" "failure" + return 2 + fi -if [ "$CURRENT_MANIFEST" != "$TARGET_MANIFEST" ]; then - LogInfo "An Update Is Available." - LogInfo "Current Version: $CURRENT_MANIFEST" - LogInfo "Latest Version: $TARGET_MANIFEST." - return 0 -fi + if [ "$CURRENT_MANIFEST" != "$TARGET_MANIFEST" ]; then + LogInfo "An Update Is Available." + LogInfo "Current Version: $CURRENT_MANIFEST" + LogInfo "Latest Version: $TARGET_MANIFEST." + return 0 + fi -LogSuccess "The Server is up to date!" -return 1 + LogSuccess "The Server is up to date!" + return 1 } InstallServer() { - DiscordMessage "${DISCORD_PRE_UPDATE_BOOT_MESSAGE}" "in-progress" - /home/steam/steamcmd/steamcmd.sh +@sSteamCmdForcePlatformType linux +@sSteamCmdForcePlatformBitness 64 +force_install_dir "/palworld" +login anonymous +app_update 2394010 validate +quit - DiscordMessage "${DISCORD_POST_UPDATE_BOOT_MESSAGE}" "success" + DiscordMessage "${DISCORD_PRE_UPDATE_BOOT_MESSAGE}" "in-progress" + /home/steam/steamcmd/steamcmd.sh +@sSteamCmdForcePlatformType linux +@sSteamCmdForcePlatformBitness 64 +force_install_dir "/palworld" +login anonymous +app_update 2394010 validate +quit + DiscordMessage "${DISCORD_POST_UPDATE_BOOT_MESSAGE}" "success" } # Returns 0 if game is installed # Returns 1 if game is not installed IsInstalled() { - if [ -e /palworld/PalServer.sh ] && [ -e /palworld/steamapps/appmanifest_2394010.acf ]; then - return 0 - fi - return 1 + if [ -e /palworld/PalServer.sh ] && [ -e /palworld/steamapps/appmanifest_2394010.acf ]; then + return 0 + fi + return 1 } # Saves the server From 6e7751c6ceee89e99e9058032732de82198a6be6 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 17 Feb 2024 14:24:31 -0500 Subject: [PATCH 26/49] Moved RCON check to RCON function in all helper functions --- scripts/helper_functions.sh | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 3ca99c60b..657fe4b2c 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -71,12 +71,15 @@ isExecutable() { # Outputs the player count if rcon is enabled get_player_count() { local player_list - if [ "${RCON_ENABLED,,}" != true ]; then + local return_val=0 + if player_list=$(RCON "ShowPlayers"); then + echo -n "${player_list}" | wc -l + else echo 0 - return 0 + return_val=1 fi - player_list=$(RCON "ShowPlayers") - echo -n "${player_list}" | wc -l + + return "$return_val" } # @@ -130,8 +133,14 @@ DiscordMessage() { # RCON Call RCON() { + local return_val=0 local args="$1" - rcon-cli -c /home/steam/server/rcon.yaml "$args" + if [ "${RCON_ENABLED,,}" = true ]; then + rcon-cli -c /home/steam/server/rcon.yaml "$args" + else + return_val=1 + fi + return "$return_val" } @@ -192,9 +201,7 @@ IsInstalled() { # Returns 1 if it is not able to save save_server() { local return_val=0 - if [ "${RCON_ENABLED,,}" = true ]; then - RCON save - else + if ! RCON save; then return_val=1 fi return "$return_val" @@ -205,11 +212,9 @@ save_server() { # Returns 1 if it is not able to be shutdown shutdown_server() { local return_val=0 - if [ "${RCON_ENABLED,,}" = true ]; then - # Do not shutdown if not able to save - if save_server; then - RCON "shutdown 1" - else + # Do not shutdown if not able to save + if save_server; then + if ! RCON "shutdown 1"; then return_val=1 fi else From 624d9ee17e81b08e0b783892c6141bf87147ff14 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 17 Feb 2024 14:30:03 -0500 Subject: [PATCH 27/49] Removed checking exit code in update.sh --- scripts/update.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/update.sh b/scripts/update.sh index d1254634b..fdbc6a96a 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -2,11 +2,9 @@ # shellcheck source=/dev/null source "/home/steam/server/helper_functions.sh" -UpdateRequired -updateRequired=$? # Check if Update was actually required -if [ "$updateRequired" != 0 ]; then - exit 0 +if ! UpdateRequired; then + exit 0 fi if [ "${UPDATE_ON_BOOT}" = false ]; then From a35af0191874f8cb875da19f5b11dcd005166fe3 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 17 Feb 2024 14:37:35 -0500 Subject: [PATCH 28/49] Fixed update.sh issues from merge --- scripts/update.sh | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/scripts/update.sh b/scripts/update.sh index fdbc6a96a..c79f87862 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -19,30 +19,18 @@ if [ "${RCON_ENABLED,,}" = false ]; then exit 1 fi -if [ "$CURRENT_MANIFEST" != "$TARGET_MANIFEST" ]; then - if [ "${RCON_ENABLED,,}" != true ]; then - echo "An update is available however auto updating without rcon is not supported" - if [ -n "${DISCORD_WEBHOOK_URL}" ]; then - /home/steam/server/discord.sh "An update is available however auto updating without rcon is not supported" "warn" - fi - exit 0 - fi +if [[ "${AUTO_UPDATE_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then + DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" +fi - echo "An update is available" - if [[ "${AUTO_UPDATE_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then - DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" - fi - if countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server_will_update"; then - LogAction "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." - rm /palworld/steamapps/appmanifest_2394010.acf +if countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server_will_update"; then + LogAction "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." + rm /palworld/steamapps/appmanifest_2394010.acf - backup - shutdown_server - elif [ -z "${AUTO_UPDATE_WARN_MINUTES}" ]; then - echo "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is empty." - else - echo "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is not an integer: ${AUTO_UPDATE_WARN_MINUTES}" - fi + backup + shutdown_server +elif [ -z "${AUTO_UPDATE_WARN_MINUTES}" ]; then + LogWarn "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is empty." else - echo "The Server is up to date!" + LogWarn "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is not an integer: ${AUTO_UPDATE_WARN_MINUTES}" fi From 0847f7bcb62b6de89126948968d11a945b309033 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 17 Feb 2024 14:42:49 -0500 Subject: [PATCH 29/49] Changed if in update.sh --- scripts/update.sh | 52 +++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/scripts/update.sh b/scripts/update.sh index c79f87862..531e6645f 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -3,34 +3,32 @@ source "/home/steam/server/helper_functions.sh" # Check if Update was actually required -if ! UpdateRequired; then - exit 0 -fi +if UpdateRequired; then + 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 [ "${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,,}" = 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 [ "${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 [[ "${AUTO_UPDATE_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then - DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" -fi + if countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server_will_update"; then + LogAction "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." + rm /palworld/steamapps/appmanifest_2394010.acf -if countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server_will_update"; then - LogAction "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." - rm /palworld/steamapps/appmanifest_2394010.acf - - backup - shutdown_server -elif [ -z "${AUTO_UPDATE_WARN_MINUTES}" ]; then - LogWarn "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is empty." -else - LogWarn "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is not an integer: ${AUTO_UPDATE_WARN_MINUTES}" -fi + backup + shutdown_server + elif [ -z "${AUTO_UPDATE_WARN_MINUTES}" ]; then + LogWarn "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is empty." + else + LogWarn "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is not an integer: ${AUTO_UPDATE_WARN_MINUTES}" + fi +fi \ No newline at end of file From ca6b52f06dc5b5f011b6a31fa7ca054c869e312a Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 17 Feb 2024 14:48:07 -0500 Subject: [PATCH 30/49] Changed shutdown to DoExit, resolves #395 --- scripts/helper_functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 657fe4b2c..782913eab 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -214,7 +214,7 @@ shutdown_server() { local return_val=0 # Do not shutdown if not able to save if save_server; then - if ! RCON "shutdown 1"; then + if ! RCON "DoExit"; then return_val=1 fi else From 381d8459c33a0b9f7d9452147f58ba05352c0c92 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 17 Feb 2024 14:56:47 -0500 Subject: [PATCH 31/49] Updated structure of backup.sh --- scripts/backup.sh | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index 5cfe83549..0fe3c5ad0 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -19,23 +19,20 @@ LogInfo "Backup created at ${FILE_PATH}" DiscordMessage "Backup created at ${FILE_PATH}" "success" if [ "${DELETE_OLD_BACKUPS,,}" != true ]; then - exit 0 + if [ -z "${OLD_BACKUP_DAYS}" ]; then + LogWarn "Unable to delete old backups, OLD_BACKUP_DAYS is empty." + DiscordMessage "Unable to delete old backups, OLD_BACKUP_DAYS is empty." "warn" + exit 1 + fi + + if [[ "${OLD_BACKUP_DAYS}" =~ ^[0-9]+$ ]]; then + LogAction "Removing Old Backups" + LogInfo "Removing backups older than ${OLD_BACKUP_DAYS} days" + DiscordMessage "Removing backups older than ${OLD_BACKUP_DAYS} days..." "in-progress" + find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -type f -name 'palworld-save-*.tar.gz' -print -delete + DiscordMessage "Removed backups older than ${OLD_BACKUP_DAYS} days" "success" + else + LogError "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" + DiscordMessage "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" "failure" + fi fi - -if [ -z "${OLD_BACKUP_DAYS}" ]; then - LogWarn "Unable to delete old backups, OLD_BACKUP_DAYS is empty." - DiscordMessage "Unable to delete old backups, OLD_BACKUP_DAYS is empty." "warn" - exit 0 -fi - -if [[ "${OLD_BACKUP_DAYS}" =~ ^[0-9]+$ ]]; then - LogAction "Removing Old Backups" - LogInfo "Removing backups older than ${OLD_BACKUP_DAYS} days" - DiscordMessage "Removing backups older than ${OLD_BACKUP_DAYS} days..." "in-progress" - find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -type f -name 'palworld-save-*.tar.gz' -print -delete - DiscordMessage "Removed backups older than ${OLD_BACKUP_DAYS} days" "success" - exit 0 -fi - -LogError "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" -DiscordMessage "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" "failure" \ No newline at end of file From 75021bdd810c73d510dc890bc1acbc914ca730d8 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 17 Feb 2024 14:58:22 -0500 Subject: [PATCH 32/49] Updated exit code in update.sh --- scripts/auto_reboot.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index fdf4e11b2..06a62e392 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -16,7 +16,7 @@ if [ "${RCON_ENABLED,,}" = true ]; then shutdown_server elif [ -z "${AUTO_REBOOT_WARN_MINUTES}" ]; then LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is empty" - exit 0 + exit 1 else LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}" fi From 9b075a04dabaa19fdd7dd4a1c1d955b6c56f72f7 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 17 Feb 2024 15:05:06 -0500 Subject: [PATCH 33/49] Updated start.sh --- scripts/start.sh | 50 ++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/scripts/start.sh b/scripts/start.sh index 9a0fa4b08..8555cab68 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -20,9 +20,7 @@ if [ "$architecture" == "arm64" ] && [ "$kernel_page_size" != "4096" ]; then exit 1 fi -IsInstalled -ServerInstalled=$? -if [ "$ServerInstalled" == 1 ]; then +if ! IsInstalled; then LogInfo "Server installation not detected." LogAction "Starting Installation" InstallServer @@ -30,9 +28,7 @@ fi # Update Only If Already Installed if [ "$ServerInstalled" == 0 ] && [ "${UPDATE_ON_BOOT,,}" == true ]; then - UpdateRequired - IsUpdateRequired=$? - if [ "$IsUpdateRequired" == 0 ]; then + if UpdateRequired; then LogAction "Starting Update" InstallServer fi @@ -78,27 +74,27 @@ if [ "${MULTITHREADING,,}" = true ]; then fi if [ "${DISABLE_GENERATE_SETTINGS,,}" = true ]; then - LogAction "GENERATING CONFIG" - LogWarn "Env vars will not be applied due to DISABLE_GENERATE_SETTINGS being set to TRUE!" - - # shellcheck disable=SC2143 - if [ ! "$(grep -s '[^[:space:]]' /palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini)" ]; then - LogAction "GENERATING CONFIG" - # Server will generate all ini files after first run. - if [ "$architecture" == "arm64" ]; then - timeout --preserve-status 15s ./PalServer-arm64.sh 1> /dev/null - else - timeout --preserve-status 15s ./PalServer.sh 1> /dev/null - fi - - # Wait for shutdown - sleep 5 - cp /palworld/DefaultPalWorldSettings.ini /palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini - fi + LogAction "GENERATING CONFIG" + LogWarn "Env vars will not be applied due to DISABLE_GENERATE_SETTINGS being set to TRUE!" + + # shellcheck disable=SC2143 + if [ ! "$(grep -s '[^[:space:]]' /palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini)" ]; then + LogAction "GENERATING CONFIG" + # Server will generate all ini files after first run. + if [ "$architecture" == "arm64" ]; then + timeout --preserve-status 15s ./PalServer-arm64.sh 1> /dev/null + else + timeout --preserve-status 15s ./PalServer.sh 1> /dev/null + fi + + # Wait for shutdown + sleep 5 + cp /palworld/DefaultPalWorldSettings.ini /palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini + fi else - LogAction "GENERATING CONFIG" - LogInfo "Using Env vars to create PalWorldSettings.ini" - /home/steam/server/compile-settings.sh || exit + LogAction "GENERATING CONFIG" + LogInfo "Using Env vars to create PalWorldSettings.ini" + /home/steam/server/compile-settings.sh || exit fi LogAction "GENERATING CRONTAB" @@ -146,4 +142,4 @@ echo "${STARTCOMMAND[*]}" "${STARTCOMMAND[@]}" DiscordMessage "${DISCORD_POST_SHUTDOWN_MESSAGE}" "failure" -exit 0 \ No newline at end of file +exit 0 From 18ddb66dface4f6a26bc2e40444fd7139bd88433 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 17 Feb 2024 15:05:46 -0500 Subject: [PATCH 34/49] Fixed spacing in init.sh --- scripts/init.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/init.sh b/scripts/init.sh index ba28d6769..a65b68c32 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -16,7 +16,7 @@ chown -R steam:steam /palworld /home/steam/ # shellcheck disable=SC2317 term_handler() { - DiscordMessage "${DISCORD_PRE_SHUTDOWN_MESSAGE}" "in-progress" + DiscordMessage "${DISCORD_PRE_SHUTDOWN_MESSAGE}" "in-progress" if ! shutdown_server; then # If it fails then kill the server From 24e045b7aca65fb8898ab29445d2ec9e6b2f275a Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 17 Feb 2024 15:05:46 -0500 Subject: [PATCH 35/49] Fixed merge issue --- scripts/auto_reboot.sh | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index 3317dadcb..06a62e392 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -24,28 +24,3 @@ else LogWarn "Unable to reboot. RCON is required." exit 1 fi - -if [ -z "${AUTO_REBOOT_WARN_MINUTES}" ]; then - LogError "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is empty." - exit 0 -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 - RCON "broadcast The_Server_will_reboot_in_${i}_Minutes" - sleep "1m" - done - RCON save - RCON "shutdown 1" - exit 0 -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 e3ae1377473c402f36c5ad75dfa2d6491180cd90 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 17 Feb 2024 15:38:20 -0500 Subject: [PATCH 36/49] Fixed update/install in start --- scripts/start.sh | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/scripts/start.sh b/scripts/start.sh index 8555cab68..e4fde9d63 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -20,19 +20,18 @@ if [ "$architecture" == "arm64" ] && [ "$kernel_page_size" != "4096" ]; then exit 1 fi -if ! IsInstalled; then +if IsInstalled; then + # Update Only If Already Installed + if [ "${UPDATE_ON_BOOT,,}" == true ] && UpdateRequired; then + LogAction "Starting Update" + InstallServer + fi +else LogInfo "Server installation not detected." LogAction "Starting Installation" InstallServer fi -# Update Only If Already Installed -if [ "$ServerInstalled" == 0 ] && [ "${UPDATE_ON_BOOT,,}" == true ]; then - if UpdateRequired; then - LogAction "Starting Update" - InstallServer - fi -fi # Check if the architecture is arm64 if [ "$architecture" == "arm64" ]; then From b089211ac1cb927ff34cba0563d1504809b27163 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 17 Feb 2024 15:48:28 -0500 Subject: [PATCH 37/49] Added broadcast function. Partially Resolves #400 --- scripts/helper_functions.sh | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 782913eab..d7d9a8f6c 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -223,6 +223,19 @@ shutdown_server() { return "$return_val" } +# Given a message this will broadcast in game +# Since RCON does not support spaces this will replace all spaces with underscores +# Returns 0 on success +# Returns 1 if not able to broadcast +broadcast_command() { + local return_val=0 + # Replaces spaces with underscore + local message="${1// /_}" + if ! RCON "broadcast ${message}"; then + return_val=1 + fi + return "$return_val" +} # Given an amount of time in minutes and a message prefix # Returns 0 on success @@ -238,11 +251,11 @@ countdown_message() { break fi if [ "$i" -eq 1 ]; then - RCON "broadcast ${message_prefix}_in_${i}_minute" + broadcast_command "${message_prefix}_in_${i}_minute" sleep 30s - RCON "broadcast ${message_prefix}_in_30_seconds" + broadcast_command "${message_prefix}_in_30_seconds" sleep 20s - RCON "broadcast ${message_prefix}_in_10_seconds" + broadcast_command "${message_prefix}_in_10_seconds" sleep 10s else case "$i" in @@ -255,7 +268,7 @@ countdown_message() { 5 ) ;& 2 ) - RCON "broadcast ${message_prefix}_in_${i}_minutes" + broadcast_command "${message_prefix}_in_${i}_minutes" ;& * ) sleep 1m From 82536b423b061daf61a3859501dac7bea9d507ea Mon Sep 17 00:00:00 2001 From: Carlos Martinez Date: Sat, 17 Feb 2024 21:47:47 -0500 Subject: [PATCH 38/49] Update scripts/start.sh Co-authored-by: Luatan <74045606+Luatan@users.noreply.github.com> --- scripts/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/start.sh b/scripts/start.sh index e4fde9d63..0dd4a5338 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -74,7 +74,7 @@ fi if [ "${DISABLE_GENERATE_SETTINGS,,}" = true ]; then LogAction "GENERATING CONFIG" - LogWarn "Env vars will not be applied due to DISABLE_GENERATE_SETTINGS being set to TRUE!" + LogWarn "Environment variables will not be applied due to DISABLE_GENERATE_SETTINGS being set to TRUE!" # shellcheck disable=SC2143 if [ ! "$(grep -s '[^[:space:]]' /palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini)" ]; then From 131638dcedb4bf63d23eeb35e65992a29e3e3792 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 17 Feb 2024 22:30:05 -0500 Subject: [PATCH 39/49] Changed exit codes for countdown_message --- scripts/auto_reboot.sh | 21 ++++++---- scripts/helper_functions.sh | 78 ++++++++++++++++++++----------------- scripts/update.sh | 26 ++++++++----- 3 files changed, 71 insertions(+), 54 deletions(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index 06a62e392..fac6ee1a1 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -12,14 +12,19 @@ if [ "${RCON_ENABLED,,}" = true ]; then fi fi - if countdown_message "${AUTO_REBOOT_WARN_MINUTES}" "The_Server_will_reboot"; then - shutdown_server - elif [ -z "${AUTO_REBOOT_WARN_MINUTES}" ]; then - LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is empty" - exit 1 - else - LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}" - 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 LogWarn "Unable to reboot. RCON is required." exit 1 diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index d7d9a8f6c..8737e7423 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -238,49 +238,55 @@ broadcast_command() { } # 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 -# If mtime is not an integer and there are players in game then return 1 +# 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 - if [[ "${mtime}" =~ ^[0-9]+$ ]]; then - for ((i = "${mtime}" ; i > 0 ; i--)); do - if [ "$(get_player_count)" -eq 0 ]; then - break - fi - if [ "$i" -eq 1 ]; then - 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 - else - case "$i" in - "$mtime" ) - ;& - 15 ) - ;& - 10 ) - ;& - 5 ) - ;& - 2 ) - broadcast_command "${message_prefix}_in_${i}_minutes" - ;& - * ) - sleep 1m - ;; - esac - fi - done - return 0 - else - # mtime is not an integer so check if there are no players - if [ "$(get_player_count)" -gt 0 ]; then + # 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 + if [ "$i" -eq 1 ]; then + 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 + else + case "$i" in + "$mtime" ) + ;& + 15 ) + ;& + 10 ) + ;& + 5 ) + ;& + 2 ) + broadcast_command "${message_prefix}_in_${i}_minutes" + ;& + * ) + sleep 1m + ;; + esac + fi + # Checking for players every minute + if [ "$(get_player_count)" -eq 0 ]; then + break + fi + 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" diff --git a/scripts/update.sh b/scripts/update.sh index 405c3831b..ec86e79b8 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -20,15 +20,21 @@ if UpdateRequired; then DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" fi - if countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server_will_update"; then - LogAction "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." - rm /palworld/steamapps/appmanifest_2394010.acf + 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 - elif [ -z "${AUTO_UPDATE_WARN_MINUTES}" ]; then - LogWarn "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is empty." - else - LogWarn "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is not an integer: ${AUTO_UPDATE_WARN_MINUTES}" - 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 fi From 958a930233dc16ff5c2b36618858684a6e54ee87 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 17 Feb 2024 23:26:57 -0500 Subject: [PATCH 40/49] Moved player count check --- scripts/helper_functions.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 8737e7423..26a790c8b 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -273,13 +273,13 @@ countdown_message() { ;& * ) sleep 1m + # Checking for players every minute + if [ "$(get_player_count)" -eq 0 ]; then + break + fi ;; esac fi - # Checking for players every minute - if [ "$(get_player_count)" -eq 0 ]; then - break - fi done # If there are players but mtime is empty elif [ -z "${mtime}" ]; then From 1baeb045b2009f4275fd0bbcef0f9f3c43f3ff16 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 17 Feb 2024 23:27:39 -0500 Subject: [PATCH 41/49] Moved case when 1 --- scripts/helper_functions.sh | 57 ++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 26a790c8b..c17a670e4 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -251,35 +251,34 @@ countdown_message() { if [ "$(get_player_count)" -gt 0 ]; then if [[ "${mtime}" =~ ^[0-9]+$ ]]; then for ((i = "${mtime}" ; i > 0 ; i--)); do - if [ "$i" -eq 1 ]; then - 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 - else - case "$i" in - "$mtime" ) - ;& - 15 ) - ;& - 10 ) - ;& - 5 ) - ;& - 2 ) - broadcast_command "${message_prefix}_in_${i}_minutes" - ;& - * ) - sleep 1m - # Checking for players every minute - if [ "$(get_player_count)" -eq 0 ]; then - break - fi - ;; - esac - fi + 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 + ;; + "$mtime" ) + ;& + 15 ) + ;& + 10 ) + ;& + 5 ) + ;& + 2 ) + broadcast_command "${message_prefix}_in_${i}_minutes" + ;& + * ) + sleep 1m + # Checking for players every minute + if [ "$(get_player_count)" -eq 0 ]; then + break + fi + ;; + esac done # If there are players but mtime is empty elif [ -z "${mtime}" ]; then From 27c1466ff2f1d0f9ebeb5c5dd03ec07164a316f5 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 17 Feb 2024 23:28:45 -0500 Subject: [PATCH 42/49] Added comment --- scripts/helper_functions.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index c17a670e4..b38ea6c11 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -274,6 +274,7 @@ countdown_message() { * ) 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 From 3e38a6e1f2c9dc4c170314f5ff7187d20914ad21 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Sat, 17 Feb 2024 23:30:57 -0500 Subject: [PATCH 43/49] Reordered cases --- scripts/helper_functions.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index b38ea6c11..7959e328f 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -260,15 +260,15 @@ countdown_message() { broadcast_command "${message_prefix}_in_10_seconds" sleep 10s ;; - "$mtime" ) + 2 ) ;& - 15 ) + 3 ) ;& 10 ) ;& - 5 ) + 15 ) ;& - 2 ) + "$mtime" ) broadcast_command "${message_prefix}_in_${i}_minutes" ;& * ) From a718120cc23602d2984bd05d03e2a6915e8ac9ad Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Mon, 19 Feb 2024 12:52:41 -0500 Subject: [PATCH 44/49] Checking if broadcast contains non-ascii characters. --- scripts/helper_functions.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index b123bb720..b03450318 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -231,6 +231,9 @@ broadcast_command() { local return_val=0 # Replaces spaces with underscore local message="${1// /_}" + if [[ $TEXT = *[![:ascii:]]* ]]; then + LogWarn "Broadcast message contains non-ascii characters: \"${message}\"" + fi if ! RCON "broadcast ${message}"; then return_val=1 fi From 408617be515384bd9555c40652b6c4a87f3dbc71 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Mon, 19 Feb 2024 15:34:51 -0500 Subject: [PATCH 45/49] Reverted spacing changes --- scripts/helper_functions.sh | 89 ++++++++----------------------------- scripts/start.sh | 45 ++++++++++--------- 2 files changed, 43 insertions(+), 91 deletions(-) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index b03450318..8c35b03da 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -96,39 +96,39 @@ export YellowBoldText='\033[1;33m' # Yellow export CyanBoldText='\033[1;36m' # Cyan LogInfo() { - Log "$1" "$WhiteText" + Log "$1" "$WhiteText" } LogWarn() { - Log "$1" "$YellowBoldText" + Log "$1" "$YellowBoldText" } LogError() { - Log "$1" "$RedBoldText" + Log "$1" "$RedBoldText" } LogSuccess() { - Log "$1" "$GreenBoldText" + Log "$1" "$GreenBoldText" } LogAction() { - Log "$1" "$CyanBoldText" "****" "****" + Log "$1" "$CyanBoldText" "****" "****" } Log() { - local message="$1" - local color="$2" - local prefix="$3" - local suffix="$4" - printf "$color%s$RESET$LINE" "$prefix$message$suffix" + local message="$1" + local color="$2" + local prefix="$3" + local suffix="$4" + printf "$color%s$RESET$LINE" "$prefix$message$suffix" } # Send Discord Message # Level is optional variable defaulting to info DiscordMessage() { - local message="$1" - local level="$2" - if [ -z "$level" ]; then - level="info" - fi - if [ -n "${DISCORD_WEBHOOK_URL}" ]; then - /home/steam/server/discord.sh "$message" "$level" & - fi + local message="$1" + local level="$2" + if [ -z "$level" ]; then + level="info" + fi + if [ -n "${DISCORD_WEBHOOK_URL}" ]; then + /home/steam/server/discord.sh "$message" "$level" & + fi } # RCON Call @@ -143,59 +143,6 @@ RCON() { return "$return_val" } - -# Returns 0 if Update Required -# Returns 1 if Update NOT Required -# Returns 2 if Check Failed -UpdateRequired() { - LogAction "Checking for new update" - - temp_file=$(mktemp) - http_code=$(curl https://api.steamcmd.net/v1/info/2394010 --output "$temp_file" --silent --location --write-out "%{http_code}") - TARGET_MANIFEST=$(grep -Po '"2394012".*"gid": "\d+"' <"$temp_file" | sed -r 's/.*("[0-9]+")$/\1/') - - CURRENT_MANIFEST=$(awk '/manifest/{count++} count==2 {print $2; exit}' /palworld/steamapps/appmanifest_2394010.acf) - rm "$temp_file" - - if [ "$http_code" -ne 200 ]; then - LogError "There was a problem reaching the Steam api. Unable to check for updates!" - DiscordMessage "There was a problem reaching the Steam api. Unable to check for updates!" "failure" - return 2 - fi - - if [ -z "$TARGET_MANIFEST" ]; then - LogError "The server response does not contain the expected BuildID. Unable to check for updates!" - DiscordMessage "Steam servers response does not contain the expected BuildID. Unable to check for updates!" "failure" - return 2 - fi - - if [ "$CURRENT_MANIFEST" != "$TARGET_MANIFEST" ]; then - LogInfo "An Update Is Available." - LogInfo "Current Version: $CURRENT_MANIFEST" - LogInfo "Latest Version: $TARGET_MANIFEST." - return 0 - fi - - LogSuccess "The Server is up to date!" - return 1 - -} - -InstallServer() { - DiscordMessage "${DISCORD_PRE_UPDATE_BOOT_MESSAGE}" "in-progress" - /home/steam/steamcmd/steamcmd.sh +@sSteamCmdForcePlatformType linux +@sSteamCmdForcePlatformBitness 64 +force_install_dir "/palworld" +login anonymous +app_update 2394010 validate +quit - DiscordMessage "${DISCORD_POST_UPDATE_BOOT_MESSAGE}" "success" -} - -# Returns 0 if game is installed -# Returns 1 if game is not installed -IsInstalled() { - if [ -e /palworld/PalServer.sh ] && [ -e /palworld/steamapps/appmanifest_2394010.acf ]; then - return 0 - fi - return 1 -} - # Saves the server # Returns 0 if it saves # Returns 1 if it is not able to save diff --git a/scripts/start.sh b/scripts/start.sh index 80939666b..e0f9bc4b8 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -73,27 +73,32 @@ if [ "${MULTITHREADING,,}" = true ]; then fi if [ "${DISABLE_GENERATE_SETTINGS,,}" = true ]; then - LogAction "GENERATING CONFIG" - LogWarn "Environment variables will not be applied due to DISABLE_GENERATE_SETTINGS being set to TRUE!" - - # shellcheck disable=SC2143 - if [ ! "$(grep -s '[^[:space:]]' /palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini)" ]; then - LogAction "GENERATING CONFIG" - # Server will generate all ini files after first run. - if [ "$architecture" == "arm64" ]; then - timeout --preserve-status 15s ./PalServer-arm64.sh 1> /dev/null - else - timeout --preserve-status 15s ./PalServer.sh 1> /dev/null - fi - - # Wait for shutdown - sleep 5 - cp /palworld/DefaultPalWorldSettings.ini /palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini - fi +LogAction "GENERATING CONFIG" +LogWarn "Environment variables will not be applied due to DISABLE_GENERATE_SETTINGS being set to TRUE!" + +# shellcheck disable=SC2143 +if [ ! "$(grep -s '[^[:space:]]' /palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini)" ]; then + LogAction "GENERATING CONFIG" + LogWarn "Environment variables will not be applied due to DISABLE_GENERATE_SETTINGS being set to TRUE!" + + # shellcheck disable=SC2143 + if [ ! "$(grep -s '[^[:space:]]' /palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini)" ]; then + LogAction "GENERATING CONFIG" + # Server will generate all ini files after first run. + if [ "$architecture" == "arm64" ]; then + timeout --preserve-status 15s ./PalServer-arm64.sh 1> /dev/null + else + timeout --preserve-status 15s ./PalServer.sh 1> /dev/null + fi + + # Wait for shutdown + sleep 5 + cp /palworld/DefaultPalWorldSettings.ini /palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini + fi else - LogAction "GENERATING CONFIG" - LogInfo "Using Env vars to create PalWorldSettings.ini" - /home/steam/server/compile-settings.sh || exit + LogAction "GENERATING CONFIG" + LogInfo "Using Env vars to create PalWorldSettings.ini" + /home/steam/server/compile-settings.sh || exit fi LogAction "GENERATING CRONTAB" From 43ca7a23dc23436b11cfcb1a00fb9e04a045fdd2 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Mon, 19 Feb 2024 15:50:27 -0500 Subject: [PATCH 46/49] Added missing fi --- scripts/start.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/start.sh b/scripts/start.sh index e0f9bc4b8..a2908dd83 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -75,6 +75,7 @@ fi if [ "${DISABLE_GENERATE_SETTINGS,,}" = true ]; then LogAction "GENERATING CONFIG" LogWarn "Environment variables will not be applied due to DISABLE_GENERATE_SETTINGS being set to TRUE!" +fi # shellcheck disable=SC2143 if [ ! "$(grep -s '[^[:space:]]' /palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini)" ]; then From acdf2591d613d6391ec074b4c232291ec7f9b6da Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Mon, 19 Feb 2024 16:11:35 -0500 Subject: [PATCH 47/49] Moved source helper_install.sh out of helper_functions.sh --- scripts/helper_functions.sh | 4 ---- scripts/helper_install.sh | 3 +++ scripts/start.sh | 4 ++++ scripts/update.sh | 4 ++++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 8c35b03da..efeb5c34b 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -241,7 +241,3 @@ countdown_message() { fi return "$return_val" } - -# Helper Functions for installation & updates -# shellcheck source=/dev/null -source "/home/steam/server/helper_install.sh" diff --git a/scripts/helper_install.sh b/scripts/helper_install.sh index 268ed4180..985fe6549 100644 --- a/scripts/helper_install.sh +++ b/scripts/helper_install.sh @@ -1,6 +1,9 @@ #!/bin/bash # This file contains functions which can be used in multiple scripts +# shellcheck source=/dev/null +source "/home/steam/server/helper_functions.sh" + # Returns 0 if game is installed # Returns 1 if game is not installed IsInstalled() { diff --git a/scripts/start.sh b/scripts/start.sh index a2908dd83..3e8d7f980 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -2,6 +2,10 @@ # shellcheck source=/dev/null source "/home/steam/server/helper_functions.sh" +# Helper Functions for installation & updates +# shellcheck source=/dev/null +source "/home/steam/server/helper_install.sh" + dirExists "/palworld" || exit isWritable "/palworld" || exit isExecutable "/palworld" || exit diff --git a/scripts/update.sh b/scripts/update.sh index ec86e79b8..2a2e4650c 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -2,6 +2,10 @@ # shellcheck source=/dev/null source "/home/steam/server/helper_functions.sh" +# Helper Functions for installation & updates +# shellcheck source=/dev/null +source "/home/steam/server/helper_install.sh" + # Check if Update was actually required if UpdateRequired; then if [ "${UPDATE_ON_BOOT}" = false ]; then From f96ef24a00ed4925432f0aabd7354cdbaaad597b Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Mon, 19 Feb 2024 16:41:17 -0500 Subject: [PATCH 48/49] Only broadcast valid messages --- scripts/helper_functions.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index efeb5c34b..96db82ad2 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -179,9 +179,9 @@ broadcast_command() { # Replaces spaces with underscore local message="${1// /_}" if [[ $TEXT = *[![:ascii:]]* ]]; then - LogWarn "Broadcast message contains non-ascii characters: \"${message}\"" - fi - if ! RCON "broadcast ${message}"; then + LogWarn "Unable to broadcast since the message contains non-ascii characters: \"${message}\"" + return_val=1 + elif ! RCON "broadcast ${message}"; then return_val=1 fi return "$return_val" From 635d201afd26b1c31cb500634c55fa400ccd45e0 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Mon, 19 Feb 2024 18:13:17 -0500 Subject: [PATCH 49/49] Fixed merge issue --- scripts/start.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/scripts/start.sh b/scripts/start.sh index 3e8d7f980..2d6d05c0e 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -77,12 +77,6 @@ if [ "${MULTITHREADING,,}" = true ]; then fi if [ "${DISABLE_GENERATE_SETTINGS,,}" = true ]; then -LogAction "GENERATING CONFIG" -LogWarn "Environment variables will not be applied due to DISABLE_GENERATE_SETTINGS being set to TRUE!" -fi - -# shellcheck disable=SC2143 -if [ ! "$(grep -s '[^[:space:]]' /palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini)" ]; then LogAction "GENERATING CONFIG" LogWarn "Environment variables will not be applied due to DISABLE_GENERATE_SETTINGS being set to TRUE!"