-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstart.sh
More file actions
148 lines (115 loc) · 3.29 KB
/
Copy pathstart.sh
File metadata and controls
148 lines (115 loc) · 3.29 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
141
142
143
144
145
146
147
148
#!/usr/bin/env bash
# Exit on error or unset variable
set -euo pipefail
# Initialize an array to hold arguments
ARGS=("python" "/app/MultiServer.py")
# PORT: maps to --port <value>
if [[ -n "${PORT:-}" ]]; then
ARGS+=("--port" "$PORT")
fi
# HOST: maps to --host <value>
if [[ -n "${HOST:-}" ]]; then
ARGS+=("--host" "$HOST")
fi
# SERVER_PASSWORD: maps to --server_password <value>
if [[ -n "${SERVER_PASSWORD:-}" ]]; then
ARGS+=("--server_password" "$SERVER_PASSWORD")
fi
# PASSWORD: maps to --password <value>
if [[ -n "${PASSWORD:-}" ]]; then
ARGS+=("--password" "$PASSWORD")
fi
# SAVE_FILE: maps to --save-file <value>
if [[ -n "${SAVE_FILE:-}" ]]; then
ARGS+=("--savefile" "$SAVE_FILE")
fi
# DISABLE_SAVE: maps to --disable_save
if [[ "${DISABLE_SAVE:-}" =~ ^[Tt][Rr][Uu][Ee]$ ]]; then
ARGS+=("--disable_save")
fi
# CERT: maps to --cert <value>
if [[ -n "${CERT:-}" ]]; then
ARGS+=("--cert" "$CERT")
fi
# CERT_KEY: maps to --cert_key <value>
if [[ -n "${CERT_KEY:-}" ]]; then
ARGS+=("--cert_key" "$CERT_KEY")
fi
# LOGLEVEL: maps to --loglevel <value>
if [[ -n "${LOGLEVEL:-}" ]]; then
ARGS+=("--loglevel" "$LOGLEVEL")
fi
# LOGTIME: maps to --logtime
if [[ "${LOGTIME:-}" =~ ^[Tt][Rr][Uu][Ee]$ ]]; then
ARGS+=("--logtime")
fi
# LOCATION_CHECK_POINTS: maps to --location_check_points <value>
if [[ -n "${LOCATION_CHECK_POINTS:-}" ]]; then
ARGS+=("--location_check_points" "$LOCATION_CHECK_POINTS")
fi
# HINT_COST: maps to --hint_cost <value>
if [[ -n "${HINT_COST:-}" ]]; then
ARGS+=("--hint_cost" "$HINT_COST")
fi
# RELEASE_MODE: maps to --release_mode <value>
if [[ -n "${RELEASE_MODE:-}" ]]; then
ARGS+=("--release_mode" "$RELEASE_MODE")
fi
# COLLECT_MODE: maps to --collect_mode <value>
if [[ -n "${COLLECT_MODE:-}" ]]; then
ARGS+=("--collect_mode" "$COLLECT_MODE")
fi
# COUNTDOWN_MODE: maps to --countdown_mode <value>
if [[ -n "${COUNTDOWN_MODE:-}" ]]; then
ARGS+=("--countdown_mode" "$COUNTDOWN_MODE")
fi
# REMAINING_MODE: maps to --remaining_mode <value>
if [[ -n "${REMAINING_MODE:-}" ]]; then
ARGS+=("--remaining_mode" "$REMAINING_MODE")
fi
#TODO autoshutdown
# USE_EMBEDDED_OPTIONS: maps to --use_embedded_options
if [[ "${USE_EMBEDDED_OPTIONS:-}" =~ ^[Tt][Rr][Uu][Ee]$ ]]; then
ARGS+=("--use_embedded_options")
fi
# COMPATIBILITY: maps to --compatibility <value>
if [[ -n "${COMPATIBILITY:-}" ]]; then
ARGS+=("--compatibility" "$COMPATIBILITY")
fi
# LOG_NETWORK: maps to --log_network
if [[ "${LOG_NETWORK:-}" =~ ^[Tt][Rr][Uu][Ee]$ ]]; then
ARGS+=("--log_network")
fi
# GAME_PATH: added as a positional argument (no flag)
if [[ -n "${GAME_PATH:-}" ]]; then
ARGS+=("$GAME_PATH")
fi
# Optional: show the final command for debugging
echo "Starting Archipelago Server:"
echo "${ARGS[*]}"
PIPE=$(mktemp -u)
mkfifo "$PIPE"
# Open FIFO for read/write to prevent blocking
exec 3<> "$PIPE"
# Start the Python server
"${ARGS[@]}" <&3 &
SERVER_PID=$!
# ----------------------------
# Signal handling
# ----------------------------
shutdown() {
echo "SIGTERM received, sending /exit"
echo "/exit" >&3
wait "$SERVER_PID"
exec 3>&-
rm -f "$PIPE"
exit 0
}
trap shutdown SIGTERM
# ----------------------------
# Wait for server to exit
# ----------------------------
wait "$SERVER_PID"
# Cleanup on normal exit
exec 3>&-
rm -f "$PIPE"