Bash_Scripts/CentOS/Arma/Arma-Start-Server.bash
2021-07-28 09:29:40 -05:00

108 lines
2.4 KiB
Bash
Executable File

#!/bin/bash --posix
set -e
usage() {
printf "%s\n" "Usage: Autodelete-Files -u <steam username> -p <steam password>
--user <steam username> | -u <steam username>
Example:
--user Sbinalla
--server <server number> | -s <server number>
Example:
--server 0"
}
error() {
printf "\n%s\n" "$1" >&2
exit 1
}
confirmation() {
while true; do
read -p "${1}" -n 1 -r choice
case "$choice" in
y | Y) return 1 ;;
n | N) return 0 ;;
*) echo -e "\nInput must be either y, Y, n, or N" ;;
esac
done
}
SERVERNUM=""
STEAMUSER=""
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}"
;;
-?*)
printf 'Unknown option: %s\n' "$1" >&2
usage
error
;;
*) # Default case: No more options, so break out of the loop.
break ;;
esac
shift
done
[[ "${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"
[[ -d ~/Arma/ ]] || \
mkdir -p ~/Arma/ && echo "Created the Arma directory..."
steamcmd +quit
steamcmd +login "${STEAMUSER}" +force_install_dir ~/Arma/Server-"${SERVERNUM}" +app_update 233780 validate +quit
[[ -d ~/Arma/Server-"${SERVERNUM}"/mods ]] || \
mkdir ~/Arma/Server-"${SERVERNUM}"/mods && echo "Creating new mods directory"
# These directories are necessary for Arma servers on linux
[[ -d ~/".local/share/Arma 3" ]] || \
mkdir -p ~/".local/share/Arma 3" && echo "Created the Arma 3 share"
[[ -d ~/".local/share/Arma 3 - Other Profiles" ]] || \
mkdir -p ~/".local/share/Arma 3 - Other Profiles" && echo "Created the Arma 3 Other Profiles"
MODS=""
for mod in $(ls ~/Arma/Server-"${SERVERNUM}"/mods/)
do
echo "Adding mod ${mod}"
MODPATH=~/Arma/Server-"${SERVERNUM}"/mods
MODS="${MODS}${MODPATH}/${mod}\;"
done
echo "Mods added to startup: ${MODS}"
SERVERPORT=$(("2300" + "${SERVERNUM}"))
tmux kill-session -t "Arma-Server-${SERVERNUM}" &>/dev/null
tmux new-session -d -s \
"Arma-Server-${SERVERNUM}" \
~/Arma/Server-"${SERVERNUM}"/arma3server \
-name=Arma-Server-"${SERVERNUM}" \
-mod="${MODS}" \
-config=~/Arma/Server-"${SERVERNUM}"/server.cfg \
-noSound \
-port="${SERVERPORT}"