diff options
Diffstat (limited to 'run-instance.sh')
| -rwxr-xr-x | run-instance.sh | 111 | 
1 files changed, 111 insertions, 0 deletions
diff --git a/run-instance.sh b/run-instance.sh new file mode 100755 index 0000000..cdb8342 --- /dev/null +++ b/run-instance.sh @@ -0,0 +1,111 @@ +#!/bin/bash + +################# +# Configuration # +################# + +DEBUG=1 + +# The root directory. +PREFIX="/home/tremded" + +# fs_basepath, fs_homepath and fs_game. +COMMON="$PREFIX/common" +HOME_PREFIX="$PREFIX/home@" +FS_GAME="slacker" + +# Config directory: as seen by tremded's vfs and the absolute path, respectively.  +CONFIG_LOCAL="config" +CONFIG_GLOBAL="$PREFIX/$CONFIG_LOCAL" + +# Executables. +GDB_WRAPPER="$PREFIX/bin/gdb-wrapper2.sh" +TREMDED_PREFIX="$PREFIX/bin/tremded@" + +#################### +# 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 { +	[ -f "$1" ] || error "%s '%s' is not a file\n" "$2" "$1" +} + +function check_dir { +	[ -d "$1" ] || error "%s '%s' is not a directory\n" "$2" "$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" +} + +################### +# 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" +HOME="$HOME_PREFIX$I" +CONFIG_LOCAL_COMMON="$CONFIG_LOCAL/common.cfg" +CONFIG_LOCAL_INST="$CONFIG_LOCAL/$I.cfg" +CONFIG_GLOBAL_COMMON="$CONFIG_GLOBAL/common.cfg" +CONFIG_GLOBAL_INST="$CONFIG_GLOBAL/$I.cfg" + +# Do some integrity tests and fix missing links. +check_file   "$TREMDED"              "the tremded" +check_dir    "$HOME"                 "the home directory" +check_file   "$CONFIG_GLOBAL_COMMON" "the common config" +check_file   "$CONFIG_GLOBAL_INST"   "the instance-specific config" +ensure_link  "${CONFIG_GLOBAL}" "$HOME/$FS_GAME/$CONFIG_LOCAL" + +# 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" \ +"$TREMDED" \ +	+exec "$CONFIG_LOCAL_COMMON" \ +	+set fs_basepath "$COMMON" \ +	+set fs_homepath "$HOME" \ +	+set fs_game "$FS_GAME" \ +	+set com_pipefile "pipe" \ +	+set dedicated 2 \ +	+exec "$CONFIG_LOCAL_INST" \ +	+map "atcs" \ +	+nocurses \ +	"$@" || error "couldn't start the server\n"  | 
