Skip to content

Commit 310bd0d

Browse files
author
Dalton
committed
AUTH-2712 fixed the mac build script
1 parent 1a96889 commit 310bd0d

File tree

1 file changed

+57
-39
lines changed

1 file changed

+57
-39
lines changed

.teamcity/build-macos.sh

Lines changed: 57 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,81 +29,99 @@ cd ../src/github.com/cloudflare/cloudflared
2929
GOCACHE="$PWD/../../../../" GOPATH="$PWD/../../../../" CGO_ENABLED=1 make cloudflared
3030

3131
# 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
32+
if [[ -n "${CFD_CODE_SIGN_KEY:-}" ]]; then
33+
if [[ -n "${CFD_CODE_SIGN_PASS:-}" ]]; then
34+
# write private key to disk and then import it keychain
35+
echo -n -e ${CFD_CODE_SIGN_KEY} | base64 -D > ${CODE_SIGN_PRIV}
36+
security import ${CODE_SIGN_PRIV} -A -P "${CFD_CODE_SIGN_PASS}"
37+
rm ${CODE_SIGN_PRIV}
38+
fi
3939
fi
4040

4141
# Add code signing certificate to the key chain
42-
if [[ -z "${CFD_CODE_SIGN_CERT}" ]]; then
42+
if [[ -n "${CFD_CODE_SIGN_CERT:-}" ]]; then
4343
# write certificate to disk and then import it keychain
4444
echo -n -e ${CFD_CODE_SIGN_CERT} | base64 -D > ${CODE_SIGN_CERT}
4545
security import ${CODE_SIGN_CERT}
4646
rm ${CODE_SIGN_CERT}
47-
else
48-
exit 1
4947
fi
5048

5149
# 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
50+
if [[ -n "${CFD_INSTALLER_KEY:-}" ]]; then
51+
if [[ -n "${CFD_INSTALLER_PASS:-}" ]]; then
52+
# write private key to disk and then import it into the keychain
53+
echo -n -e ${CFD_INSTALLER_KEY} | base64 -D > ${INSTALLER_PRIV}
54+
security import ${INSTALLER_PRIV} -A -P "${CFD_INSTALLER_PASS}"
55+
rm ${INSTALLER_PRIV}
56+
fi
5957
fi
6058

6159
# Add package signing certificate to the key chain
62-
if [[ -z "${CFD_INSTALLER_CERT}" ]]; then
60+
if [[ -n "${CFD_INSTALLER_CERT:-}" ]]; then
6361
# write certificate to disk and then import it keychain
6462
echo -n -e ${CFD_INSTALLER_CERT} | base64 -D > ${INSTALLER_CERT}
6563
security import ${INSTALLER_CERT}
6664
rm ${INSTALLER_CERT}
67-
else
68-
exit 1
6965
fi
7066

7167
# 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
68+
if [[ -n "${CFD_CODE_SIGN_NAME:-}" ]]; then
7569
CODE_SIGN_NAME="${CFD_CODE_SIGN_NAME}"
70+
else
71+
if [[ -n "$(security find-identity -v | cut -d'"' -f 2 -s | grep "Developer ID Application:")" ]]; then
72+
CODE_SIGN_NAME=$(echo "something else" | grep "Developer ID Application:")
73+
else
74+
CODE_SIGN_NAME=""
75+
fi
7676
fi
7777

7878
# 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
79+
if [[ -n "${CFD_INSTALLER_NAME:-}" ]]; then
8280
PKG_SIGN_NAME="${CFD_INSTALLER_NAME}"
81+
else
82+
if [[ -n "$(security find-identity -v | cut -d'"' -f 2 -s | grep "Developer ID Installer:")" ]]; then
83+
PKG_SIGN_NAME=$(security find-identity -v | cut -d'"' -f 2 -s | grep "Developer ID Installer:")
84+
else
85+
PKG_SIGN_NAME=""
86+
fi
87+
8388
fi
8489

8590
# sign the cloudflared binary
86-
codesign -s "${CODE_SIGN_NAME}" -f -v --timestamp --options runtime ${BINARY_NAME}
91+
if [[ -n "${CODE_SIGN_NAME:-}" ]]; then
92+
codesign -s "${CODE_SIGN_NAME}" -f -v --timestamp --options runtime ${BINARY_NAME}
93+
fi
94+
8795

8896
# creating build directory
89-
mkdir ${TARGET_DIRECTORY}
90-
mkdir ${TARGET_DIRECTORY}/contents
91-
cp -r .mac_resources/scripts ${TARGET_DIRECTORY}/scripts
97+
mkdir "${TARGET_DIRECTORY}"
98+
mkdir "${TARGET_DIRECTORY}/contents"
99+
cp -r ".mac_resources/scripts" "${TARGET_DIRECTORY}/scripts"
92100

93101
# copy cloudflared into the build directory
94-
cp ${BINARY_NAME} {$TARGET_DIRECTORY}/contents/${PRODUCT}
102+
cp ${BINARY_NAME} "${TARGET_DIRECTORY}/contents/${PRODUCT}"
95103

96104
# compress cloudflared into a tar and gzipped file
97-
tar czf "$FILENAME" ${BINARY_NAME}
105+
tar czf "$FILENAME" "${BINARY_NAME}"
98106

99107
# 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}
108+
if [[ -n "${PKG_SIGN_NAME:-}" ]]; then
109+
pkgbuild --identifier com.cloudflare.${PRODUCT} \
110+
--version ${VERSION} \
111+
--scripts ${TARGET_DIRECTORY}/scripts \
112+
--root ${TARGET_DIRECTORY}/contents \
113+
--install-location /usr/local/bin \
114+
--sign "${PKG_SIGN_NAME}" \
115+
${PKGNAME}
116+
else
117+
pkgbuild --identifier com.cloudflare.${PRODUCT} \
118+
--version ${VERSION} \
119+
--scripts ${TARGET_DIRECTORY}/scripts \
120+
--root ${TARGET_DIRECTORY}/contents \
121+
--install-location /usr/local/bin \
122+
${PKGNAME}
123+
fi
124+
107125

108126
# cleaning up the build directory
109127
rm -rf $TARGET_DIRECTORY

0 commit comments

Comments
 (0)