-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsteam_build_upload_linux.sh
More file actions
executable file
·292 lines (254 loc) · 7.56 KB
/
steam_build_upload_linux.sh
File metadata and controls
executable file
·292 lines (254 loc) · 7.56 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
#!/usr/bin/env bash
set -euo pipefail
# Usage:
# ./steam_build_upload_linux.sh [steam_build_username]
# Optional environment overrides:
# STEAM_SDK_ROOT
# CONTENT_BUILDER_DIR
# STEAM_BUILDER_DIR
# STEAM_CONTENT_DIR
# STEAM_APP_BUILD_VDF
# STEAM_APP_ID
# STEAM_DEPOT_ID_LINUX (defaults to 4509323 for this project)
# STEAM_BUILD_DESC
# STEAM_SET_LIVE
# STEAM_PREVIEW (0|1)
# STEAM_USERNAME
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [[ -n "${STEAM_SDK_ROOT:-}" ]]; then
STEAM_SDK_ROOT="$STEAM_SDK_ROOT"
else
# Common Linux custom install locations (including local Documents SDK extractions).
for sdk_glob in "$HOME/Documents/Steam/steamworks_sdk_"*/sdk "$HOME/Documents/Steam/steamworks_sdk_"*; do
if [[ -d "$sdk_glob" ]]; then
STEAM_SDK_ROOT="$sdk_glob"
break
fi
done
for sdk_candidate in \
"$HOME/SteamworksSDK/sdk" \
"$HOME/SteamworksSDK" \
"$HOME/Steam/steamapps/common/Steamworks SDK/sdk" \
"$HOME/Steam/steamapps/common/Steamworks SDK" \
"$HOME/.steam/steam/steamapps/common/Steamworks SDK/sdk" \
"$HOME/.steam/steam/steamapps/common/Steamworks SDK"; do
if [[ -n "${STEAM_SDK_ROOT:-}" ]]; then
break
fi
if [[ -d "$sdk_candidate" ]]; then
STEAM_SDK_ROOT="$sdk_candidate"
break
fi
done
STEAM_SDK_ROOT="${STEAM_SDK_ROOT:-$HOME/SteamworksSDK/sdk}"
fi
if [[ -n "${CONTENT_BUILDER_DIR:-}" ]]; then
CONTENT_BUILDER_DIR="$CONTENT_BUILDER_DIR"
elif [[ -d "$STEAM_SDK_ROOT/tools/ContentBuilder" ]]; then
CONTENT_BUILDER_DIR="$STEAM_SDK_ROOT/tools/ContentBuilder"
elif [[ -d "$STEAM_SDK_ROOT/sdk/tools/ContentBuilder" ]]; then
CONTENT_BUILDER_DIR="$STEAM_SDK_ROOT/sdk/tools/ContentBuilder"
else
CONTENT_BUILDER_DIR="$STEAM_SDK_ROOT/tools/ContentBuilder"
fi
STEAM_BUILDER_DIR="${STEAM_BUILDER_DIR:-$CONTENT_BUILDER_DIR/builder_linux}"
STEAM_CONTENT_DIR="${STEAM_CONTENT_DIR:-$CONTENT_BUILDER_DIR/content/linux}"
STEAM_APP_BUILD_VDF="${STEAM_APP_BUILD_VDF:-}"
STEAM_APP_ID="${STEAM_APP_ID:-4509320}"
STEAM_DEPOT_ID_LINUX="${STEAM_DEPOT_ID_LINUX:-4509323}"
STEAM_BUILD_DESC="${STEAM_BUILD_DESC:-Linux build $(date '+%Y-%m-%d %H:%M:%S')}"
STEAM_SET_LIVE="${STEAM_SET_LIVE:-}"
STEAM_PREVIEW="${STEAM_PREVIEW:-0}"
STEAM_USERNAME="${STEAM_USERNAME:-${1:-semjonprophet}}"
GENERATED_VDF_DIR=""
find_linux_build_dir() {
local release_dir="$REPO_DIR/release"
local candidate=""
local candidates=(
"$release_dir/linux-unpacked"
"$release_dir/linux-arm64-unpacked"
"$release_dir/linux-ia32-unpacked"
"$release_dir/linux"
)
for candidate in "${candidates[@]}"; do
if [[ -d "$candidate" ]]; then
echo "$candidate"
return 0
fi
done
return 1
}
resolve_steamcmd_bin() {
local candidates=(
"$STEAM_BUILDER_DIR/steamcmd.sh"
"$STEAM_BUILDER_DIR/steamcmd"
"$CONTENT_BUILDER_DIR/builder_linux/steamcmd.sh"
"$CONTENT_BUILDER_DIR/builder/steamcmd.sh"
)
local cmd=""
local cmd_dir=""
local wrapped_bin=""
for cmd in "${candidates[@]}"; do
cmd_dir="$(dirname "$cmd")"
wrapped_bin="$cmd_dir/linux32/steamcmd"
if [[ -f "$wrapped_bin" ]] && [[ ! -x "$wrapped_bin" ]]; then
chmod +x "$wrapped_bin" >/dev/null 2>&1 || true
fi
if [[ -f "$cmd" ]] && [[ ! -x "$cmd" ]]; then
chmod +x "$cmd" >/dev/null 2>&1 || true
fi
if [[ -x "$cmd" ]]; then
echo "$cmd"
return 0
fi
done
if command -v steamcmd >/dev/null 2>&1; then
command -v steamcmd
return 0
fi
return 1
}
ensure_steamcmd_runtime() {
local cmd="$1"
local wrapped_bin=""
if [[ "$cmd" == *.sh ]]; then
wrapped_bin="$(dirname "$cmd")/linux32/steamcmd"
else
wrapped_bin="$cmd"
fi
if [[ ! -f "$wrapped_bin" ]]; then
return 0
fi
if file "$wrapped_bin" 2>/dev/null | grep -q "ELF 32-bit"; then
if [[ ! -e /lib/ld-linux.so.2 ]] && [[ ! -e /lib32/ld-linux.so.2 ]]; then
echo "ERROR: SteamCMD requires 32-bit glibc loader (ld-linux.so.2), but it is missing." >&2
echo "Install on Ubuntu:" >&2
echo " sudo dpkg --add-architecture i386 && sudo apt update" >&2
echo " sudo apt install libc6:i386 libstdc++6:i386 libgcc-s1:i386" >&2
return 1
fi
fi
return 0
}
create_temp_app_build_vdf() {
if [[ -z "$STEAM_DEPOT_ID_LINUX" ]]; then
echo "ERROR: STEAM_DEPOT_ID_LINUX is required when STEAM_APP_BUILD_VDF is not provided." >&2
return 1
fi
if [[ ! "$STEAM_APP_ID" =~ ^[0-9]+$ ]]; then
echo "ERROR: STEAM_APP_ID must be numeric (current: \"$STEAM_APP_ID\")." >&2
return 1
fi
if [[ ! "$STEAM_DEPOT_ID_LINUX" =~ ^[0-9]+$ ]]; then
echo "ERROR: STEAM_DEPOT_ID_LINUX must be numeric (current: \"$STEAM_DEPOT_ID_LINUX\")." >&2
return 1
fi
if [[ ! "$STEAM_PREVIEW" =~ ^[01]$ ]]; then
echo "ERROR: STEAM_PREVIEW must be 0 or 1 (current: \"$STEAM_PREVIEW\")." >&2
return 1
fi
GENERATED_VDF_DIR="$(mktemp -d /tmp/mountea-steam-build-XXXXXX)"
local vdf_path="$GENERATED_VDF_DIR/app_build_${STEAM_APP_ID}_linux.vdf"
local build_output_dir="$CONTENT_BUILDER_DIR/output"
cat >"$vdf_path" <<EOF
"AppBuild"
{
"AppID" "$STEAM_APP_ID"
"Desc" "$STEAM_BUILD_DESC"
"Preview" "$STEAM_PREVIEW"
"ContentRoot" "$STEAM_CONTENT_DIR"
"BuildOutput" "$build_output_dir"
"Depots"
{
"$STEAM_DEPOT_ID_LINUX"
{
"FileMapping"
{
"LocalPath" "*"
"DepotPath" "."
"Recursive" "1"
}
}
}
}
EOF
if [[ -n "$STEAM_SET_LIVE" ]]; then
local setlive_tmp
setlive_tmp="$(mktemp /tmp/mountea-steam-setlive-XXXXXX)"
awk -v branch="$STEAM_SET_LIVE" '
/^[[:space:]]*"Preview"[[:space:]]*/ {
print
print "\t\"SetLive\" \"" branch "\""
next
}
{ print }
' "$vdf_path" >"$setlive_tmp"
mv "$setlive_tmp" "$vdf_path"
fi
echo "$vdf_path"
}
cleanup_temp_vdf() {
if [[ -n "$GENERATED_VDF_DIR" ]] && [[ -d "$GENERATED_VDF_DIR" ]]; then
rm -rf "$GENERATED_VDF_DIR"
fi
}
trap cleanup_temp_vdf EXIT
echo
echo "[1/3] Building Steam package..."
if [[ ! -d "$REPO_DIR/node_modules" ]]; then
echo "ERROR: node_modules not found. Run \"npm ci\" in \"$REPO_DIR\" first." >&2
exit 1
fi
(
cd "$REPO_DIR"
# Use native env var assignment on Linux to avoid requiring cross-env.
VITE_DIST_CHANNEL=steam STEAM_APP_ID="$STEAM_APP_ID" npx --no-install vite build
VITE_DIST_CHANNEL=steam STEAM_APP_ID="$STEAM_APP_ID" \
node scripts/run-electron-builder.mjs \
--dir \
--config.extraMetadata.mounteaDistChannel=steam \
--config.extraMetadata.mounteaSteamAppId="$STEAM_APP_ID"
)
if ! SRC_DIR="$(find_linux_build_dir)"; then
echo "ERROR: Build output not found under \"$REPO_DIR/release\" (expected linux-unpacked)." >&2
exit 1
fi
echo
echo "[2/3] Copying build to Steam ContentBuilder..."
mkdir -p "$STEAM_CONTENT_DIR"
rsync -rl --delete "$SRC_DIR"/ "$STEAM_CONTENT_DIR"/
if ! STEAMCMD_BIN="$(resolve_steamcmd_bin)"; then
echo "ERROR: steamcmd not found. Checked ContentBuilder and PATH." >&2
exit 1
fi
if ! ensure_steamcmd_runtime "$STEAMCMD_BIN"; then
exit 1
fi
if [[ -n "$STEAM_APP_BUILD_VDF" ]]; then
if [[ "$STEAM_APP_BUILD_VDF" != /* ]]; then
STEAM_APP_BUILD_VDF="$STEAM_BUILDER_DIR/$STEAM_APP_BUILD_VDF"
fi
if [[ ! -f "$STEAM_APP_BUILD_VDF" ]]; then
echo "ERROR: App build VDF not found: \"$STEAM_APP_BUILD_VDF\"" >&2
exit 1
fi
else
if ! STEAM_APP_BUILD_VDF="$(create_temp_app_build_vdf)"; then
exit 1
fi
fi
echo
echo "[3/3] Uploading build to Steam depot..."
if [[ "$STEAMCMD_BIN" == *.sh ]]; then
bash "$STEAMCMD_BIN" +login "$STEAM_USERNAME" +run_app_build "$STEAM_APP_BUILD_VDF" +quit
else
STEAMCMD_DIR="$(cd "$(dirname "$STEAMCMD_BIN")" && pwd)"
STEAMCMD_EXE="$(basename "$STEAMCMD_BIN")"
(
cd "$STEAMCMD_DIR"
"./$STEAMCMD_EXE" +login "$STEAM_USERNAME" +run_app_build "$STEAM_APP_BUILD_VDF" +quit
)
fi
echo
echo "SUCCESS: Build packed, copied, and uploaded."
echo "Next: set the new BuildID live on your Steam branch in Steamworks."