Bash_Scripts/CentOS/Arma/Arma-Start-Server.bash
2021-08-04 21:17:20 -05:00

151 lines
3.5 KiB
Bash
Executable File

#!/bin/bash --posix
usage() {
printf "%s\n" \
"Usage: $(basename "${0}") -s <server id> -n | $(basename "${0}") -s <server id> -u <steam username>
--user <steam username> | -u <steam username>
The username used to login for steam
Example:
--user Sbinalla
Note:
Only required when --no-update is not passed
--server <server number> | -s <server number>
The server number (the ID of the server within the Arma directory)
Example:
--server 0
--no-update | -n
Skips the steam update and validation and just starts the server
Example:
--no-update"
}
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=""
no_update=0
use_checksum=0
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}"
;;
-n | --no-update)
no_update=1
;;
-f | --force-checksum)
use_checksum=0
;;
-?*)
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}" == "" && ${no_update} == 0 ]] && error "Error: A steam user must be provided"
[[ -d ~/Arma/ ]] || \
mkdir -p ~/Arma/ && echo "Created the Arma directory..."
if [ ${no_update} == 0 ]; then
steamcmd +quit
steamcmd +login "${steamuser}" +force_install_dir ~/Arma/Server-"${servernum}" +app_update 233780 validate +quit
fi
[[ -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"
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}"
MODS="${MODS}mods/${mod};"
echo "Successfully added mod ${mod}"
done
echo "Mods added to startup: ${MODS}"
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=server.cfg
-noSound
-port=${SERVERPORT}
-mod=\"${MODS}\""
echo "Starting new session..."
tmux new-session -d -s \
"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
fi