152 lines
3.6 KiB
Bash
Executable File
152 lines
3.6 KiB
Bash
Executable File
#!/bin/bash --posix
|
|
|
|
usage() {
|
|
printf "%s\n" \
|
|
"Usage: Autodelete-Files -u <steam username> -p <steam password>
|
|
--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
|
|
|
|
--force-checksum | -c
|
|
"
|
|
}
|
|
|
|
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"
|
|
|
|
|
|
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};"
|
|
echo "Successfully added mod ${mod}"
|
|
done
|
|
|
|
echo "Mods added to startup: ${MODS}"
|
|
|
|
SERVERPORT=$(("2300" + "${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
|
|
-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}\""
|
|
else
|
|
echo "The session Arma-Server-${servernum} already exists, please close it before running a new session"
|
|
exit 1
|
|
fi
|