From 130d665f1a07a24923e18be2354bfceffcddb693 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 16 Oct 2015 21:02:42 +1000 Subject: [PATCH 1/8] Add support for downloading updates before applying --- tools/arkmanager | 70 ++++++++++++++++++++++++++++++++++++-------- tools/arkmanager.cfg | 1 + 2 files changed, 58 insertions(+), 13 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 14bcbf5..8c7ed59 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -749,6 +749,7 @@ doUpdate() { local validate= local modupdate= local saveworld= + local downloadonly= for arg in "$@"; do if [ "$arg" == "--force" ]; then @@ -766,6 +767,10 @@ doUpdate() { modupdate=1 elif [ "$arg" == "--backup" ]; then arkBackupPreUpdate=true + elif [ "$arg" =~ "^--stagingdir=" ]; then + arkStagingDir="${ark#--stagingdir=}" + elif [ "$arg" == "--downloadonly" ]; then + downloadonly=1 fi done @@ -782,9 +787,37 @@ doUpdate() { if isUpdateNeeded; then appupdate=1 + + if [ -n "${arkStagingDir}" -a "${arkStagingDir}" != "${arkserverroot}" ]; then + if [ ! -d "$arkStagingDir/ShooterGame" ]; then + cp -al "$arkserverroot/ShooterGame/." "$arkStagingDir/ShooterGame" + cp -al "$arkserverroot/Engine/." "$arkStagingDir/Engine" + cp -al "$arkserverroot/linux64/." "$arkStagingDir/linux64" + cp -al "$arkserverroot/PackageInfo.bin" "$arkStagingDir/PackageInfo.bin" + cp -al "$arkserverroot/steamclient.so" "$arkStagingDir/steamclient.so" + cp -a "$arkserverroot/steamapps/." "$arkStagingDir/steamapps" + rm -rf "$arkStagingDir/ShooterGame/Content/Mods/"* + rm -rf "$arkStagingDir/ShooterGame/Saved/"* + fi + + cd "$steamcmdroot" + ./$steamcmdexec +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} +force_install_dir "$arkStagingDir" +app_update $appid $validate +quit + if [ -d "${arkStagingDir}/steamapps/downloading/${appid}" ]; then + echo "Update download interrupted" + return 1 + fi + fi fi - if [ -n "$appupdate" -o -n "$modupdate" ]; then + if [ -n "$downloadonly" ]; then + if [ -n "$appupdate" -a -n "$arkStagingDir" -a "$arkStagingDir" != "$arkserverroot" ]; then + echo "Server update downloaded" + fi + if [ -n "$modupdate" ]; then + echo "Mod update downloaded" + fi + echo "Not applying update - download-only enabled" + elif [ -n "$appupdate" -o -n "$modupdate" ]; then if isTheServerRunning; then if [ "$updatetype" == "safe" ]; then while [ ! `find $arkserverroot/ShooterGame/Saved/SavedArks -mmin -1 -name ${serverMap##*/}.ark` ]; do @@ -811,16 +844,25 @@ doUpdate() { fi doStop - + # If user wants to back-up, we do it here. - + if [ "$arkBackupPreUpdate" == "true" ]; then doBackup fi if [ -n "$appupdate" ]; then - cd "$steamcmdroot" - ./$steamcmdexec +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} +force_install_dir "$arkserverroot" +app_update $appid $validate +quit + if [ -d "${arkStagingDir}" -a "${arkStagingDir}" != "${arkserverroot}" ]; then + cp -alu --remove-destination "$arkStagingDir/ShooterGame/." "$arkserverroot/ShooterGame" + cp -alu --remove-destination "$arkStagingDir/Engine/." "$arkserverroot/Engine" + cp -alu --remove-destination "$arkStagingDir/linux64/." "$arkserverroot/linux64" + cp -alu --remove-destination "$arkStagingDir/PackageInfo.bin" "$arkserverroot/PackageInfo.bin" + cp -alu --remove-destination "$arkStagingDir/steamclient.so" "$arkserverroot/steamclient.so" + cp -au --remove-destination "$arkStagingDir/steamapps/." "$arkserverroot/steamapps" + else + cd "$steamcmdroot" + ./$steamcmdexec +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} +force_install_dir "$arkserverroot" +app_update $appid $validate +quit + fi # the current version should be the last version. We set our version getCurrentVersion echo "`timestamp`: update to $instver complete" >> "$logdir/update.log" @@ -834,7 +876,7 @@ doUpdate() { fi done fi - + # we restart the server only if it was started before the update if [ $serverWasAlive -eq 1 ]; then doStart @@ -1365,13 +1407,15 @@ while true; do echo "useconfig Use the configuration overrides in the specified config name or file" echo echo "Update command takes the below options:" - echo " --force Apply update without checking the current version" - echo " --safe Wait for server to perform world save and update." - echo " --warn Warn players before updating server" - echo " --validate Validates all ARK server files" - echo " --saveworld Saves world before update" - echo " --update-mods Updates installed and requested mods" - echo " --backup Takes a backup of the save files before updating" + echo " --force Apply update without checking the current version" + echo " --safe Wait for server to perform world save and update." + echo " --warn Warn players before updating server" + echo " --validate Validates all ARK server files" + echo " --saveworld Saves world before update" + echo " --update-mods Updates installed and requested mods" + echo " --backup Takes a backup of the save files before updating" + echo " --downloadonly Download the mod and/or server update without applying it" + echo " Requires arkStagingDir be set to a staging directory on the same filesystem as the server" exit 1 ;; *) diff --git a/tools/arkmanager.cfg b/tools/arkmanager.cfg index b2a174f..22ef80d 100644 --- a/tools/arkmanager.cfg +++ b/tools/arkmanager.cfg @@ -18,6 +18,7 @@ arkwarnminutes="60" # number of arkautorestartfile="ShooterGame/Saved/.autorestart" # path to autorestart file arkBackupPreUpdate="false" # set this to true if you want to perform a backup before updating arkTimeToKeepBackupFiles="10" #Set to Automatically Remove backups older than n days +#arkStagingDir="/home/steam/ARK-Staging" # Uncomment to enable downloading updates before restarting the server # Update warning messages # Modify as desired, putting the %d replacement operator where the number belongs From f5d9ddc0c0f13aa223df04e9d6f4cad38a4c4a42 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Thu, 5 Nov 2015 22:33:48 +1000 Subject: [PATCH 2/8] Add support for separate filesystems --- tools/arkmanager | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 8c7ed59..01fd811 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -790,12 +790,17 @@ doUpdate() { if [ -n "${arkStagingDir}" -a "${arkStagingDir}" != "${arkserverroot}" ]; then if [ ! -d "$arkStagingDir/ShooterGame" ]; then - cp -al "$arkserverroot/ShooterGame/." "$arkStagingDir/ShooterGame" - cp -al "$arkserverroot/Engine/." "$arkStagingDir/Engine" - cp -al "$arkserverroot/linux64/." "$arkStagingDir/linux64" - cp -al "$arkserverroot/PackageInfo.bin" "$arkStagingDir/PackageInfo.bin" - cp -al "$arkserverroot/steamclient.so" "$arkStagingDir/steamclient.so" - cp -a "$arkserverroot/steamapps/." "$arkStagingDir/steamapps" + mkdir -p "$arkStagingDir" + if [ "$(stat -c "%d" "$arkserverroot")" == "$(stat -c "%d" "$arkStagingDir")" ]; then + cp -al "$arkserverroot/ShooterGame/." "$arkStagingDir/ShooterGame" + cp -al "$arkserverroot/Engine/." "$arkStagingDir/Engine" + cp -al "$arkserverroot/linux64/." "$arkStagingDir/linux64" + cp -al "$arkserverroot/PackageInfo.bin" "$arkStagingDir/PackageInfo.bin" + cp -al "$arkserverroot/steamclient.so" "$arkStagingDir/steamclient.so" + cp -a "$arkserverroot/steamapps/." "$arkStagingDir/steamapps" + else + rsync -a "$arkserverroot/." "$arkStagingDir/." + fi rm -rf "$arkStagingDir/ShooterGame/Content/Mods/"* rm -rf "$arkStagingDir/ShooterGame/Saved/"* fi @@ -853,12 +858,16 @@ doUpdate() { if [ -n "$appupdate" ]; then if [ -d "${arkStagingDir}" -a "${arkStagingDir}" != "${arkserverroot}" ]; then - cp -alu --remove-destination "$arkStagingDir/ShooterGame/." "$arkserverroot/ShooterGame" - cp -alu --remove-destination "$arkStagingDir/Engine/." "$arkserverroot/Engine" - cp -alu --remove-destination "$arkStagingDir/linux64/." "$arkserverroot/linux64" - cp -alu --remove-destination "$arkStagingDir/PackageInfo.bin" "$arkserverroot/PackageInfo.bin" - cp -alu --remove-destination "$arkStagingDir/steamclient.so" "$arkserverroot/steamclient.so" - cp -au --remove-destination "$arkStagingDir/steamapps/." "$arkserverroot/steamapps" + if [ "$(stat -c "%d" "$arkserverroot")" == "$(stat -c "%d" "$arkStagingDir")" ]; then + cp -alu --remove-destination "$arkStagingDir/ShooterGame/." "$arkserverroot/ShooterGame" + cp -alu --remove-destination "$arkStagingDir/Engine/." "$arkserverroot/Engine" + cp -alu --remove-destination "$arkStagingDir/linux64/." "$arkserverroot/linux64" + cp -alu --remove-destination "$arkStagingDir/PackageInfo.bin" "$arkserverroot/PackageInfo.bin" + cp -alu --remove-destination "$arkStagingDir/steamclient.so" "$arkserverroot/steamclient.so" + cp -au --remove-destination "$arkStagingDir/steamapps/." "$arkserverroot/steamapps" + else + rsync -a "$arkStagingDir/." "$arkserverroot" + fi else cd "$steamcmdroot" ./$steamcmdexec +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} +force_install_dir "$arkserverroot" +app_update $appid $validate +quit From c71ffd2dd9d00e3a4fb49d6f78671500ed811be8 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Thu, 5 Nov 2015 22:42:50 +1000 Subject: [PATCH 3/8] Fix error in update option parsing --- tools/arkmanager | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager b/tools/arkmanager index 01fd811..0b189fa 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -767,7 +767,7 @@ doUpdate() { modupdate=1 elif [ "$arg" == "--backup" ]; then arkBackupPreUpdate=true - elif [ "$arg" =~ "^--stagingdir=" ]; then + elif [[ "$arg" =~ "^--stagingdir=" ]]; then arkStagingDir="${ark#--stagingdir=}" elif [ "$arg" == "--downloadonly" ]; then downloadonly=1 From 78f0ccbc4af54edf1b5a7ea24186743a26aac86c Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 6 Nov 2015 00:34:36 +1000 Subject: [PATCH 4/8] Add some notifications on what the updater is doing --- tools/arkmanager | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/arkmanager b/tools/arkmanager index 0b189fa..dbfb293 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -771,6 +771,10 @@ doUpdate() { arkStagingDir="${ark#--stagingdir=}" elif [ "$arg" == "--downloadonly" ]; then downloadonly=1 + else + echo "Unrecognized option $arg" + echo "Try 'arkmanager -h' or 'arkmanager --help' for more information." + exit 1 fi done @@ -790,6 +794,7 @@ doUpdate() { if [ -n "${arkStagingDir}" -a "${arkStagingDir}" != "${arkserverroot}" ]; then if [ ! -d "$arkStagingDir/ShooterGame" ]; then + echo "Copying to staging directory" mkdir -p "$arkStagingDir" if [ "$(stat -c "%d" "$arkserverroot")" == "$(stat -c "%d" "$arkStagingDir")" ]; then cp -al "$arkserverroot/ShooterGame/." "$arkStagingDir/ShooterGame" @@ -805,6 +810,7 @@ doUpdate() { rm -rf "$arkStagingDir/ShooterGame/Saved/"* fi + echo "Downloading ARK update" cd "$steamcmdroot" ./$steamcmdexec +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} +force_install_dir "$arkStagingDir" +app_update $appid $validate +quit if [ -d "${arkStagingDir}/steamapps/downloading/${appid}" ]; then @@ -858,6 +864,7 @@ doUpdate() { if [ -n "$appupdate" ]; then if [ -d "${arkStagingDir}" -a "${arkStagingDir}" != "${arkserverroot}" ]; then + echo "Applying update from staging directory" if [ "$(stat -c "%d" "$arkserverroot")" == "$(stat -c "%d" "$arkStagingDir")" ]; then cp -alu --remove-destination "$arkStagingDir/ShooterGame/." "$arkserverroot/ShooterGame" cp -alu --remove-destination "$arkStagingDir/Engine/." "$arkserverroot/Engine" @@ -869,6 +876,7 @@ doUpdate() { rsync -a "$arkStagingDir/." "$arkserverroot" fi else + echo "Performing ARK update" cd "$steamcmdroot" ./$steamcmdexec +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} +force_install_dir "$arkserverroot" +app_update $appid $validate +quit fi @@ -880,6 +888,7 @@ doUpdate() { if [ -n "$modupdate" ]; then for modid in $(getModIds); do if isModUpdateNeeded $modid; then + echo "Updating mod $modid" doExtractMod $modid echo "`timestamp`: Mod $modid updated" >> "$logdir/update.log" fi From 388b8b180d6638a82f09e7fa70a581d1d6786b37 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 6 Nov 2015 00:38:43 +1000 Subject: [PATCH 5/8] Update arkStagingDir comment --- tools/arkmanager.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/arkmanager.cfg b/tools/arkmanager.cfg index 22ef80d..07be321 100644 --- a/tools/arkmanager.cfg +++ b/tools/arkmanager.cfg @@ -18,7 +18,7 @@ arkwarnminutes="60" # number of arkautorestartfile="ShooterGame/Saved/.autorestart" # path to autorestart file arkBackupPreUpdate="false" # set this to true if you want to perform a backup before updating arkTimeToKeepBackupFiles="10" #Set to Automatically Remove backups older than n days -#arkStagingDir="/home/steam/ARK-Staging" # Uncomment to enable downloading updates before restarting the server +#arkStagingDir="/home/steam/ARK-Staging" # Uncomment to enable updates to be fully downloaded before restarting the server (reduces downtime while updating) # Update warning messages # Modify as desired, putting the %d replacement operator where the number belongs From ffdeafec0cd807fc4d7fd6463c8ab28f48fb00f4 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 6 Nov 2015 00:52:40 +1000 Subject: [PATCH 6/8] Move `steamcmd` execution to a helper function --- tools/arkmanager | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index dbfb293..a9c4238 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -285,6 +285,13 @@ doBroadcastWithEcho(){ doBroadcast "$1" } +# +# SteamCMD helper function +# +function runSteamCMD(){ + "$steamcmdroot/$steamcmdexec" +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} "$@" +quit +} + # # Check if a new version is available but not apply it # @@ -364,7 +371,7 @@ function getCurrentVersion(){ # function getAvailableVersion(){ rm -f "$steamcmd_appinfocache" - bnumber=`$steamcmdroot/$steamcmdexec +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} +app_info_update 1 +app_info_print "$appid" +quit | while read name val; do if [ "${name}" == "{" ]; then parseSteamACF ".depots.branches.public" "buildid"; break; fi; done` + bnumber=`runSteamCMD +app_info_update 1 +app_info_print "$appid" +quit | while read name val; do if [ "${name}" == "{" ]; then parseSteamACF ".depots.branches.public" "buildid"; break; fi; done` if [ -z "$bnumber" ]; then bnumber="Unknown" fi @@ -659,6 +666,13 @@ doStopAll(){ done } +# +# install / update / download update +# +runSteamCMDAppUpdate(){ + runSteamCMD +force_install_dir "$1" +app_update $appid $2 +} + # # install of ARK server # @@ -676,7 +690,7 @@ doInstall() { cd "$steamcmdroot" # install the server - ./$steamcmdexec +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} +force_install_dir "$arkserverroot" +app_update $appid validate +quit + runSteamCMDAppUpdate "$arkserverroot" validate # the current version should be the last version. We set our version getCurrentVersion } @@ -812,7 +826,7 @@ doUpdate() { echo "Downloading ARK update" cd "$steamcmdroot" - ./$steamcmdexec +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} +force_install_dir "$arkStagingDir" +app_update $appid $validate +quit + runSteamCMDAppUpdate "$arkStagingDir" $validate if [ -d "${arkStagingDir}/steamapps/downloading/${appid}" ]; then echo "Update download interrupted" return 1 @@ -878,7 +892,7 @@ doUpdate() { else echo "Performing ARK update" cd "$steamcmdroot" - ./$steamcmdexec +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} +force_install_dir "$arkserverroot" +app_update $appid $validate +quit + runSteamCMDAppUpdate "$arkserverroot" $validate fi # the current version should be the last version. We set our version getCurrentVersion @@ -928,7 +942,7 @@ doDownloadMod(){ cd "$steamcmdroot" while true; do - ./$steamcmdexec +@NoPromptForPassword 1 +login ${steamlogin:-anonymous} +workshop_download_item $mod_appid $modid +quit + runSteamCMD +workshop_download_item $mod_appid $modid if [ ! -d "$moddldir" ]; then break; fi local newsize="`du -s "$moddldir" | cut -f1`" if [ $newsize -eq $dlsize ]; then break; fi From 914bbdb626f861e0f8cfd5bf9e8668504d4c0ad0 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Sun, 8 Nov 2015 06:42:39 +1000 Subject: [PATCH 7/8] Add status messages in mod download --- tools/arkmanager | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/arkmanager b/tools/arkmanager index a9c4238..f97c9e8 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -942,11 +942,15 @@ doDownloadMod(){ cd "$steamcmdroot" while true; do + echo "Downloading mod $modid" runSteamCMD +workshop_download_item $mod_appid $modid + echo + echo "Checking mod $modid" if [ ! -d "$moddldir" ]; then break; fi local newsize="`du -s "$moddldir" | cut -f1`" if [ $newsize -eq $dlsize ]; then break; fi dlsize=$newsize + echo "Mod $modid not fully downloaded - retrying" done if [ -f "$modsrcdir/mod.info" ]; then From 74fe4c958ecc29d31d1063aa7bf423b53b3f2658 Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Thu, 12 Nov 2015 01:19:49 +1000 Subject: [PATCH 8/8] Remove files removed by Steam update --- tools/arkmanager | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/arkmanager b/tools/arkmanager index f97c9e8..647d2eb 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -889,6 +889,18 @@ doUpdate() { else rsync -a "$arkStagingDir/." "$arkserverroot" fi + cd "$arkserverroot" + find Engine ShooterGame linux64 -depth -print | + grep -v '^ShooterGame/\(Saved\|Content/Mods\)' | + while read f; do + if [ ! -e "staging/${f}" ]; then + if [ -f "$f" ]; then + rm "${f}" + else + rmdir "${f}" + fi + fi + done else echo "Performing ARK update" cd "$steamcmdroot"