-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpackage_macos.sh
executable file
·111 lines (99 loc) · 2.46 KB
/
package_macos.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
#!/bin/sh
# submit a package to be notarized
# returns: notarization uuid
notary_submit() {
xcrun altool -f dist/dcrinstall-${VERSION}/${EXE}.pkg \
--notarize-app \
--primary-bundle-id org.decred.dcrinstall.pkg \
--asc-provider ${IDENTITY} \
-p @keychain:${KEYCHAIN} 2>&1 \
| perl -ne 'print if s/^RequestUUID = //'
}
# check notarization status after successful submission
# arg 1: uuid
# returns: altool output
notary_status() {
local _uuid=$1
xcrun altool --notarization-info ${_uuid} -p @keychain:${KEYCHAIN} 2>&1
}
# write an install script read from stdin
# arg 1: script name
installscript() {
local _script=${SCRIPTS}/$1
cat >${_script}
chmod 0755 ${_script}
}
[ $(uname) = Darwin ] || {
echo "$0 must be run from darwin" 2>&1
exit 1
}
[ $# = 3 ] || {
echo "usage: $0 version identity arch" 2>&1
exit 2
}
VERSION=$1
IDENTITY=$2
ARCH=$3
KEYCHAIN=${KEYCHAIN:-signer}
DIST=dist/darwin
SCRIPTS=darwin/scripts
EXE=dcrinstall-darwin-${ARCH}-${VERSION}
BUILD=dist/dcrinstall-${VERSION}/${EXE}
PREFIX=${PREFIX:-/usr/local}
[ -x ${BUILD} ] || go run . -dist dcrinstall -target darwin/${ARCH}
[ -x ${BUILD} ] || {
echo "cannot package ${BUILD}: executable missing" 2>&1
exit 1
}
set -ex
[ -d ${DIST} ] && rm -rf ${DIST}
[ -d ${SCRIPTS} ] && rm -rf ${SCRIPTS}
mkdir -p ${DIST}
mkdir -p ${SCRIPTS}
# prepare directory with package files
install -m 0755 ${BUILD} ${DIST}/dcrinstall
[ $ARCH = arm64 ] && codesign --remove-signature ${DIST}/dcrinstall
codesign -s ${IDENTITY} --options runtime ${DIST}/dcrinstall
installscript postinstall <<EOF
#!/bin/sh
echo ${PREFIX}/decred > /etc/paths.d/decred
EOF
# generate signed package for notarization
pkgbuild --identifier org.decred.dcrinstall \
--version ${VERSION} \
--root ${DIST} \
--install-location ${PREFIX}/decred \
--scripts ${SCRIPTS} \
--sign ${IDENTITY} \
dist/dcrinstall-${VERSION}/${EXE}.pkg
# submit notarization
_uuid=$(notary_submit)
# poll notarization status until no longer in-progress
set +ex
while :; do
sleep 60
_date=$(date)
_output=$(notary_status ${_uuid})
_status=$(echo "${_output}" | perl -ne 'print if s/^\s*Status: //')
echo "check at ${_date}: Status: ${_status}"
case ${_status} in
"in progress")
continue
;;
"success")
# move on to stapling
break
;;
"")
echo "warn: unknown status -- full output:\n${_output}" 2>&1
continue
;;
*)
echo "${_output}" 2>&1
exit 1
;;
esac
done
set -ex
# staple package with notarization ticket
stapler staple dist/dcrinstall-${VERSION}/${EXE}.pkg