#!/bin/bash #################### # Helper functions # #################### SELF="$0" function error { tput setaf 9 tput bold printf "%s: ERROR: " "$0" printf "$@" tput sgr0 exit 1 } function debug { if [ "$DEBUG" -ne 1 ]; then return fi tput setaf 12 printf "[DEBUG] " printf "$@" tput sgr0 } function check_file { [ -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 { [ -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" } ################# # Configuration # ################# # Load the script configuration and set some defaults. source run-instance.local.sh || error "missing config\n" [ -z "$PREFIX" ] && error "PREFIX is not set\n" # fs_basepath, fs_overpath, fs_homepath and fs_game. true ${COMMON:="$PREFIX/common"} true ${OVER_PREFIX:="$PREFIX/over@"} true ${HOME_PREFIX:="$PREFIX/home@"} true ${FS_GAME:="slacker"} # 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"} true ${TREMDED_PREFIX:="$PREFIX/bin/tremded@"} # Debugging true ${DEBUG:=1} true ${NO_DEBUGGER:=0} if [ "$NO_DEBUGGER" -ne 0 ]; then GDB_WRAPPER="exec" fi ################### # The entry point # ################### # Check the argument. [ -z "$1" ] && error "instance name is missing\nusage: %s [INSTANCE]\n" "$SELF" # Figure out all the instance-specific paths. I="$1" TREMDED="$TREMDED_PREFIX$I" OVER="$OVER_PREFIX$I" HOME="$HOME_PREFIX$I" CONFIG_COMMON="$CONFIG_GLOBAL/common.cfg" CONFIG_INST="$CONFIG_GLOBAL/$I.cfg" # Do some integrity checks. [ "$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" \ || error "couldn't overwrite the autogen\n" # cd to HOME (that's where cores will appear) and start the server. cd "$HOME" || error "cannot chdir to %s\n" "$HOME" "$GDB_WRAPPER" "$TREMDED" \ +set fs_basepath "$COMMON" \ +set fs_overpath "$OVER" \ +set fs_homepath "$HOME" \ +set fs_game "$FS_GAME" \ +set com_pipefile "pipe" \ +set dedicated 2 \ +map "atcs" \ +nocurses \ "$@" || error "couldn't start the server\n"