Files
dayz-servers/modserver/globals.sh
2023-11-20 20:44:19 -06:00

126 lines
2.7 KiB
Bash

#!/bin/sh
#
# values used on both the modserver and individual servers
# ------------------------------------------------------------
################### GLOBAL VARS ##############################
export DAYZ_GAME_ID=221100
export DAYZ_SERVER_ID=223350
export STEAM_USER="yzaddayz"
export DEBUG=false
export REMOTE_DIR="/mnt/dayz"
export REMOTE_MAPS="$REMOTE_DIR/stock/maps"
export REMOTE_MODS="$REMOTE_DIR/mods"
export REMOTE_STOCK_SERVER="$REMOTE_DIR/stock/DayZServer"
export REMOTE_STOCK_GAME="$REMOTE_DIR/stock/DayZ"
################### GLOBAL VARS ##############################
################### GLOBAL ALIASES ###########################
alias do_sync='rsync -rvltDhu --delete --partial --progress'
################### GLOBAL ALIASES ###########################
################### GLOBAL FUNCTIONS #########################
msg() {
printf '[*] %s\n' "$*"
}
errmsg() {
>&2 printf '[Error]: %s\n' "$*"
}
die() {
errmsg "$*"
exit 1
}
isnum() {
case $1 in
''|*[!0-9]*)
exit 1
;;
*)
exit 0
esac
}
isempty() {
for arg in "$@" ; do
# exit in error if file
if [ -f "$arg" ] ; then
exit 1
elif [ -L "$arg" ] ; then
# if is a symlink, check what it points to
# note: this only checks one-link level deep
if [ -d "$(readlink "$arg")" ] ; then
exit 0
else
exit 1
fi
elif [ -d "$arg" ] ; then
:
else
# is not a directory or a link to a directory
exit 1
fi
# there should be a way to make this be builtins only
# using printf and glob expansions, look into later
if /bin/rmdir "$arg" 2>/dev/null ; then
/bin/mkdir -p "$arg"
exit 0
else
exit 1
fi
done
}
mount_dayz_network_drive() {
if ! is_network_drive_mounted ; then
sudo mkdir -p /mnt/dayz
if [ -e /proc/version ] ; then
read -r ver < /proc/version
case $ver in
# WSL
*icrosoft*)
msg "Detected WSL, mounting via drvfs"
sudo mount -t drvfs -o user=samba \
//truenas.local.wvr.sh/dayz /mnt/dayz
;;
*)
msg "Detected Linux, mounting via cifs"
# shellcheck disable=2046
sudo mount -t cifs //truenas.local.wvr.sh/dayz /mnt/dayz \
-o rw \
-o credentials=/root/sambacreds.txt \
-o iocharset=utf8 \
-o vers=3.0 \
-o uid=$(id -u) \
-o gid=$(id -g)
esac
unset ver
else
errmsg 'could not find /proc/version'
exit 1
fi
fi
if ! is_network_drive_mounted ; then
errmsg 'Could not mount network drive'
exit 1
fi
}
is_network_drive_mounted() {
if [ ! -f "$REMOTE_DIR/canary" ] ; then
return 1
fi
# test write
touch /mnt/dayz/canary.test
if [ $? -eq 0 ] ; then
rm /mnt/dayz/canary.test
else
errmsg "Mounted network drive but we do not have write access."
exit 1
fi
}
################### GLOBAL FUNCTIONS #########################