#!/bin/bash set -e ROHOMEPATH=/nwn/home HOMEPATH=/nwn/run # Let's make a shadow-copy of home and link us in for p in database hak modules override portraits saves servervault tlk development; do if [ ! -d $ROHOMEPATH/$p ]; then mkdir -p -v $ROHOMEPATH/$p; fi if [ ! -e $HOMEPATH/$p ]; then ln -vs $ROHOMEPATH/$p $HOMEPATH/; fi done for p in dialog.tlk dialogf.tlk; do if [ ! -L $HOMEPATH/$p ]; then ln -vs $ROHOMEPATH/$p $HOMEPATH/; fi done if [ -e $ROHOMEPATH/settings.tml ] && [ ! -e $HOMEPATH/settings.tml ]; then ln -vs $ROHOMEPATH/settings.tml $HOMEPATH/; fi # Setup read-only copies of nwn and nwnplayer.ini if [ -f $ROHOMEPATH/nwn.ini ]; then <$ROHOMEPATH/nwn.ini awk -f /nwn/prep-nwn-ini.awk >$HOMEPATH/nwn.ini fi if [ -f $ROHOMEPATH/nwnplayer.ini ]; then <$ROHOMEPATH/nwnplayer.ini awk -f /nwn/prep-nwnplayer-ini.awk >$HOMEPATH/nwnplayer.ini fi if [ -f $ROHOMEPATH/cryptographic_secret ]; then cp -a $ROHOMEPATH/cryptographic_secret $HOMEPATH/ fi function backup_runtime_configuration { # If we generated a cryptographic_secret, put it back into the public dir if [ -f $HOMEPATH/cryptographic_secret ] && [ ! -f $ROHOMEPATH/cryptographic_secret ]; then cp -va $HOMEPATH/cryptographic_secret $ROHOMEPATH/cryptographic_secret fi # If we generated a settings.tml, put it back into the public dir if [ -f $HOMEPATH/settings.tml ] && [ ! -f $ROHOMEPATH/settings.tml ]; then cp -va $HOMEPATH/settings.tml $ROHOMEPATH/settings.tml fi } (sleep 10; backup_runtime_configuration) & args=() if [[ "${NWN_MODULEURL}" != "" ]]; then args+=("-moduleurl" "${NWN_MODULEURL}") else args+=("-module" "${NWN_MODULE:-DockerDemo}") fi if [[ "${NWN_NWSYNCURL}" != "" ]]; then args+=("-nwsyncurl" "${NWN_NWSYNCURL}") fi if [[ "${NWN_NWSYNCHASH}" != "" ]]; then args+=("-nwsynchash" "${NWN_NWSYNCHASH}") fi if [[ "${NWN_MODULEHASH}" != "" ]]; then args+=("-modulehash" "${NWN_MODULEHASH}") fi copycrashlog() { inotifywait -mq -e moved_to -e create "$HOMEPATH" --format "%f" | while read f do # check if the file is a crash log file if [[ $f = nwserver-crash*.log ]]; then cp -a $HOMEPATH/$f $ROHOMEPATH/ fi done } copycrashlog & copyruntimeconfiguration() { inotifywait -mq -e close_write "$HOMEPATH" --format "%f" | while read f do if [[ $f = cryptographic_secret ]] || [[ $f = settings.tml ]]; then backup_runtime_configuration fi done } copyruntimeconfiguration & set +e exec env LD_PRELOAD="/nwn/rs/runtime.so" ./nwserver-linux \ $NWN_EXTRA_ARGS \ -port ${NWN_PORT:-5121} \ -interactive \ -servername "${NWN_SERVERNAME:-I was too lazy to configure my server.}" \ -publicserver "${NWN_PUBLICSERVER:-0}" \ -maxclients "${NWN_MAXCLIENTS:-96}" \ -minlevel "${NWN_MINLEVEL:-1}" \ -maxlevel "${NWN_MAXLEVEL:-40}" \ -pauseandplay "${NWN_PAUSEANDPLAY:-1}" \ -pvp "${NWN_PVP:-2}" \ -servervault "${NWN_SERVERVAULT:-1}" \ -elc "${NWN_ELC:-1}" \ -ilr "${NWN_ILR:-1}" \ -gametype "${NWN_GAMETYPE:-0}" \ -oneparty "${NWN_ONEPARTY:-0}" \ -difficulty "${NWN_DIFFICULTY:-3}" \ -autosaveinterval "${NWN_AUTOSAVEINTERVAL:-0}" \ -playerpassword "${NWN_PLAYERPASSWORD}" \ -dmpassword "${NWN_DMPASSWORD}" \ -adminpassword "${NWN_ADMINPASSWORD}" \ -reloadwhenempty "${NWN_RELOADWHENEMPTY:-0}" \ "${args[@]}" RET=$? set -e backup_runtime_configuration # If this thing crashed, copy the log to the public home so the user # can deliberate over it. if ls $HOMEPATH/nwserver-crash* 1> /dev/null 2>&1; then echo "The server crashed with return code "$RET". Trying to save crash data into your mounted server home." cp -va $HOMEPATH/nwserver-crash*.log $ROHOMEPATH/ || true fi exit $RET