77 lines
3.1 KiB
Shell
Executable file
77 lines
3.1 KiB
Shell
Executable file
#!/bin/bash
|
|
# Builds Mulberry for iOS on Linux: swift.org toolchain + iPhoneOS SDK, no Xcode.
|
|
# Outputs build/Mulberry-<version>-iOS.ipa (TrollStore) and build/Mulberry-<version>-iOS-rootless.deb.
|
|
# Signing uses a local ldid if present, otherwise ldid on the iPhone over SSH ($IPHONE).
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")"
|
|
|
|
VERSION=${VERSION:-1.0.0}
|
|
BUILD=${BUILD:-$(date +%Y%m%d%H%M)}
|
|
SWIFT=${SWIFT:-$HOME/.local/opt/swift/usr/bin}
|
|
SDK=${SDK:-$HOME/.local/opt/dl/sdk18/iPhoneOS18.6.sdk}
|
|
TARGET=arm64-apple-ios17.0
|
|
IPHONE=${IPHONE:-mobile@192.168.1.94}
|
|
IPHONE_KEY=${IPHONE_KEY:-$HOME/.ssh/iphone_key}
|
|
CONFIG=${CONFIG:-release}
|
|
|
|
OUT=build
|
|
APP=$OUT/Payload/Mulberry.app
|
|
APPEX=$APP/PlugIns/MulberryWidgets.appex
|
|
rm -rf "$OUT/Payload" "$OUT/deb"
|
|
mkdir -p "$APPEX" "$OUT/obj"
|
|
|
|
OPT=(-O -wmo)
|
|
[ "$CONFIG" = debug ] && OPT=(-Onone -g)
|
|
|
|
common=(-target "$TARGET" -sdk "$SDK" -swift-version 5 "${OPT[@]}"
|
|
-use-ld=lld -Xlinker -dead_strip
|
|
-Xcc -Wno-unused-command-line-argument)
|
|
|
|
echo "== app"
|
|
"$SWIFT/swiftc" "${common[@]}" -module-name Mulberry \
|
|
$(find App Shared -name '*.swift' | sort) \
|
|
-o "$APP/Mulberry"
|
|
|
|
echo "== widget extension"
|
|
"$SWIFT/swiftc" "${common[@]}" -module-name MulberryWidgets -application-extension \
|
|
$(find Widget Shared -name '*.swift' | sort) \
|
|
-o "$APPEX/MulberryWidgets"
|
|
|
|
echo "== bundle"
|
|
sed -e "s/@VERSION@/$VERSION/" -e "s/@BUILD@/$BUILD/" Resources/Info.plist > "$APP/Info.plist"
|
|
sed -e "s/@VERSION@/$VERSION/" -e "s/@BUILD@/$BUILD/" Resources/Widget-Info.plist > "$APPEX/Info.plist"
|
|
cp Resources/AppIcon*.png "$APP/"
|
|
printf 'APPL????' > "$APP/PkgInfo"
|
|
|
|
echo "== sign"
|
|
if command -v ldid >/dev/null; then
|
|
ldid -Spackaging/widget.entitlements "$APPEX/MulberryWidgets"
|
|
ldid -Spackaging/app.entitlements "$APP/Mulberry"
|
|
else
|
|
ssh_=(ssh -i "$IPHONE_KEY" -o BatchMode=yes -o ConnectTimeout=10 "$IPHONE")
|
|
remote=/var/mobile/Documents/mulberry-sign
|
|
"${ssh_[@]}" "rm -rf $remote && mkdir -p $remote"
|
|
scp -i "$IPHONE_KEY" -q "$APP/Mulberry" "$APPEX/MulberryWidgets" packaging/app.entitlements packaging/widget.entitlements "$IPHONE:$remote/"
|
|
"${ssh_[@]}" "cd $remote && ldid -Swidget.entitlements MulberryWidgets && ldid -Sapp.entitlements Mulberry"
|
|
scp -i "$IPHONE_KEY" -q "$IPHONE:$remote/Mulberry" "$APP/Mulberry"
|
|
scp -i "$IPHONE_KEY" -q "$IPHONE:$remote/MulberryWidgets" "$APPEX/MulberryWidgets"
|
|
"${ssh_[@]}" "rm -rf $remote"
|
|
fi
|
|
|
|
echo "== ipa"
|
|
rm -f "$OUT/Mulberry-$VERSION-iOS.ipa"
|
|
(cd "$OUT" && zip -qry "Mulberry-$VERSION-iOS.ipa" Payload)
|
|
|
|
echo "== deb (rootless)"
|
|
D=$OUT/deb
|
|
mkdir -p "$D/data/var/jb/Applications" "$D/control"
|
|
cp -a "$APP" "$D/data/var/jb/Applications/"
|
|
sed "s/@VERSION@/$VERSION/" packaging/control > "$D/control/control"
|
|
cp packaging/postinst packaging/prerm "$D/control/"
|
|
(cd "$D/control" && tar --owner=0 --group=0 -czf ../control.tar.gz .)
|
|
(cd "$D/data" && tar --owner=0 --group=0 -cJf ../data.tar.xz .)
|
|
echo "2.0" > "$D/debian-binary"
|
|
rm -f "$OUT/Mulberry-$VERSION-iOS-rootless.deb"
|
|
(cd "$D" && ar rc "../Mulberry-$VERSION-iOS-rootless.deb" debian-binary control.tar.gz data.tar.xz)
|
|
|
|
ls -la "$OUT"/*.ipa "$OUT"/*.deb
|