#!/bin/bash # Builds one Stemify IPA on a Mac. ios/scripts/build-remote.sh runs this on WHITE-M1AIR from DevOps. # build-ipa.sh public build/public/stemify-.ipa org.cdnutter.stemify, ad-hoc signed. Gitea releases (main) + iOS Repos /personal. # build-ipa.sh dev build/dev/stemify--dev.ipa org.cdnutter.stemify-dev, ribbon icon, DEV BUILD banner. # Gitea pre-releases (dev branch) + iOS Repos /dev. # build-ipa.sh signed build/signed/stemify--signed.ipa org.cdnutter.stemify, signed with the # personal profile (CarPlay, Siri). Never published anywhere. # signed needs prov/Stemify.mobileprovision (App ID org.cdnutter.stemify) and the Apple Development identity in # ~/Library/Keychains/build.keychain-db (password in ~/.config/signing/keychain_pass). # prov/StemifyWidgets.mobileprovision (org.cdnutter.stemify.widgets) is optional, without it the widgets are left out. # build/work is scratch and is wiped each run. set -euo pipefail cd "$(dirname "$0")/.." export PATH=/opt/homebrew/bin:$PATH B=build; OUT=$B/work; APP=$OUT/Payload/Stemify.app; EXT=$APP/PlugIns/StemifyWidgets.appex MODE=${1:-dev} case $MODE in public) APP_ID=org.cdnutter.stemify; APP_NAME=Stemify; APP_ICON=AppIcon; SUFFIX= ;; dev) APP_ID=org.cdnutter.stemify-dev; APP_NAME=Stemify; APP_ICON=AppIconDev; SUFFIX=-dev ;; signed) APP_ID=org.cdnutter.stemify; APP_NAME=Stemify; APP_ICON=AppIcon; SUFFIX=-signed ;; *) echo "usage: $0 public|dev|signed" >&2; exit 1 ;; esac DD=$B/dd-$MODE # Dev builds are marked as such (Info key StemifyChannel) and put the build number in the # version string (1.0 -> 1.0.26), so SideStore sees every dev upload as an update. CHANNEL=$([ "$MODE" = dev ] && echo dev || echo release) MV=$(sed -nE 's/^ *MARKETING_VERSION: "(.*)"/\1/p' project.yml) BN=$(sed -nE 's/^ *CURRENT_PROJECT_VERSION: "(.*)"/\1/p' project.yml) # iOS allows at most three numbers, so dev keeps major.minor and puts the build last (0.9.0 build 27 -> 0.9.27). [ "$MODE" = dev ] && MV=$(echo "$MV" | cut -d. -f1-2).$BN # "0.9.0" -> 0.9.0, "1.0 RC 1" -> 1.0-rc1, used in file names and release tags. VERSION=$(sed -nE 's/^ *VERSION_LABEL: "(.*)"/\1/p' project.yml | tr 'A-Z' 'a-z' | sed -E 's/ (rc|beta) /-\1/; s/ /-/g') IPA=$B/$MODE/stemify-$VERSION$SUFFIX.ipa KC=$HOME/Library/Keychains/build.keychain-db if [ "$MODE" = signed ]; then for f in prov/Stemify.mobileprovision $KC $HOME/.config/signing/keychain_pass; do [ -f $f ] || { echo "missing $f" >&2; exit 1; }; done PROF_ID=$(security cms -D -i prov/Stemify.mobileprovision | plutil -extract Entitlements.application-identifier raw -) [ "${PROF_ID#*.}" = "$APP_ID" ] || { echo "prov/Stemify.mobileprovision is for ${PROF_ID#*.}, need a profile for $APP_ID" >&2; exit 1; } fi rm -rf $OUT && mkdir -p $OUT/Payload $B/$MODE # xcodebuild compiles the app, the widget extension, the asset catalog and the App Intents metadata. xcodegen generate -q xcodebuild -project Stemify.xcodeproj -scheme Stemify -configuration Release -sdk iphoneos \ -destination generic/platform=iOS -derivedDataPath $DD APP_ID=$APP_ID APP_NAME="$APP_NAME" APP_ICON=$APP_ICON STEMIFY_CHANNEL=$CHANNEL MARKETING_VERSION=$MV CODE_SIGNING_ALLOWED=NO -quiet build cp -R $DD/Build/Products/Release-iphoneos/Stemify.app $APP [ -d $EXT ] || { echo "widget extension missing" >&2; exit 1; } if [ "$MODE" != signed ]; then # Ad-hoc signature carrying only the App Group, so Sideloadly/AltStore keep the widgets' shared data when re-signing. cat > $OUT/group.plist < com.apple.security.application-groupsgroup.$APP_ID PL codesign -f -s - --entitlements $OUT/group.plist $EXT codesign -f -s - --entitlements $OUT/group.plist $APP else security unlock-keychain -p "$(cat $HOME/.config/signing/keychain_pass)" $KC ID=$(security find-identity -v -p codesigning $KC | sed -nE 's/.*"(Apple Development:.*)"/\1/p' | head -1) [ -n "$ID" ] || { echo "no Apple Development identity in $KC" >&2; exit 1; } security cms -D -i prov/Stemify.mobileprovision > $OUT/prov.plist /usr/libexec/PlistBuddy -x -c 'Print :Entitlements' $OUT/prov.plist > $OUT/ent.plist if [ -f prov/StemifyWidgets.mobileprovision ]; then security cms -D -i prov/StemifyWidgets.mobileprovision > $OUT/wprov.plist /usr/libexec/PlistBuddy -x -c 'Print :Entitlements' $OUT/wprov.plist > $OUT/went.plist cp prov/StemifyWidgets.mobileprovision $EXT/embedded.mobileprovision codesign -f -s "$ID" --keychain $KC --entitlements $OUT/went.plist --timestamp=none $EXT else rm -rf $APP/PlugIns fi cp prov/Stemify.mobileprovision $APP/embedded.mobileprovision codesign -f -s "$ID" --keychain $KC --entitlements $OUT/ent.plist --timestamp=none $APP fi rm -f $IPA (cd $OUT && zip -qry ../$MODE/$(basename $IPA) Payload) echo "$IPA"