-
Notifications
You must be signed in to change notification settings - Fork 9
/
BuildLoopCaregiver.sh
executable file
·841 lines (724 loc) · 29.9 KB
/
BuildLoopCaregiver.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
#!/bin/bash # script BuildLoopCaregiver.sh
# -----------------------------------------------------------------------------
# This file is GENERATED. DO NOT EDIT directly.
# If you want to modify this file, edit the corresponding file in the src/
# directory and then run the build script to regenerate this output file.
# -----------------------------------------------------------------------------
############################################################
# Required parameters for any build script that uses
# inline build_functions
############################################################
BUILD_DIR=~/Downloads/"BuildLoop"
OVERRIDE_FILE=LoopConfigOverride.xcconfig
DEV_TEAM_SETTING_NAME="LOOP_DEVELOPMENT_TEAM"
# *** Start of inlined file: inline_functions/build_functions.sh ***
# *** Start of inlined file: inline_functions/common.sh ***
STARTING_DIR="${PWD}"
############################################################
# define some font styles and colors
############################################################
# remove special font
NC='\033[0m'
# add special font
#INFO_FONT='\033[1;36m'
INFO_FONT='\033[1m'
SUCCESS_FONT='\033[1;32m'
ERROR_FONT='\033[1;31m'
function section_divider() {
echo -e ""
echo -e "--------------------------------"
echo -e ""
}
function section_separator() {
# Clears the screen without clearing the scrollback buffer, suppressing any error messages
echo -e "\033[2J\033[H" 2>/dev/null
section_divider
}
function return_when_ready() {
echo -e "${INFO_FONT}Return when ready to continue${NC}"
read -p "" dummy
}
# Skip if this script is called from another script, then this has already been displayed
if [ "$0" != "_" ]; then
# Inform the user about env variables set
# Variables definition
variables=(
"SCRIPT_BRANCH: Indicates the lnl-scripts branch in use."
"LOCAL_SCRIPT: Set to 1 to run scripts from the local directory."
"FRESH_CLONE: Lets you use an existing clone (saves time)."
"CLONE_STATUS: Can be set to 0 for success (default) or 1 for error."
"SKIP_OPEN_SOURCE_WARNING: If set, skips the open source warning for build scripts."
"CUSTOM_URL: Overrides the repo url."
"CUSTOM_BRANCH: Overrides the branch used for git clone."
"CUSTOM_MACOS_VER: Overrides the detected macOS version."
"CUSTOM_XCODE_VER: Overrides the detected Xcode version."
"DELETE_SELECTED_FOLDERS: Echoes folder names but does not delete them"
"PATCH_BRANCH: Indicates the source branch for patches."
"PATCH_REPO: Specifies the URL of the patch source repository."
"LOCAL_PATCH_FOLDER: Defines a local directory for sourcing patches."
"CUSTOMIZATION_DEBUG: Determines the verbosity of the customization debug output."
)
# Flag to check if any variable is set
any_variable_set=false
# Iterate over each variable
for var in "${variables[@]}"; do
# Split the variable name and description
IFS=":" read -r name description <<<"$var"
# Check if the variable is set
if [ -n "${!name}" ]; then
# If this is the first variable set, print the initial message
if ! $any_variable_set; then
section_separator
echo -e "For your information, you are running this script in customized mode"
echo -e "You might be using a branch other than main, and using SCRIPT_BRANCH"
echo -e "Developers might have additional environment variables set:"
any_variable_set=true
fi
# Print the variable name, value, and description
echo " - $name: ${!name}"
echo " $description"
fi
done
if $any_variable_set; then
echo
echo "To clear the values, close this terminal and start a new one."
echo "Sleeping for 2 sec then continuing"
sleep 2
fi
fi
function choose_option() {
echo -e "Type a number from the list below and return to proceed."
section_divider
}
function invalid_entry() {
echo -e "\n${ERROR_FONT}Invalid option${NC}\n"
}
function do_continue() {
:
}
function menu_select() {
choose_option
local options=("${@:1:$#/2}")
local actions=("${@:$(($# + 1))/2+1}")
while true; do
select opt in "${options[@]}"; do
for i in $(seq 0 $((${#options[@]} - 1))); do
if [ "$opt" = "${options[$i]}" ]; then
eval "${actions[$i]}"
return
fi
done
invalid_entry
break
done
done
}
function exit_or_return_menu() {
if [ "$0" != "_" ]; then
# Called directly
echo "Exit Script"
else
# Called from BuildSelectScript
echo "Return to Menu"
fi
}
function exit_script() {
if [ "$0" != "_" ]; then
# Called directly
exit_message
else
# Called from BuildSelectScript
exit 0
fi
}
function exit_message() {
section_divider
echo -e "${INFO_FONT}Exit from Script${NC}\n"
echo -e " You may close the terminal"
echo -e "or"
echo -e " You can press the up arrow ⬆️ on the keyboard"
echo -e " and return to repeat script from beginning"
section_divider
exit 0
}
function erase_previous_line {
if [ -n "$TERM" ]; then
(tput cuu1 && tput el) 2>/dev/null || true
fi
}
# *** End of inlined file: inline_functions/common.sh ***
############################################################
# Common functions used by multiple build scripts
# - Explanation of variables, Default values
############################################################
# Variables set by BuildXXX script that calls this inline script
#
# Required: BUILD_DIR
# it is where the download folder will be created
# For example: BUILD_DIR=~/Downloads/BuildLoop
#
# Required: OVERRIDE_FILE
# name of the automatic signing file
# For example: OVERRIDE_FILE=LoopConfigOverride.xcconfig
# Required: DEV_TEAM_SETTING_NAME
# keyword used in the automatic signing file
# e.g., ${DEV_TEAM_SETTING_NAME} = Apple Developer TeamID
# Loop and Loop associated apps use: "LOOP_DEVELOPMENT_TEAM"
# iAPS uses: "DEVELOPER_TEAM"
# Default: some projects create or use the override file in the BUILD_DIR
# Some, like iAPS, use a file in the downloaded clone itself
# in that case, set USE_OVERRIDE_IN_REPO to 1 in the src/Build script
: ${USE_OVERRIDE_IN_REPO:="0"}
# Default: some projects use submodules (and need --recurse-submodule)
# Some, like iAPS and LoopFollow, do not use submodules
# in that case, set CLONE_SUB_MODULES to 0 in the src/Build script
: ${CLONE_SUB_MODULES:="1"}
# Accept build_warning before creating folders
# *** Start of inlined file: inline_functions/build_warning.sh ***
############################################################
# warning used by all scripts that build an app
############################################################
function open_source_warning() {
# Skip open source warning if opted out using env variable or this script is run from another script
if [ "${SKIP_OPEN_SOURCE_WARNING}" = "1" ] || [ "$0" = "_" ]; then return; fi
local documentation_link="${1:-}"
section_separator
echo -e "${INFO_FONT}*** IMPORTANT ***${NC}\n"
echo -e "This project is:"
echo -e "${INFO_FONT} Open Source software"
echo -e " Not \"approved\" for therapy${NC}"
echo -e ""
echo -e " You take full responsibility when you build"
echo -e " or run an open source app, and"
echo -e " ${INFO_FONT}you do so at your own risk.${NC}"
echo -e ""
echo -e "To increase (decrease) font size"
echo -e " Hold down the CMD key and hit + (-)"
echo -e "\n${INFO_FONT}By typing 1 and ENTER, you indicate you understand"
echo -e "\n--------------------------------\n${NC}"
options=("Agree" "Cancel")
select opt in "${options[@]}"; do
case $opt in
"Agree")
break
;;
"Cancel")
echo -e "\n${INFO_FONT}User did not agree to terms of use.${NC}\n\n"
exit_script
;;
*)
echo -e "\n${INFO_FONT}User did not agree to terms of use.${NC}\n\n"
invalid_entry
exit_script
;;
esac
done
# Warning has been issued
SKIP_OPEN_SOURCE_WARNING=1
echo -e "${NC}\n\n\n\n"
}
# *** End of inlined file: inline_functions/build_warning.sh ***
# Messages prior to opening xcode
# *** Start of inlined file: inline_functions/before_final_return_message.sh ***
function before_final_return_message() {
echo ""
echo -e "${INFO_FONT}BEFORE you hit return:${NC}"
echo " *** Unlock your phone and plug it into your computer"
echo " Trust computer if asked"
echo ""
echo -e "${INFO_FONT}AFTER you hit return, Xcode will open automatically${NC}"
echo " For new phone or new watch (never used with Xcode),"
echo " review Developer Mode Information:"
echo -e " https://loopkit.github.io/loopdocs/build/step14/#prepare-your-phone-and-watch"
echo ""
echo " For phones that have Developer Mode enabled continue with these steps"
echo " Upper middle of Xcode:"
echo " Confirm your phone or simulator choice is selected"
echo " Upper right of Xcode:"
echo " Wait for packages to finish being copied or downloaded"
echo " When you see indexing, you can start the build"
echo " Click on Play button to build and run on the selected device"
}
function after_final_return_message() {
section_divider
echo "If you need to find this download in a terminal, copy and paste the next line:"
echo ""
echo "cd ${LOCAL_DIR}/${REPO_NAME}"
}
# *** End of inlined file: inline_functions/before_final_return_message.sh ***
# clean provisioning profiles saved on disk
# *** Start of inlined file: inline_functions/clean_profiles.sh ***
############################################################
# clean_profiles function
# Action: deletes saved mobileprovisions from Mac
# Information:
# If Xcode is open, *.mobileprovisions are deleted and new ones generated
# The path changed between Xcode 15 and Xcode 16, delete both folders
############################################################
clean_profiles() {
xcode15_path=${HOME}/Library/MobileDevice/Provisioning\ Profiles
xcode16_path=${HOME}/Library/Developer/Xcode/UserData/Provisioning\ Profiles
echo -e "\n✅ Cleaning Profiles"
echo -e " This ensures the next app you build with Xcode will last a year."
if [[ -d "$xcode15_path" ]]; then
rm -rf "$xcode15_path"
fi
if [[ -d "$xcode16_path" ]]; then
rm -rf "$xcode16_path"
fi
echo -e "✅ Profiles are cleaned."
}
# *** End of inlined file: inline_functions/clean_profiles.sh ***
############################################################
# Common functions used by multiple build scripts
# - Start of build_functions.sh common code
############################################################
SCRIPT_DIR="${BUILD_DIR}/Scripts"
if [ ! -d "${BUILD_DIR}" ]; then
mkdir "${BUILD_DIR}"
fi
############################################################
# set up nominal values
# these can be later overwritten by flags
# for convenience when testing (or for advanced users)
############################################################
# FRESH_CLONE
# Default value is 1, which means:
# Download fresh clone every time script is run
: ${FRESH_CLONE:="1"}
# CLONE_STATUS used to test error messages
# Default value is 0, which means no errors with clone
: ${CLONE_STATUS:="0"}
# Prepare date-time stamp for folder
DOWNLOAD_DATE=$(date +'%y%m%d-%H%M')
# This enables the selection of a custom branch via enviroment variable
# It can also be passed in as argument $1
# If passed in, it overwrites the environment variable
# When CUSTOM_BRANCH is set, the menu which asks which branch is skipped
CUSTOM_BRANCH=${1:-$CUSTOM_BRANCH}
############################################################
# Define the rest of the functions (usage defined above):
############################################################
# *** Start of inlined file: inline_functions/building_verify_version.sh ***
#This should be the latest iOS version
#This is the highest version we expect users to have on their iPhones
LATEST_IOS_VER="18.0"
#This should be the lowest xcode version required to build to LATEST_IOS_VER
LOWEST_XCODE_VER="15.4"
#This should be the latest known xcode version
#LOWEST_XCODE_VER and LATEST_XCODE_VER will probably be equal but we should have suport for a span of these
LATEST_XCODE_VER="16.0"
#This is the lowest version of macOS required to run LOWEST_XCODE_VER
LOWEST_MACOS_VER="14.6"
# The compare_versions function takes two version strings as input arguments,
# sorts them in ascending order using the sort command with the -V flag (version sorting),
# and returns the first version (i.e., the lowest one) using head -n1.
#
# Example:
# compare_versions "1.2.3" "1.1.0" will return "1.1.0"
function compare_versions() {
printf '%s\n%s\n' "$1" "$2" | sort -V | head -n1
}
function check_versions() {
section_divider
echo "Verifying Xcode and macOS versions..."
if ! command -v xcodebuild >/dev/null; then
echo " Xcode not found. Please install Xcode and try again."
exit_or_return_menu
fi
if [ -n "$CUSTOM_XCODE_VER" ]; then
XCODE_VER="$CUSTOM_XCODE_VER"
else
XCODE_VER=$(xcodebuild -version | awk '/Xcode/{print $NF}')
fi
if [ -n "$CUSTOM_MACOS_VER" ]; then
MACOS_VER="$CUSTOM_MACOS_VER"
else
MACOS_VER=$(sw_vers -productVersion)
fi
echo " Xcode found: Version $XCODE_VER"
# Check if Xcode version is greater than the latest known version
if [ "$(compare_versions "$XCODE_VER" "$LATEST_XCODE_VER")" = "$LATEST_XCODE_VER" ] && [ "$XCODE_VER" != "$LATEST_XCODE_VER" ]; then
echo ""
echo "You have a newer Xcode version ($XCODE_VER) than"
echo " the latest released version known by this script ($LATEST_XCODE_VER)."
echo "You can probably continue; but if you have problems, refer to"
echo " https://developer.apple.com/support/xcode/"
options=("Continue" "$(exit_or_return_menu)")
actions=("return" "exit_script")
menu_select "${options[@]}" "${actions[@]}"
# Check if Xcode version is less than the lowest required version
elif [ "$(compare_versions "$XCODE_VER" "$LOWEST_XCODE_VER")" = "$XCODE_VER" ] && [ "$XCODE_VER" != "$LOWEST_XCODE_VER" ]; then
if [ "$(compare_versions "$MACOS_VER" "$LOWEST_MACOS_VER")" != "$LOWEST_MACOS_VER" ]; then
echo ""
echo "Your macOS version ($MACOS_VER) is lower than $LOWEST_MACOS_VER"
echo " required to build for iOS $LATEST_IOS_VER."
echo "Please update macOS to version $LOWEST_MACOS_VER or later."
echo ""
echo "If you can't update, follow the GitHub build option here:"
echo " https://loopkit.github.io/loopdocs/gh-actions/gh-overview/"
fi
echo ""
echo "You need to upgrade Xcode to version $LOWEST_XCODE_VER or later to build for iOS $LATEST_IOS_VER."
echo "If your iOS is at a lower version, refer to the compatibility table in LoopDocs"
echo " https://loopkit.github.io/loopdocs/build/xcode-version/#compatible-versions"
options=("Continue with lower iOS version" "$(exit_or_return_menu)")
actions=("return" "exit_script")
menu_select "${options[@]}" "${actions[@]}"
else
echo "Your Xcode version can build up to iOS $LATEST_IOS_VER."
fi
}
# *** End of inlined file: inline_functions/building_verify_version.sh ***
# *** Start of inlined file: inline_functions/building_config_override.sh ***
function check_config_override_existence_offer_to_configure() {
section_separator
# Automatic signing functionality:
# 1) Use existing Override file
# 2) Copy team from latest provisioning profile
# 3) Enter team manually with option to skip
# Options for USE_OVERRIDE_IN_REPO
# 0 means copy file in repo up 2 levels and use that
# 1 create the file in the repo and add development team
# 2 create the file in the repo with extra line(s) and the team
if [[ $USE_OVERRIDE_IN_REPO -ge 1 ]]; then
OVERRIDE_FULLPATH="${LOCAL_DIR}/$REPO_NAME/${OVERRIDE_FILE}"
else
OVERRIDE_FULLPATH="${BUILD_DIR}/${OVERRIDE_FILE}"
fi
if [ -f ${OVERRIDE_FULLPATH} ] && \
grep -q "^$DEV_TEAM_SETTING_NAME" ${OVERRIDE_FULLPATH}; then
# how_to_find_your_id
report_persistent_config_override
else
PROFILES_DIR="$HOME/Library/MobileDevice/Provisioning Profiles"
if [ -d "${PROFILES_DIR}" ]; then
latest_file=$(find "${PROFILES_DIR}" -type f -name "*.mobileprovision" -print0 | xargs -0 ls -t | head -n1)
if [ -n "$latest_file" ]; then
# Decode the .mobileprovision file using the security command
decoded_xml=$(security cms -D -i "$latest_file")
# Extract the Team ID from the XML
DEVELOPMENT_TEAM=$(echo "$decoded_xml" | awk -F'[<>]' '/<key>TeamIdentifier<\/key>/ { getline; getline; print $3 }')
fi
fi
if [ -n "$DEVELOPMENT_TEAM" ]; then
echo -e "Using TeamIdentifier from the latest provisioning profile\n"
set_development_team "$DEVELOPMENT_TEAM"
report_persistent_config_override
else
echo -e "Choose 1 to Sign Automatically or "
echo -e " 2 to Sign Manually (later in Xcode)"
echo -e "\nIf you choose Sign Automatically, script guides you"
echo -e " to create a permanent signing file"
echo -e " containing your Apple Developer ID"
choose_option
options=("Sign Automatically" "Sign Manually" "$(exit_or_return_menu)")
select opt in "${options[@]}"
do
case $opt in
"Sign Automatically")
create_persistent_config_override
break
;;
"Sign Manually")
break
;;
"$(exit_or_return_menu)")
exit_script
;;
*) # Invalid option
invalid_entry
;;
esac
done
fi
fi
}
function report_persistent_config_override() {
echo -e "Your Apple Developer ID was found automatically:"
grep "^$DEV_TEAM_SETTING_NAME" ${OVERRIDE_FULLPATH}
echo -e "\nIf that is correct your app will be automatically signed\n"
options=("ID is OK" "Editing Instructions" "$(exit_or_return_menu)")
select opt in "${options[@]}"
do
case $opt in
"ID is OK")
break
;;
"Editing Instructions")
section_divider
echo -e " Part 1: How to find your Apple Developer ID"
echo -e ""
how_to_find_your_id
echo -e ""
echo -e " Part 2: Edit the automatic signing file before hitting return"
echo -e " step 1: open finder, "
echo -e " step 2: locate and double click on"
echo -e " ${OVERRIDE_FULLPATH/$HOME/~}"
echo -e " to open that file in Xcode"
echo -e " step 3: find the line that starts with "
echo -e " ${DEV_TEAM_SETTING_NAME}="
echo -e " and modify the value to be your "
echo -e " Apple Developer ID"
echo -e " step 4: save the file"
echo -e ""
echo -e " When ready to proceed, hit return"
return_when_ready
break
;;
"$(exit_or_return_menu)")
exit_script
;;
*) # Invalid option
invalid_entry
;;
esac
done
}
function how_to_find_your_id() {
echo -e "Your Apple Developer ID is the 10-character Team ID"
echo -e " found on the Membership page after logging into your account at:"
echo -e " https://developer.apple.com/account/#!/membership\n"
echo -e "It may be necessary to click on the Membership Details icon"
}
function create_persistent_config_override() {
section_separator
echo -e "The Apple Developer page will open when you hit return\n"
how_to_find_your_id
echo -e "That page will be opened for you."
echo -e " Once you get your ID, you will enter it in this terminal window"
return_when_ready
#
open "https://developer.apple.com/account/#!/membership"
echo -e "\n *** \nClick in terminal window so you can"
read -p "Enter the ID and return: " devID
#
section_separator
if [ ${#devID} -ne 10 ]; then
echo -e "Something was wrong with the entry"
echo -e "You can manually sign each target in Xcode"
else
echo -e "Creating ${OVERRIDE_FULLPATH}"
echo -e " with your Apple Developer ID\n"
# For Loop, copy the file and add developer ID
# For other apps, create file with developer ID
set_development_team $devID
report_persistent_config_override
echo -e "\nXcode uses the permanent file to automatically sign your targets"
fi
}
set_development_team() {
team_id="$1"
if [[ $USE_OVERRIDE_IN_REPO == "0" ]] &&
[[ -f "${LOCAL_DIR}/$REPO_NAME/${OVERRIDE_FILE}" ]]; then
cp -p "${LOCAL_DIR}/$REPO_NAME/${OVERRIDE_FILE}" "${OVERRIDE_FULLPATH}"
elif [[ $USE_OVERRIDE_IN_REPO == "1" ]] || \
[[ $USE_OVERRIDE_IN_REPO == "2" ]]; then
echo "// Automatic Signing File" > ${OVERRIDE_FULLPATH}
fi
if [[ $USE_OVERRIDE_IN_REPO == "2" ]]; then
for str in ${ADDED_LINE_FOR_OVERRIDE[@]}; do
echo "$str" >> ${OVERRIDE_FULLPATH}
done
fi
echo "$DEV_TEAM_SETTING_NAME = $team_id" >> ${OVERRIDE_FULLPATH}
}
# *** End of inlined file: inline_functions/building_config_override.sh ***
function standard_build_train() {
verify_xcode_path
check_versions
clone_repo
automated_clone_download_error_check
check_config_override_existence_offer_to_configure
ensure_a_year
}
function ensure_a_year() {
section_separator
echo -e "${INFO_FONT}Ensure a year by deleting old provisioning profiles${NC}"
echo -e " Unless you have a specific reason, choose option 1\n"
options=("Ensure a Year" "Skip" "$(exit_or_return_menu)")
select opt in "${options[@]}"
do
case $opt in
"Ensure a Year")
clean_profiles
break
;;
"Skip")
break
;;
"$(exit_or_return_menu)")
exit_script
;;
*) # Invalid option
invalid_entry
;;
esac
done
}
function clone_repo() {
section_divider
if [ "$SUPPRESS_BRANCH" == "true" ]; then
LOCAL_DIR="${BUILD_DIR}/${APP_NAME}-${DOWNLOAD_DATE}"
else
LOCAL_DIR="${BUILD_DIR}/${APP_NAME}_${BRANCH//\//-}-${DOWNLOAD_DATE}"
fi
if [ ${FRESH_CLONE} == 1 ]; then
mkdir "${LOCAL_DIR}"
else
LOCAL_DIR="${STARTING_DIR}"
fi
cd "${LOCAL_DIR}"
if [ ${FRESH_CLONE} == 1 ]; then
if [ "$SUPPRESS_BRANCH" == "true" ]; then
echo -e " -- Downloading ${APP_NAME} to your Downloads folder --"
else
echo -e " -- Downloading ${APP_NAME} ${BRANCH} to your Downloads folder --"
fi
echo -e " ${LOCAL_DIR}\n"
echo -e "Issuing this command:"
if [[ $CLONE_SUB_MODULES == "1" ]]; then
echo -e " git clone --branch=${BRANCH} --recurse-submodules ${REPO}"
git clone --branch=$BRANCH --recurse-submodules $REPO
else
echo -e " git clone --branch=${BRANCH} ${REPO}"
git clone --branch=$BRANCH $REPO
fi
clone_exit_status=$?
else
clone_exit_status=${CLONE_STATUS}
fi
}
function automated_clone_download_error_check() {
# Check if the clone was successful
if [ $clone_exit_status -eq 0 ]; then
# Use this flag to modify exit_or_return_menu
echo -e "✅ ${SUCCESS_FONT}Successful Download. Proceed to the next step...${NC}"
return_when_ready
else
echo -e "❌ ${ERROR_FONT}An error occurred during download. Please investigate the issue.${NC}"
exit_message
fi
}
function verify_xcode_path() {
section_divider
echo -e "Verifying xcode-select path...\n"
# Get the path set by xcode-select
xcode_path=$(xcode-select -p)
# Check if the path contains "Xcode.app"
if [[ -x "$xcode_path/usr/bin/xcodebuild" ]]; then
echo -e "✅ ${SUCCESS_FONT}xcode-select path correctly set: $xcode_path${NC}"
echo -e "Continuing the script..."
else
echo -e "❌ ${ERROR_FONT}xcode-select is not pointing to the correct Xcode path."
echo -e " It is set to: $xcode_path${NC}"
echo -e "Please choose an option below to proceed:\n"
options=("Correct xcode-select path" "Skip" "$(exit_or_return_menu)")
select opt in "${options[@]}"
do
case $opt in
"Correct xcode-select path")
xcode_path=$(mdfind -name Xcode.app 2>/dev/null)
if [ -z "$xcode_path" ]; then
echo -e "❌ ${ERROR_FONT}Xcode.app not found.${NC}"
echo -e "Please use this guide to set the xcode-select path: https://loopkit.github.io/loopdocs/build/step9/#command-line-tools"
exit_message
else
echo -e "Using this location: $xcode_path"
DEVELOPER_DIR_PATH="$xcode_path/Contents/Developer"
if [ ! -d "$DEVELOPER_DIR_PATH" ]
then
echo -e "❌ ${ERROR_FONT}Developer directory not found in Xcode.app. Please ensure you have the correct version of Xcode installed..${NC}"
echo -e "Please use this guide to set the xcode-select path: https://loopkit.github.io/loopdocs/build/step9/#command-line-tools"
exit_message
else
echo -e "You might be prompted for your password."
echo -e " Use the password for logging into your Mac."
sudo xcode-select -s "$DEVELOPER_DIR_PATH"
# Check if the path was corrected successfully
xcode_path=$(xcode-select -p)
if [[ "$xcode_path" == *Xcode.app* ]]; then
echo -e "✅ ${SUCCESS_FONT}xcode-select path has been corrected.${NC}"
return_when_ready
break
else
echo -e "❌ ${ERROR_FONT}Failed to set xcode-select path correctly.${NC}"
exit_message
fi
fi
fi
;;
"Skip")
break
;;
"$(exit_or_return_menu)")
exit_script
;;
*) # Invalid option
invalid_entry
;;
esac
done
fi
}
function branch_select() {
local url=$1
local branch=$2
local repo_name=$(basename $url .git)
local app_name=${3:-$(basename $url .git)}
local suppress_branch=${3:+true}
REPO=$url
BRANCH=$branch
REPO_NAME=$repo_name
APP_NAME=$app_name
SUPPRESS_BRANCH=$suppress_branch
}
############################################################
# End of functions used by script
# - end of build_functions.sh common code
############################################################
# *** End of inlined file: inline_functions/build_functions.sh ***
############################################################
# The rest of this is specific to the particular script
############################################################
open_source_warning
############################################################
# Welcome & Branch Selection
############################################################
URL_THIS_SCRIPT="https://github.com/LoopKit/LoopCaregiver.git"
function choose_dev_branch() {
branch_select ${URL_THIS_SCRIPT} dev
}
if [ -z "$CUSTOM_BRANCH" ]; then
section_separator
echo -e "\n ${INFO_FONT}You are running the script for LoopCaregiver (LCG)"
echo -e " This app is under development and may require frequent builds${NC}"
echo -e " You need Xcode and Xcode command line tools installed"
echo -e ""
echo -e " If you have not read this section of LoopDocs - please review before continuing"
echo -e " https://loopkit.github.io/loopdocs/nightscout/remote-overrides"
echo -e ""
echo -e " If you have not joined zulipchat Loop Caregiver App stream - do so now"
echo -e " https://loop.zulipchat.com/#narrow/stream/358458-Loop-Caregiver-App"
options=("Continue" "$(exit_or_return_menu)")
actions=("choose_dev_branch" "exit_script")
menu_select "${options[@]}" "${actions[@]}"
else
branch_select ${URL_THIS_SCRIPT} $CUSTOM_BRANCH
fi
############################################################
# Standard Build train
############################################################
standard_build_train
############################################################
# Open Xcode
############################################################
section_divider
before_final_return_message
echo -e ""
return_when_ready
cd $REPO_NAME
xed .
after_final_return_message
exit_script
# *** End of inlined file: src/BuildLoopCaregiver.sh ***