Arma Script 1.0 :letsgo: -- README docs

This commit is contained in:
Price Hiller 2021-07-30 14:27:08 -05:00
parent dfc01357bc
commit dc5d7e4f43
6 changed files with 97 additions and 52 deletions

View File

@ -9,4 +9,4 @@ echo \
tmux attach-session -t "Arma-Server-${1}" tmux attach-session -t "Arma-Server-${1}"
exit ${?} exit ${?

View File

@ -5,5 +5,7 @@
# E.g. game is set to run on port 100, then ports 100-104 need to be opened # 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 # By default Arma 3 runs from port 2302
firewall-cmd --zone=public --add-port=2300-2309/udp --permanent 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 firewall-cmd --reload

View File

@ -2,7 +2,7 @@
usage() { usage() {
printf "%s\n" \ printf "%s\n" \
"Usage: Autodelete-Files -u <steam username> -p <steam password> "Usage: $(basename "${0}") -u <steam username> -p <steam password>
--user <steam username> | -u <steam username> --user <steam username> | -u <steam username>
The username used to login for steam The username used to login for steam
@ -21,10 +21,8 @@ usage() {
Skips the steam update and validation and just starts the server Skips the steam update and validation and just starts the server
Example: Example:
--no-update --no-update"
--force-checksum | -c
"
} }
error() { error() {
@ -108,43 +106,45 @@ fi
mkdir -p ~/".local/share/Arma 3 - Other Profiles" && echo "Created the Arma 3 Other Profiles" 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="" MODS=""
MODPATH=~/Arma/Server-"${servernum}"/mods MODPATH=~/Arma/Server-"${servernum}"/mods
for mod in $(ls "${MODPATH}") for mod in $(ls "${MODPATH}")
do do
echo "Adding mod ${mod}" echo "Adding mod ${mod}"
new_mod="${MODPATH}/${mod}" MODS="${MODS}mods/${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};"
echo "Successfully added mod ${mod}" echo "Successfully added mod ${mod}"
done done
echo "Mods added to startup: ${MODS}" 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 tmux has-session -t "Arma-Server-${servernum}" 2>/dev/null
if [ ${?} != 0 ]; then if [ ${?} != 0 ]; then
echo \ echo \
"Startup Args: "Startup Args:
-name=Arma-Server-${servernum} -name=Arma-Server-${servernum}
-config=~/Arma/Server-${servernum}/server.cfg -config=server.cfg
-noSound -noSound
-port=${SERVERPORT} -port=${SERVERPORT}
-mod=\"${MODS}\"" -mod=\"${MODS}\""
echo "Starting new session..." echo "Starting new session..."
cd ~/Arma/Server-"${servernum}"/
tmux new-session -d -s \ tmux new-session -d -s \
"Arma-Server-${servernum}" \ "Arma-Server-${servernum}" \
~/Arma/Server-"${servernum}"/arma3server_x64 \ ~/Arma/Server-"${servernum}"/arma3server_x64 \
-name=Arma-Server-"${servernum}" \ -name=Arma-Server-${servernum} -config=server.cfg -noSound -port=${SERVERPORT} -mod="${MODS}"
-config=~/Arma/Server-"${servernum}"/server.cfg \
-noSound \
-port="${SERVERPORT}" \
-mod="\"${MODS}\""
else else
echo "The session Arma-Server-${servernum} already exists, please close it before running a new session" echo "The session Arma-Server-${servernum} already exists, please close it before running a new session"
exit 1 exit 1

View File

@ -1,5 +1,6 @@
#!/bin/bash --posix #!/bin/bash --posix
set +e
usage() { usage() {
printf "%s\n" \ printf "%s\n" \
@ -13,9 +14,6 @@ usage() {
--workshop-id <int> | -w <int> --workshop-id <int> | -w <int>
Example: Example:
--workshop-id 450814997 --workshop-id 450814997
--mod-name <string> | -m <string>
Example:
--mod-name @cba3
Note: Note:
All mod names are converted to lowercase, Arma 3 requires lowercase mod names for linux." All mod names are converted to lowercase, Arma 3 requires lowercase mod names for linux."
} }
@ -47,7 +45,7 @@ confirmation() {
SERVERNUM="" SERVERNUM=""
STEAMUSER="" STEAMUSER=""
WORKSHOPID="" WORKSHOPID=""
MODNAME="" #MODNAME=""
# Arg parsing is done here # Arg parsing is done here
while :; do while :; do
@ -72,10 +70,10 @@ while :; do
shift shift
WORKSHOPID="${1}" WORKSHOPID="${1}"
;; ;;
-m | --mod-name) # -m | --mod-name)
shift # shift
MODNAME="${1}" # MODNAME="${1}"
;; # ;;
-?*) -?*)
printf 'Unknown option: %s\n' "$1" >&2 printf 'Unknown option: %s\n' "$1" >&2
usage usage
@ -96,42 +94,37 @@ done
[[ "${WORKSHOPID}" == "" ]] && error "Error: An argument for workshop-id must be provided" [[ "${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" [[ "${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!" [[ -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 ## Converts the modname to lowercase as Arma 3 on linux requires lowercase mod directory names
MODNAME=$(echo "${MODNAME}" | tr '[:upper:]' '[:lower:]') #MODNAME=$(echo "${MODNAME}" | tr '[:upper:]' '[:lower:]')
#
# Prefix mod with @ ## Prefix mod with @
MODNAME="@${MODNAME}" #MODNAME="@${MODNAME}"
# Create the mods directory if it doesn't exist # Create the mods directory if it doesn't exist
[[ -d ~/Arma/Server-"${SERVERNUM}"/mods ]] \ [[ -d ~/Arma/Server-"${SERVERNUM}"/mods ]] \
|| mkdir -p ~/Arma/Server-"${SERVERNUM}"/mods && echo "Info: Created mods directory as it did not exist" || 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 # 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" && echo && echo "Info: Finished Downloading mod"
# Finally install the mod into the mods directory # Finally install the mod into the mods directory
echo "Info: Installing the mod ${MODNAME}" echo "Info: Installing the mod ${WORKSHOPID}"
[[ -d "${HOME}/Arma/Server-${SERVERNUM}/mods/${MODNAME}" ]] && rm -rf "${HOME}/Arma/Server-${SERVERNUM}/mods/${MODNAME}" [[ -d "${HOME}/Arma/Server-${SERVERNUM}/mods/${WORKSHOPID}" ]] && rm -rf "${HOME}/Arma/Server-${SERVERNUM}/mods/${WORKSHOPID}"
[[ -d ~/Arma/Server-"${SERVERNUM}"/mods/"${MODNAME}" ]] \ [[ -d ~/Arma/Server-"${SERVERNUM}"/mods/"${WORKSHOPID}" ]] \
|| mkdir -p ~/Arma/Server-"${SERVERNUM}"/mods/"${MODNAME}" \ || mkdir -p ~/Arma/Server-"${SERVERNUM}"/mods/"${WORKSHOPID}" \
&& echo "Info: Created the ${MODNAME} directory within mods" && echo "Info: Created the ${WORKSHOPID} directory within mods"
mv "${HOME}/Arma/Server-${SERVERNUM}/steamapps/workshop/content/107410/${WORKSHOPID}"/* "${HOME}/Arma/Server-${SERVERNUM}/mods/${MODNAME}" 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}")" [[ -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 ${WORKSHOPID} to Server-${SERVERNUM}"
echo "Info: Successfully installed the mod ${MODNAME} (${WORKSHOPID}) to Server-${SERVERNUM}"

View File

@ -28,7 +28,7 @@ def parse_html(html: str) -> list[list[str, int]]:
continue continue
mod_workshop_id = int(mod_link.split("id=")[-1]) 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]) mods.append([mod_name, mod_workshop_id])
return mods return mods
@ -66,7 +66,7 @@ def main(args: list[str]):
mods = parse_html(html) mods = parse_html(html)
for mod in mods: 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}\"") print(f"Executing: \"{command}\"")
result = subprocess.run( result = subprocess.run(
command.split(" ") command.split(" ")

50
CentOS/Arma/README.md Normal file
View File

@ -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 <steam username> -s <server id> -w <workshop id>`
- 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 <path/to/modlist> <steam username> <server number>`
- Example:
- `Arma-Parse-Modlist ~/Arma-Modlist.html treatybreaker 0`
- This would install all mods in the given modlist to "Arma-Server-0"
- Positional Arguments
- `<path/to/modlist>`
- The absolute path to a given modlist, using relative paths *may* work, but is not supported nor
recommended
- `<steam username>`
- The steam user that is used to login and download mods from the steam workshop
- `<server number>`
- 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