-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgame-streamer.sh
More file actions
executable file
·153 lines (130 loc) · 5.9 KB
/
Copy pathgame-streamer.sh
File metadata and controls
executable file
·153 lines (130 loc) · 5.9 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
#!/bin/bash
# Sets up the game-streaming feature: prompts for which cluster nodes have
# NVIDIA GPUs, labels them `nvidia-gpu=true`, and deploys MediaMTX (the SRT/HLS
# publish target). Production streamer pods are spawned per-match by the
# 5stack API on nodes carrying that label.
#
# NVIDIA-only today. AMD (issue #467) and Intel (issue #468) are tracked but
# not yet supported.
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$REPO_DIR/utils/utils.sh" "$@"
PREVIOUS_GPU_VENDOR="${GPU_VENDOR:-}"
PREVIOUS_GPU_NODES="${GPU_NODES:-}"
case "$PREVIOUS_GPU_VENDOR" in
nvidia) DEFAULT_VENDOR_CHOICE=1 ;;
amd) DEFAULT_VENDOR_CHOICE=2 ;;
intel) DEFAULT_VENDOR_CHOICE=3 ;;
*) DEFAULT_VENDOR_CHOICE=1 ;;
esac
interactive_menu VENDOR_INDEX \
"Which GPU vendor will the streamer nodes use?" \
$((DEFAULT_VENDOR_CHOICE - 1)) \
"NVIDIA" \
"AMD (not yet supported)" \
"Intel (not yet supported)"
case "$VENDOR_INDEX" in
0) GPU_VENDOR=nvidia ;;
1)
err "AMD GPUs are not supported yet."
err " Tracking issue: https://github.com/5stackgg/5stack-panel/issues/467"
err " Docs: https://docs.5stack.gg/advanced/game-streaming/amd"
exit 1
;;
2)
err "Intel GPUs are not supported yet."
err " Tracking issue: https://github.com/5stackgg/5stack-panel/issues/468"
err " Docs: https://docs.5stack.gg/advanced/game-streaming/intel"
exit 1
;;
esac
step "Discovering cluster nodes"
ALL_NODES=$(kubectl --kubeconfig=$KUBECONFIG get nodes -o jsonpath='{.items[*].metadata.name}')
ALL_NODES_ARR=()
for node in $ALL_NODES; do ALL_NODES_ARR+=("$node"); done
if [ ${#ALL_NODES_ARR[@]} -eq 0 ]; then
err "no cluster nodes found via kubectl. Check KUBECONFIG=$KUBECONFIG."
exit 1
fi
interactive_checklist GPU_NODES \
"Select nodes that have GPUs:" \
"$PREVIOUS_GPU_NODES" \
"${ALL_NODES_ARR[@]}"
for node in $GPU_NODES; do
if ! echo "$ALL_NODES" | tr ' ' '\n' | grep -qx "$node"; then
err "node '$node' is not in this cluster."
err "Available: $ALL_NODES"
exit 1
fi
done
step "Labeling GPU nodes"
for node in $ALL_NODES; do
if echo " $GPU_NODES " | grep -q " $node "; then
kubectl --kubeconfig=$KUBECONFIG label node "$node" nvidia-gpu=true 5stack-game-streamer=true --overwrite >/dev/null
ok "$node: labeled as GPU node"
elif echo " $PREVIOUS_GPU_NODES " | grep -q " $node "; then
kubectl --kubeconfig=$KUBECONFIG label node "$node" nvidia-gpu- 5stack-game-streamer- >/dev/null 2>&1 || true
warn "$node: GPU labels removed"
fi
done
update_env_var ".5stack-env.config" "GPU_VENDOR" "$GPU_VENDOR"
update_env_var ".5stack-env.config" "GPU_NODES" "\"$GPU_NODES\""
if [ -z "$GPU_NODES" ]; then
err "no GPU nodes selected; the streamer cannot run without a GPU node."
exit 1
fi
step "Configuring Steam credentials"
SECRETS_OVERLAY="overlays/local-secrets"
STEAM_SECRETS_FILE="$SECRETS_OVERLAY/steam-secrets.env"
STEAM_USER_CURRENT=$(grep -h "^STEAM_USER=" "$STEAM_SECRETS_FILE" | cut -d '=' -f2-)
STEAM_PASSWORD_CURRENT=$(grep -h "^STEAM_PASSWORD=" "$STEAM_SECRETS_FILE" | cut -d '=' -f2-)
if [ -z "$STEAM_USER_CURRENT" ] || [ -z "$STEAM_PASSWORD_CURRENT" ]; then
echo
echo "Steam credentials are required for the streamer to download CS2."
warn "This account must NOT have Steam Guard / 2FA enabled."
warn " steamcmd cannot prompt for an auth code; the streamer will hang."
warn " Use a dedicated Steam account with 2FA disabled."
echo
fi
while [ -z "$STEAM_USER_CURRENT" ]; do
read -p "Steam username: " STEAM_USER_CURRENT
done
if [ "$STEAM_USER_CURRENT" != "$(grep -h "^STEAM_USER=" "$STEAM_SECRETS_FILE" | cut -d '=' -f2-)" ]; then
update_env_var "$STEAM_SECRETS_FILE" "STEAM_USER" "$STEAM_USER_CURRENT"
fi
while [ -z "$STEAM_PASSWORD_CURRENT" ]; do
read -s -p "Steam password: " STEAM_PASSWORD_CURRENT
echo ""
done
if [ "$STEAM_PASSWORD_CURRENT" != "$(grep -h "^STEAM_PASSWORD=" "$STEAM_SECRETS_FILE" | cut -d '=' -f2-)" ]; then
update_env_var "$STEAM_SECRETS_FILE" "STEAM_PASSWORD" "$STEAM_PASSWORD_CURRENT"
fi
# Always asked, with the current value as the default -- the same shape as the
# GPU vendor and node prompts above, where re-running this script is how you
# change an answer.
#
# This used to be guarded by `[ "$GAME_STREAM_DOMAIN" = "hls.example.com" ]`,
# which could never be true. That placeholder lives in
# overlays/mediamtx/mediamtx.env.example, and setup-env.sh copies it to
# mediamtx.env when the file is missing -- but GAME_STREAM_DOMAIN is read from
# api-config.env, which setup-env.sh defaults to hls.$WEB_DOMAIN. The check was
# comparing against a placeholder from a file this variable never comes from,
# so the prompt never ran and the playback domain could not be changed here.
DEFAULT_HLS="${GAME_STREAM_DOMAIN:-hls.$WEB_DOMAIN}"
read -p "Enter the playback domain for game streams (default: $DEFAULT_HLS): " GAME_STREAM_DOMAIN_INPUT
GAME_STREAM_DOMAIN_INPUT="${GAME_STREAM_DOMAIN_INPUT:-$DEFAULT_HLS}"
if [ -z "$GAME_STREAM_DOMAIN_INPUT" ] || echo "$GAME_STREAM_DOMAIN_INPUT" | grep -q ' '; then
err "Invalid domain '$GAME_STREAM_DOMAIN_INPUT'."
exit 1
fi
if [ "$GAME_STREAM_DOMAIN_INPUT" != "$GAME_STREAM_DOMAIN" ]; then
GAME_STREAM_DOMAIN="$GAME_STREAM_DOMAIN_INPUT"
update_env_var "overlays/config/api-config.env" "GAME_STREAM_DOMAIN" "$GAME_STREAM_DOMAIN"
# api-config.env is the source of truth; mediamtx.env is a mirror kustomize
# reads as a replacement source. setup-env.sh syncs the two at startup,
# which has already happened by now, so a change made here has to be
# written through to both or mediamtx keeps serving the old host.
update_env_var "overlays/mediamtx/mediamtx.env" "GAME_STREAM_DOMAIN" "$GAME_STREAM_DOMAIN"
ok "playback domain set to $GAME_STREAM_DOMAIN"
fi
source "$REPO_DIR/update.sh" "$@"
banner "Game Streamer : Updated"