package.sh 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. #!/bin/bash
  2. set -e
  3. command -v realpath >/dev/null 2>&1 || realpath() {
  4. [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
  5. }
  6. BASEDIR="$(dirname "$(realpath $0)")"
  7. usage() {
  8. echo "usage: $0 MODE inputXcarchive outputPath [TEAM_ID PROFILE_NAME SIGNING_METHOD]"
  9. echo " MODE is one of:"
  10. echo " deb (Cydia DEB)"
  11. echo " ipa (unsigned IPA of full build with all entitlements)"
  12. echo " ipa-se (unsigned IPA of SE build)"
  13. echo " ipa-remote (unsigned IPA of Remote build)"
  14. echo " ipa-hv (unsigned IPA of full build without JIT entitlement)"
  15. echo " ipa-[se-|remote-]signed (signed IPA with valid PROFILE_NAME and TEAM_ID)"
  16. echo " inputXcarchive is path to UTM.xcarchive"
  17. echo " outputPath is path to an EMPTY output directory for UTM.ipa or UTM.deb"
  18. echo " TEAM_ID is only used for ipa-signed and is the name of the team matching the profile"
  19. echo " PROFILE_NAME is only used for ipa-signed and is the name of the signing profile"
  20. echo " SIGNING_METHOD is only used for ipa-signed and is either 'development' (default) or 'app-store'"
  21. exit 1
  22. }
  23. if [ $# -lt 2 ]; then
  24. usage
  25. fi
  26. MODE=$1
  27. INPUT=$2
  28. OUTPUT=$3
  29. BUNDLE_ID=
  30. case $MODE in
  31. deb | ipa | ipa-hv | ipa-signed )
  32. NAME="UTM"
  33. BUNDLE_ID="com.utmapp.UTM"
  34. INPUT_APP="$INPUT/Products/Applications/UTM.app"
  35. ;;
  36. ipa-se | ipa-se-signed )
  37. NAME="UTM SE"
  38. BUNDLE_ID="com.utmapp.UTM-SE"
  39. INPUT_APP="$INPUT/Products/Applications/UTM SE.app"
  40. ;;
  41. ipa-remote | ipa-remote-signed )
  42. NAME="UTM Remote"
  43. BUNDLE_ID="com.utmapp.UTM-Remote"
  44. INPUT_APP="$INPUT/Products/Applications/UTM Remote.app"
  45. ;;
  46. * )
  47. usage
  48. ;;
  49. esac
  50. if [ ! -d "$INPUT_APP" ]; then
  51. echo "Invalid xcarchive input!"
  52. usage
  53. fi
  54. if [ -z "$OUTPUT" ]; then
  55. echo "Invalid output path"
  56. usage
  57. fi
  58. itunes_sign() {
  59. local INPUT=$1
  60. local OUTPUT=$2
  61. local TEAM_ID=$3
  62. local PROFILE_NAME=$4
  63. local SIGNING_METHOD=$5
  64. local OPTIONS="/tmp/options.$$.plist"
  65. if [ -z "$PROFILE_NAME" -o -z "$TEAM_ID" ]; then
  66. echo "Invalid profile name or team id!"
  67. usage
  68. fi
  69. if [ -z "$SIGNING_METHOD" ]; then
  70. SIGNING_METHOD="development"
  71. fi
  72. cat >"$OPTIONS" <<EOL
  73. <?xml version="1.0" encoding="UTF-8"?>
  74. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  75. <plist version="1.0">
  76. <dict>
  77. <key>compileBitcode</key>
  78. <false/>
  79. <key>method</key>
  80. <string>${SIGNING_METHOD}</string>
  81. <key>provisioningProfiles</key>
  82. <dict>
  83. <key>${BUNDLE_ID}</key>
  84. <string>${PROFILE_NAME}</string>
  85. </dict>
  86. <key>signingStyle</key>
  87. <string>manual</string>
  88. <key>stripSwiftSymbols</key>
  89. <true/>
  90. <key>teamID</key>
  91. <string>${TEAM_ID}</string>
  92. <key>thinning</key>
  93. <string>&lt;none&gt;</string>
  94. </dict>
  95. </plist>
  96. EOL
  97. xcodebuild -exportArchive -exportOptionsPlist "$OPTIONS" -archivePath "$INPUT" -exportPath "$OUTPUT"
  98. rm "$OPTIONS"
  99. }
  100. fake_sign() {
  101. local _name=$1
  102. local _bundle_id=$2
  103. local _input=$3
  104. local _output=$4
  105. local _fakeent=$5
  106. mkdir -p "$_output"
  107. cp -a "$_input" "$_output/"
  108. find "$_output" -type d -path '*/Frameworks/*.framework' -exec ldid -S \{\} \;
  109. if [ ! -z "${_fakeent}" ]; then
  110. ldid -S${_fakeent} -I${_bundle_id} "$_output/Applications/$_name.app/$_name"
  111. fi
  112. }
  113. create_deb() {
  114. local INPUT=$1
  115. local INPUT_APP="$INPUT/Products/Applications/UTM.app"
  116. local OUTPUT=$2
  117. local FAKEENT=$3
  118. local DEB_TMP="$OUTPUT/deb"
  119. local IPA_PATH="$DEB_TMP/var/tmp/com.utmapp.UTM"
  120. local SIZE_KIB=`du -sk "$INPUT_APP"| cut -f 1`
  121. local VERSION=`/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "$INPUT_APP/Info.plist"`
  122. mkdir -p "$OUTPUT"
  123. rm -rf "$DEB_TMP"
  124. mkdir -p "$DEB_TMP/DEBIAN"
  125. cat >"$DEB_TMP/DEBIAN/control" <<EOL
  126. Package: com.utmapp.UTM
  127. Version: ${VERSION}
  128. Section: Productivity
  129. Architecture: all
  130. Depends: firmware (>=14.0), net.angelxwind.appsyncunified
  131. Installed-Size: ${SIZE_KIB}
  132. Maintainer: osy <dev@getutm.app>
  133. Description: Virtual machines for iOS
  134. Homepage: https://getutm.app/
  135. Name: UTM
  136. Author: osy
  137. Depiction: https://cydia.getutm.app/depiction/web/com.utmapp.UTM.html
  138. Icon: https://cydia.getutm.app/assets/com.utmapp.UTM/icon.png
  139. Moderndepiction: https://cydia.getutm.app/depiction/native/com.utmapp.UTM.json
  140. Sileodepiction: https://cydia.getutm.app/depiction/native/com.utmapp.UTM.json
  141. Tags: compatible_min::ios14.0
  142. EOL
  143. xcrun -sdk iphoneos clang -arch arm64 -fobjc-arc -miphoneos-version-min=11.0 "$BASEDIR/deb/postinst.m" "$BASEDIR/deb/MobileCoreServices.tbd" -o "$DEB_TMP/DEBIAN/postinst"
  144. strip "$DEB_TMP/DEBIAN/postinst"
  145. ldid -S"$BASEDIR/deb/postinst.xml" "$DEB_TMP/DEBIAN/postinst"
  146. xcrun -sdk iphoneos clang -arch arm64 -fobjc-arc -miphoneos-version-min=11.0 "$BASEDIR/deb/prerm.m" "$BASEDIR/deb/MobileCoreServices.tbd" -o "$DEB_TMP/DEBIAN/prerm"
  147. strip "$DEB_TMP/DEBIAN/prerm"
  148. ldid -S"$BASEDIR/deb/prerm.xml" "$DEB_TMP/DEBIAN/prerm"
  149. mkdir -p "$IPA_PATH"
  150. create_fake_ipa "UTM" "com.utmapp.UTM" "$INPUT" "$IPA_PATH" "$FAKEENT"
  151. dpkg-deb -b -Zgzip -z9 "$DEB_TMP" "$OUTPUT/UTM.deb"
  152. rm -r "$DEB_TMP"
  153. }
  154. create_fake_ipa() {
  155. local NAME=$1
  156. local BUNDLE_ID=$2
  157. local INPUT=$3
  158. local OUTPUT=$4
  159. local FAKEENT=$5
  160. pwd="$(pwd)"
  161. mkdir -p "$OUTPUT"
  162. rm -rf "$OUTPUT/Applications" "$OUTPUT/Payload" "$OUTPUT/UTM.ipa"
  163. fake_sign "$NAME" "$BUNDLE_ID" "$INPUT/Products/Applications" "$OUTPUT" "$FAKEENT"
  164. mv "$OUTPUT/Applications" "$OUTPUT/Payload"
  165. cd "$OUTPUT"
  166. zip -r "$NAME.ipa" "Payload" -x "._*" -x ".DS_Store" -x "__MACOSX"
  167. rm -r "Payload"
  168. cd "$pwd"
  169. }
  170. case $MODE in
  171. deb )
  172. FAKEENT="/tmp/fakeent.$$.plist"
  173. cat >"$FAKEENT" <<EOL
  174. <?xml version="1.0" encoding="UTF-8"?>
  175. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  176. <plist version="1.0">
  177. <dict>
  178. <key>com.apple.developer.kernel.increased-memory-limit</key>
  179. <true/>
  180. <key>com.apple.developer.kernel.extended-virtual-addressing</key>
  181. <true/>
  182. <key>dynamic-codesigning</key>
  183. <true/>
  184. <key>com.apple.private.iokit.IOServiceSetAuthorizationID</key>
  185. <true/>
  186. <key>com.apple.security.exception.iokit-user-client-class</key>
  187. <array>
  188. <string>AppleUSBHostDeviceUserClient</string>
  189. <string>AppleUSBHostInterfaceUserClient</string>
  190. </array>
  191. <key>com.apple.system.diagnostics.iokit-properties</key>
  192. <true/>
  193. <key>com.apple.vm.device-access</key>
  194. <true/>
  195. <key>com.apple.private.hypervisor</key>
  196. <true/>
  197. <key>com.apple.private.memorystatus</key>
  198. <true/>
  199. </dict>
  200. </plist>
  201. EOL
  202. create_deb "$INPUT" "$OUTPUT" "$FAKEENT"
  203. rm "$FAKEENT"
  204. ;;
  205. ipa )
  206. FAKEENT="/tmp/fakeent.$$.plist"
  207. cat >"$FAKEENT" <<EOL
  208. <?xml version="1.0" encoding="UTF-8"?>
  209. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  210. <plist version="1.0">
  211. <dict>
  212. <key>get-task-allow</key>
  213. <true/>
  214. <key>com.apple.developer.kernel.increased-memory-limit</key>
  215. <true/>
  216. <key>com.apple.developer.kernel.extended-virtual-addressing</key>
  217. <true/>
  218. <key>dynamic-codesigning</key>
  219. <true/>
  220. <key>com.apple.private.iokit.IOServiceSetAuthorizationID</key>
  221. <true/>
  222. <key>com.apple.security.exception.iokit-user-client-class</key>
  223. <array>
  224. <string>AppleUSBHostDeviceUserClient</string>
  225. <string>AppleUSBHostInterfaceUserClient</string>
  226. </array>
  227. <key>com.apple.system.diagnostics.iokit-properties</key>
  228. <true/>
  229. <key>com.apple.vm.device-access</key>
  230. <true/>
  231. <key>com.apple.private.hypervisor</key>
  232. <true/>
  233. <key>com.apple.private.memorystatus</key>
  234. <true/>
  235. </dict>
  236. </plist>
  237. EOL
  238. create_fake_ipa "$NAME" "$BUNDLE_ID" "$INPUT" "$OUTPUT" "$FAKEENT"
  239. rm "$FAKEENT"
  240. ;;
  241. ipa-hv )
  242. FAKEENT="/tmp/fakeent.$$.plist"
  243. cat >"$FAKEENT" <<EOL
  244. <?xml version="1.0" encoding="UTF-8"?>
  245. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  246. <plist version="1.0">
  247. <dict>
  248. <key>get-task-allow</key>
  249. <true/>
  250. <key>com.apple.developer.kernel.increased-memory-limit</key>
  251. <true/>
  252. <key>com.apple.developer.kernel.extended-virtual-addressing</key>
  253. <true/>
  254. <key>com.apple.private.iokit.IOServiceSetAuthorizationID</key>
  255. <true/>
  256. <key>com.apple.security.exception.iokit-user-client-class</key>
  257. <array>
  258. <string>AGXCommandQueue</string>
  259. <string>AGXDevice</string>
  260. <string>AGXDeviceUserClient</string>
  261. <string>AGXSharedUserClient</string>
  262. <string>AppleUSBHostDeviceUserClient</string>
  263. <string>AppleUSBHostInterfaceUserClient</string>
  264. <string>IOSurfaceRootUserClient</string>
  265. <string>IOAccelContext</string>
  266. <string>IOAccelContext2</string>
  267. <string>IOAccelDevice</string>
  268. <string>IOAccelDevice2</string>
  269. <string>IOAccelSharedUserClient</string>
  270. <string>IOAccelSharedUserClient2</string>
  271. <string>IOAccelSubmitter2</string>
  272. </array>
  273. <key>com.apple.system.diagnostics.iokit-properties</key>
  274. <true/>
  275. <key>com.apple.vm.device-access</key>
  276. <true/>
  277. <key>com.apple.private.hypervisor</key>
  278. <true/>
  279. <key>com.apple.private.memorystatus</key>
  280. <true/>
  281. <key>com.apple.private.security.no-sandbox</key>
  282. <true/>
  283. <key>com.apple.private.security.storage.AppDataContainers</key>
  284. <true/>
  285. <key>com.apple.private.security.storage.MobileDocuments</key>
  286. <true/>
  287. <key>platform-application</key>
  288. <true/>
  289. </dict>
  290. </plist>
  291. EOL
  292. create_fake_ipa "$NAME" "$BUNDLE_ID" "$INPUT" "$OUTPUT" "$FAKEENT"
  293. rm "$FAKEENT"
  294. ;;
  295. ipa-se )
  296. FAKEENT="/tmp/fakeent.$$.plist"
  297. cat >"$FAKEENT" <<EOL
  298. <?xml version="1.0" encoding="UTF-8"?>
  299. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  300. <plist version="1.0">
  301. <dict>
  302. <key>com.apple.developer.kernel.increased-memory-limit</key>
  303. <true/>
  304. <key>com.apple.developer.kernel.extended-virtual-addressing</key>
  305. <true/>
  306. </dict>
  307. </plist>
  308. EOL
  309. create_fake_ipa "$NAME" "$BUNDLE_ID" "$INPUT" "$OUTPUT" "$FAKEENT"
  310. ;;
  311. ipa-remote )
  312. create_fake_ipa "$NAME" "$BUNDLE_ID" "$INPUT" "$OUTPUT"
  313. ;;
  314. ipa-signed | ipa-se-signed )
  315. FAKEENT="/tmp/fakeent.$$.plist"
  316. cat >"$FAKEENT" <<EOL
  317. <?xml version="1.0" encoding="UTF-8"?>
  318. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  319. <plist version="1.0">
  320. <dict>
  321. <key>com.apple.developer.kernel.increased-memory-limit</key>
  322. <true/>
  323. <key>com.apple.developer.kernel.extended-virtual-addressing</key>
  324. <true/>
  325. </dict>
  326. </plist>
  327. EOL
  328. TMPINPUT="/tmp/UTM.$$.xcarchive"
  329. cp -a "$INPUT" "$TMPINPUT"
  330. BUILT_PATH=$(find "$TMPINPUT" -name '*.app' -type d | head -1)
  331. PLATFORM="$(/usr/libexec/PlistBuddy -c "Print :DTPlatformName" "$BUILT_PATH/Info.plist")"
  332. if [ "$PLATFORM" != "xros" ]; then
  333. codesign --force --sign - --entitlements "$FAKEENT" --timestamp=none "$BUILT_PATH"
  334. fi
  335. itunes_sign "$TMPINPUT" "$OUTPUT" $4 $5 $6
  336. rm -rf "$TMPINPUT"
  337. ;;
  338. ipa-remote-signed )
  339. itunes_sign "$INPUT" "$OUTPUT" $4 $5 $6
  340. ;;
  341. esac