@@ -13,9 +13,97 @@ export GO111MODULE=on
1313# build 'cloudflared-darwin-amd64.tgz'
1414mkdir -p artifacts
1515FILENAME=" $( pwd) /artifacts/cloudflared-darwin-amd64.tgz"
16+ PKGNAME=" $( pwd) /artifacts/cloudflared-amd64.pkg"
17+ TARGET_DIRECTORY=" .build"
18+ BINARY_NAME=" cloudflared"
19+ VERSION=$( git describe --tags --always --dirty=" -dev" )
20+ PRODUCT=" cloudflared"
21+ CODE_SIGN_PRIV=" code_sign.pk12"
22+ CODE_SIGN_CERT=" code_sign.cer"
23+ INSTALLER_PRIV=" installer.pk12"
24+ INSTALLER_CERT=" installer.cer"
1625export PATH=" $PATH :/usr/local/bin"
1726mkdir -p ../src/github.com/cloudflare/
1827cp -r . ../src/github.com/cloudflare/cloudflared
1928cd ../src/github.com/cloudflare/cloudflared
2029GOCACHE=" $PWD /../../../../" GOPATH=" $PWD /../../../../" CGO_ENABLED=1 make cloudflared
21- tar czf " $FILENAME " cloudflared
30+
31+ # Add code signing private key to the key chain
32+ if [[ -z " ${CFD_CODE_SIGN_KEY} " ]]; then
33+ # write private key to disk and then import it keychain
34+ echo -n -e ${CFD_CODE_SIGN_KEY} | base64 -D > ${CODE_SIGN_PRIV}
35+ security import ${CODE_SIGN_PRIV} -A -P " ${CFD_CODE_SIGN_PASS} "
36+ rm ${CODE_SIGN_PRIV}
37+ else
38+ exit 1
39+ fi
40+
41+ # Add code signing certificate to the key chain
42+ if [[ -z " ${CFD_CODE_SIGN_CERT} " ]]; then
43+ # write certificate to disk and then import it keychain
44+ echo -n -e ${CFD_CODE_SIGN_CERT} | base64 -D > ${CODE_SIGN_CERT}
45+ security import ${CODE_SIGN_CERT}
46+ rm ${CODE_SIGN_CERT}
47+ else
48+ exit 1
49+ fi
50+
51+ # Add package signing private key to the key chain
52+ if [[ -z " ${CFD_INSTALLER_KEY} " ]]; then
53+ # write private key to disk and then import it into the keychain
54+ echo -n -e ${CFD_INSTALLER_KEY} | base64 -D > ${INSTALLER_PRIV}
55+ security import ${INSTALLER_PRIV} -A -P " ${CFD_INSTALLER_PASS} "
56+ rm ${INSTALLER_PRIV}
57+ else
58+ exit 1
59+ fi
60+
61+ # Add package signing certificate to the key chain
62+ if [[ -z " ${CFD_INSTALLER_CERT} " ]]; then
63+ # write certificate to disk and then import it keychain
64+ echo -n -e ${CFD_INSTALLER_CERT} | base64 -D > ${INSTALLER_CERT}
65+ security import ${INSTALLER_CERT}
66+ rm ${INSTALLER_CERT}
67+ else
68+ exit 1
69+ fi
70+
71+ # get the code signing certificate name
72+ if [[ -z " ${CFD_CODE_SIGN_NAME} " ]]; then
73+ CODE_SIGN_NAME=$( security find-identity -v | cut -d' "' -f 2 -s | grep " Developer ID Application:" )
74+ else
75+ CODE_SIGN_NAME=" ${CFD_CODE_SIGN_NAME} "
76+ fi
77+
78+ # get the package signing certificate name
79+ if [[ -z " ${CFD_INSTALLER_NAME} " ]]; then
80+ PKG_SIGN_NAME=$( security find-identity -v | cut -d' "' -f 2 -s | grep " Developer ID Installer:" )
81+ else
82+ PKG_SIGN_NAME=" ${CFD_INSTALLER_NAME} "
83+ fi
84+
85+ # sign the cloudflared binary
86+ codesign -s " ${CODE_SIGN_NAME} " -f -v --timestamp --options runtime ${BINARY_NAME}
87+
88+ # creating build directory
89+ mkdir ${TARGET_DIRECTORY}
90+ mkdir ${TARGET_DIRECTORY} /contents
91+ cp -r .mac_resources/scripts ${TARGET_DIRECTORY} /scripts
92+
93+ # copy cloudflared into the build directory
94+ cp ${BINARY_NAME} {$TARGET_DIRECTORY }/contents/${PRODUCT}
95+
96+ # compress cloudflared into a tar and gzipped file
97+ tar czf " $FILENAME " ${BINARY_NAME}
98+
99+ # build the installer package
100+ pkgbuild --identifier com.cloudflare.${PRODUCT} \
101+ --version ${VERSION} \
102+ --scripts ${TARGET_DIRECTORY} /scripts \
103+ --root ${TARGET_DIRECTORY} /contents \
104+ --install-location /usr/local/bin \
105+ --sign " ${PKG_SIGN_NAME} " \
106+ ${PKGNAME}
107+
108+ # cleaning up the build directory
109+ rm -rf $TARGET_DIRECTORY
0 commit comments