-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPkgAndNotarize.sh
118 lines (88 loc) · 3.4 KB
/
PkgAndNotarize.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/zsh
signature="Developer ID Installer: Armin Briegel (JME5BW3F3R)"
dev_team="JME5BW3F3R" # asc-provider
dev_account="[email protected]"
dev_keychain_label="Developer-altool"
projectdir=$(dirname $0)
builddir="$projectdir/build"
pkgroot="$builddir/pkgroot"
infoplist="$projectdir/desktoppr/Info.plist"
plistbuddy="/usr/libexec/PlistBuddy"
# functions
requeststatus() { # $1: requestUUID
requestUUID=${1?:"need a request UUID"}
req_status=$(xcrun altool --notarization-info "$requestUUID" \
--username "$dev_account" \
--password "@keychain:$dev_keychain_label" 2>&1 | awk -F ': ' '/Status:/ { print $2; }' )
echo "$req_status"
}
notarizefile() { # $1: path to file to notarize, $2: identifier
filepath=${1:?"need a filepath"}
identifier=${2:?"need an identifier"}
# upload file
echo "## uploading $filepath for notarization"
requestUUID=$(xcrun altool --notarize-app \
--primary-bundle-id "$identifier" \
--username "$dev_account" \
--password "@keychain:$dev_keychain_label" \
--asc-provider "$dev_team" \
--file "$filepath" 2>&1 | awk '/RequestUUID/ { print $NF; }')
echo "Notarization RequestUUID: $requestUUID"
if [[ $requestUUID == "" ]]; then
echo "could not upload for notarization"
exit 1
fi
# wait for status to be not "in progress" any more
request_status="in progress"
while [[ "$request_status" == "in progress" ]]; do
echo -n "waiting... "
sleep 10
request_status=$(requeststatus "$requestUUID")
echo "$request_status"
done
if [[ $request_status != "success" ]]; then
echo "## could not notarize $filepath"
xcrun altool --notarization-info "$requestUUID" \
--username "$dev_account" \
--password "@keychain:$dev_keychain_label"
exit 1
fi
}
# build clean install
echo "## building with Xcode"
xcodebuild clean install -quiet
if [[ ! -d $pkgroot ]]; then
echo "couldn't find pkgroot $pkgroot"
exit 1
fi
# get project meta data
if [[ ! -r $infoplist ]]; then
echo "cannot find Info.plist $infoplist"
fi
version=$($plistbuddy -c "print CFBundleVersion" "$infoplist")
identifier=$($plistbuddy -c "print CFBundleIdentifier" "$infoplist")
productname=$($plistbuddy -c "print CFBundleName" "$infoplist")
pkgpath="$builddir/$productname-$version.pkg"
componentpath="$builddir/$productname.pkg"
echo "## building pkg: $pkgpath"
pkgbuild --root "$pkgroot" \
--version "$version" \
--identifier "$identifier" \
--sign "Developer ID Installer: Armin Briegel (JME5BW3F3R)" \
"$componentpath"
productbuild --package "$componentpath" \
--product "$projectdir/requirements.plist" \
--sign "Developer ID Installer: Armin Briegel (JME5BW3F3R)" \
"$pkgpath"
# upload for notarization
notarizefile "$pkgpath" "$identifier"
# staple result
echo "## Stapling $pkgpath"
xcrun stapler staple "$pkgpath"
# also create a zip archive
zippath="$builddir/$productname-$version.zip"
zip "$zippath" -j "$pkgroot"/usr/local/bin/desktoppr
# upload zip for notarization
notarizefile "$zippath" "$identifier"
echo '## Done!'
exit 0