-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame-server-admin-launcher.sh
More file actions
executable file
·430 lines (375 loc) · 14.8 KB
/
Copy pathgame-server-admin-launcher.sh
File metadata and controls
executable file
·430 lines (375 loc) · 14.8 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
#!/usr/bin/env bash
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk>
#
# @a2ml-metadata begin
# (
# id = "game-server-admin-launcher"
# type = "launcher"
# version = "1.0.0"
# app-name = "game-server-admin"
# app-display = "Game Server Admin"
# app-url = ""
# runtime-kind = "process"
# standards-compliance = [
# "launcher-standard.adoc"
# "LM-LA-LIFECYCLE-STANDARD.adoc"
# "cross-platform-system-integration-modes"
# ]
# standard-spec-version = "0.2.0"
# generator = "launch-scaffolder"
# )
# @a2ml-metadata end
#
# ============================================================================
# game-server-admin-launcher.sh — Game Server Admin
# ============================================================================
# GENERATED by launch-scaffolder from game-server-admin.launcher.a2ml.
# Do NOT edit this file directly — your edits will be overwritten on the next
# `launch-scaffolder realign`. Put per-app tweaks in the [exceptions] block of
# the .launcher.a2ml config instead.
# ============================================================================
set -euo pipefail
# ----------------------------------------------------------------------------
# CONFIGURATION
# ----------------------------------------------------------------------------
APP_NAME="game-server-admin"
APP_DISPLAY="Game Server Admin"
APP_DESC="Game Server Admin — multi-game server orchestration UI"
APP_CATEGORIES="Game;Network;System;"
APP_GENERIC_NAME="Game Server Admin"
RUNTIME_KIND="process"
REPO_DIR="/var/mnt/eclipse/repos/fleet-ecosystem/game-server-admin"
ICON_SOURCE="/var/mnt/eclipse/repos/fleet-ecosystem/game-server-admin/assets/icon-256.png"
# Absolute path back to the per-app `<app>.launcher.a2ml` config that
# produced this script. Consumed by the --integ / --disinteg arms when
# the `launch-scaffolder` binary is on $PATH, so they can delegate to
# the Rust implementation instead of running the shell fallback.
CONFIG_FILE="/var/mnt/eclipse/repos/fleet-ecosystem/game-server-admin/game-server-admin.launcher.a2ml"
URL=""
PID_FILE="/tmp/game-server-admin.pid"
LOG_FILE="/tmp/game-server-admin.log"
# Explicit argv from [runtime].command
START_COMMAND=(/home/hyper/.local/bin/game-server-admin-launcher --gossamer )
MODE="${1:---start}"
FORCE="false"
[[ "${2:-}" == "--force" ]] && FORCE="true"
# ----------------------------------------------------------------------------
# LOGGING HELPERS
# ----------------------------------------------------------------------------
log() { echo -e "\033[0;32m[$APP_DISPLAY]\033[0m $1"; }
warn() { echo -e "\033[0;33m[$APP_DISPLAY]\033[0m $1" >&2; }
err() { echo -e "\033[0;31m[$APP_DISPLAY]\033[0m ERROR: $1" >&2; }
is_gui_context() {
[ ! -t 2 ] && { [ -n "${DISPLAY:-}" ] || [ -n "${WAYLAND_DISPLAY:-}" ]; }
}
gui_error() {
local title="$1"
local body="$2"
err "$title"
echo "$body" | sed 's/^/ /' >&2
if is_gui_context; then
if command -v kdialog >/dev/null 2>&1; then kdialog --title "$APP_DISPLAY: $title" --error "$body" 2>/dev/null &
elif command -v zenity >/dev/null 2>&1; then zenity --error --title="$APP_DISPLAY: $title" --text="$body" --width=500 2>/dev/null &
elif command -v notify-send >/dev/null 2>&1; then notify-send --urgency=critical --icon=dialog-error "$APP_DISPLAY: $title" "$body" 2>/dev/null &
elif command -v xmessage >/dev/null 2>&1; then xmessage -center "$APP_DISPLAY: $title\n\n$body" 2>/dev/null &
fi
fi
}
# ----------------------------------------------------------------------------
# PLATFORM DETECTION
# ----------------------------------------------------------------------------
detect_platform() {
case "$(uname -s)" in
Linux*) echo "linux" ;;
Darwin*) echo "macos" ;;
CYGWIN*|MINGW*|MSYS*|Windows_NT) echo "windows" ;;
*) echo "unknown" ;;
esac
}
PLATFORM="$(detect_platform)"
case "$PLATFORM" in
linux)
APPS_DIR="$HOME/.local/share/applications"
ICON_DIR="$HOME/.local/share/icons/hicolor/256x256/apps"
DESKTOP_SHORTCUT_DIR="$HOME/Desktop"
BIN_DIR="$HOME/.local/bin"
DESKTOP_FILE_TARGET="$APPS_DIR/${APP_NAME}.desktop"
DESKTOP_SHORTCUT_TARGET="$DESKTOP_SHORTCUT_DIR/${APP_NAME}.desktop"
ICON_TARGET="$ICON_DIR/${APP_NAME}.png"
LAUNCHER_TARGET="$BIN_DIR/${APP_NAME}-launcher"
;;
macos)
APPS_DIR="$HOME/Applications"
DESKTOP_SHORTCUT_DIR="$HOME/Desktop"
BIN_DIR="$HOME/.local/bin"
DESKTOP_FILE_TARGET="$APPS_DIR/${APP_DISPLAY}.app"
DESKTOP_SHORTCUT_TARGET="$DESKTOP_SHORTCUT_DIR/${APP_DISPLAY}.command"
ICON_TARGET="$APPS_DIR/${APP_DISPLAY}.app/Contents/Resources/icon.png"
LAUNCHER_TARGET="$BIN_DIR/${APP_NAME}-launcher"
;;
windows)
APPDATA_DIR="${APPDATA:-$HOME/AppData/Roaming}"
START_MENU_DIR="$APPDATA_DIR/Microsoft/Windows/Start Menu/Programs"
DESKTOP_SHORTCUT_DIR="$HOME/Desktop"
BIN_DIR="$HOME/.local/bin"
DESKTOP_FILE_TARGET="$START_MENU_DIR/${APP_DISPLAY}.lnk"
DESKTOP_SHORTCUT_TARGET="$DESKTOP_SHORTCUT_DIR/${APP_DISPLAY}.lnk"
ICON_TARGET="$BIN_DIR/${APP_NAME}.ico"
LAUNCHER_TARGET="$BIN_DIR/${APP_NAME}-launcher.sh"
;;
*)
APPS_DIR=""; DESKTOP_SHORTCUT_DIR=""; BIN_DIR="$HOME/.local/bin"
DESKTOP_FILE_TARGET=""; DESKTOP_SHORTCUT_TARGET=""; ICON_TARGET=""
LAUNCHER_TARGET="$BIN_DIR/${APP_NAME}-launcher"
;;
esac
# ----------------------------------------------------------------------------
# PROCESS MANAGEMENT
# ----------------------------------------------------------------------------
is_running() {
[ -f "$PID_FILE" ] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null
}
clear_stale_pid() {
if [ -f "$PID_FILE" ] && ! kill -0 "$(cat "$PID_FILE")" 2>/dev/null; then
rm -f "$PID_FILE"
fi
}
start_server() {
clear_stale_pid
if is_running; then
log "Already running (PID $(cat "$PID_FILE"))"
return 0
fi
if [ -z "${START_COMMAND:-}" ] || { [ ! "${START_COMMAND:0:1}" = "(" ] && [ ! -x "${START_COMMAND%% *}" ] && ! command -v "${START_COMMAND%% *}" >/dev/null 2>&1; }; then
if [ -z "${START_COMMAND:-}" ]; then
gui_error "No startup command found" \
"$APP_DISPLAY is installed, but I don't know how to start it. Check the
[runtime].startup-command-search or [runtime].command in game-server-admin.launcher.a2ml."
return 1
fi
fi
log "Starting $APP_DISPLAY..."
cd "$REPO_DIR" 2>/dev/null || true
nohup "${START_COMMAND[@]}" >"$LOG_FILE" 2>&1 &
echo $! > "$PID_FILE"
sleep 0.2
if ! kill -0 "$(cat "$PID_FILE")" 2>/dev/null; then
gui_error "Process exited immediately" "Check $LOG_FILE"
rm -f "$PID_FILE"
return 1
fi
log "Started (PID $(cat "$PID_FILE"))"
return 0
}
stop_server() {
if ! is_running; then
log "No running instance found"
return 0
fi
log "Stopping $APP_DISPLAY..."
kill "$(cat "$PID_FILE")" 2>/dev/null || true
rm -f "$PID_FILE"
log "Stopped"
}
open_browser() {
if [ -z "$URL" ]; then
log "No URL configured for $APP_DISPLAY"
return 1
fi
log "Opening $URL..."
case "$PLATFORM" in
linux)
if command -v xdg-open >/dev/null 2>&1; then xdg-open "$URL" &
elif command -v firefox >/dev/null 2>&1; then firefox "$URL" &
elif command -v chromium >/dev/null 2>&1; then chromium "$URL" &
else warn "No browser found — open manually: $URL"; fi ;;
macos) open "$URL" 2>/dev/null || warn "Open manually: $URL" ;;
windows)
if command -v start >/dev/null 2>&1; then start "$URL"
elif command -v cygstart >/dev/null 2>&1; then cygstart "$URL"
else warn "Open manually: $URL"; fi ;;
*) warn "Unknown platform — open manually: $URL" ;;
esac
}
# ----------------------------------------------------------------------------
# SYSTEM INTEGRATION — --integ / --disinteg
# ----------------------------------------------------------------------------
already_integrated() {
[ -f "$DESKTOP_FILE_TARGET" ] || [ -f "$LAUNCHER_TARGET" ]
}
write_linux_desktop_file() {
local target="$1"
local icon_name
if [ -f "$ICON_TARGET" ]; then
icon_name="$APP_NAME"
else
icon_name="package-x-generic"
fi
# keepopen.sh implements the standard fallback ladder: GUI → TUI →
# bash-at-repo-root. See launcher-standard.adoc §Fallback Ladder.
local keepopen="/var/mnt/eclipse/repos/.desktop-tools/keepopen.sh"
local gui_cmd tui_cmd
# process: GUI = start then tail log so terminal stays open;
# TUI = just tail the existing log; Shell = repo root.
gui_cmd="$LAUNCHER_TARGET --start && tail -f $LOG_FILE"
tui_cmd="tail -n 200 -f $LOG_FILE"
cat > "$target" <<EOF
[Desktop Entry]
Type=Application
Version=1.0
Name=$APP_DISPLAY
GenericName=$APP_GENERIC_NAME
Comment=$APP_DESC
Exec=$keepopen "$APP_DISPLAY" "$REPO_DIR" "$gui_cmd" "$tui_cmd" "$LOG_FILE"
Icon=$icon_name
Terminal=true
Categories=$APP_CATEGORIES
StartupNotify=true
StartupWMClass=$APP_NAME
Actions=stop;status;
[Desktop Action stop]
Name=Stop
Exec=$LAUNCHER_TARGET --stop
[Desktop Action status]
Name=Status
Exec=$LAUNCHER_TARGET --status
EOF
chmod 444 "$target"
}
do_integ_linux() {
mkdir -p "$APPS_DIR" "$ICON_DIR" "$BIN_DIR" "$DESKTOP_SHORTCUT_DIR"
local script_path="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
cp "$script_path" "$LAUNCHER_TARGET"
chmod +x "$LAUNCHER_TARGET"
log " + launcher: $LAUNCHER_TARGET"
if [ -n "$ICON_SOURCE" ] && [ -f "$ICON_SOURCE" ]; then
cp "$ICON_SOURCE" "$ICON_TARGET"
log " + icon: $ICON_TARGET"
else
log " · no custom icon — using system fallback (package-x-generic)"
fi
write_linux_desktop_file "$DESKTOP_FILE_TARGET"
log " + menu: $DESKTOP_FILE_TARGET"
write_linux_desktop_file "$DESKTOP_SHORTCUT_TARGET"
log " + desktop: $DESKTOP_SHORTCUT_TARGET"
command -v update-desktop-database >/dev/null 2>&1 && \
update-desktop-database "$APPS_DIR" 2>/dev/null || true
if command -v gio >/dev/null 2>&1; then
gio set "$DESKTOP_FILE_TARGET" "metadata::trusted" true 2>/dev/null || true
gio set "$DESKTOP_SHORTCUT_TARGET" "metadata::trusted" true 2>/dev/null || true
fi
if [ -x "/var/mnt/eclipse/repos/.desktop-tools/verify-desktop-integrity.sh" ]; then
/var/mnt/eclipse/repos/.desktop-tools/verify-desktop-integrity.sh --generate 2>/dev/null \
&& log " + integrity hashes generated" \
|| log " · integrity hash generation failed (non-fatal)"
fi
}
do_integ() {
# Fast path: delegate to `launch-scaffolder provision` when it's on
# $PATH and the source config is still where it was at mint time.
# Keeps one authoritative implementation instead of drifting between
# this template and the Rust binary. Falls through to the shell
# implementation if either condition fails.
if command -v launch-scaffolder >/dev/null 2>&1 && [ -n "$CONFIG_FILE" ] && [ -f "$CONFIG_FILE" ]; then
local forward=(launch-scaffolder provision --integ "$CONFIG_FILE" --no-confirm)
[ "$FORCE" = "true" ] && forward+=(--force)
log "Delegating to launch-scaffolder provision..."
exec "${forward[@]}"
fi
if already_integrated && [ "$FORCE" != "true" ]; then
warn "$APP_DISPLAY is already integrated."
read -rp "Reinstall? [y/N] " confirm
[[ ! "$confirm" =~ ^[Yy]$ ]] && { log "Nothing changed."; return 0; }
fi
log "Integrating $APP_DISPLAY with the $PLATFORM desktop..."
case "$PLATFORM" in
linux) do_integ_linux ;;
*) err "Only Linux integration is implemented in the generated template so far."; return 1 ;;
esac
log "✓ $APP_DISPLAY is now in your menu and on your Desktop."
}
do_disinteg() {
# Fast path: delegate to `launch-scaffolder provision --disinteg`
# when available. Stop any running process first so the binary
# doesn't have to re-implement the process-management arm.
if is_running; then
log " • stopping running server"
stop_server
fi
if command -v launch-scaffolder >/dev/null 2>&1 && [ -n "$CONFIG_FILE" ] && [ -f "$CONFIG_FILE" ]; then
log "Delegating to launch-scaffolder provision..."
exec launch-scaffolder provision --disinteg "$CONFIG_FILE" --no-confirm
fi
log "Removing $APP_DISPLAY system integration..."
local removed_anything="false"
local targets=(
"$DESKTOP_FILE_TARGET"
"$DESKTOP_SHORTCUT_TARGET"
"$ICON_TARGET"
"$LAUNCHER_TARGET"
)
for t in "${targets[@]}"; do
[ -z "$t" ] && continue
if [ -e "$t" ] || [ -L "$t" ]; then
rm -rf "$t"
log " - removed $t"
removed_anything="true"
fi
done
[ "$PLATFORM" = "linux" ] && command -v update-desktop-database >/dev/null 2>&1 && \
update-desktop-database "$APPS_DIR" 2>/dev/null || true
rm -f "$PID_FILE"
if [ "$removed_anything" = "true" ]; then
log "✓ $APP_DISPLAY removed from your system."
else
log "Nothing to remove — $APP_DISPLAY was not integrated here."
fi
}
show_help() {
cat <<EOF
$APP_DISPLAY launcher — $APP_DESC
Usage: $0 [MODE] [--force]
Runtime modes:
--start Start the process (default)
--stop Stop the process
--status Show running status
--auto Alias for --start
System integration:
--integ Install desktop entry + shortcut + icon (idempotent; --force to reinstall)
--disinteg Remove everything --integ installed (idempotent)
Misc:
--help This text
Detected platform: $PLATFORM
Runtime kind: $RUNTIME_KIND
Repo: $REPO_DIR
EOF
}
# ----------------------------------------------------------------------------
# MAIN SWITCH
# ----------------------------------------------------------------------------
case "$MODE" in
--start) start_server ;;
--stop) stop_server ;;
--status)
if is_running; then
log "Running (PID $(cat "$PID_FILE"))${URL:+ — $URL}"
else
log "Not running${URL:+ — $URL}"
fi
;;
--browser|--web)
log "$APP_DISPLAY has no URL — --browser is not applicable"
;;
--auto)
start_server
;;
--integ) do_integ ;;
--disinteg) do_disinteg ;;
--help|-h) show_help ;;
*)
err "Unknown mode: $MODE"
show_help
exit 2
;;
esac