BuildLoopFollow.sh 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. # !/bin/bash
  2. BUILD_DIR=~/Downloads/BuildLoopFollow
  3. OVERRIDE_FILE=ConfigOverride.xcconfig
  4. OVERRIDE_FULLPATH="${BUILD_DIR}/${OVERRIDE_FILE}"
  5. DEV_TEAM_SETTING_NAME="LF_DEVELOPMENT_TEAM"
  6. ## Unmodified code from Loop build_functions.sh for constistancy - BEGIN
  7. RED='\033[0;31m'
  8. GREEN='\033[0;32m'
  9. PURPLE='\033[0;35m'
  10. BOLD='\033[1m'
  11. NC='\033[0m'
  12. function exit_message() {
  13. section_divider
  14. echo -e "\nShell Script Completed\n"
  15. echo -e " * You may close the terminal window now if you want"
  16. echo -e " or"
  17. echo -e " * You can press the up arrow ⬆️ on the keyboard"
  18. echo -e " and return to repeat script from beginning.\n\n"
  19. exit 0
  20. }
  21. function section_separator() {
  22. clear
  23. echo -e "--------------------------------\n"
  24. }
  25. function section_divider() {
  26. echo -e "--------------------------------\n"
  27. }
  28. function return_when_ready() {
  29. echo -e "${RED}${BOLD}Return when ready to continue${NC}"
  30. read -p "" dummy
  31. }
  32. function cancel_entry() {
  33. echo -e "\n${RED}${BOLD}User canceled${NC}\n"
  34. exit_message
  35. }
  36. function invalid_entry() {
  37. echo -e "\n${RED}${BOLD}User canceled by entering an invalid option${NC}\n"
  38. exit_message
  39. }
  40. function choose_or_cancel() {
  41. echo -e "\nType a number from the list below and return to proceed."
  42. echo -e "${RED}${BOLD} To cancel, any entry not in list also works${NC}"
  43. echo -e "\n--------------------------------\n"
  44. }
  45. function how_to_find_your_id() {
  46. echo -e "Your Apple Developer ID is the 10-character Team ID"
  47. echo -e " found on the Membership page after logging into your account at:"
  48. echo -e " https://developer.apple.com/account/#!/membership\n"
  49. echo -e "It may be necessary to click on the Membership Details icon"
  50. }
  51. function clone_download_error_check() {
  52. # indicate that a clone was created
  53. CLONE_OBTAINED=1
  54. echo -e "--------------------------------\n"
  55. echo -e "🛑 Check for successful Download\n"
  56. echo -e " Please scroll up and look for the word ${BOLD}error${NC} in the window above."
  57. echo -e " OR use the Find command for terminal, hold down CMD key and tap F,"
  58. echo -e " then type error (in new row, top of terminal) and hit return"
  59. echo -e " Be sure to click in terminal again if you use CMD-F"
  60. echo -e " If there are no errors listed, code has successfully downloaded, Continue."
  61. echo -e " If you see the word error in the download, Cancel and resolve the problem."
  62. choose_or_cancel
  63. }
  64. ## Unmodified code from Loop build_functions.sh for constistancy - END
  65. ## Modified code from Loop build_functions.sh that should be backward compatible - BEGIN
  66. function report_persistent_config_override() {
  67. echo -e "The file used by Xcode to sign your app is found at:"
  68. echo -e " ${OVERRIDE_FULLPATH}"
  69. echo -e " The line containing the team id is shown next:"
  70. grep "^$DEV_TEAM_SETTING_NAME" ${OVERRIDE_FULLPATH}
  71. echo -e "\nIf the line has your Apple Developer ID"
  72. echo -e " your target(s) will be automatically signed"
  73. echo -e "WARNING: Any line that starts with // is ignored\n"
  74. echo -e " If ID is not OK:"
  75. echo -e " Edit the ${OVERRIDE_FILE} before hitting return"
  76. echo -e " step 1: open finder, navigate to "${BUILD_DIR#*Users/*/}""
  77. echo -e " step 2: locate and double click on "${OVERRIDE_FILE}""
  78. echo -e " this will open that file in Xcode"
  79. echo -e " step 3: edit in Xcode and save file\n"
  80. echo -e " If ID is OK, hit return"
  81. return_when_ready
  82. }
  83. ## Modified code from Loop build_functions.sh that should be backward compatible - END
  84. set_development_team() {
  85. team_id="$1"
  86. echo "$DEV_TEAM_SETTING_NAME = $team_id" >> ${OVERRIDE_FULLPATH}
  87. }
  88. function check_config_override_existence_offer_to_configure() {
  89. section_separator
  90. # Automatic signing functionality:
  91. # 1) Use existing LoopFollow team
  92. # 2) Copy team from Loop
  93. # 3) Copy team from latest provisioning profile
  94. # 4) Enter team manually with option to skip
  95. if [ -f ${OVERRIDE_FULLPATH} ] && grep -q "^$DEV_TEAM_SETTING_NAME" ${OVERRIDE_FULLPATH}; then
  96. how_to_find_your_id
  97. report_persistent_config_override
  98. else
  99. if [ -f "../../BuildLoop/LoopConfigOverride.xcconfig" ] && grep -q '^LOOP_DEVELOPMENT_TEAM' "../../BuildLoop/LoopConfigOverride.xcconfig"; then
  100. echo -e "Using existing LOOP_DEVELOPMENT_TEAM setting\n"
  101. DEVELOPMENT_TEAM=$(grep '^LOOP_DEVELOPMENT_TEAM' "../../BuildLoop/LoopConfigOverride.xcconfig" | awk '{print $3}')
  102. set_development_team "$DEVELOPMENT_TEAM"
  103. how_to_find_your_id
  104. report_persistent_config_override
  105. else
  106. PROFILES_DIR="$HOME/Library/MobileDevice/Provisioning Profiles"
  107. if [ -d "${PROFILES_DIR}" ]; then
  108. latest_file=$(find "${PROFILES_DIR}" -type f -name "*.mobileprovision" -print0 | xargs -0 ls -t | head -n1)
  109. if [ -n "$latest_file" ]; then
  110. # Decode the .mobileprovision file using the security command
  111. decoded_xml=$(security cms -D -i "$latest_file")
  112. # Extract the Team ID from the XML
  113. DEVELOPMENT_TEAM=$(echo "$decoded_xml" | awk -F'[<>]' '/<key>TeamIdentifier<\/key>/ { getline; getline; print $3 }')
  114. fi
  115. fi
  116. if [ -n "$DEVELOPMENT_TEAM" ]; then
  117. echo -e "Using TeamIdentifier from the latest provisioning profile\n"
  118. set_development_team "$DEVELOPMENT_TEAM"
  119. how_to_find_your_id
  120. report_persistent_config_override
  121. else
  122. echo -e "Choose 1 to Sign Automatically or "
  123. echo -e " 2 to Sign Manually (later in Xcode)"
  124. echo -e "\nIf you choose Sign Automatically, script guides you"
  125. echo -e " to create a permanent signing file"
  126. echo -e " containing your Apple Developer ID"
  127. choose_or_cancel
  128. options=("Sign Automatically" "Sign Manually" "Cancel")
  129. select opt in "${options[@]}"
  130. do
  131. case $opt in
  132. "Sign Automatically")
  133. create_persistent_config_override
  134. break
  135. ;;
  136. "Sign Manually")
  137. break
  138. ;;
  139. "Cancel")
  140. cancel_entry
  141. ;;
  142. *) # Invalid option
  143. invalid_entry
  144. ;;
  145. esac
  146. done
  147. fi
  148. fi
  149. fi
  150. }
  151. function create_persistent_config_override() {
  152. section_separator
  153. echo -e "The Apple Developer page will open when you hit return\n"
  154. how_to_find_your_id
  155. echo -e "That page will be opened for you."
  156. echo -e " Once you get your ID, you will enter it in this terminal window"
  157. return_when_ready
  158. #
  159. open "https://developer.apple.com/account/#!/membership"
  160. echo "Please click in terminal window and enter your Apple Developer Team ID (10 characters) or press Enter to skip:"
  161. while true; do
  162. read DEVELOPMENT_TEAM
  163. if [ -z "$DEVELOPMENT_TEAM" ]; then
  164. echo -e "You can manually sign target(s) in Xcode"
  165. break
  166. elif [ ${#DEVELOPMENT_TEAM} -eq 10 ]; then
  167. set_development_team "$DEVELOPMENT_TEAM"
  168. break
  169. else
  170. echo "Invalid Team ID. Please enter a valid 10-character Team ID or press Enter to skip."
  171. fi
  172. done
  173. #
  174. section_separator
  175. }
  176. # Check if a argument is provided for the repo
  177. if [ "$#" -ge 1 ]; then
  178. REPO="$1"
  179. else
  180. REPO="https://github.com/jonfawcett/LoopFollow"
  181. fi
  182. # Check if a second argument is provided for the branch
  183. if [ "$#" -ge 2 ]; then
  184. CUSTOM_BRANCH="$2"
  185. fi
  186. if [ "$#" -ge 1 ]; then
  187. echo "[DEBUG] Repo URL: $REPO"
  188. if [ -n "$CUSTOM_BRANCH" ]; then
  189. echo "[DEBUG] Custom Branch: $CUSTOM_BRANCH"
  190. fi
  191. return_when_ready
  192. fi
  193. section_separator
  194. 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"
  195. echo -e "Type 1 and hit enter to begin.\nType 2 and hit enter to cancel."
  196. choose_or_cancel
  197. options=("Continue" "Cancel")
  198. select opt in "${options[@]}"
  199. do
  200. case $opt in
  201. "Continue")
  202. break
  203. ;;
  204. "Cancel")
  205. cancel_entry
  206. ;;
  207. *)
  208. invalid_entry
  209. ;;
  210. esac
  211. done
  212. if [ -z "$CUSTOM_BRANCH" ]; then
  213. section_separator
  214. 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"
  215. choose_or_cancel
  216. options=("Main Branch" "Dev Branch" "Cancel")
  217. select opt in "${options[@]}"
  218. do
  219. case $opt in
  220. "Main Branch")
  221. FOLDERNAME=LoopFollow-Main
  222. BRANCH=Main
  223. break
  224. ;;
  225. "Dev Branch")
  226. FOLDERNAME=LoopFollow-Dev
  227. BRANCH=dev
  228. break
  229. ;;
  230. "Cancel")
  231. cancel_entry
  232. ;;
  233. *)
  234. invalid_entry
  235. ;;
  236. esac
  237. done
  238. else
  239. BRANCH="$CUSTOM_BRANCH"
  240. FOLDERNAME="LoopFollow-$BRANCH"
  241. fi
  242. section_separator
  243. echo -e "Would you like to delete prior downloads of Loop Follow before proceeding?\n"
  244. echo -e "Type 1 and hit enter to delete.\nType 2 and hit enter to continue without deleting"
  245. choose_or_cancel
  246. options=("Delete old downloads" "Do not delete old downloads" "Cancel")
  247. select opt in "${options[@]}"
  248. do
  249. case $opt in
  250. "Delete old downloads")
  251. # Delete all folders below ~/Downloads/BuildLoopFollow but preserve ConfigOverride.xcconfig
  252. find ~/Downloads/BuildLoopFollow -mindepth 1 -maxdepth 1 -type d -exec rm -rf {} +
  253. break
  254. ;;
  255. "Do not delete old downloads")
  256. break
  257. ;;
  258. "Cancel")
  259. cancel_entry
  260. ;;
  261. *)
  262. invalid_entry
  263. ;;
  264. esac
  265. done
  266. section_separator
  267. echo -e "The code will now begin downloading.\nThe files will be saved in your Downloads folder.\n"
  268. echo -e "Type 1 and hit enter to begin downloading.\nType 2 and hit enter to cancel.\n"
  269. choose_or_cancel
  270. options=("Continue" "Cancel")
  271. select opt in "${options[@]}"
  272. do
  273. case $opt in
  274. "Continue")
  275. break
  276. ;;
  277. "Cancel")
  278. cancel_entry
  279. ;;
  280. *)
  281. invalid_entry
  282. ;;
  283. esac
  284. done
  285. section_separator
  286. LOOP_BUILD=$(date +'%y%m%d-%H%M')
  287. LOOP_DIR=~/Downloads/BuildLoopFollow/$FOLDERNAME-$LOOP_BUILD
  288. mkdir -p $LOOP_DIR
  289. cd $LOOP_DIR
  290. echo -e "Downloading Loop Follow to your Downloads folder."
  291. pwd
  292. echo -e
  293. git clone --branch=$BRANCH --recurse-submodules $REPO
  294. clone_download_error_check
  295. options=("Continue" "Cancel")
  296. select opt in "${options[@]}"
  297. do
  298. case $opt in
  299. "Continue")
  300. break
  301. ;;
  302. "Cancel")
  303. cancel_entry
  304. ;;
  305. *)
  306. invalid_entry
  307. ;;
  308. esac
  309. done
  310. check_config_override_existence_offer_to_configure
  311. section_separator
  312. echo -e "Type 1 and hit enter to open Xcode. You may close the terminal after Xcode opens"
  313. choose_or_cancel
  314. options=("Continue" "Cancel")
  315. select opt in "${options[@]}"
  316. do
  317. case $opt in
  318. "Continue")
  319. break
  320. ;;
  321. "Cancel")
  322. cancel_entry
  323. ;;
  324. *)
  325. invalid_entry
  326. ;;
  327. esac
  328. done
  329. cd LoopFollow
  330. Echo Open xcode
  331. xed ./LoopFollow.xcworkspace
  332. exit