-
Notifications
You must be signed in to change notification settings - Fork 4
/
open-unity.sh
executable file
·1143 lines (976 loc) · 29.8 KB
/
open-unity.sh
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
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash -eu
# ------------------------------------------------------------
# Copyright (c) 2020, 2021, 2022 Andreia Gaita <[email protected]>
# Licensed under the MIT License.
# ------------------------------------------------------------
{ set +x; } 2>/dev/null
SOURCE=$0
DIR="$( pwd )"
# unity version, pass -n|--unity to set
UNITYVERSION=""
# default cache server, pass --cache to set
CACHESERVER="cachepi"
#default cache server version (2 is accelerator)
CACHEVERSION=2
# folder where you stuff all your Unitys, pass in -u to set
BASEUNITYPATH="/Applications/Unity/Hub/Editor"
ISMAC=1
ISWIN=
HUBPATH=""
OS="Mac"
BIN=""
UNITYTOOLSPATH=""
CONFIGURATION=Dev
BUILD=0
BATCH=0
QUIT=0
LICENSE=
LICRETURN=0
LISTVERSIONS=0
SWITCHVERSION=0
PRINT=0
SKIPPATHCHECK=0
AUTOCONFIRM=0
FOREGROUND=0
PROJECTPATH=
TARGET=""
METHOD=""
ARGS=()
UNITY_ARGS=()
UNITYPATH=""
if [[ -e "/c/" ]]; then
OS="Windows"
ISMAC=
ISWIN=1
fi
if [[ "$OS" == "Windows" ]]; then
BIN="/usr/bin/"
fi
RM="${BIN}rm"
CAT="${BIN}cat"
GREP="${BIN}grep"
CUT="${BIN}cut"
DATE="${BIN}date"
CP="${BIN}cp"
BIN2TXT="binary2text"
SED="sed"
MKDIR="mkdir -p"
LS="ls -y"
if [[ "$($LS -y>/dev/null 2>&1 && echo 0 || echo 1)" == "1" ]];then
LS="ls"
fi
if [[ -z ${TMPDIR:-} ]]; then
TMPDIR=/tmp
fi
if [[ "$OS" == "Windows" ]]; then
BASEUNITYPATH="/c/Program Files/Unity/Hub/Editor"
BIN2TXT="${BIN2TXT}.exe"
fi
function usage_platforms() {
cat << EOF
Build Targets (optional, autodetected from current project settings):
-w|--windows Set build target to Win64
-m|--mac Set build target to Mac
-l|--linux Set build target to Linux
-a|--android Set build target to Android
-i|--ios Set build target to iOS
-x|--xbox Set build target to Xbox One
-s|--ps4 Set build target to ps4
-5|--ps5 Set build target to ps5
-n|--switch Set build target to Switch
-g|--webgl Set build target to WebGL
-xx|--xbox1gdk Set build target to GameCore Xbox One
-xs|--xboxs Set build target to GameCore Xbox Series S/X
--tvos Set build target to tvOS
--stadia Set build target to Stadia
EOF
}
function usage() {
cat << EOF
Usage:
open.sh [Options] [Build Target] [Batch mode flags] [other flags passed to Unity directly]
Example:
./open.sh -p [Path to Unity Project folder]
By default it will detect what build target and Unity version the project is currently set to and use that.
Use -h for a list of all the options.
Use --trace to enable bash trace mode (see everything as it is executed)
-ov|--open-version List all available Unity versions for selection and open the project with the selected version
-u [value] Path to directory where Unity versions are installed (default: $BASEUNITYPATH)
EOF
}
function help() {
usage
usage_platforms
cat << EOF
General Options:
-p|--path [value] Project path relative to the current directory (optional, current directory by default)
-v|--version [value] Unity version (optional, autodetected by default from project settings)
-lv|--list-versions List all available Unity versions
-ov|--open-version List all available Unity versions for selection and open the project with the selected version
-u [value] Path to directory where Unity versions are installed (default: $BASEUNITYPATH)
--unity Path to Unity.exe/Unity.app executable
--print Print the current version of Unity and the current build target that the project is set to.
--no-project Run unity without passing in a project path, it uses a temporary path instead.
This is especially useful for switching licenses, where you don't want Unity
to spend time importing a project.
Unity will complain that the path doesn't contain a project, but the license
update runs before that, so you can ignore the errors.
-y|--auto-confirm Don't ask for confirmation before running Unity
-f|--foreground Run Unity in the foreground (off by default)
Batch mode:
-q|--quit Run Unity with -quit flag
--no-quit Don't send the -q argument to Unity, even if other flags imply it.
-b|--batch Runs Unity in -batchmode mode. The default method name is BuildHelp.BuildIt_[TARGET]_[CONFIGURATION]
Use -e to set the method name, or -d/-r/-c to use the default name with a specific configuration.
Implies -q
-e|--method [value] Run Unity by invoking a method and exiting. Implies -q.
-d|--debug Used with -b, sets the method to BuildHelp.BuildIt_[TARGET]_Dev
-r|--release Used with -b, sets the method to BuildHelp.BuildIt_[TARGET]_Release
-c|--configuration [value] Used with -b, sets the method to BuildHelp.BuildIt_[TARGET]_[CONFIGURATION],
where CONFIGURATION is what you set here.
Cache server:
-z|--cache [value] IP or hostname of unity accelerator
-k|--nocache Don't add any cache server parameters
--v1 Use cache server v1
--v2 Use cache server v2 (accelerator)
License management:
-lic|--license Select license to use, returning the current one first.
Run this with --no-project for switching licenses without opening a project.
-llist|--license-list List configured licenses
-lset|--license-set Configure a license
-lrem|--license-remove Remove a configured license
-lret|--license-return Return the current license
EOF
}
function main() {
if [[ "$OS" == "Windows" ]]; then
HUBPATH="$( echo ~/AppData/Roaming/UnityHub/ | xargs realpath )" || true
else
HUBPATH="$( cd ~/Library/Application\ Support/UnityHub/ && pwd )" || true
fi
if [[ -d $HUBPATH ]]; then
HUBPATH="$HUBPATH/secondaryInstallPath.json"
fi
if [[ -f $HUBPATH ]]; then
tmp="$( $CAT "$HUBPATH" | $SED -E 's, ,\\ ,g' | $SED -E 's,",,g' )"
if [[ x"$tmp" != x"" ]]; then
BASEUNITYPATH="$tmp"
if [[ "$OS" == "Windows" ]]; then
BASEUNITYPATH="$( realpath "$BASEUNITYPATH" )"
fi
fi
fi
local ARGSONLY=0
while (( "$#" )); do
if [[ "$ARGSONLY" == "1" ]]; then
ARGS+=("$1")
shift
continue
fi
case "$1" in
-d|--debug)
CONFIGURATION="Dev"
;;
-r|--release)
CONFIGURATION="Release"
;;
-b|--batch)
BATCH=1
QUIT=1
;;
-b|--build)
BUILD=1
BATCH=1
QUIT=1
;;
-c)
shift
CONFIGURATION=$1
;;
-v|--version)
shift
UNITYVERSION="$1"
;;
-p|--path)
shift
PROJECTPATH="${DIR}/${1}"
;;
-e|--method)
shift
METHOD=$1
QUIT=1
;;
-z|--cache)
shift
CACHESERVER="$1"
CUSTOM_CACHESERVER=1
;;
-u)
shift
BASEUNITYPATH="$1"
;;
--unity)
shift
UNITYPATH="$1"
;;
-q|--quit)
QUIT=1
;;
--noquit)
QUIT=0
;;
--v1)
CACHEVERSION=1
;;
--v2)
CACHEVERSION=2
;;
-k|--nocache)
CACHEVERSION=0
;;
-lv|--list-versions)
LISTVERSIONS=1
;;
-ov|--open-version)
SWITCHVERSION=1
;;
--print)
PRINT=1
;;
-lic|--license)
LICENSE=0
LICRETURN=1
if [[ ${2:-0} == [1-9] ]]; then
LICENSE=$2
shift
fi
;;
-lset|--license-set)
shift
license_set $@
exit 0
;;
-llist|--license-list)
shift
license_list $@
exit 0
;;
-lrem|--license-remove)
shift
license_remove $@
exit 0
;;
-lret|--license-return)
LICENSE=
LICRETURN=1
if [[ ${2:-0} == [1-9] ]]; then
LICENSE=$2
shift
fi
;;
--no-project)
PROJECTPATH=$TMPDIR
SKIPPATHCHECK=1
;;
-y|--auto-confirm)
AUTOCONFIRM=1
;;
-f|--foreground)
FOREGROUND=1
;;
-h|--help)
help
exit 0
;;
--args)
ARGSONLY=1
;;
--trace)
{ set -x; } 2>/dev/null
;;
*)
# check if it's a platform flag, otherwise append it to the arguments
local tmp=$(platforms "$1")
if [[ -n $tmp ]]; then
TARGET=$tmp
elif [[ -d "$1" && "$PROJECTPATH" == "" ]]; then
PROJECTPATH=$(cd "$1" && pwd)
else
ARGS+=("$1")
fi
;;
esac
shift
done
if [[ "${LISTVERSIONS}" == "1" ]]; then
unityversions
exit 0
fi
if [[ -f ~/.spoiledcat/defaults.yaml ]]; then
eval $(parse_yaml ~/.spoiledcat/defaults.yaml "OU_")
if [[ x"${CUSTOM_CACHESERVER:-}" != x"1" && x"$CACHEVERSION" != x"0" && -n ${OU_cacheserver_name:-} ]]; then
CACHESERVER=${OU_cacheserver_name}
fi
fi
if [[ "$PROJECTPATH" == "" ]]; then
PROJECTPATH="$DIR"
fi
PROJECTPATH="$(echo "$PROJECTPATH" | $SED -E 's,/$,,')"
LOGFOLDER="$PROJECTPATH/Logs"
LOGFILE="$LOGFOLDER/Editor.log"
if [[ ! -d "${PROJECTPATH}/Assets" && $SKIPPATHCHECK != 1 ]]; then
echo "" >&2
echo "Error: Invalid path ${PROJECTPATH}" >&2
echo "Would you like to create a new project in ${PROJECTPATH}?"
read -n1 -r -p "Press y to create a new project in ${PROJECTPATH}, or any key to cancel..." key
if [[ "$key" == 'y' ]]; then
$MKDIR "${PROJECTPATH}/Assets"
else
usage
exit 1
fi
fi
if [[ "${SWITCHVERSION}" == "1" ]]; then
unityversions
local available=$($LS "$BASEUNITYPATH"|grep -v Hub)
available=(${available})
echo "Select a version, or enter to cancel"
local selection=
read -r selection
if [[ x"${selection:-}"x =~ ^x[1-9]{1}[0-9]*x$ ]]; then
selection=$((selection-1))
UNITYVERSION=${available[selection]}
else
echo "Set which Unity to use with -v" >&2
usage
exit 2
fi
fi
# print data about the project and exit
if [[ "${PRINT}" == "1" ]]; then
if [[ -f "$PROJECTPATH/ProjectSettings/ProjectVersion.txt" ]]; then
UNITYVERSION="$( $CAT "$PROJECTPATH/ProjectSettings/ProjectVersion.txt" | $GREP "m_EditorVersion:" | $CUT -d' ' -f 2)"
fi
local _latestunity=$($LS "$BASEUNITYPATH"|grep -v Hub|tail -n1)
UNITYPATH="${BASEUNITYPATH}/${_latestunity}"
if [[ "$OS" == "Mac" ]]; then
UNITYTOOLSPATH="$UNITYPATH/Unity.app/Contents/Tools"
UNITYPATH="$UNITYPATH/Unity.app/Contents/MacOS"
else
UNITYTOOLSPATH="$UNITYPATH/Editor/Data/Tools"
UNITYPATH="$UNITYPATH/Editor"
fi
EDITORUSERBUILDSETTINGS="$PROJECTPATH/Library/EditorUserBuildSettings.asset"
BUILDSETTINGS="$DIR/buildsettings.txt"
$RM -f "$BUILDSETTINGS" || true
TARGET="Not Set"
if [[ -e "$EDITORUSERBUILDSETTINGS" ]]; then
"$UNITYTOOLSPATH/$BIN2TXT" "$EDITORUSERBUILDSETTINGS" "$BUILDSETTINGS" || true
if [[ -e "$BUILDSETTINGS" ]]; then
ACTIVETARGET="$( $CAT "$BUILDSETTINGS" | $GREP "m_ActiveBuildTarget " | CUT -d' ' -f 2)"
$RM -f "$BUILDSETTINGS" || true
TARGET=$(platforms "$ACTIVETARGET")
if [[ "$TARGET" == "" ]]; then
TARGET=Unknown
fi
fi
fi
cat << EOF
Project: ${PROJECTPATH}
Unity version: ${UNITYVERSION}
Build Target: ${TARGET}
EOF
exit 0
fi
if [[ "${UNITYPATH}" == "" ]]; then
if [[ "${UNITYVERSION}" == "" ]]; then
if [[ -f "$PROJECTPATH/ProjectSettings/ProjectVersion.txt" ]]; then
UNITYVERSION="$( $CAT "$PROJECTPATH/ProjectSettings/ProjectVersion.txt" | $GREP "m_EditorVersion:" | $CUT -d' ' -f 2)"
else
echo "" >&2
echo "Error: No Unity version detected in project." >&2
unityversions
local available=$($LS "$BASEUNITYPATH"|grep -v Hub)
available=(${available})
echo "Select a version, or enter to cancel"
local selection=
read -r selection
if [[ x"${selection:-}"x =~ ^x[1-9]{1}[0-9]*x$ ]]; then
selection=$((selection-1))
UNITYVERSION=${available[selection]}
else
echo "Set which Unity to use -v" >&2
usage
exit 2
fi
fi
else
if [[ ! -d "${BASEUNITYPATH}/${UNITYVERSION}" && -d "${BASEUNITYPATH}/${UNITYVERSION}f1" ]]; then
UNITYVERSION="${UNITYVERSION}f1"
fi
if [[ ! -d "${BASEUNITYPATH}/${UNITYVERSION}" && -d "${BASEUNITYPATH}/${UNITYVERSION}f2" ]]; then
UNITYVERSION="${UNITYVERSION}f2"
fi
if [[ ! -d "${BASEUNITYPATH}/${UNITYVERSION}" && -d "${BASEUNITYPATH}/${UNITYVERSION}f3" ]]; then
UNITYVERSION="${UNITYVERSION}f3"
fi
if [[ ! -d "${BASEUNITYPATH}/${UNITYVERSION}" && -d "${BASEUNITYPATH}/${UNITYVERSION}f4" ]]; then
UNITYVERSION="${UNITYVERSION}f4"
fi
fi
if [[ -d "${BASEUNITYPATH}/${UNITYVERSION}" ]]; then
echo "Using Unity v$UNITYVERSION"
UNITYPATH="${BASEUNITYPATH}/${UNITYVERSION}"
else
echo "" >&2
echo "Error: Unity not found at ${BASEUNITYPATH}/${UNITYVERSION}" >&2
echo "Install Unity v$UNITYVERSION or use a different version with -ov or -v" >&2
usage
exit 2
fi
if [[ "$OS" == "Mac" ]]; then
UNITYTOOLSPATH="$UNITYPATH/Unity.app/Contents/Tools"
UNITYPATH="$UNITYPATH/Unity.app/Contents/MacOS"
else
UNITYTOOLSPATH="$UNITYPATH/Editor/Data/Tools"
UNITYPATH="$UNITYPATH/Editor"
fi
else
UNITYTOOLSPATH="$UNITYPATH/Data/Tools"
fi
if [[ ! -d "${UNITYPATH}" ]]; then
echo "" >&2
echo "Error: Unity not found at ${UNITYPATH}" >&2
usage
exit 1
fi
if [[ ! -f "$UNITYTOOLSPATH/$BIN2TXT" ]]; then
echo "Error: Unity not found at ${UNITYPATH}" >&2
exit 1
fi
if [[ "$TARGET" == "" ]]; then
EDITORUSERBUILDSETTINGS="$PROJECTPATH/Library/EditorUserBuildSettings.asset"
BUILDSETTINGS="$DIR/buildsettings.txt"
$RM -f "$BUILDSETTINGS" || true
if [[ -e "$EDITORUSERBUILDSETTINGS" ]]; then
"$UNITYTOOLSPATH/$BIN2TXT" "$EDITORUSERBUILDSETTINGS" "$BUILDSETTINGS" || true
if [[ -e "$BUILDSETTINGS" ]]; then
ACTIVETARGET="$( $CAT "$BUILDSETTINGS" | $GREP "m_ActiveBuildTarget " | CUT -d' ' -f 2)"
$RM -f "$BUILDSETTINGS" || true
TARGET=$(platforms "$ACTIVETARGET")
if [[ "$TARGET" == "" ]]; then
echo "Error: Invalid target $ACTIVETARGET" >&2
usage
usage_platforms
exit 1
fi
fi
fi
fi
if [[ "$TARGET" == "" ]]; then
echo "" >&2
local currentplat=-w
[[ -n $ISMAC ]] && currentplat=-m
TARGET=$(platforms "$currentplat")
echo "Project has no active target, defaulting to ${TARGET}" >&2
echo "Pass one of the platform flags to set a specific platform." >&2
fi
if [[ "$BUILD" == "1" && "$METHOD" == "" ]]; then
METHOD="BuildHelp.BuildIt_${TARGET}_${CONFIGURATION}"
fi
UNITY_ARGS+=("-disable-assembly-updater")
if [[ "$CACHEVERSION" == "1" ]]; then
UNITY_ARGS+=("-CacheServerIPAddress" "$CACHESERVER")
elif [[ "$CACHEVERSION" == "2" ]]; then
UNITY_ARGS+=("-cacheServerEndpoint" "$CACHESERVER" "-adb2" "-EnableCacheServer")
fi
if [[ "$BATCH" == "1" ]]; then
UNITY_ARGS+=("-batchmode" "-nographics")
fi
if [[ "$QUIT" == "1" ]]; then
UNITY_ARGS+=("-quit")
fi
if [[ x"$METHOD" != x"" ]]; then
UNITY_ARGS+=("-executeMethod" "${METHOD}")
fi
UNITY_ARGS+=("-logFile" "$LOGFILE")
# do the license dance when the user has selected an existing configured license
if [[ x"$LICENSE" != x"" || "$LICRETURN" == "1" ]]; then
if [[ ! -f ~/.spoiledcat/licenses.yaml ]]; then
echo "There are no configured license"
return 0
fi
eval $(parse_yaml ~/.spoiledcat/licenses.yaml "UL_")
if [[ -z ${UL_licenses_:-} ]]; then
echo "There are no configured license"
return 0
fi
local onlyreturn=0
if [[ "$LICENSE" == "" ]]; then
onlyreturn=1
fi
if [[ $LICENSE != [1-9] ]]; then
local action=""
if [[ $onlyreturn == 1 ]]; then
action="return? If they all share the same credentials, pick any."
else
action="switch to?"
fi
echo ""
echo "Which license to you want to ${action}"
license_select
fi
license=($(license_get "$LICENSE"))
UNITY_ARGS_LICENSE=("${UNITY_ARGS[@]}" "-batchmode" "-quit" "-projectPath" "$TMPDIR" "-nographics" "-username" "${license[0]}" "-password" "${license[1]}")
if [[ "$LICRETURN" == "1" ]]; then
echo ""
echo "Returning license first..."
echo ""
run_unity 1 "${UNITY_ARGS_LICENSE[@]}" "-returnlicense"
fi
if [[ $onlyreturn == 1 ]]; then
return 0
else
echo ""
run_unity 1 "${UNITY_ARGS_LICENSE[@]}" "-serial" "${license[2]}"
fi
fi
UNITY_ARGS+=("-buildTarget" "$TARGET" "-projectPath" "$PROJECTPATH" "${ARGS[@]}")
echo "Opening project ${PROJECTPATH} with $UNITYVERSION : $TARGET"
run_unity $FOREGROUND "${UNITY_ARGS[@]}"
}
function run_unity {
local wait=$1
shift
local cmd=($"$UNITYPATH/Unity")
while (( "$#" )); do
cmd+=("$1")
shift
done
echo "${cmd[@]}"
if [[ $AUTOCONFIRM != 1 ]]; then
read -n1 -r -p "Press space to continue..." key
if [[ x"$key" != x'' ]]; then
return
fi
fi
SUBFILENAME=$( $DATE +%Y%m%d-%H%M%S )
if [[ -e "$LOGFILE" ]]; then
$CP "$LOGFILE" "$LOGFOLDER/Editor_$SUBFILENAME.log"
fi
{ set +e; } 2>/dev/null
oldifs=$IFS
# really make sure bash doesn't split words and add quotes when we're invoking this
IFS=$
if [[ $wait == 1 ]]; then
${cmd[@]}
else
${cmd[@]} &
fi
IFS=$oldifs
{ set -e; } 2>/dev/null
echo ""
return 0
}
# ======= HELPERS ========== #
function unityversions() {
local available=$($LS "$BASEUNITYPATH"|grep -v Hub)
local availablecount=(${available#})
availablecount=${#availablecount[@]}
available=(${available})
availablecount=$((availablecount-1))
for i in $(seq 0 $availablecount); do
echo "$((i+1))) ${available[$i]}"
done
}
function platforms() {
case $1 in
2|-m|--mac) echo 'Mac';;
5|--win32) echo 'Win32';;
9|-i|--ios) echo 'iOS';;
13|-a|--android) echo 'Android';;
19|-w|--windows) echo 'Win64';;
20|-g|--webgl) echo 'WebGL';;
24|-l|--linux) echo 'Linux64';;
31|-s|--ps4) echo 'PS4';;
33|-x|--xbox) echo 'XboxOne';;
37|--tvos) echo 'tvOS';;
38|-n|--switch) echo 'Switch';;
40|--stadia) echo 'Stadia';;
42|-xs|--scarlett|--xboxs) echo 'GameCoreScarlett';;
43|-xx|--xbox1gdk) echo 'GameCoreXboxOne';;
44|-5|--ps5) echo 'PS5';;
*) echo '';;
esac
}
LIC_PLAT=("" General Switch PS4 PS5 "Xbox One" "Xbox S/X")
function license_select {
licensecount=(${UL_licenses_#})
licensecount=${#licensecount[@]}
for i in $(seq 1 "$licensecount"); do
local plat="UL_licenses_${i}_platform"
local license="UL_licenses_${i}_license"
echo "$i) ${!plat} => ${!license}"
done
local selection=
read -r selection
if [[ ${selection:-} == [1-9] ]]; then
LICENSE=$selection
fi
}
function license_get {
local platform="UL_licenses_${1}_platform"
local license="UL_licenses_${1}_license"
local username="UL_licenses_${1}_username"
local password="UL_licenses_${1}_password"
printf '%q %q %q' "${!username}" "${!password}" "${!license}"
}
function license_set {
cat << EOF
This will store a license key so you can switch licenses with the --license option, for the given platform.
Note: Unity requires passing the username, password and license key on the command line as plain text arguments in order to switch licenses.
The values set here are stored in plaintext in ~/.spoiledcat/licenses.yaml
EOF
local continue
echo ""
read -n1 -r -p 'Continue? (Enter or Space to continue, or any other key to quit):' continue
if [[ -n "$continue" ]]; then
echo ""
echo "Exiting"
return
fi
local platform
local user
local pwd
local license
cat << EOF
Platform for this key:
EOF
local count=${#LIC_PLAT[@]}
count=$((count-1))
for i in $(seq 1 $count); do
cat << EOF
$i) ${LIC_PLAT[$i]}
EOF
done
local selection=
read -r -p "Which selection? " selection
if [[ ${selection:-} != [1-9] ]]; then
echo ""
echo "Exiting"
return
fi
if [[ -z ${LIC_PLAT[$selection]:-} ]] ; then
echo ""
echo "Exiting"
return
fi
local platform=${LIC_PLAT[$selection]}
{ set -u; } 2>/dev/null
echo ""
echo "Platform selected: $platform"
echo ""
read -r -p "Unity username: " username
read -r -s -p "Unity password: " password
echo ""
read -r -p "Unity license key: " license
echo ""
$MKDIR ~/.spoiledcat
if [[ -f ~/.spoiledcat/licenses.yaml ]]; then
eval $(parse_yaml ~/.spoiledcat/licenses.yaml "UL_")
if [[ -z ${UL_licenses_:-} ]]; then
local entry=$(format_license_entry "$platform" "$username" "$password" "$license")
cat > ~/.spoiledcat/licenses.yaml << EOF
licenses:
${entry}
EOF
else
lic_add_or_update "$platform" "$username" "$password" "$license"
fi
else
local entry=$(format_license_entry "$platform" "$username" "$password" "$license")
cat > ~/.spoiledcat/licenses.yaml << EOF
licenses:
${entry}
EOF
fi
}
function license_list() {
if [[ ! -f ~/.spoiledcat/licenses.yaml ]]; then
echo "There are no configured license"
return 0
fi
eval $(parse_yaml ~/.spoiledcat/licenses.yaml "UL_")
if [[ -z ${UL_licenses_:-} ]]; then
echo "There are no configured license"
return 0
fi
licensecount=(${UL_licenses_#})
licensecount=${#licensecount[@]}
for i in $(seq 1 "$licensecount"); do
local platform="UL_licenses_${i}_platform"
local license="UL_licenses_${i}_license"
echo "${!platform} => ${!license}"
done
}
function license_remove() {
if [[ ! -f ~/.spoiledcat/licenses.yaml ]]; then
echo "There are no configured license"
return 0
fi
eval $(parse_yaml ~/.spoiledcat/licenses.yaml "UL_")
if [[ -z ${UL_licenses_:-} ]]; then
echo "There are no configured license"
return 0
fi
cat <<EOF
Select the key to remove:
EOF
licensecount=(${UL_licenses_#})
licensecount=${#licensecount[@]}
for i in $(seq 1 "$licensecount"); do
local platform="UL_licenses_${i}_platform"
local license="UL_licenses_${i}_license"
echo "$i) ${!platform} => ${!license}"
done
local selection=
read -r selection
if [[ ${selection:-} == [1-9] ]]; then
lic_remove "$selection"
fi
}
function lic_remove() {
local index=$1
shift
local yaml=""
local licensecount=(${UL_licenses_#})
licensecount=${#licensecount[@]}
for i in $(seq 1 "$licensecount"); do
local platform="UL_licenses_${i}_platform"
platform=${!platform}
if [[ $i == $index ]]; then
echo "Removing $platform"
continue
fi
local username="UL_licenses_${i}_username"
username=${!username}
local password="UL_licenses_${i}_password"
password=${!password}
local license="UL_licenses_${i}_license"
license=${!license}
local entry=$(format_license_entry "$platform" "$username" "$password" "$license")
yaml=$(cat <<EOF
${yaml}
${entry}
EOF
)
done
cat > ~/.spoiledcat/licenses.yaml << EOF
licenses:
${yaml}
EOF
}
function lic_add_or_update() {
local newplat=$1
shift
local newuser=$1
shift
local newpwd=$1
shift
local newkey=$1
shift
local yaml=""
local found=
local licensecount=(${UL_licenses_#})
licensecount=${#licensecount[@]}
for i in $(seq 1 "$licensecount"); do
local platform="UL_licenses_${i}_platform"
platform=${!platform}
local username="UL_licenses_${i}_username"
username=${!username}
local password="UL_licenses_${i}_password"
password=${!password}
local license="UL_licenses_${i}_license"
license=${!license}
if [[ "$platform" == "$newplat" ]]; then
found=1
username=$newuser
password=$newpwd
license=$newkey
fi
local entry=$(format_license_entry "$platform" "$username" "$password" "$license")
yaml=$(cat <<EOF
${yaml}
${entry}
EOF
)
done
if [[ -z $found ]]; then
local entry=$(format_license_entry "$newplat" "$newuser" "$newpwd" "$newkey")
yaml=$(cat <<EOF
${yaml}
${entry}
EOF
)
fi
cat > ~/.spoiledcat/licenses.yaml << EOF
licenses:
${yaml}
EOF
}
function format_license_entry() {
local platform=$1
shift
local username=$1
shift
local password=$1
shift
local license=$1
shift
cat <<EOF
- platform: ${platform}
username: ${username}
password: ${password}
license: ${license}
EOF
}
# source: https://github.com/mrbaseman/parse_yaml.git