summaryrefslogtreecommitdiff
path: root/run-instance.sh
blob: 2cdfad995ca59d1b32e4f28d25f4e50de1ea822b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/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.
CONFIG_PREFIX="$PREFIX/config/"

# 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"
}

###################
# 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_COMMON="$CONFIG_PREFIX/common.cfg"
CONFIG_INST="$CONFIG_PREFIX/$I.cfg"

# Do some integrity checks.
check_file   "$TREMDED"       "the tremded"
check_dir    "$HOME"          "the home directory"
check_file   "$CONFIG_COMMON" "the common config"
check_file   "$CONFIG_INST"   "the instance-specific config"

# 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" \
	+exec "$CONFIG_LOCAL_COMMON" \
	+set fs_basepath "$COMMON" \
	+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"