Add update --update-mods option

This commit is contained in:
Ben Peddell 2015-09-16 19:48:52 +10:00
parent b5819d517d
commit e9b987f19a

View File

@ -509,6 +509,7 @@ doUpdate() {
local appupdate= local appupdate=
local updatetype=normal local updatetype=normal
local validate= local validate=
local modupdate=
for arg in "$@"; do for arg in "$@"; do
if [ "$arg" == "--force" ]; then if [ "$arg" == "--force" ]; then
@ -520,16 +521,27 @@ doUpdate() {
elif [ "$arg" == "--validate" ]; then elif [ "$arg" == "--validate" ]; then
validate=validate validate=validate
appupdate=1 appupdate=1
elif [ "$arg" == "--update-mods" ]; then
modupdate=1
fi fi
done done
if [ -n "$modupdate" ]; then
if ! doDownloadAllMods; then
modupdate=
fi
if ! isAnyModUpdateNeeded; then
modupdate=
fi
fi
cd "$arkserverroot" cd "$arkserverroot"
if isUpdateNeeded; then if isUpdateNeeded; then
appupdate=1 appupdate=1
fi fi
if [ -n "$appupdate" ]; then if [ -n "$appupdate" -o -n "$modupdate" ]; then
if isTheServerRunning; then if isTheServerRunning; then
if [ "$updatetype" == "safe" ]; then if [ "$updatetype" == "safe" ]; then
while [ ! `find $arkserverroot/ShooterGame/Saved/SavedArks -mmin -1 -name ${serverMap##*/}.ark` ]; do while [ ! `find $arkserverroot/ShooterGame/Saved/SavedArks -mmin -1 -name ${serverMap##*/}.ark` ]; do
@ -551,11 +563,22 @@ doUpdate() {
fi fi
doStop doStop
cd "$steamcmdroot" if [ -n "$appupdate" ]; then
./$steamcmdexec +login anonymous +force_install_dir "$arkserverroot" +app_update $appid $validate +quit cd "$steamcmdroot"
# the current version should be the last version. We set our version ./$steamcmdexec +login anonymous +force_install_dir "$arkserverroot" +app_update $appid $validate +quit
getCurrentVersion # the current version should be the last version. We set our version
echo "`timestamp`: update to $instver complete" >> "$logdir/update.log" getCurrentVersion
echo "`timestamp`: update to $instver complete" >> "$logdir/update.log"
fi
if [ -n "$modupdate" ]; then
for modid in $(getModIds); do
if isModUpdateNeeded $modid; then
doExtractMod $modid
echo "`timestamp`: Mod $modid updated" >> "$logdir/update.log"
fi
done
fi
# we restart the server only if it was started before the update # we restart the server only if it was started before the update
if [ $serverWasAlive -eq 1 ]; then if [ $serverWasAlive -eq 1 ]; then
@ -567,6 +590,18 @@ doUpdate() {
fi; fi;
} }
#
# Get the Mod IDs of the installed mods and the requested mods
#
getModIds(){
(
echo "${serverMapModId}"
echo "${ark_TotalConversionMod}"
echo "${ark_GameModIds}" | tr ',' '\n'
find "${arkserverroot}/ShooterGame/Content/Mods" -maxdepth 1 -type d -printf "%P\n"
) | sort | uniq | grep '^[1-9][0-9]*$'
}
# #
# Downloads a mod from the Steam workshop # Downloads a mod from the Steam workshop
# #
@ -594,6 +629,51 @@ doDownloadMod(){
fi fi
} }
#
# Downloads all installed and requested mods from the Steam workshop
#
doDownloadAllMods(){
for modid in $(getModIds); do
doDownloadMod $modid || return 1
done
}
#
# Checks if the files a mod owns need to be updated
#
isModUpdateNeeded(){
local modid=$1
local modsrcdir="$steamcmdroot/steamapps/workshop/content/$mod_appid/$modid"
local moddestdir="$arkserverroot/ShooterGame/Content/Mods/$modid"
if [ -f "$modsrcdir/mod.info" ]; then
if [ -f "$modsrcdir/LinuxNoEditor/mod.info" ]; then
modsrcdir="$modsrcdir/LinuxNoEditor"
fi
find "$modsrcdir" -type f ! -name "*.z.uncompressed_size" -printf "%P\n" | while read f; do
if [ ! -f "$moddestdir/${f%.z}" -o "$modsrcdir/$f" -nt "$moddestdir/${f%.z}" ]; then
return 0
fi
done
fi
return 1
}
#
# Checks if any installed or requested mods need to be updated
#
isAnyModUpdateNeeded(){
for modid in $(getModIds); do
if isModUpdateNeeded $modid; then
return 0
fi
done
return 1
}
# #
# Extracts a mod into the ARK Mods directory # Extracts a mod into the ARK Mods directory
# #
@ -958,26 +1038,29 @@ while true; do
;; ;;
-h|--help) -h|--help)
echo -e "Usage: arkmanager [OPTION]\n" echo -e "Usage: arkmanager [OPTION]\n"
echo "Option Description" echo "Option Description"
echo "backup Saves a backup of your server inside the backup directory" echo "backup Saves a backup of your server inside the backup directory"
echo "broadcast <msg> Sends a message to all users connected to server" echo "broadcast <msg> Sends a message to all users connected to server"
echo "saveworld Saves the game world to disk" echo "saveworld Saves the game world to disk"
echo "rconcmd <cmd> Execute RCON command on server" echo "rconcmd <cmd> Execute RCON command on server"
echo "checkupdate Check for a new ARK server version" echo "checkupdate Check for a new ARK server version"
echo "install Install the ARK server files from steamcmd" echo "install Install the ARK server files from steamcmd"
echo "restart Stops the server and then starts it" echo "installmod <modid> Installs a mod from the Steam workshop"
echo "restart --all Restarts all servers specified in configfile_xxxxx" echo "restart Stops the server and then starts it"
echo "start Starts the server" echo "restart --all Restarts all servers specified in configfile_xxxxx"
echo "start --all Starts all servers specified in configfile_xxxxx" echo "start Starts the server"
echo "stop Stops the server" echo "start --all Starts all servers specified in configfile_xxxxx"
echo "stop --all Stops all servers specified in configfile_xxxxx" echo "stop Stops the server"
echo "status Returns the status of the current ARK server instance" echo "stop --all Stops all servers specified in configfile_xxxxx"
echo "update Check for a new ARK server version, if needed, stops the server, updates it, and starts it again" echo "status Returns the status of the current ARK server instance"
echo "update --force Apply update without check the current version" echo "update Check for a new ARK server version, if needed, stops the server, updates it, and starts it again"
echo "update --safe Wait for server to perform world save and update." echo "update --force Apply update without checking the current version"
echo "update --warn Warn players before updating server" echo "update --safe Wait for server to perform world save and update."
echo "upgrade Check for a new ARK Server Tools version and upgrades it if needed" echo "update --warn Warn players before updating server"
echo "useconfig <name> Use the configuration overrides in the specified config name or file" echo "update --validate Validates all ARK server files"
echo "update --update-mods Updates installed and requested mods"
echo "upgrade Check for a new ARK Server Tools version and upgrades it if needed"
echo "useconfig <name> Use the configuration overrides in the specified config name or file"
exit 1 exit 1
;; ;;
*) *)