forked from loopandlearn/LoopFollow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildLoopFollow.sh
363 lines (332 loc) · 11.8 KB
/
BuildLoopFollow.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
# !/bin/bash
BUILD_DIR=~/Downloads/BuildLoopFollow
OVERRIDE_FILE=LoopFollowConfigOverride.xcconfig
OVERRIDE_FULLPATH="${BUILD_DIR}/${OVERRIDE_FILE}"
DEV_TEAM_SETTING_NAME="LF_DEVELOPMENT_TEAM"
## Unmodified code from Loop build_functions.sh for constistancy - BEGIN
RED='\033[0;31m'
GREEN='\033[0;32m'
PURPLE='\033[0;35m'
BOLD='\033[1m'
NC='\033[0m'
function exit_message() {
section_divider
echo -e "\nShell Script Completed\n"
echo -e " * You may close the terminal window now if you want"
echo -e " or"
echo -e " * You can press the up arrow ⬆️ on the keyboard"
echo -e " and return to repeat script from beginning.\n\n"
exit 0
}
function section_separator() {
clear
echo -e "--------------------------------\n"
}
function section_divider() {
echo -e "--------------------------------\n"
}
function return_when_ready() {
echo -e "${RED}${BOLD}Return when ready to continue${NC}"
read -p "" dummy
}
function cancel_entry() {
echo -e "\n${RED}${BOLD}User canceled${NC}\n"
exit_message
}
function invalid_entry() {
echo -e "\n${RED}${BOLD}User canceled by entering an invalid option${NC}\n"
exit_message
}
function choose_or_cancel() {
echo -e "\nType a number from the list below and return to proceed."
echo -e "${RED}${BOLD} To cancel, any entry not in list also works${NC}"
echo -e "\n--------------------------------\n"
}
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 clone_download_error_check() {
# indicate that a clone was created
CLONE_OBTAINED=1
echo -e "--------------------------------\n"
echo -e "🛑 Check for successful Download\n"
echo -e " Please scroll up and look for the word ${BOLD}error${NC} in the window above."
echo -e " OR use the Find command for terminal, hold down CMD key and tap F,"
echo -e " then type error (in new row, top of terminal) and hit return"
echo -e " Be sure to click in terminal again if you use CMD-F"
echo -e " If there are no errors listed, code has successfully downloaded, Continue."
echo -e " If you see the word error in the download, Cancel and resolve the problem."
choose_or_cancel
}
## Unmodified code from Loop build_functions.sh for constistancy - END
## Modified code from Loop build_functions.sh that should be backward compatible - BEGIN
function report_persistent_config_override() {
echo -e "The file used by Xcode to sign your app is found at:"
echo -e " ${OVERRIDE_FULLPATH}"
echo -e " The line containing the team id is shown next:"
grep "^$DEV_TEAM_SETTING_NAME" ${OVERRIDE_FULLPATH}
echo -e "\nIf the line has your Apple Developer ID"
echo -e " your target(s) will be automatically signed"
echo -e "WARNING: Any line that starts with // is ignored\n"
echo -e " If ID is not OK:"
echo -e " Edit the ${OVERRIDE_FILE} before hitting return"
echo -e " step 1: open finder, navigate to "${BUILD_DIR#*Users/*/}""
echo -e " step 2: locate and double click on "${OVERRIDE_FILE}""
echo -e " this will open that file in Xcode"
echo -e " step 3: edit in Xcode and save file\n"
echo -e " If ID is OK, hit return"
return_when_ready
}
## Modified code from Loop build_functions.sh that should be backward compatible - END
set_development_team() {
team_id="$1"
echo "$DEV_TEAM_SETTING_NAME = $team_id" >> ${OVERRIDE_FULLPATH}
}
function check_config_override_existence_offer_to_configure() {
section_separator
# Automatic signing functionality:
# 1) Use existing LoopFollow team
# 2) Copy team from Loop
# 3) Copy team from latest provisioning profile
# 4) Enter team manually with option to skip
if [ -f ${OVERRIDE_FULLPATH} ] && grep -q "^$DEV_TEAM_SETTING_NAME" ${OVERRIDE_FULLPATH}; then
how_to_find_your_id
report_persistent_config_override
else
if [ -f "../../BuildLoop/LoopConfigOverride.xcconfig" ] && grep -q '^LOOP_DEVELOPMENT_TEAM' "../../BuildLoop/LoopConfigOverride.xcconfig"; then
echo -e "Using existing LOOP_DEVELOPMENT_TEAM setting\n"
DEVELOPMENT_TEAM=$(grep '^LOOP_DEVELOPMENT_TEAM' "../../BuildLoop/LoopConfigOverride.xcconfig" | awk '{print $3}')
set_development_team "$DEVELOPMENT_TEAM"
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"
how_to_find_your_id
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_or_cancel
options=("Sign Automatically" "Sign Manually" "Cancel")
select opt in "${options[@]}"
do
case $opt in
"Sign Automatically")
create_persistent_config_override
break
;;
"Sign Manually")
break
;;
"Cancel")
cancel_entry
;;
*) # Invalid option
invalid_entry
;;
esac
done
fi
fi
fi
}
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 "Please click in terminal window and enter your Apple Developer Team ID (10 characters) or press Enter to skip:"
while true; do
read DEVELOPMENT_TEAM
if [ -z "$DEVELOPMENT_TEAM" ]; then
echo -e "You can manually sign target(s) in Xcode"
break
elif [ ${#DEVELOPMENT_TEAM} -eq 10 ]; then
set_development_team "$DEVELOPMENT_TEAM"
break
else
echo "Invalid Team ID. Please enter a valid 10-character Team ID or press Enter to skip."
fi
done
#
section_separator
}
# Check if a argument is provided for the repo
if [ "$#" -ge 1 ]; then
REPO="$1"
else
REPO="https://github.com/jonfawcett/LoopFollow"
fi
# Check if a second argument is provided for the branch
if [ "$#" -ge 2 ]; then
CUSTOM_BRANCH="$2"
fi
if [ "$#" -ge 1 ]; then
echo "[DEBUG] Repo URL: $REPO"
if [ -n "$CUSTOM_BRANCH" ]; then
echo "[DEBUG] Custom Branch: $CUSTOM_BRANCH"
fi
return_when_ready
fi
section_separator
echo -e "Welcome to Loop Follow.\nThis script will assist you in downloading and building the app.\nBefore you begin, please ensure that you have Xcode installed and your phone is plugged into your computer\n"
echo -e "Type 1 and hit enter to begin.\nType 2 and hit enter to cancel."
choose_or_cancel
options=("Continue" "Cancel")
select opt in "${options[@]}"
do
case $opt in
"Continue")
break
;;
"Cancel")
cancel_entry
;;
*)
invalid_entry
;;
esac
done
if [ -z "$CUSTOM_BRANCH" ]; then
section_separator
echo -e "Please select which version of Loop Follow you would like to download and build.\nDev branch has the latest features but may contain more bugs.\n\nType the number 1 or 2 and hit enter to select the branch.\nType 3 and hit enter to cancel.\n"
choose_or_cancel
options=("Main Branch" "Dev Branch" "Cancel")
select opt in "${options[@]}"
do
case $opt in
"Main Branch")
FOLDERNAME=LoopFollow-Main
BRANCH=Main
break
;;
"Dev Branch")
FOLDERNAME=LoopFollow-Dev
BRANCH=dev
break
;;
"Cancel")
cancel_entry
;;
*)
invalid_entry
;;
esac
done
else
BRANCH="$CUSTOM_BRANCH"
FOLDERNAME="LoopFollow-$BRANCH"
fi
section_separator
echo -e "Would you like to delete prior downloads of Loop Follow before proceeding?\n"
echo -e "Type 1 and hit enter to delete.\nType 2 and hit enter to continue without deleting"
choose_or_cancel
options=("Delete old downloads" "Do not delete old downloads" "Cancel")
select opt in "${options[@]}"
do
case $opt in
"Delete old downloads")
# Delete all folders below ~/Downloads/BuildLoopFollow but preserve the permanent config file.
find ~/Downloads/BuildLoopFollow -mindepth 1 -maxdepth 1 -type d -exec rm -rf {} +
break
;;
"Do not delete old downloads")
break
;;
"Cancel")
cancel_entry
;;
*)
invalid_entry
;;
esac
done
section_separator
echo -e "The code will now begin downloading.\nThe files will be saved in your Downloads folder.\n"
echo -e "Type 1 and hit enter to begin downloading.\nType 2 and hit enter to cancel.\n"
choose_or_cancel
options=("Continue" "Cancel")
select opt in "${options[@]}"
do
case $opt in
"Continue")
break
;;
"Cancel")
cancel_entry
;;
*)
invalid_entry
;;
esac
done
section_separator
LOOP_BUILD=$(date +'%y%m%d-%H%M')
LOOP_DIR=~/Downloads/BuildLoopFollow/$FOLDERNAME-$LOOP_BUILD
mkdir -p $LOOP_DIR
cd $LOOP_DIR
echo -e "Downloading Loop Follow to your Downloads folder."
pwd
echo -e
git clone --branch=$BRANCH --recurse-submodules $REPO
clone_download_error_check
options=("Continue" "Cancel")
select opt in "${options[@]}"
do
case $opt in
"Continue")
break
;;
"Cancel")
cancel_entry
;;
*)
invalid_entry
;;
esac
done
check_config_override_existence_offer_to_configure
section_separator
echo -e "Type 1 and hit enter to open Xcode. You may close the terminal after Xcode opens"
choose_or_cancel
options=("Continue" "Cancel")
select opt in "${options[@]}"
do
case $opt in
"Continue")
break
;;
"Cancel")
cancel_entry
;;
*)
invalid_entry
;;
esac
done
cd LoopFollow
Echo Open xcode
xed ./LoopFollow.xcworkspace
exit