-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathswift-support
89 lines (75 loc) · 2.88 KB
/
swift-support
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
#!/bin/bash
# Usage:
# 1. Copy the script into a text editor and save it with no extension
# 2. Make it executable like so: chmod +x path/to/script
# 3. Run it from the Terminal in one of two ways:
# * path/to/script ipa_path="path/to/ipa" archive_path="path/to/xcarchive"
# * path/to/script ipa_path="path/to/ipa" toolchain_path="path/to/toolchain"
for ARGUMENT in "$@"
do
KEY=$(echo $ARGUMENT | cut -f1 -d=)
VALUE=$(echo $ARGUMENT | cut -f2 -d=)
case "$KEY" in
ipa_path) ipaPath=${VALUE} ;; # Format: "Path/to/app.ipa"
archive_path) archivePath=${VALUE} ;; # Format: "Path/to/app.xcarchive"
toolchain_path) toolchainPath=${VALUE} ;; # Format: "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.0/iphoneos"
*)
esac
done
# Derived Variables
ipaDirectory=$(dirname "$ipaPath")
ipaName=$(basename "$ipaPath")
zipName=${ipaName/.ipa/.zip}
appName=${ipaName/.ipa/}
zipSuffix=-unzipped
unzippedDirectoryName=${appName}${zipSuffix}
newIpaSuffix=-swift-support
newIpaName=${appName}${newIpaSuffix}
swiftSupportPath=SwiftSupport/iphoneos
ipaSwiftSupportDirectory=${ipaDirectory}/${unzippedDirectoryName}/${swiftSupportPath}
# Changes the .ipa file extension to .zip and unzips it
function unzipIPA {
mv "${ipaDirectory}/${ipaName}" "${ipaDirectory}/${zipName}"
unzip "${ipaDirectory}/${zipName}" -d "${ipaDirectory}/${unzippedDirectoryName}"
}
# Copies the SwiftSupport folder from the .xcarchive into the .ipa
function copySwiftSupportFromArchiveIntoIPA {
mkdir -p "$ipaSwiftSupportDirectory"
cd "${archivePath}/${swiftSupportPath}"
for file in *.dylib; do
cp "$file" "$ipaSwiftSupportDirectory"
done
}
# Creates the SwiftSupport folder from the Xcode toolchain and copies it into the .ipa
function copySwiftSupportFromToolchainIntoIPA {
mkdir -p "$ipaSwiftSupportDirectory"
cd "${ipaDirectory}/${unzippedDirectoryName}/Payload/${appName}.app/Frameworks"
for file in "${toolchainPath}"/*.dylib; do
cp "${file}" "$ipaSwiftSupportDirectory"
done
}
# Adds the SwiftSupport folder from one of two sources depending on the presence of an .xcarchive
function addSwiftSupportFolder {
if [ -z "$archivePath" ]
then
copySwiftSupportFromToolchainIntoIPA
else
copySwiftSupportFromArchiveIntoIPA
fi
}
# Zips the new folder back up and changes the extension to .ipa
function createAppStoreIPA {
cd "${ipaDirectory}/${unzippedDirectoryName}"
zip -r "${ipaDirectory}/${newIpaName}.zip" ./*
mv "${ipaDirectory}/${newIpaName}.zip" "${ipaDirectory}/${newIpaName}.ipa"
}
# Renames original .ipa and deletes the unzipped folder
function cleanUp {
mv "${ipaDirectory}/${zipName}" "${ipaDirectory}/${ipaName}"
rm -r "${ipaDirectory}/${unzippedDirectoryName}"
}
# Execute Steps
unzipIPA
addSwiftSupportFolder
createAppStoreIPA
cleanUp