Skip to content
This repository was archived by the owner on Nov 14, 2023. It is now read-only.

Commit 249624d

Browse files
add: macOS sign and notarize process.
See [Issue GerryFerdinandus#41]
1 parent 4eef43b commit 249624d

File tree

8 files changed

+194
-10
lines changed

8 files changed

+194
-10
lines changed
File renamed without changes.

enduser/trackereditor.app/Contents/MacOS/.gitkeep renamed to enduser/macos/app/trackereditor.app/Contents/MacOS/.gitkeep

File renamed without changes.
File renamed without changes.

enduser/trackereditor.app/Contents/Resources/iconfile.icns renamed to enduser/macos/app/trackereditor.app/Contents/Resources/iconfile.icns

File renamed without changes.

enduser/macos/entitlements.plist

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.app-sandbox</key>
6+
<true/>
7+
<key>com.apple.security.files.user-selected.read-write</key>
8+
<true/>
9+
<key>com.apple.security.network.client</key>
10+
<true/>
11+
</dict>
12+
</plist>

scripts/travis_add_macos_cert.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env sh
2+
3+
#must run on griet server only
4+
if [ -z "${TRAVIS}" ]
5+
then
6+
echo "This is not TRAVIS CI build server "
7+
exit 1
8+
fi
9+
10+
# secure/hidden variable from travis
11+
# CERTIFICATE_OSX_P12
12+
# CERTIFICATE_PASSWORD
13+
14+
15+
# constant variable
16+
KEY_CHAIN=build.keychain
17+
CERTIFICATE_P12=certificate.p12
18+
19+
# Recreate the certificate from the secure environment variable
20+
echo $CERTIFICATE_OSX_P12 | base64 --decode > $CERTIFICATE_P12
21+
22+
# create a keychain
23+
security create-keychain -p travis $KEY_CHAIN
24+
25+
# Make the keychain the default so identities are found
26+
security default-keychain -s $KEY_CHAIN
27+
28+
# Unlock the keychain
29+
security unlock-keychain -p travis $KEY_CHAIN
30+
31+
security import $CERTIFICATE_P12 -k $KEY_CHAIN -P $CERTIFICATE_PASSWORD -T /usr/bin/codesign;
32+
33+
security set-key-partition-list -S apple-tool:,apple: -s -k travis $KEY_CHAIN
34+
35+
# remove certs
36+
rm -fr *.p12

scripts/travis_deploy.sh

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,13 @@ elif [ "$TRAVIS_OS_NAME" = "osx" ]
1414
then
1515
# Apple macOS
1616
echo "Building zip file for macOS"
17-
cd enduser
1817

19-
# Move the executable to the application bundle
20-
mv trackereditor trackereditor.app/Contents/MacOS
18+
# Add certificate into the macOS system
19+
source ./scripts/travis_add_macos_cert.sh
2120

22-
# Move the trackers list to application bundle
23-
mv add_trackers.txt trackereditor.app/Contents/MacOS
24-
mv remove_trackers.txt trackereditor.app/Contents/MacOS
21+
# sign + zip the app
22+
source ./scripts/travis_sign_macos_app.sh
2523

26-
# Create the zip file.
27-
zip -j ../$RELEASE_ZIP_FILE *.txt
28-
zip -r ../$RELEASE_ZIP_FILE trackereditor.app
29-
cd ..
3024
elif [ "$TRAVIS_OS_NAME" = "windows" ]
3125
then
3226
# Windows

scripts/travis_sign_macos_app.sh

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#!/usr/bin/env sh
2+
3+
# secure/hidden variable from travis
4+
#CERTIFICATE_ID="..."
5+
#USERNAME="..."
6+
#APP_SPECIFIC_PASSWORD="..."
7+
#RELEASE_ZIP_FILE="..."
8+
9+
# path to app
10+
FILE_APP='enduser/macos/app/trackereditor.app'
11+
PLISTBUDDY_APP='/usr/libexec/PlistBuddy'
12+
13+
if [ ! -x "${PLISTBUDDY_APP}" ]
14+
then
15+
echo "Couldn't find PlistBuddy"
16+
exit 1
17+
fi
18+
19+
# copy everything into enduser/macos/app folder
20+
#
21+
# Move the executable to the application bundle
22+
mv enduser/trackereditor enduser/macos/app/trackereditor.app/Contents/MacOS
23+
24+
# Move the trackers list to application bundle
25+
mv enduser/add_trackers.txt enduser/macos/app/trackereditor.app/Contents/MacOS
26+
mv enduser/remove_trackers.txt enduser/macos/app/trackereditor.app/Contents/MacOS
27+
28+
# move all the *.txt file
29+
mv enduser/*.txt enduser/macos/app
30+
31+
# sign the app. -sign is the developer cetificate ID
32+
# entitlements does not work at this moment
33+
#codesign --timestamp --entitlements enduser/macos/entitlements.plist --force --options runtime --deep --sign $CERTIFICATE_ID $FILE_APP
34+
codesign --timestamp --force --options runtime --deep --sign $CERTIFICATE_ID $FILE_APP
35+
36+
# Check exit code
37+
exit_code=$?
38+
if [ "${exit_code}" != "0" ]
39+
then
40+
echo "codesign failed: ${exit_code}"
41+
exit 1
42+
fi
43+
44+
#must use ditto to compress the file application folder only for notarize. Zip program will not work!
45+
/usr/bin/ditto -c -k --keepParent "$FILE_APP" "$RELEASE_ZIP_FILE"
46+
47+
# upload zip to notarize service. for RequestUUID
48+
# -- username is the normal apple ID. example [email protected]
49+
# -- password is 'app specific password' generated via apple web site. Security -> app-specific password
50+
echo "Uploading to notarize server"
51+
xcrun altool --notarize-app --output-format xml --primary-bundle-id "trackereditor" --username $USERNAME --password $APP_SPECIFIC_PASSWORD --file $RELEASE_ZIP_FILE > "result.plist"
52+
53+
# remove the uploaded zip file. need to be created again later.
54+
rm $RELEASE_ZIP_FILE
55+
56+
57+
# Check exit code
58+
exit_code=$?
59+
if [ "${exit_code}" != "0" ]
60+
then
61+
echo "notarize-app failed: ${exit_code}"
62+
cat "result.plist"
63+
exit 1
64+
fi
65+
66+
# Get the RequestUUID
67+
RequestUUID="$("${PLISTBUDDY_APP}" -c "Print notarization-upload:RequestUUID" "result.plist")"
68+
echo "RequestUUID: ${RequestUUID}"
69+
70+
# wait till notarize apple server is finish with the processing the zip upload.
71+
for (( ; ; ))
72+
do
73+
74+
# get status from apple notarize server
75+
xcrun altool --output-format xml --notarization-info "${RequestUUID}" -u $USERNAME -p $APP_SPECIFIC_PASSWORD > "result.plist"
76+
# Check exit code
77+
exit_code=$?
78+
if [ "${exit_code}" != "0" ]
79+
then
80+
echo "notarization-info failed: ${exit_code}"
81+
cat "result.plist"
82+
# print the error in the URL
83+
LogFileURL="$("${PLISTBUDDY_APP}" -c "Print notarization-info:LogFileURL" "result.plist")"
84+
if [ ! -z "${LogFileURL}" ]
85+
then
86+
curl "${LogFileURL}"
87+
fi
88+
exit 1
89+
fi
90+
91+
# get the status.
92+
StatusCode="$("${PLISTBUDDY_APP}" -c "Print notarization-info:Status" "result.plist")"
93+
echo "Status: ${StatusCode}"
94+
95+
# if no status code present in result then it is still busy
96+
if [ "${StatusCode}" == "in progress" ]
97+
then
98+
sleep 15
99+
else
100+
echo "Finish waiting."
101+
#cat "result.plist"
102+
# Check if everything is correct
103+
StatusCode="$("${PLISTBUDDY_APP}" -c "Print notarization-info:'Status Code'" "result.plist")"
104+
echo "Status code: ${StatusCode}"
105+
if [ "${StatusCode}" == "0" ]
106+
then
107+
# there are no error.
108+
break
109+
else
110+
# print the error in the URL
111+
LogFileURL="$("${PLISTBUDDY_APP}" -c "Print notarization-info:LogFileURL" "result.plist")"
112+
if [ ! -z "${LogFileURL}" ]
113+
then
114+
curl "${LogFileURL}"
115+
fi
116+
exit 1
117+
fi
118+
fi
119+
done
120+
121+
# verify sign *.app is succes full
122+
spctl --assess --type execute --verbose $FILE_APP
123+
# Check exit code
124+
exit_code=$?
125+
if [ "${exit_code}" != "0" ]
126+
then
127+
echo "spctl failed: ${exit_code}"
128+
exit 1
129+
fi
130+
131+
# staple the *.app
132+
xcrun stapler staple $FILE_APP
133+
# Check exit code
134+
exit_code=$?
135+
if [ "${exit_code}" != "0" ]
136+
then
137+
echo "spctl stapler: ${exit_code}"
138+
exit 1
139+
fi
140+
141+
# zip only the app folder with extra text file.
142+
/usr/bin/ditto -c -k "enduser/macos/app" "$RELEASE_ZIP_FILE"

0 commit comments

Comments
 (0)