#!/bin/sh # # shellcheck disable=1090,2034,2011 # # "should check code directly not $?" # shellcheck disable=2181 # --------------------------------------------------- # =================================================== # 01. Attempt to load global DayZ values # =================================================== echo "Starting, attempting to load globals.sh" GLOBALS_FILE="$PWD/globals.sh" if [ -e "$GLOBALS_FILE" ] ; then chmod +x "$GLOBALS_FILE" . "$GLOBALS_FILE" else die "Could not load: $GLOBALS_FILE" fi # =================================================== # 02. Local script variables # =================================================== export STEAMCMD_USER=steam export MODLISTS="$PWD/modlists" export LOCAL_STOCK="$HOME/stock" export LOCAL_STOCK_GAME="$LOCAL_STOCK/DayZ" export LOCAL_STOCK_SERVER="$LOCAL_STOCK/DayZServer" export LOCAL_STOCK_MODS="$LOCAL_STOCK/mods" # =================================================== # 03. Mount network drive # =================================================== if ! is_network_drive_mounted ; then mount_dayz_network_drive if ! is_network_drive_mounted ; then die "Could not mount network drive" fi fi # =================================================== # 04. Checks # =================================================== mkdir -p "$LOCAL_STOCK_GAME" "$LOCAL_STOCK_SERVER" "$LOCAL_STOCK_MODS" 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 "$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 # =================================================== # 05. Begin functions # =================================================== update_server() { echo msg "============== UPDATING DAYZ SERVER =================" echo steamcmd -tcp \ +force_install_dir "$LOCAL_STOCK_SERVER" \ +@sSteamCmdForcePlatformType windows \ +@ShutdownOnFailedCommand 1 \ +login "$STEAM_USER" \ +app_update "$DAYZ_SERVER_ID" \ +quit is_network_drive_mounted && do_sync "$LOCAL_STOCK_SERVER"/ "$REMOTE_STOCK_SERVER" echo msg "============ DONE UPDATING SERVER =====================" echo } update_game() { echo msg "========== UPDATING DAYZ GAME ================" echo steamcmd -tcp \ +force_install_dir "$LOCAL_STOCK_GAME" \ +@sSteamCmdForcePlatformType windows \ +@ShutdownOnFailedCommand 1 \ +login "$STEAM_USER" \ +app_update "$DAYZ_GAME_ID" \ +quit is_network_drive_mounted && do_sync "$LOCAL_STOCK_GAME"/ "$REMOTE_STOCK_GAME" echo msg "============= DONE UPDATING GAME ===================" echo } # args: $1 = server_modlist.txt to update update_mods_for_server() { echo msg "======= UPDATING MODS FOR: $1 ========" echo mods_file="$MODLISTS/$1" map_name=${1%.txt} mkdir -p "$REMOTE_MODS/$map_name" # Create temporary file to list all the mod_id's we are # going to download. This speeds up steamcmd and avoids rate limits. tempfile="/tmp/$map_name-mods_to_download.txt" :> "$tempfile" # load the server_modlist.txt, copying the mod id's we need to update # to the temp file, while skipping comments and blank lines # # format should be: "mod_id^nickname" # # # Dabs Framework # # https://steamcommunity.com/sharedfiles/filedetails/?id=2545327648 # 2545327648^dabsframework # while read -r mod ; do case "$mod" in \#*|''|' ') ;; *) mod=${mod%%^*} # check validity of syntax if [ -z "$mod" ] ; then die "mod for $map_name appears to be empty - syntax error" fi # if ! isnum "$mod" ; then # die "mod $mod for $map_name does not appear to be a number" # fi printf "%s\n" "$mod" >> "$tempfile" mkdir -p "$LOCAL_STOCK_MODS/$mod" esac done <"$mods_file" unset mod echo echo "tempfile:" cat "$tempfile" echo # shellcheck disable=2046 steamcmd \ -tcp \ +force_install_dir "$LOCAL_STOCK_MODS" \ +@sSteamCmdForcePlatformType windows \ +@ShutdownOnFailedCommand 1 \ +login "$STEAM_USER" \ +workshop_download_item \ "$DAYZ_GAME_ID" \ $(xargs < "$tempfile") \ +quit msg "exiting - test" exit 1 if [ $? -ne 0 ] ; then die "Problem downloading mods for $map_name" fi echo msg "------------ RENAMING MODS -------------" echo mods_to_copy="$LOCAL_STOCK_MODS/mods_to_copy" rm -rf "$mods_to_copy" 2>/dev/null ||: mkdir -p "$mods_to_copy" :> "$mods_to_copy/mods.txt" while read -r mod ; do # skip comments, blank lines case "$mod" in \#*|''|' ') ;; *) mod_id=${mod%%^*} mod_name=${mod##*^} do_sync "$LOCAL_STOCK_MODS/$mod_id"/ "$mods_to_copy/@${mod_name}" printf '@%s\n' "$mod_name" >> "$mods_to_copy/mods.txt" esac done < "$mods_file" echo msg "----------- SYNCING MODS -------------" echo do_sync "$mods_to_copy"/ "$REMOTE_MODS" rm -f "$tempfile" 2>/dev/null ||: unset tempfile mod map_name mods_file mods_to_copy mod_name mod_id echo msg "======= DONE UPDATING MODS FOR: $1 ========" echo } main() { update_server update_game 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" done } main "$@"