-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrun
More file actions
executable file
·140 lines (120 loc) · 2.97 KB
/
Copy pathrun
File metadata and controls
executable file
·140 lines (120 loc) · 2.97 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env bash
SCRIPT_DIR=$(cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P)
LOG_DIR=$SCRIPT_DIR/logs
BUILD_DIR=$SCRIPT_DIR/builddir
GS_SRC=$SCRIPT_DIR/Server
FORCE_REBUILD=0
REFRESH_BUILD=1
GS_EXEC="cd $GS_SRC && java -Dnashorn.args=--no-deprecation-warning -jar $BUILD_DIR/server.jar"
# 0: parallel
# 1: fancy tmux
# 2: tests only
RUN_MODE=0
help()
{
echo "Usage: $0 [-h] [-q] [-r] [-t] [-x] [-e <filename>] [-o <filename>]"
echo " -h: Display this message."
echo " -q: Don't perform the incremental build."
echo " -r: Force clean rebuild."
echo " -t: Only run tests, not the JARs."
echo " -x: Run in a fancy tmux session."
echo " -e: Write STDERR to 'logs/filename' as well as the terminal.";
echo " -o: Write STDOUT to 'logs/filename' as well as the terminal."
}
error()
{
echo "$1";
exit 1;
}
rebuild_project()
{
"$SCRIPT_DIR/build" -qgc
}
refresh_project()
{
"$SCRIPT_DIR/build" -qg
}
verify_binaries_exist()
{
if [ ! -f "$SCRIPT_DIR/build/server.jar" ]; then
error "Game server binary does not exist.";
fi
}
run_server_parallel()
{
if ! [ -x "$(command -v java)" ]; then
error "Java is not installed."
fi
echo "Running in parallel. All logs redirected to proper files."
sh -c "$GS_EXEC" & wait
}
run_server_tmux()
{
if ! [ -x "$(command -v tmux)" ]; then
error "tmux is not installed. Install tmux or don't use this option."
fi
tmux new-session "$GS_EXEC"
}
run_server_tests()
{
cd "$GS_SRC" || error "Could not change to game server source directory."
sh mvnw test
}
while getopts ":hqrtxe:o:" arg; do
case $arg in
h)
help
exit 0
;;
q)
REFRESH_BUILD=0
;;
r)
FORCE_REBUILD=1
;;
t)
RUN_MODE=2
;;
o)
GS_EXEC="$GS_EXEC > >(tee $LOG_DIR/${OPTARG})"
;;
e)
GS_EXEC="$GS_EXEC 2> >(tee $LOG_DIR/${OPTARG})"
;;
x)
RUN_MODE=1
;;
*)
error "Argument -$arg is not a known or valid argument."
;;
esac
done
if [ ! -d $LOG_DIR ]; then
mkdir -p $LOG_DIR
fi
if [ ! -d $GS_SRC/target ]; then
rebuild_project || error "Failed to perform a clean build."
else
if [ $FORCE_REBUILD -eq 1 ]; then
rebuild_project || error "Failed to perform a clean build."
else
if [ $REFRESH_BUILD -eq 1 ]; then
refresh_project || error "Failed to perform an incremental build."
fi
fi
fi;
cd "$SCRIPT_DIR/builddir" || error "Failed to navigate to the build directory."
case $RUN_MODE in
0)
# The trap will allow the script to kill the background
# Java instances upon exiting.
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
run_server_parallel
;;
1)
run_server_tmux
;;
2)
run_server_tests
;;
esac