Repository navigation
Expand file tree
/
Copy pathsteamline.sh
More file actions
executable file
·626 lines (537 loc) · 17.3 KB
/
Copy pathsteamline.sh
File metadata and controls
executable file
·626 lines (537 loc) · 17.3 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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
#!/usr/bin/env bash
set -euo pipefail
program_dir="$(cd "$(dirname "$0")" && pwd)"
repo_root="$(cd "$program_dir/.." && pwd)"
config_file=""
check_only=false
mounted_dmg_dir=""
mounted_dmg_created=false
cleanup() {
if [[ "$mounted_dmg_created" == true && -n "$mounted_dmg_dir" && -d "$mounted_dmg_dir" ]]; then
hdiutil detach "$mounted_dmg_dir" -quiet >/dev/null 2>&1 || true
rmdir "$mounted_dmg_dir" >/dev/null 2>&1 || true
fi
}
trap cleanup EXIT
resolve_path() {
local candidate="$1"
local base_dir="$2"
if [[ "$candidate" = /* ]]; then
printf '%s\n' "$candidate"
return
fi
if [[ -n "$base_dir" ]]; then
printf '%s/%s\n' "$base_dir" "$candidate"
return
fi
printf '%s/%s\n' "$PWD" "$candidate"
}
to_vdf_path() {
local path_value="$1"
printf '%s\n' "${path_value//\\/\\\\}"
}
escape_sed_replacement() {
printf '%s' "$1" | sed -e 's/[\\&|]/\\\\&/g'
}
render_vdf_template() {
local template_file="$1"
local output_file="$2"
local app_id_escaped
local game_name_escaped
local build_output_escaped
local depot_linux_escaped
local depot_windows_escaped
local depot_mac_escaped
local linux_local_escaped
local windows_local_escaped
local mac_local_escaped
local mac_bundle_name_escaped
app_id_escaped="$(escape_sed_replacement "$steam_app_id")"
game_name_escaped="$(escape_sed_replacement "$steam_game_name")"
build_output_escaped="$(escape_sed_replacement "$build_output_path")"
depot_linux_escaped="$(escape_sed_replacement "$steam_depot_linux")"
depot_windows_escaped="$(escape_sed_replacement "$steam_depot_windows")"
depot_mac_escaped="$(escape_sed_replacement "$steam_depot_mac")"
linux_local_escaped="$(escape_sed_replacement "$linux_local")"
windows_local_escaped="$(escape_sed_replacement "$windows_local")"
mac_local_escaped="$(escape_sed_replacement "$mac_local")"
mac_bundle_name_escaped="$(escape_sed_replacement "$mac_bundle_name")"
sed \
-e "s|__APP_ID__|$app_id_escaped|g" \
-e "s|__GAME_NAME__|$game_name_escaped|g" \
-e "s|__BUILD_OUTPUT__|$build_output_escaped|g" \
-e "s|__DEPOT_LINUX__|$depot_linux_escaped|g" \
-e "s|__DEPOT_WINDOWS__|$depot_windows_escaped|g" \
-e "s|__DEPOT_MAC__|$depot_mac_escaped|g" \
-e "s|__LINUX_LOCAL__|$linux_local_escaped|g" \
-e "s|__WINDOWS_LOCAL__|$windows_local_escaped|g" \
-e "s|__MAC_LOCAL__|$mac_local_escaped|g" \
-e "s|__MAC_BUNDLE_NAME__|$mac_bundle_name_escaped|g" \
"$template_file" > "$output_file"
}
find_default_config() {
local candidates=(
"$PWD/steamline.config.env"
"$PWD/steamline.config.local.env"
"$repo_root/steamline.config.env"
"$repo_root/steamline.config.local.env"
"$program_dir/steamline.config.local.env"
"$program_dir/steamline.config.env"
)
for candidate in "${candidates[@]}"; do
if [[ -f "$candidate" ]]; then
printf '%s\n' "$candidate"
return
fi
done
printf '%s\n' "$repo_root/steamline.config.env"
}
pre_scan_args() {
local index=1
while [[ $index -le $# ]]; do
local arg="${!index}"
case "$arg" in
--config|--env-file)
local next=$((index + 1))
config_file="${!next}"
index=$((index + 2))
;;
*)
index=$((index + 1))
;;
esac
done
}
usage() {
cat <<EOF
Usage: $(basename "$0") [options]
Options:
--config FILE Path to game config file (default: steamline.config.env)
--sdk-root DIR Override Steamworks SDK root (default: ~/steam-sdk)
--linux-path DIR Override Linux build folder
--windows-path DIR Override Windows build folder
--mac-path DIR Override macOS build folder (without .app name)
--game-name NAME Game name used to derive macOS app bundle (NAME.app)
--username USER Steam account username
--password PASS Steam account password
--check Validate config/files without login/upload
-h, --help Show this help
Config variables (in steamline.config.env):
STEAM_SDK_ROOT
STEAM_BUILD_PATH_LINUX
STEAM_BUILD_PATH_WINDOWS
STEAM_BUILD_PATH_MAC
STEAM_GAME_NAME
STEAM_APP_ID
STEAM_DEPOT_ID_LINUX
STEAM_DEPOT_ID_WINDOWS
STEAM_DEPOT_ID_MAC
STEAM_USERNAME
STEAM_PASSWORD
Hardcoded app build location:
<repo>/steamline/app_build.vdf
Credentials:
STEAM_USERNAME and STEAM_PASSWORD are read from steamline.config.env
(or passed with --username/--password).
EOF
}
pre_scan_args "$@"
if [[ -z "$config_file" ]]; then
config_file="$(find_default_config)"
elif [[ "$config_file" != /* ]]; then
config_file="$(resolve_path "$config_file" "$PWD")"
fi
if [[ ! -f "$config_file" ]]; then
echo "Config file not found: $config_file"
echo "Create one in your game repo (example: steamline.config.env)."
echo "A starter template is in steamline/examples/steamline.config.env.example."
exit 1
fi
config_dir="$(cd "$(dirname "$config_file")" && pwd)"
set -a
# shellcheck disable=SC1090
source "$config_file"
set +a
config_steam_sdk_root="${STEAM_SDK_ROOT:-}"
config_steam_build_path_linux="${STEAM_BUILD_PATH_LINUX:-}"
config_steam_build_path_windows="${STEAM_BUILD_PATH_WINDOWS:-}"
config_steam_build_path_mac="${STEAM_BUILD_PATH_MAC:-}"
config_steam_game_name="${STEAM_GAME_NAME:-}"
config_steam_app_id="${STEAM_APP_ID:-}"
config_steam_depot_linux="${STEAM_DEPOT_ID_LINUX:-}"
config_steam_depot_windows="${STEAM_DEPOT_ID_WINDOWS:-}"
config_steam_depot_mac="${STEAM_DEPOT_ID_MAC:-}"
if [[ -n "$config_steam_sdk_root" ]]; then
STEAM_SDK_ROOT="$config_steam_sdk_root"
fi
if [[ -n "$config_steam_build_path_linux" ]]; then
STEAM_BUILD_PATH_LINUX="$config_steam_build_path_linux"
fi
if [[ -n "$config_steam_build_path_windows" ]]; then
STEAM_BUILD_PATH_WINDOWS="$config_steam_build_path_windows"
fi
if [[ -n "$config_steam_build_path_mac" ]]; then
STEAM_BUILD_PATH_MAC="$config_steam_build_path_mac"
fi
if [[ -n "$config_steam_game_name" ]]; then
STEAM_GAME_NAME="$config_steam_game_name"
fi
if [[ -n "$config_steam_app_id" ]]; then
STEAM_APP_ID="$config_steam_app_id"
fi
if [[ -n "$config_steam_depot_linux" ]]; then
STEAM_DEPOT_ID_LINUX="$config_steam_depot_linux"
fi
if [[ -n "$config_steam_depot_windows" ]]; then
STEAM_DEPOT_ID_WINDOWS="$config_steam_depot_windows"
fi
if [[ -n "$config_steam_depot_mac" ]]; then
STEAM_DEPOT_ID_MAC="$config_steam_depot_mac"
fi
sdk_root="${STEAM_SDK_ROOT:-$HOME/steam-sdk}"
steam_build_path_linux="${STEAM_BUILD_PATH_LINUX:-./build/Linux}"
steam_build_path_windows="${STEAM_BUILD_PATH_WINDOWS:-./build/Windows}"
steam_build_path_mac="${STEAM_BUILD_PATH_MAC:-./build/Mac}"
steam_game_name="${STEAM_GAME_NAME:-Game}"
steam_app_id="${STEAM_APP_ID:-0}"
steam_depot_linux="${STEAM_DEPOT_ID_LINUX:-0}"
steam_depot_windows="${STEAM_DEPOT_ID_WINDOWS:-0}"
steam_depot_mac="${STEAM_DEPOT_ID_MAC:-0}"
steam_username="${STEAM_USERNAME:-}"
steam_password="${STEAM_PASSWORD:-}"
while [[ $# -gt 0 ]]; do
case "$1" in
--config|--env-file)
shift 2
;;
--sdk-root)
sdk_root="$2"
shift 2
;;
--linux-path)
steam_build_path_linux="$2"
shift 2
;;
--windows-path)
steam_build_path_windows="$2"
shift 2
;;
--mac-path)
steam_build_path_mac="$2"
shift 2
;;
--game-name)
steam_game_name="$2"
shift 2
;;
--username)
steam_username="$2"
shift 2
;;
--password)
steam_password="$2"
shift 2
;;
--check)
check_only=true
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown option: $1"
usage
exit 2
;;
esac
done
if [[ "$sdk_root" == ~* ]]; then
sdk_root="${sdk_root/#\~/$HOME}"
fi
build_path_linux_abs="$(resolve_path "$steam_build_path_linux" "$config_dir")"
build_path_windows_abs="$(resolve_path "$steam_build_path_windows" "$config_dir")"
build_path_mac_abs="$(resolve_path "$steam_build_path_mac" "$config_dir")"
mac_bundle_name="${steam_game_name}.app"
mac_bundle_abs="$build_path_mac_abs/$mac_bundle_name"
resolve_mac_bundle_from_dmg() {
local mac_dir="$1"
local game_name="$2"
local preferred_dmg="$mac_dir/$game_name.dmg"
local dmg_path=""
if [[ -f "$preferred_dmg" ]]; then
dmg_path="$preferred_dmg"
else
dmg_path="$(find "$mac_dir" -maxdepth 1 -type f -name '*.dmg' | head -n 1)"
fi
if [[ -z "$dmg_path" ]]; then
return 1
fi
local existing_mount
existing_mount="$(DMG_PATH="$dmg_path" python3 - <<'PY'
import os
import plistlib
import subprocess
dmg = os.environ['DMG_PATH']
plist = plistlib.loads(subprocess.check_output(['hdiutil', 'info', '-plist']))
for image in plist.get('images', []):
if image.get('image-path') == dmg:
for entity in image.get('system-entities', []):
mount_point = entity.get('mount-point')
if mount_point:
print(mount_point)
raise SystemExit(0)
raise SystemExit(1)
PY
)" || true
if [[ -n "$existing_mount" && -d "$existing_mount" ]]; then
mounted_dmg_dir="$existing_mount"
mounted_dmg_created=false
else
mounted_dmg_dir="$(mktemp -d /tmp/steamline-dmg.XXXXXX)"
if ! hdiutil attach "$dmg_path" -nobrowse -readonly -mountpoint "$mounted_dmg_dir" >/dev/null; then
echo "Failed to mount DMG: $dmg_path"
return 1
fi
mounted_dmg_created=true
fi
local expected_app="$mounted_dmg_dir/$game_name.app"
if [[ -d "$expected_app" ]]; then
printf '%s\n' "$expected_app"
return 0
fi
local discovered_app
discovered_app="$(find "$mounted_dmg_dir" -maxdepth 2 -type d -name '*.app' | head -n 1)"
if [[ -n "$discovered_app" ]]; then
printf '%s\n' "$discovered_app"
return 0
fi
echo "Mounted DMG does not contain an .app bundle: $dmg_path"
return 1
}
extract_mac_bundle_from_dmg() {
local dmg_path="$1"
local mac_dir="$2"
local game_name="$3"
local target_app="$mac_dir/$game_name.app"
local mount_point
mount_point="$(mktemp -d /tmp/steamline-dmg.XXXXXX)"
if ! hdiutil attach "$dmg_path" -nobrowse -readonly -mountpoint "$mount_point" >/dev/null; then
rmdir "$mount_point" >/dev/null 2>&1 || true
echo "Failed to mount DMG: $dmg_path"
return 1
fi
local app_source="$mount_point/$game_name.app"
if [[ ! -d "$app_source" ]]; then
app_source="$(find "$mount_point" -maxdepth 2 -type d -name '*.app' | head -n 1)"
fi
if [[ -z "$app_source" || ! -d "$app_source" ]]; then
hdiutil detach "$mount_point" -quiet >/dev/null 2>&1 || true
rmdir "$mount_point" >/dev/null 2>&1 || true
echo "No .app bundle found in DMG: $dmg_path"
return 1
fi
rm -rf "$target_app"
cp -R "$app_source" "$target_app"
hdiutil detach "$mount_point" -quiet >/dev/null 2>&1 || true
rmdir "$mount_point" >/dev/null 2>&1 || true
printf '%s\n' "$target_app"
}
extract_mac_bundle_from_zip() {
local zip_path="$1"
local mac_dir="$2"
local game_name="$3"
local target_app="$mac_dir/$game_name.app"
local tmp_extract
tmp_extract="$(mktemp -d "${TMPDIR:-/tmp}/steamline-zip.XXXXXX")"
if command -v unzip >/dev/null 2>&1; then
unzip -oq "$zip_path" -d "$tmp_extract"
elif command -v bsdtar >/dev/null 2>&1; then
bsdtar -xf "$zip_path" -C "$tmp_extract"
else
rm -rf "$tmp_extract"
echo "Need unzip or bsdtar to extract macOS ZIP: $zip_path"
return 1
fi
local app_source="$tmp_extract/$game_name.app"
if [[ ! -d "$app_source" ]]; then
app_source="$(find "$tmp_extract" -type d -name '*.app' | head -n 1)"
fi
if [[ -z "$app_source" || ! -d "$app_source" ]]; then
rm -rf "$tmp_extract"
echo "No .app bundle found in ZIP: $zip_path"
return 1
fi
rm -rf "$target_app"
cp -R "$app_source" "$target_app"
rm -rf "$tmp_extract"
printf '%s\n' "$target_app"
}
latest_mac_archive() {
local mac_dir="$1"
local newest=""
while IFS= read -r archive; do
if [[ -z "$newest" || "$archive" -nt "$newest" ]]; then
newest="$archive"
fi
done < <(find "$mac_dir" -maxdepth 1 -type f \( -name '*.zip' -o -name '*.dmg' \))
printf '%s\n' "$newest"
}
ensure_mac_bundle_fresh() {
local mac_dir="$1"
local game_name="$2"
local target_app="$mac_dir/$game_name.app"
local archive
archive="$(latest_mac_archive "$mac_dir")"
if [[ -n "$archive" ]]; then
if [[ ! -d "$target_app" || "$archive" -nt "$target_app" ]]; then
echo "Refreshing macOS app from archive: $(basename "$archive")"
if [[ "$archive" == *.zip ]]; then
extract_mac_bundle_from_zip "$archive" "$mac_dir" "$game_name" >/dev/null || return 1
else
extract_mac_bundle_from_dmg "$archive" "$mac_dir" "$game_name" >/dev/null || return 1
fi
fi
fi
[[ -d "$target_app" ]] || return 1
printf '%s\n' "$target_app"
}
if [[ ! -d "$build_path_linux_abs" ]]; then
echo "Missing Linux build folder: $build_path_linux_abs"
exit 1
fi
if [[ ! -d "$build_path_windows_abs" ]]; then
echo "Missing Windows build folder: $build_path_windows_abs"
exit 1
fi
mac_bundle_abs="$(ensure_mac_bundle_fresh "$build_path_mac_abs" "$steam_game_name")" || {
if [[ ! -d "$mac_bundle_abs" ]]; then
mac_bundle_abs="$(resolve_mac_bundle_from_dmg "$build_path_mac_abs" "$steam_game_name")" || {
echo "Missing macOS app bundle: $mac_bundle_abs"
echo "No usable .app found directly in $build_path_mac_abs or via archive extraction."
exit 1
}
fi
}
content_builder_root=""
if [[ -d "$sdk_root/tools/ContentBuilder" ]]; then
content_builder_root="$sdk_root/tools/ContentBuilder"
elif [[ -d "$sdk_root/sdk/tools/ContentBuilder" ]]; then
content_builder_root="$sdk_root/sdk/tools/ContentBuilder"
elif [[ -d "$program_dir/sdk/tools/ContentBuilder" ]]; then
content_builder_root="$program_dir/sdk/tools/ContentBuilder"
fi
if [[ -z "$content_builder_root" ]]; then
echo "Unable to locate Steamworks ContentBuilder."
echo "Checked:"
echo "- $sdk_root/tools/ContentBuilder"
echo "- $sdk_root/sdk/tools/ContentBuilder"
echo "- $program_dir/sdk/tools/ContentBuilder"
echo "Set STEAM_SDK_ROOT in $config_file (recommended: ~/steam-sdk)."
exit 1
fi
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
steamcmd_rel="builder_linux/steamcmd.sh"
elif [[ "$OSTYPE" == "darwin"* ]]; then
steamcmd_rel="builder_osx/steamcmd.sh"
elif [[ "$OSTYPE" == "msys"* || "$OSTYPE" == "cygwin"* || "$OSTYPE" == "win32"* ]]; then
steamcmd_rel="builder/steamcmd.exe"
else
echo "Unsupported OS: $OSTYPE"
exit 2
fi
steamcmd_path="$content_builder_root/$steamcmd_rel"
if [[ ! -e "$steamcmd_path" ]]; then
echo "SteamCMD executable not found: $steamcmd_path"
exit 1
fi
app_build_file="$program_dir/app_build.vdf"
depot_linux_file="$program_dir/depot_build_linux.vdf"
depot_windows_file="$program_dir/depot_build_windows.vdf"
depot_macos_file="$program_dir/depot_build_macos.vdf"
template_dir="$program_dir/vdf"
app_build_template="$template_dir/app_build.vdf.tpl"
depot_linux_template="$template_dir/depot_build_linux.vdf.tpl"
depot_windows_template="$template_dir/depot_build_windows.vdf.tpl"
depot_macos_template="$template_dir/depot_build_macos.vdf.tpl"
for template_file in \
"$app_build_template" \
"$depot_linux_template" \
"$depot_windows_template" \
"$depot_macos_template"; do
if [[ ! -f "$template_file" ]]; then
echo "Missing VDF template: $template_file"
exit 1
fi
done
build_output_dir="${TMPDIR:-/tmp}/steamline-build-output-${steam_app_id}"
mkdir -p "$build_output_dir"
linux_local="$(to_vdf_path "$build_path_linux_abs")/*"
windows_local="$(to_vdf_path "$build_path_windows_abs")/*"
mac_local="$(to_vdf_path "$mac_bundle_abs")/*"
build_output_path="$(to_vdf_path "$build_output_dir")"
if [[ ! -f "$app_build_file" ]]; then
render_vdf_template "$app_build_template" "$app_build_file"
echo "Created missing VDF: $app_build_file"
else
echo "Using existing VDF: $app_build_file"
fi
if [[ ! -f "$depot_linux_file" ]]; then
render_vdf_template "$depot_linux_template" "$depot_linux_file"
echo "Created missing VDF: $depot_linux_file"
else
echo "Using existing VDF: $depot_linux_file"
fi
if [[ ! -f "$depot_windows_file" ]]; then
render_vdf_template "$depot_windows_template" "$depot_windows_file"
echo "Created missing VDF: $depot_windows_file"
else
echo "Using existing VDF: $depot_windows_file"
fi
if [[ ! -f "$depot_macos_file" ]]; then
render_vdf_template "$depot_macos_template" "$depot_macos_file"
echo "Created missing VDF: $depot_macos_file"
else
echo "Using existing VDF: $depot_macos_file"
fi
echo "Steamline preflight checks passed."
echo "- Config: $config_file"
echo "- App build: $app_build_file"
echo "- Linux path: $build_path_linux_abs"
echo "- Windows path: $build_path_windows_abs"
echo "- Mac path: $build_path_mac_abs"
echo "- Game name: $steam_game_name"
echo "- Build output: $build_output_dir"
echo "- SDK root: $sdk_root"
echo "- SteamCMD: $steamcmd_path"
if [[ "$check_only" == true ]]; then
echo "Check mode enabled; skipping Steam login/upload."
exit 0
fi
if [[ -z "$steam_username" && -f "$program_dir/.steam_username" ]]; then
read -r steam_username < "$program_dir/.steam_username"
fi
if [[ -z "$steam_username" ]]; then
echo "Missing Steam username. Set STEAM_USERNAME in env/config or pass --username."
exit 1
fi
if [[ -z "$steam_password" ]]; then
echo -n "Steam password for $steam_username: "
read -rs steam_password
echo
fi
set +e
"$steamcmd_path" \
+login "$steam_username" "$steam_password" \
+run_app_build "$app_build_file" \
+quit
exit_code=$?
set -e
echo
if [[ "$exit_code" -eq 0 ]]; then
echo "Steam upload complete."
else
echo "Steam upload failed with exit code $exit_code"
fi
exit "$exit_code"