From 600cd2bcf31c9337f5332a6dbcbe60d5e04b1fd9 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Wed, 27 Dec 2017 10:50:45 +0000 Subject: Bring back config dir linking. The configs aren't exec'd on the command line anymore, but the server operator might still want to exec them on-the-fly to update settings. --- run-instance.sh | 51 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/run-instance.sh b/run-instance.sh index 05b9947..52805a4 100755 --- a/run-instance.sh +++ b/run-instance.sh @@ -27,11 +27,31 @@ function debug { } function check_file { - [ -f "$1" ] || error "%s '%s' is not a file\n" "$2" "$1" + [ -e "$1" ] || error "'%s' doesn't exist\n" "$1" + [ -d "$1" ] && error "'%s' is a directory, not a file\n" "$1" + [ -f "$1" ] || error "'%s' exists but isn't a file\n" "$1" } function check_dir { - [ -d "$1" ] || error "%s '%s' is not a directory\n" "$2" "$1" + [ -e "$1" ] || error "'%s' doesn't exist\n" "$1" + [ -f "$1" ] && error "'%s' is a file, not a directory\n" "$1" + [ -d "$1" ] || error "'%s' exists but isn't a directory\n" "$1" +} + +function ensure_link { + if [ -L "$2" ]; then + debug "ensure_link: '%s' already exists\n" "$2" + if [ `readlink "$2"` == "$1" ]; then + return + fi + + debug "ensure_link: ...and points at '%s' instead of '%s'\n" `readlink "$2"` "$1" + unlink "$2" || error "couldn't unlink '%s'\n" "$2" + fi + + mkdir -p `dirname "$2"` || error + ln -s "$1" "$2" || error "linking failed\n" + debug "ensure_link: linked '%s' -> '%s'\n" "$2" "$1" } ################# @@ -48,8 +68,9 @@ true ${OVER_PREFIX:="$PREFIX/over@"} true ${HOME_PREFIX:="$PREFIX/home@"} true ${FS_GAME:="slacker"} -# Config directory. -true ${CONFIG_PREFIX:="$PREFIX/config/"} +# Config directory: as seen by tremded's vfs and the absolute path, respectively. +true ${CONFIG_LOCAL:="config"} +true ${CONFIG_GLOBAL:="$PREFIX/$CONFIG_LOCAL"} # Executables. true ${GDB_WRAPPER:="$PREFIX/bin/gdb-wrapper2.sh"} @@ -75,16 +96,22 @@ I="$1" TREMDED="$TREMDED_PREFIX$I" OVER="$OVER_PREFIX$I" HOME="$HOME_PREFIX$I" -CONFIG_COMMON="$CONFIG_PREFIX/common.cfg" -CONFIG_INST="$CONFIG_PREFIX/$I.cfg" +CONFIG_COMMON="$CONFIG_GLOBAL/common.cfg" +CONFIG_INST="$CONFIG_GLOBAL/$I.cfg" # Do some integrity checks. -check_file "$TREMDED" "the tremded" -check_dir "$OVER" "the over directory" -check_file "$OVER/$FS_GAME/game.so" "the game.so" -check_dir "$HOME" "the home directory" -check_file "$CONFIG_COMMON" "the common config" -check_file "$CONFIG_INST" "the instance-specific config" +[ "$NO_DEBUGGER" -eq 0 ] && check_file "$GDB_WRAPPER" +check_file "$TREMDED" +check_dir "$COMMON" +check_file "$COMMON/base/data-1.1.0.pk3" +check_dir "$OVER" +check_dir "$OVER/$FS_GAME" +check_file "$OVER/$FS_GAME/game.so" +check_dir "$HOME" +check_dir "$HOME/$FS_GAME" +check_file "$CONFIG_COMMON" +check_file "$CONFIG_INST" +ensure_link "$CONFIG_GLOBAL" "$HOME/$FS_GAME/$CONFIG_LOCAL" # Server configuration is done by overwiting the autogen. cat "$CONFIG_COMMON" "$CONFIG_INST" > "$HOME/$FS_GAME/autogen_server.cfg" \ -- cgit