From 68aec6aa7a4f51d99942d3196e9234d33b53c5f8 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 10 Feb 2024 18:06:55 -0500 Subject: [PATCH 01/15] Updated feature branch with latest main changes --- scripts/helper_functions.sh | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 606655d9a..3690ab6d6 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -77,4 +77,52 @@ get_player_count() { fi player_list=$(rcon-cli -c /home/steam/server/rcon.yaml "ShowPlayers") echo -n "${player_list}" | wc -l +} +# +# Log Definitions +# +export LINE='\n' +export RESET='\033[0m' # Text Reset +export WhiteText='\033[0;37m' # White + +# Bold +export RedBoldText='\033[1;31m' # Red +export GreenBoldText='\033[1;32m' # Green +export YellowBoldText='\033[1;33m' # Yellow +export CyanBoldText='\033[1;36m' # Cyan + +LogInfo() { + Log "$1" "$WhiteText" +} +LogWarn() { + Log "$1" "$YellowBoldText" +} +LogError() { + Log "$1" "$RedBoldText" +} +LogSuccess() { + Log "$1" "$GreenBoldText" +} +LogAction() { + Log "$1" "$CyanBoldText" "****" "****" +} +Log() { + 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 } \ No newline at end of file From ecdf2dfdb9141980ceeceeb1cfcfaa4a7fe7ece7 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 10 Feb 2024 18:12:44 -0500 Subject: [PATCH 02/15] Updated feature branch with latest main changes --- scripts/update.sh | 66 +++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/scripts/update.sh b/scripts/update.sh index f9b6528ce..5b74f8bc9 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -3,10 +3,8 @@ 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 + LogWarn "Update on Boot needs to be enabled for auto updating" + DiscordMessage "Update on Boot needs to be enabled for auto updating" "warn" exit 0 fi @@ -18,41 +16,37 @@ TARGET_MANIFEST=$(grep -Po '"2394012".*"gid": "\d+"' <"$temp_file" | sed -r 's/. 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 + 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" 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 + 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" 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" - 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 - 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 - rcon-cli -c /home/steam/server/rcon.yaml "broadcast Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes" - sleep "${AUTO_UPDATE_WARN_MINUTES}m" - 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 + +if [ "CURRENT_MANIFEST" = "$TARGET_MANIFEST" ]; then + LogSuccess "The Server is up to date!" + exit 0 +fi + +if [ "${RCON_ENABLED,,}" = false ]; then + LogError "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 [ "$(get_player_count)" -gt 0 ]; then + LogAction "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." + DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" + rcon-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes" + sleep "${AUTO_UPDATE_WARN_MINUTES}m" +fi + +rm /palworld/steamapps/appmanifest_2394010.acf +backup +rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" + From 32c358da55482d55ad3a835ccf4c69979ad60b55 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 10 Feb 2024 18:18:31 -0500 Subject: [PATCH 03/15] Implemented Logging and discord functions throughout script. --- scripts/init.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/scripts/init.sh b/scripts/init.sh index 35ee2253a..de593dabd 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -1,11 +1,12 @@ #!/bin/bash +source "/home/steam/server/helper_functions.sh" if [[ ! "${PUID}" -eq 0 ]] && [[ ! "${PGID}" -eq 0 ]]; then - printf "\e[0;32m*****EXECUTING USERMOD*****\e[0m\n" + LogAction "EXECUTING USERMOD" usermod -o -u "${PUID}" steam groupmod -o -g "${PGID}" steam else - printf "\033[31m%s\n" "Running as root is not supported, please fix your PUID and PGID!" + LogError "Running as root is not supported, please fix your PUID and PGID!" exit 1 fi @@ -14,9 +15,7 @@ chown -R steam:steam /palworld /home/steam/ # shellcheck disable=SC2317 term_handler() { - if [ -n "${DISCORD_WEBHOOK_URL}" ] && [ -n "${DISCORD_PRE_SHUTDOWN_MESSAGE}" ]; then - su steam -c "/home/steam/server/discord.sh '${DISCORD_PRE_SHUTDOWN_MESSAGE}' in-progress" & - fi + DiscordMessage "${DISCORD_PRE_SHUTDOWN_MESSAGE}" "in-progress" if [ "${RCON_ENABLED,,}" = true ]; then rcon-cli save @@ -37,7 +36,7 @@ wait "$killpid" mapfile -t backup_pids < <(pgrep backup) if [ "${#backup_pids[@]}" -ne 0 ]; then - echo "Waiting for backup to finish" + LogInfo "Waiting for backup to finish" for pid in "${backup_pids[@]}"; do tail --pid="$pid" -f 2>/dev/null done @@ -45,7 +44,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 From 125aee87353c83e5a3e247f6e276cae186f764e4 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 10 Feb 2024 18:23:34 -0500 Subject: [PATCH 04/15] Implemented Logging and discord functions throughout script. --- scripts/restore.sh | 58 ++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/scripts/restore.sh b/scripts/restore.sh index 207748fb3..63a7bf4bb 100644 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -1,9 +1,10 @@ #!/bin/bash +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,84 +12,84 @@ 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" rcon-cli -c /home/steam/server/rcon.yaml save 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." + 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" @@ -98,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 @@ -116,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 From 24575a7fa3e91df3da3a39223800dd4dfc63974b Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 10 Feb 2024 18:46:34 -0500 Subject: [PATCH 05/15] Moved Update Check Logic to separate function for use in other scripts. --- scripts/update.sh | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/scripts/update.sh b/scripts/update.sh index 5b74f8bc9..34274d371 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -2,43 +2,25 @@ # shellcheck source=/dev/null source "/home/steam/server/helper_functions.sh" -if [ "${UPDATE_ON_BOOT}" = false ]; then - LogWarn "Update on Boot needs to be enabled for auto updating" - DiscordMessage "Update on Boot needs to be enabled for auto updating" "warn" - 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}") +updateRequired=$(UpdateRequired) -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 - 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" - exit 1 +# Check if Update was actually required +if [ "$updateRequired" != 0 ]; then + exit 0 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" +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 [ "CURRENT_MANIFEST" = "$TARGET_MANIFEST" ]; then - LogSuccess "The Server is up to date!" - exit 0 -fi - if [ "${RCON_ENABLED,,}" = false ]; then - LogError "An update is available however auto updating without rcon is not supported" + 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 [ "$(get_player_count)" -gt 0 ]; then LogAction "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" @@ -48,5 +30,4 @@ fi rm /palworld/steamapps/appmanifest_2394010.acf backup -rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" - +rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" \ No newline at end of file From 183de8c7e9f9309db82df9488290c12973d7a630 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 10 Feb 2024 18:49:01 -0500 Subject: [PATCH 06/15] Seperated Update & Install logic and cleaned up logging functions --- scripts/start.sh | 71 +++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 37 deletions(-) diff --git a/scripts/start.sh b/scripts/start.sh index 704e9e879..9b348a7ae 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -16,21 +16,25 @@ kernel_page_size=$(getconf PAGESIZE) # Check kernel page size for arm64 hosts before running steamcmd 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 @@ -47,9 +51,10 @@ else fi 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 @@ -70,14 +75,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 +93,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 +124,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 +136,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 - +DiscordMessage "${DISCORD_POST_SHUTDOWN_MESSAGE}" "failure" exit 0 From f65863d1258a51a2eef5cf7b434a517955435155 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 10 Feb 2024 19:09:08 -0500 Subject: [PATCH 07/15] Implemented Utility functions for server installation detection and update required detection --- scripts/helper_functions.sh | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 3690ab6d6..5c7b7dd58 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -125,4 +125,63 @@ DiscordMessage() { if [ -n "${DISCORD_WEBHOOK_URL}" ]; then /home/steam/server/discord.sh "$message" "$level" & fi +} + + +# 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}") + +CURRENTBUILD=$(awk '/buildid/{ print $2 }' < /palworld/steamapps/appmanifest_2394010.acf) +TARGETBUILD=$(grep -P '"public": {"buildid": "\d+"' -o <"$temp_file" | sed -r 's/.*("[0-9]+")$/\1/') +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 "$TARGETBUILD" ]; 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 [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then + LogAction "An Update Is Available." + LogInfo "Current Version: $CURRENTBUILD" + LogInfo "Target Version: $TARGETBUILD." + return 0 +fi + +LogSuccess "The Server is up to date!" +return 1 + +} + +InstallServer() { + DiscordMessage "${DISCORD_PRE_UPDATE_BOOT_MESSAGE}" "in-progress" + SteamCMD +app_update 2394010 validate + DiscordMessage "${DISCORD_POST_UPDATE_BOOT_MESSAGE}" "success" +} + +#Steam Commands +SteamCMD() { + local extraArgs="$1" + /home/steam/steamcmd/steamcmd.sh +@sSteamCmdForcePlatformType linux +@sSteamCmdForcePlatformBitness 64 +force_install_dir "/palworld" +login anonymous "$extraArgs" +quit +} + +# Returns 0 if game is installed +# Returns 1 if game is not installed +IsInstalled() { + if [ -e palworld/Palworld.sh ] && [ -e palworld/steamapps/appmanifest_2394010.acf ]; then + return 0 + fi + return 1 } \ No newline at end of file From 2b509d752d3eac69fa0ead5575eb1cf7a640ec89 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 10 Feb 2024 19:09:31 -0500 Subject: [PATCH 08/15] Removed IF Nesting When Possible Removed redundant code with utility functions, Discord and Logging --- scripts/auto_reboot.sh | 47 ++++++++++++++++--------------- scripts/backup.sh | 55 ++++++++++++++++--------------------- scripts/compile-settings.sh | 8 +++--- scripts/discord.sh | 9 +++--- scripts/start.sh | 2 +- 5 files changed, 59 insertions(+), 62 deletions(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index 313df8b4c..527fa89ab 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -2,29 +2,32 @@ # shellcheck source=/dev/null source "/home/steam/server/helper_functions.sh" -if [ "${RCON_ENABLED,,}" = true ]; then - if [ "${AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE,,}" != true ]; then - players_count=$(get_player_count) +if [ "${RCON_ENABLED,,}" != true ]; then + LogWarn "Unable to reboot. RCON is required." + exit 0 +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 + LogError "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is empty." + exit 0 +fi - 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 +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 - rcon-cli -c /home/steam/server/rcon.yaml save - 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}" - fi -else - echo "Unable to reboot. RCON is required." +if [[ "${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 + rcon-cli -c /home/steam/server/rcon.yaml save + rcon-cli -c /home/steam/server/rcon.yaml "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 diff --git a/scripts/backup.sh b/scripts/backup.sh index c82909e5a..bc2f5fed5 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -1,9 +1,7 @@ #!/bin/bash +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" if [ "${RCON_ENABLED,,}" = true ]; then rcon-cli -c /home/steam/server/rcon.yaml save fi @@ -12,38 +10,33 @@ 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" < Date: Sat, 10 Feb 2024 19:34:40 -0500 Subject: [PATCH 09/15] Fixed logic around install & update detection --- scripts/helper_functions.sh | 14 ++++---------- scripts/update.sh | 4 ++-- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 5c7b7dd58..059ec2854 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -154,9 +154,9 @@ if [ -z "$TARGETBUILD" ]; then fi if [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then - LogAction "An Update Is Available." + LogInfo "An Update Is Available." LogInfo "Current Version: $CURRENTBUILD" - LogInfo "Target Version: $TARGETBUILD." + LogInfo "Latest Version: $TARGETBUILD." return 0 fi @@ -167,20 +167,14 @@ return 1 InstallServer() { DiscordMessage "${DISCORD_PRE_UPDATE_BOOT_MESSAGE}" "in-progress" - SteamCMD +app_update 2394010 validate + /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" } -#Steam Commands -SteamCMD() { - local extraArgs="$1" - /home/steam/steamcmd/steamcmd.sh +@sSteamCmdForcePlatformType linux +@sSteamCmdForcePlatformBitness 64 +force_install_dir "/palworld" +login anonymous "$extraArgs" +quit -} - # Returns 0 if game is installed # Returns 1 if game is not installed IsInstalled() { - if [ -e palworld/Palworld.sh ] && [ -e palworld/steamapps/appmanifest_2394010.acf ]; then + if [ -e /palworld/PalServer.sh ] && [ -e /palworld/steamapps/appmanifest_2394010.acf ]; then return 0 fi return 1 diff --git a/scripts/update.sh b/scripts/update.sh index 34274d371..66c69321b 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -2,8 +2,8 @@ # shellcheck source=/dev/null source "/home/steam/server/helper_functions.sh" -updateRequired=$(UpdateRequired) - +UpdateRequired +updateRequired=$? # Check if Update was actually required if [ "$updateRequired" != 0 ]; then exit 0 From 5322b52253454eeb4a0379e725d91a208a461855 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 10 Feb 2024 20:09:11 -0500 Subject: [PATCH 10/15] Added Comments --- scripts/start.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/start.sh b/scripts/start.sh index 3d7eb763d..da9f5b040 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -50,6 +50,8 @@ else STARTCOMMAND=("./PalServer.sh") fi + +#Validate Installation if ! fileExists "${STARTCOMMAND[0]}"; then LogError "Server Not Installed Properly" exit 1 @@ -58,6 +60,7 @@ fi isReadable "${STARTCOMMAND[0]}" || exit isExecutable "${STARTCOMMAND[0]}" || exit +# Prepare Arguments if [ -n "${PORT}" ]; then STARTCOMMAND+=("-port=${PORT}") fi From aa29a759785cc1b289c9dafa02e8f5309f69ac80 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sun, 11 Feb 2024 11:56:44 -0500 Subject: [PATCH 11/15] Fixed ShellCheck source errors --- scripts/backup.sh | 1 + scripts/discord.sh | 1 + scripts/init.sh | 1 + scripts/restore.sh | 1 + scripts/start.sh | 2 +- 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index bc2f5fed5..ab5b5c525 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -1,4 +1,5 @@ #!/bin/bash +# shellcheck source=/dev/null source "/home/steam/server/helper_functions.sh" DiscordMessage "Creating backup..." "in-progress" diff --git a/scripts/discord.sh b/scripts/discord.sh index bc9484f75..ba30a48c9 100644 --- a/scripts/discord.sh +++ b/scripts/discord.sh @@ -1,4 +1,5 @@ #!/bin/bash +# shellcheck source=/dev/null source "/home/steam/server/helper_functions.sh" # Defaults diff --git a/scripts/init.sh b/scripts/init.sh index de593dabd..b9508dc06 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -1,4 +1,5 @@ #!/bin/bash +# shellcheck source=/dev/null source "/home/steam/server/helper_functions.sh" if [[ ! "${PUID}" -eq 0 ]] && [[ ! "${PGID}" -eq 0 ]]; then diff --git a/scripts/restore.sh b/scripts/restore.sh index 63a7bf4bb..5b96d80e9 100644 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -1,4 +1,5 @@ #!/bin/bash +# shellcheck source=/dev/null source "/home/steam/server/helper_functions.sh" # Backup file directory path diff --git a/scripts/start.sh b/scripts/start.sh index da9f5b040..9a0fa4b08 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -14,7 +14,7 @@ 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 LogError "Only ARM64 hosts with 4k page size is supported." exit 1 From 9647231d53bef67d76d2f34590e49db2d9bbe724 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 10 Feb 2024 19:09:08 -0500 Subject: [PATCH 12/15] Implemented Utility functions for server installation detection and update required detection --- scripts/helper_functions.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 059ec2854..61bcac876 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -78,6 +78,7 @@ get_player_count() { player_list=$(rcon-cli -c /home/steam/server/rcon.yaml "ShowPlayers") echo -n "${player_list}" | wc -l } + # # Log Definitions # @@ -128,6 +129,7 @@ DiscordMessage() { } + # Returns 0 if Update Required # Returns 1 if Update NOT Required # Returns 2 if Check Failed From bfffb89f3f9a45c56934af42cf14d79d57c5fdf1 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 10 Feb 2024 19:09:31 -0500 Subject: [PATCH 13/15] Removed IF Nesting When Possible Removed redundant code with utility functions, Discord and Logging --- scripts/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/start.sh b/scripts/start.sh index 9a0fa4b08..da9f5b040 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -14,7 +14,7 @@ architecture=$(dpkg --print-architecture) # Get host kernel page size kernel_page_size=$(getconf PAGESIZE) -# Check kernel page size for arm64 hosts before running steamcmdac +# Check kernel page size for arm64 hosts before running steamcmd if [ "$architecture" == "arm64" ] && [ "$kernel_page_size" != "4096" ]; then LogError "Only ARM64 hosts with 4k page size is supported." exit 1 From 6d81cb0fe486e553a4fd925b576470d35375196b Mon Sep 17 00:00:00 2001 From: Patrick Date: Sun, 11 Feb 2024 11:56:44 -0500 Subject: [PATCH 14/15] Fixed ShellCheck source errors --- scripts/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/start.sh b/scripts/start.sh index da9f5b040..9a0fa4b08 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -14,7 +14,7 @@ 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 LogError "Only ARM64 hosts with 4k page size is supported." exit 1 From ce5e967cd382e199ebc093ade03be7abef7337c7 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sun, 11 Feb 2024 16:47:27 -0500 Subject: [PATCH 15/15] Moved rcon-cli to utility function --- scripts/auto_reboot.sh | 6 +++--- scripts/backup.sh | 2 +- scripts/helper_functions.sh | 19 ++++++++++++------- scripts/init.sh | 4 ++-- scripts/restore.sh | 4 ++-- scripts/update.sh | 4 ++-- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index 527fa89ab..13f1de424 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -22,11 +22,11 @@ fi if [[ "${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" + RCON "broadcast The_Server_will_reboot_in_${i}_Minutes" sleep "1m" done - rcon-cli -c /home/steam/server/rcon.yaml save - rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" + RCON save + RCON "shutdown 1" exit 0 fi diff --git a/scripts/backup.sh b/scripts/backup.sh index ab5b5c525..119ffa126 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -4,7 +4,7 @@ source "/home/steam/server/helper_functions.sh" DiscordMessage "Creating backup..." "in-progress" if [ "${RCON_ENABLED,,}" = true ]; then - rcon-cli -c /home/steam/server/rcon.yaml save + RCON save fi DATE=$(date +"%Y-%m-%d_%H-%M-%S") diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 61bcac876..4be52b842 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -75,7 +75,7 @@ get_player_count() { echo 0 return 0 fi - player_list=$(rcon-cli -c /home/steam/server/rcon.yaml "ShowPlayers") + player_list=$(RCON "ShowPlayers") echo -n "${player_list}" | wc -l } @@ -128,6 +128,11 @@ DiscordMessage() { fi } +# RCON Call +RCON() { + local args="$1" + echo rcon-cli -c /home/steam/server/rcon.yaml "$args" +} # Returns 0 if Update Required @@ -138,9 +143,9 @@ 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/') -CURRENTBUILD=$(awk '/buildid/{ print $2 }' < /palworld/steamapps/appmanifest_2394010.acf) -TARGETBUILD=$(grep -P '"public": {"buildid": "\d+"' -o <"$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 @@ -149,16 +154,16 @@ if [ "$http_code" -ne 200 ]; then return 2 fi -if [ -z "$TARGETBUILD" ]; then +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 [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then +if [ "$CURRENT_MANIFEST" != "$TARGET_MANIFEST" ]; then LogInfo "An Update Is Available." - LogInfo "Current Version: $CURRENTBUILD" - LogInfo "Latest Version: $TARGETBUILD." + LogInfo "Current Version: $CURRENT_MANIFEST" + LogInfo "Latest Version: $TARGET_MANIFEST." return 0 fi diff --git a/scripts/init.sh b/scripts/init.sh index b9508dc06..219be9bb6 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -19,8 +19,8 @@ term_handler() { DiscordMessage "${DISCORD_PRE_SHUTDOWN_MESSAGE}" "in-progress" if [ "${RCON_ENABLED,,}" = true ]; then - rcon-cli save - rcon-cli "shutdown 1" + RCON save + RCON "shutdown 1" else # Does not save kill -SIGTERM "$(pidof PalServer-Linux-Test)" fi diff --git a/scripts/restore.sh b/scripts/restore.sh index 5b96d80e9..9f4bac15b 100644 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -63,8 +63,8 @@ if [ -f "$BACKUP_FILE" ]; then if [ "${RCON_ENABLED}" = true ]; then LogAction "Shutting Down Server" - rcon-cli -c /home/steam/server/rcon.yaml save - rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" + RCON save + RCON "shutdown 1" else LogWarn "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 66c69321b..5489bf5c9 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -24,10 +24,10 @@ fi if [ "$(get_player_count)" -gt 0 ]; then LogAction "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" - rcon-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes" + RCON "broadcast The_Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes" sleep "${AUTO_UPDATE_WARN_MINUTES}m" fi rm /palworld/steamapps/appmanifest_2394010.acf backup -rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" \ No newline at end of file +RCON "shutdown 1" \ No newline at end of file