-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsignApp.sh
executable file
·89 lines (76 loc) · 2.15 KB
/
signApp.sh
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
if [ $# -lt 3 ]; then
echo "usage: $0 source identity [-p provisioning] [-e entitlements] target.ipa" >&2
exit 1
fi
ORIGINAL_FILE="$1"
CERTIFICATE="$2"
NEW_PROVISION=
ENTITLEMENTS=
OPTIND=3
while getopts p:e: opt; do
case $opt in
p)
NEW_PROVISION="$OPTARG"
echo "Specified provisioning profile: $NEW_PROVISION" >&2
;;
e)
ENTITLEMENTS="$OPTARG"
echo "Specified signing entitlements: $ENTITLEMENTS" >&2
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
shift $((OPTIND-1))
NEW_FILE="$1"
# Check if the supplied file is an ipa or an app file
if [ "${ORIGINAL_FILE##*.}" = "ipa" ]
then
# Unzip the old ipa quietly
unzip -q "$ORIGINAL_FILE" -d temp
elif [ "${ORIGINAL_FILE##*.}" = "app" ]
then
# Copy the app file into an ipa-like structure
mkdir -p "temp/Payload"
cp -Rf "$ORIGINAL_FILE" "temp/Payload/"
else
echo "Error: Only can resign .app files and .ipa files." >&2
exit
fi
# Set the app name
# The app name is the only file within the Payload directory
APP_NAME=$(ls temp/Payload/)
echo "APP_NAME=$APP_NAME" >&2
# Replace the embedded mobile provisioning profile
if [ "$NEW_PROVISION" != "" ]; then
echo "Adding the new provision: $NEW_PROVISION"
cp "$NEW_PROVISION" "temp/Payload/$APP_NAME/embedded.mobileprovision"
fi
# Resign the application
echo "Resigning application using certificate: $CERTIFICATE" >&2
if [ "$ENTITLEMENTS" != "" ]; then
echo "Using Entitlements: $ENTITLEMENTS" >&2
/usr/bin/codesign -f -s "$CERTIFICATE" --entitlements="$ENTITLEMENTS" "temp/Payload/$APP_NAME"
else
/usr/bin/codesign -f -s "$CERTIFICATE" "temp/Payload/$APP_NAME"
fi
# Repackage quietly
echo "Repackaging as $NEW_FILE"
# Zip up the contents of the temp folder
# Navigate to the temporary directory (sending the output to null)
# Zip all the contents, saving the zip file in the above directory
# Navigate back to the orignating directory (sending the output to null)
pushd temp > /dev/null
zip -qry ../temp.ipa *
popd > /dev/null
# Move the resulting ipa to the target destination
mv temp.ipa "$NEW_FILE"
# Remove the temp directory
rm -rf "temp"