Bash_Scripts/CentOS/Arma/Mods/Arma-Install-Mod.bash
2021-08-04 21:17:20 -05:00

133 lines
3.7 KiB
Bash
Executable File

#!/bin/bash --posix
set +e
usage() {
printf "%s\n" \
"Usage: $(basename "${0}") -u <steam username> -s <server number> -w <workshop id> -m <mod name>
--user <string> | -u <string>
Example:
--user Sbinalla
--server <int> | -s <int>
Example:
--server 0
--workshop-id <int> | -w <int>
Example:
--workshop-id 450814997
Note:
All mod names are converted to lowercase, Arma 3 requires lowercase mod names for linux."
}
error() {
printf "\n%s\n" "$1" >&2
exit 1
}
confirmation() {
local choice
while true; do
read -p "${1}" -n 1 -r choice
case "${choice}" in
y | Y)
echo ""
return 1
;;
n | N)
echo ""
return 0
;;
*) echo -e "\nInput must be either y, Y, n, or N" ;;
esac
done
}
## Variable setup
SERVERNUM=""
STEAMUSER=""
WORKSHOPID=""
#MODNAME=""
# Arg parsing is done here
while :; do
case $1 in
-h | -\? | --help)
usage # Display a usage synopsis.
exit
;;
--) # End of all options.
shift
break
;;
-s | --server)
shift
SERVERNUM="${1}"
;;
-u | --user)
shift
STEAMUSER="${1}"
;;
-w | --workshop-id)
shift
WORKSHOPID="${1}"
;;
# -m | --mod-name)
# shift
# MODNAME="${1}"
# ;;
-?*)
printf 'Unknown option: %s\n' "$1" >&2
usage
error
;;
*) # Default case: No more options, so break out of the loop.
break ;;
esac
shift
done
## Next chunk is checks to see that variables are passed and match correct arguments etc.
[[ "${SERVERNUM}" == "" ]] && error "Error: A server number must be provided"
[[ "${SERVERNUM}" =~ [^0-9]+. ]] && error "Error: The argument for server must be a number"
[[ "${STEAMUSER}" == "" ]] && error "Error: A steam user 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"
#[[ "${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}"
# 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}"
# Download the mod
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 ${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/"${WORKSHOPID}"/ -name "*.bikey")
[[ -z "${bikey_location}" ]] || cp -f "${bikey_location}" "${HOME}/Arma/Server-${SERVERNUM}/keys/$(basename "${bikey_location}")"
echo "Info: Successfully installed the mod ${WORKSHOPID} to Server-${SERVERNUM}"