lockserver

This commit is contained in:
2023-11-25 01:05:22 -06:00
parent 4bc6f900b3
commit 4a718e39e4
4 changed files with 145 additions and 64 deletions

View File

@@ -29,6 +29,7 @@ export LOCAL_STOCK="$HOME/stock"
export LOCAL_STOCK_GAME="$LOCAL_STOCK/DayZ"
export LOCAL_STOCK_SERVER="$LOCAL_STOCK/DayZServer"
export LOCAL_MODS="$HOME/mods"
export LOCKFILE="$REMOTE_DIR/lockfile"
# ===================================================
# 03. Mount network drive
@@ -44,23 +45,31 @@ fi
# ===================================================
# 04. Checks
# ===================================================
mkdir -p "$LOCAL_STOCK_GAME" "$LOCAL_STOCK_SERVER" "$LOCAL_MODS"
check() {
mkdir -p "$LOCAL_STOCK_GAME" "$LOCAL_STOCK_SERVER" "$LOCAL_MODS"
if [ "$USER" != "$STEAMCMD_USER" ] ; then
die "Current user: '$USER' does not match '$STEAMCMD_USER'"
fi
if [ "$USER" != "$STEAMCMD_USER" ] ; then
die "Current user: '$USER' does not match '$STEAMCMD_USER'"
fi
if [ ! -d "$MODLISTS" ] ; then
die "Could not find modlists at: $MODLISTS"
fi
if [ ! -d "$MODLISTS" ] ; then
die "Could not find modlists at: $MODLISTS"
fi
if [ ! -d "$REMOTE_MODS" ] ; then
die "Could not find remote mods at: $REMOTE_MODS"
fi
if [ ! -d "$REMOTE_MODS" ] ; then
die "Could not find remote mods at: $REMOTE_MODS"
fi
if [ ! -d "$REMOTE_MAPS" ] ; then
die "Could not find remote maps at: $REMOTE_MAPS"
fi
if [ ! -d "$REMOTE_MAPS" ] ; then
die "Could not find remote maps at: $REMOTE_MAPS"
fi
if islocked_remote_server ; then
die "Remote server already locked?"
fi
msg "Health checks passed successfully."
}
# ===================================================
# 05. Begin functions
@@ -259,18 +268,45 @@ update_stock_maps() {
# --------------------------------------------------------------------------------------------------------------------
}
islocked_remote_server() {
if [ -e "$LOCKFILE" ] ; then
msg "Server is not currently locked!"
return 0
else
return 1
fi
}
lock_remote_server() {
msg "Locking remote server."
if ! echo 'locked' | tee "$LOCKFILE" ; then
die "Could not create: $LOCKFILE"
fi
}
unlock_remote_server() {
msg "Unlocking remote server."
rm -f "$LOCKFILE" || die "Could not remove: $LOCKFILE"
}
main() {
check || die "Failed to pass health checks"
lock_remote_server
update_server
update_game
update_stock_maps
for server in $(ls "$MODLISTS" | xargs) ; do
[ -f "$MODLISTS/$server" ] || continue
update_mods_for_server "$server"
unset server
# rm -rf "$HOME/.steam/debian-installation/steamapps/workshop/downloads"
# mkdir -p "$HOME/.steam/debian-installation/steamapps/workshop/downloads"
[ -f "$MODLISTS/$server" ] || continue
update_mods_for_server "$server"
unset server
# rm -rf "$HOME/.steam/debian-installation/steamapps/workshop/downloads"
# mkdir -p "$HOME/.steam/debian-installation/steamapps/workshop/downloads"
done
unlock_remote_server
}
main "$@"
main "$@" || exit 1