Add more dependency checking to make sure things don't run when they're not met.

This commit is contained in:
Daniel Ceregatti 2022-03-26 18:04:04 -07:00
parent 618488224f
commit ccc9302a3e

View file

@ -25,7 +25,8 @@ DEFAULT_CFG="${CFG_SRC_FILES}/default.cfg"
# Battle Eye files # Battle Eye files
BE_SERVER_FILE="beserver_x64.cfg" BE_SERVER_FILE="beserver_x64.cfg"
BE_SERVER_DST="${SERVER_FILES}/battleye/${BE_SERVER_FILE}" BE_SERVER_DIR="${SERVER_FILES}/battleye"
BE_SERVER_DST="${BE_SERVER_DIR}/${BE_SERVER_FILE}"
BE_SERVER_SRC="${CFG_SRC_FILES}/${BE_SERVER_FILE}" BE_SERVER_SRC="${CFG_SRC_FILES}/${BE_SERVER_FILE}"
# Server configuration file # Server configuration file
@ -37,7 +38,7 @@ SERVER_CFG_SRC="${CFG_SRC_FILES}/${SERVER_CFG_FILE}"
SERVER_INSTALL_FILE="${SERVER_FILES}/DayZServer" SERVER_INSTALL_FILE="${SERVER_FILES}/DayZServer"
# Steam files # Steam files
STEAM_LOGIN_DST="${HOME}/.steamlogin" STEAM_LOGIN_DST="${HOME}/steamlogin"
STEAMCMD=steamcmd.sh STEAMCMD=steamcmd.sh
# Workshop # Workshop
@ -52,6 +53,7 @@ fn_prompt_yn(){
echo echo
return 0 return 0
else else
echo
return 1 return 1
fi fi
} }
@ -63,8 +65,11 @@ fn_loadconfig_dayz(){
then then
echo "Creating initial server configuration file" echo "Creating initial server configuration file"
cp "${SERVER_CFG_SRC}" "${SERVER_CFG_DST}" cp "${SERVER_CFG_SRC}" "${SERVER_CFG_DST}"
elif diff -q "${SERVER_CFG_SRC}" "${SERVER_CFG_DST}" > /dev/null elif ! diff -q "${SERVER_CFG_SRC}" "${SERVER_CFG_DST}"
then then
echo "========================================================================="
diff -Nau --color "${SERVER_CFG_SRC}" "${SERVER_CFG_DST}"
echo "========================================================================="
if fn_prompt_yn "The new server configuration file differs from what's installed. Use it?" if fn_prompt_yn "The new server configuration file differs from what's installed. Use it?"
then then
echo "Updating the server configuration file" echo "Updating the server configuration file"
@ -77,16 +82,23 @@ fn_loadconfig_dayz(){
# Checks for the destination file are already done before calls to this # Checks for the destination file are already done before calls to this
fn_do_rcon(){ fn_do_rcon(){
echo -n "Creating the Battle Eye configuration file " if [ ! -d "${BE_SERVER_DIR}" ]
cp "${BE_SERVER_SRC}" "${BE_SERVER_DST}"
# Set a random RCON password, unless one's set in the environment
if grep -q RCON_PASSWORD "${BE_SERVER_SRC}"
then then
RCON_PASSWORD=$(< /dev/urandom tr -dc 'A-Za-z0-9' | head -c10) echo
echo -e "using random RCON password ${yellow}${RCON_PASSWORD}${default}" echo -e "${yellow}DayZ is not installed yet. Can't manage RCON until then${default}"
sed -i "${BE_SERVER_DST}" -e "s/RCON_PASSWORD/${RCON_PASSWORD}/" echo
else else
echo "using the RCON_PASSWORD already set in ${BE_SERVER_SRC}." echo -n "Creating the Battle Eye configuration file "
cp "${BE_SERVER_SRC}" "${BE_SERVER_DST}"
# Set a random RCON password, unless one's set in the environment
if grep -q RCON_PASSWORD "${BE_SERVER_SRC}"
then
RCON_PASSWORD=$(< /dev/urandom tr -dc 'A-Za-z0-9' | head -c10)
echo -e "using random RCON password ${yellow}${RCON_PASSWORD}${default}"
sed -i "${BE_SERVER_DST}" -e "s/RCON_PASSWORD/${RCON_PASSWORD}/"
else
echo "using the RCON_PASSWORD already set in ${BE_SERVER_SRC}."
fi
fi fi
} }
@ -149,6 +161,7 @@ fn_steam_login(){
echo "Steam login set to 'anonymous'" echo "Steam login set to 'anonymous'"
steamlogin="anonymous" steamlogin="anonymous"
fi fi
echo "steamlogin=${steamlogin}" > "${STEAM_LOGIN_DST}"
${STEAMCMD} +force_install_dir ${SERVER_FILES} +login "${steamlogin}" +quit ${STEAMCMD} +force_install_dir ${SERVER_FILES} +login "${steamlogin}" +quit
fi fi
} }
@ -281,9 +294,12 @@ fn_rcon(){
then then
fn_do_rcon fn_do_rcon
fi fi
echo "==================================================================" if [ -f "${BE_SERVER_DST}" ]
cat "${BE_SERVER_DST}" then
echo "==================================================================" echo "=================================================================="
cat "${BE_SERVER_DST}"
echo "=================================================================="
fi
;; ;;
reset) reset)
if fn_prompt_yn "Reset RCON password?" if fn_prompt_yn "Reset RCON password?"
@ -328,8 +344,7 @@ case "${1}" in
**) **)
echo echo
echo -e "${red}Unknown or missing option: '${1}'${default}" echo -e "${red}Unknown or missing option: '${1}'${default}"
echo -e "${green}Usage: $(basename $0) [ backup | login | rcon [ show | reset ] | stop | update | workshop [ add id | list | remove id ] ]${default}" echo -e "${green}Usage: $(basename $0) [ backup | install | login | rcon [ show | reset ] | stop | update | workshop [ add id | list | remove id ] ]${default}"
echo echo
exit 0
;; ;;
esac esac