From dc5d7e4f4389e6259f57a3fc8ea4afcf29af74bf Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Fri, 30 Jul 2021 14:27:08 -0500 Subject: [PATCH] Arma Script 1.0 :letsgo: -- README docs --- CentOS/Arma/Arma-Connect-Server.bash | 2 +- CentOS/Arma/Arma-Open-Ports.bash | 2 + CentOS/Arma/Arma-Start-Server.bash | 40 +++++++-------- CentOS/Arma/Mods/Arma-Install-Mod.bash | 51 ++++++++----------- ...-Arma-Modlist.py => Arma-Parse-Modlist.py} | 4 +- CentOS/Arma/README.md | 50 ++++++++++++++++++ 6 files changed, 97 insertions(+), 52 deletions(-) rename CentOS/Arma/Mods/{Parse-Arma-Modlist.py => Arma-Parse-Modlist.py} (95%) create mode 100644 CentOS/Arma/README.md diff --git a/CentOS/Arma/Arma-Connect-Server.bash b/CentOS/Arma/Arma-Connect-Server.bash index b89322d..ef22eca 100755 --- a/CentOS/Arma/Arma-Connect-Server.bash +++ b/CentOS/Arma/Arma-Connect-Server.bash @@ -9,4 +9,4 @@ echo \ tmux attach-session -t "Arma-Server-${1}" -exit ${?} \ No newline at end of file +exit ${? \ No newline at end of file diff --git a/CentOS/Arma/Arma-Open-Ports.bash b/CentOS/Arma/Arma-Open-Ports.bash index bf5ccec..6d08652 100755 --- a/CentOS/Arma/Arma-Open-Ports.bash +++ b/CentOS/Arma/Arma-Open-Ports.bash @@ -5,5 +5,7 @@ # E.g. game is set to run on port 100, then ports 100-104 need to be opened # By default Arma 3 runs from port 2302 firewall-cmd --zone=public --add-port=2300-2309/udp --permanent +firewall-cmd -zone=public --add-port=2344-2345/udp --permanent +firewall-cmd -zone=public --add-port=2344-2345/tcp --permanent firewall-cmd --reload diff --git a/CentOS/Arma/Arma-Start-Server.bash b/CentOS/Arma/Arma-Start-Server.bash index eb7b16d..719c07d 100755 --- a/CentOS/Arma/Arma-Start-Server.bash +++ b/CentOS/Arma/Arma-Start-Server.bash @@ -2,7 +2,7 @@ usage() { printf "%s\n" \ -"Usage: Autodelete-Files -u -p +"Usage: $(basename "${0}") -u -p --user | -u The username used to login for steam @@ -21,10 +21,8 @@ usage() { Skips the steam update and validation and just starts the server Example: - --no-update + --no-update" - --force-checksum | -c - " } error() { @@ -108,43 +106,45 @@ fi mkdir -p ~/".local/share/Arma 3 - Other Profiles" && echo "Created the Arma 3 Other Profiles" +for fd in $(find /home/Arma/Arma/Server-"${servernum}"/mods/); do + new_name="$(echo "$(basename "${fd}")" | tr '[:upper:]' '[:lower:]')" + new_name="${new_name//-/$''}" + new_name="${new_name// /$'_'}" + dir="$(dirname "${fd}")" + mv "${fd}" "${dir}/${new_name}" 2>/dev/null +done + MODS="" MODPATH=~/Arma/Server-"${servernum}"/mods for mod in $(ls "${MODPATH}") do echo "Adding mod ${mod}" - new_mod="${MODPATH}/${mod}" -# rsync -ah -r --info=progress2 "${new_mod}" ~/Arma/Server-"${servernum}"/ -# rsync_error=${?} -# [[ ${rsync_error} != 0 ]] && \ -# echo "Rsync error: ${rsync_error}, could be an interrupt - exiting..." && exit ${rsync_error} - MODS="${MODS}\\${new_mod};" + MODS="${MODS}mods/${mod};" echo "Successfully added mod ${mod}" done echo "Mods added to startup: ${MODS}" -SERVERPORT=$(("2300" + "${servernum}")) +SERVERPORT=$(("5" * "${servernum}")) +SERVERPORT=$(("2300" + "${SERVERPORT}")) + +cd ~/Arma/Server-"${servernum}" tmux has-session -t "Arma-Server-${servernum}" 2>/dev/null if [ ${?} != 0 ]; then echo \ "Startup Args: -name=Arma-Server-${servernum} - -config=~/Arma/Server-${servernum}/server.cfg + -config=server.cfg -noSound -port=${SERVERPORT} -mod=\"${MODS}\"" echo "Starting new session..." - cd ~/Arma/Server-"${servernum}"/ + tmux new-session -d -s \ - "Arma-Server-${servernum}" \ - ~/Arma/Server-"${servernum}"/arma3server_x64 \ - -name=Arma-Server-"${servernum}" \ - -config=~/Arma/Server-"${servernum}"/server.cfg \ - -noSound \ - -port="${SERVERPORT}" \ - -mod="\"${MODS}\"" + "Arma-Server-${servernum}" \ + ~/Arma/Server-"${servernum}"/arma3server_x64 \ + -name=Arma-Server-${servernum} -config=server.cfg -noSound -port=${SERVERPORT} -mod="${MODS}" else echo "The session Arma-Server-${servernum} already exists, please close it before running a new session" exit 1 diff --git a/CentOS/Arma/Mods/Arma-Install-Mod.bash b/CentOS/Arma/Mods/Arma-Install-Mod.bash index 2194b64..095517f 100755 --- a/CentOS/Arma/Mods/Arma-Install-Mod.bash +++ b/CentOS/Arma/Mods/Arma-Install-Mod.bash @@ -1,5 +1,6 @@ #!/bin/bash --posix +set +e usage() { printf "%s\n" \ @@ -13,9 +14,6 @@ usage() { --workshop-id | -w Example: --workshop-id 450814997 - --mod-name | -m - Example: - --mod-name @cba3 Note: All mod names are converted to lowercase, Arma 3 requires lowercase mod names for linux." } @@ -47,7 +45,7 @@ confirmation() { SERVERNUM="" STEAMUSER="" WORKSHOPID="" -MODNAME="" +#MODNAME="" # Arg parsing is done here while :; do @@ -72,10 +70,10 @@ while :; do shift WORKSHOPID="${1}" ;; - -m | --mod-name) - shift - MODNAME="${1}" - ;; +# -m | --mod-name) +# shift +# MODNAME="${1}" +# ;; -?*) printf 'Unknown option: %s\n' "$1" >&2 usage @@ -96,42 +94,37 @@ done [[ "${WORKSHOPID}" == "" ]] && error "Error: An argument for workshop-id must be provided" [[ "${WORKSHOPID}" =~ [^0-9]+. ]] && error "Error: The argument for workshop-id must be a number" -[[ "${MODNAME}" == "" ]] && error "Error: An argument for mod-name must be provided" +#[[ "${MODNAME}" == "" ]] && error "Error: An argument for mod-name must be provided" [[ -d ~/Arma/Server-"${SERVERNUM}" ]] || error "Error: Arma Server ${SERVERNUM} does not exist!" -# Converts the modname to lowercase as Arma 3 on linux requires lowercase mod directory names -MODNAME=$(echo "${MODNAME}" | tr '[:upper:]' '[:lower:]') - -# Prefix mod with @ -MODNAME="@${MODNAME}" +## Converts the modname to lowercase as Arma 3 on linux requires lowercase mod directory names +#MODNAME=$(echo "${MODNAME}" | tr '[:upper:]' '[:lower:]') +# +## Prefix mod with @ +#MODNAME="@${MODNAME}" # Create the mods directory if it doesn't exist [[ -d ~/Arma/Server-"${SERVERNUM}"/mods ]] \ || mkdir -p ~/Arma/Server-"${SERVERNUM}"/mods && echo "Info: Created mods directory as it did not exist" -echo "Info: Downloading mod ${WORKSHOPID} as ${MODNAME}" +echo "Info: Downloading mod ${WORKSHOPID}" # Download the mod -steamcmd +login "${STEAMUSER}" +force_install_dir ~/Arma/Server-"${SERVERNUM}" +workshop_download_item 107410 "${WORKSHOPID}" +quit \ +steamcmd +login "${STEAMUSER}" +force_install_dir ~/Arma/Server-"${SERVERNUM}" +workshop_download_item 107410 "${WORKSHOPID}" validate +quit \ && echo && echo "Info: Finished Downloading mod" # Finally install the mod into the mods directory -echo "Info: Installing the mod ${MODNAME}" -[[ -d "${HOME}/Arma/Server-${SERVERNUM}/mods/${MODNAME}" ]] && rm -rf "${HOME}/Arma/Server-${SERVERNUM}/mods/${MODNAME}" -[[ -d ~/Arma/Server-"${SERVERNUM}"/mods/"${MODNAME}" ]] \ - || mkdir -p ~/Arma/Server-"${SERVERNUM}"/mods/"${MODNAME}" \ - && echo "Info: Created the ${MODNAME} directory within mods" -mv "${HOME}/Arma/Server-${SERVERNUM}/steamapps/workshop/content/107410/${WORKSHOPID}"/* "${HOME}/Arma/Server-${SERVERNUM}/mods/${MODNAME}" +echo "Info: Installing the mod ${WORKSHOPID}" +[[ -d "${HOME}/Arma/Server-${SERVERNUM}/mods/${WORKSHOPID}" ]] && rm -rf "${HOME}/Arma/Server-${SERVERNUM}/mods/${WORKSHOPID}" +[[ -d ~/Arma/Server-"${SERVERNUM}"/mods/"${WORKSHOPID}" ]] \ + || mkdir -p ~/Arma/Server-"${SERVERNUM}"/mods/"${WORKSHOPID}" \ + && echo "Info: Created the ${WORKSHOPID} directory within mods" +mv "${HOME}/Arma/Server-${SERVERNUM}/steamapps/workshop/content/107410/${WORKSHOPID}"/* "${HOME}/Arma/Server-${SERVERNUM}/mods/${WORKSHOPID}" -bikey_location=$(find ~/Arma/Server-"${SERVERNUM}"/mods/"${MODNAME}"/ -name "*.bikey") +bikey_location=$(find ~/Arma/Server-"${SERVERNUM}"/mods/"${WORKSHOPID}"/ -name "*.bikey") [[ -z "${bikey_location}" ]] || cp -f "${bikey_location}" "${HOME}/Arma/Server-${SERVERNUM}/keys/$(basename "${bikey_location}")" -for fd in $(find "${HOME}/Arma/Server-${SERVERNUM}/mods/${MODNAME}"); do - new_name="$(basename "$(echo ${fd} | tr '[:upper:]' '[:lower:]')")" - mv "${fd}" "$(dirname "${fd}")/${new_name}" 2>/dev/null -done - -echo "Info: Successfully installed the mod ${MODNAME} (${WORKSHOPID}) to Server-${SERVERNUM}" +echo "Info: Successfully installed the mod ${WORKSHOPID} to Server-${SERVERNUM}" diff --git a/CentOS/Arma/Mods/Parse-Arma-Modlist.py b/CentOS/Arma/Mods/Arma-Parse-Modlist.py similarity index 95% rename from CentOS/Arma/Mods/Parse-Arma-Modlist.py rename to CentOS/Arma/Mods/Arma-Parse-Modlist.py index 2a94c09..52c3f1d 100644 --- a/CentOS/Arma/Mods/Parse-Arma-Modlist.py +++ b/CentOS/Arma/Mods/Arma-Parse-Modlist.py @@ -28,7 +28,7 @@ def parse_html(html: str) -> list[list[str, int]]: continue mod_workshop_id = int(mod_link.split("id=")[-1]) - mod_name: str = mod.find("td").contents[-1].casefold().strip().replace(" ", "_") + mod_name: str = mod.find("td").contents[-1].replace(" ", "_").replace("-", "") mods.append([mod_name, mod_workshop_id]) return mods @@ -66,7 +66,7 @@ def main(args: list[str]): mods = parse_html(html) for mod in mods: - command = f"Arma-Install-Mod -s {server} -w {mod[-1]} -m {mod[0]} -u {user}" + command = f"Arma-Install-Mod -s {server} -w {mod[-1]} -u {user}" print(f"Executing: \"{command}\"") result = subprocess.run( command.split(" ") diff --git a/CentOS/Arma/README.md b/CentOS/Arma/README.md new file mode 100644 index 0000000..825c6aa --- /dev/null +++ b/CentOS/Arma/README.md @@ -0,0 +1,50 @@ +# Arma Scripts Documentation +All script usages can be found by passing the "-h" flag unless explicity stated otherwise, for example: +`Arma-Start-Server -h` + +## Arma-Install-Mod +Used to install mods to an Arma 3 Server + +- Usage: + - `Arma-Install-Mod -u -s -w ` + - Example: + - `Arma-Install-Mod -u treatybreaker -s 0 -w 463939057 -m ace3` + - This would install the ace3 mod to the server named "Arma-Server-0" + - Flags + - `-u` | `--user` + - The steam user that is used to login and download mods from the steam workshop + - `-s` | `--server` + - The server number corresponding to the server in ~/Arma/ where the server number is the last character in + the server name + - E.g. The server is named: "Server-0" then the server number would be "0" + - `-w` | `--workshop-id` + - The workshop id from the arma3 workshop (the last numbers in the steam workshop url) + - Example: https://steamcommunity.com/workshop/filedetails/?id=463939057, the workshop-id would be + 463939057 + +## Arma-Parse-Modlist +In the Arma 3 launcher it is possible to export a selected modlist as a html file. The exported modlist can be used with +`Arma-Parse-Modlist` to automatically install all mods from a given modlist -- significantly faster than using +`Arma-Install-Mod` on files one at a time. + +A modlist can be exported to the server via scp like so: + +`scp Arma-Modlist.html user@host:~/` -- this will send the modlist to the home directory of the given user + +- Usage + - `Arma-Parse-Modlist ` + - Example: + - `Arma-Parse-Modlist ~/Arma-Modlist.html treatybreaker 0` + - This would install all mods in the given modlist to "Arma-Server-0" + - Positional Arguments + - `` + - The absolute path to a given modlist, using relative paths *may* work, but is not supported nor + recommended + - `` + - The steam user that is used to login and download mods from the steam workshop + - `` + - The server number corresponding to the server in ~/Arma/ where the server number is the last character in + the server name + - E.g. The server is named: "Server-0" then the server number would be "0" + +## Arma-Start-Server