-
Notifications
You must be signed in to change notification settings - Fork 18
/
build_hello.zsh
executable file
·127 lines (115 loc) · 3.94 KB
/
build_hello.zsh
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
119
120
121
122
123
124
125
126
127
#!/bin/zsh
#
# Build script for Hello
# ./build_hello.zsh "CREATE_PKG"
# Variables
XCODE_PATH="/Applications/Xcode_13.1.app"
SIGNING_IDENTITY="Developer ID Installer: Clever DevOps Co. (9GQZ7KUFR6)"
MP_SHA="71c57fcfdf43692adcd41fa7305be08f66bae3e5"
MP_BINDIR="/tmp/munki-pkg"
CONSOLEUSER=$(/usr/bin/stat -f "%Su" /dev/console)
TOOLSFULLDIR=$(pwd)
TOOLSDIR=$(dirname $0)
BUILDSFULLDIR="$TOOLSFULLDIR/build"
BUILDSDIR="$TOOLSDIR/build"
OUTPUTSDIR="$TOOLSDIR/outputs"
MP_ZIP="/tmp/munki-pkg.zip"
XCODE_BUILD_PATH="$XCODE_PATH/Contents/Developer/usr/bin/xcodebuild"
XCODE_NOTARY_PATH="$XCODE_PATH/Contents/Developer/usr/bin/notarytool"
XCODE_STAPLER_PATH="$XCODE_PATH/Contents/Developer/usr/bin/stapler"
CURRENT_HELLO_MAIN_BUILD_VERSION=$(/usr/libexec/PlistBuddy -c Print:CFBundleVersion $TOOLSDIR/hello/Info.plist)
DATE=$(/bin/date -u "+%m%d%Y%H%M%S")
# automate the build version bump
AUTOMATED_HELLO_BUILD="$CURRENT_HELLO_MAIN_BUILD_VERSION.$DATE"
/usr/bin/xcrun agvtool new-version -all $AUTOMATED_HELLO_BUILD
/usr/bin/xcrun agvtool new-marketing-version $AUTOMATED_HELLO_BUILD
# Create files to use for build process info
echo "$AUTOMATED_HELLO_BUILD" > $TOOLSDIR/build_info.txt
# Ensure Xcode is set to run-time
sudo xcode-select -s "$XCODE_PATH"
# build hello
echo "Building hello"
if [ -e $XCODE_BUILD_PATH ]; then
XCODE_BUILD="$XCODE_BUILD_PATH"
else
ls -la /Applications
echo "Could not find required Xcode build. Exiting..."
exit 1
fi
$XCODE_BUILD -scheme "hello (Release)" -project "$TOOLSDIR/hello.xcodeproj" BUILD_DIR=${BUILDSFULLDIR} CODE_SIGN_IDENTITY=$CODE_SIGN_IDENTITY OTHER_CODE_SIGN_FLAGS="--timestamp"
XCB_RESULT="$?"
if [ "${XCB_RESULT}" != "0" ]; then
echo "Error running xcodebuild: ${XCB_RESULT}" 1>&2
exit 1
fi
if ! [ -n "$1" ]; then
echo "Did not pass option to create package"
exit 0
fi
# Create outputs folder
if [ -e $OUTPUTSDIR ]; then
/bin/rm -rf $OUTPUTSDIR
fi
/bin/mkdir -p "$OUTPUTSDIR"
# move the app to the payload folder
echo "Moving hello.app to payload folder"
HELLO_PKG_PATH="$TOOLSDIR/helloPkg"
if [ -e $HELLO_PKG_PATH ]; then
/bin/rm -rf $HELLO_PKG_PATH
fi
/bin/mkdir -p "$HELLO_PKG_PATH/payload/Applications/Utilities"
/usr/bin/sudo /usr/sbin/chown -R ${CONSOLEUSER}:wheel "$HELLO_PKG_PATH"
/bin/mv "$GITHUB_WORKSPACE/Build/Release/hello.app" "$HELLO_PKG_PATH/payload/Applications/Utilities/hello.app"
# Download specific version of munki-pkg
echo "Downloading munki-pkg tool from github..."
if [ -f "${MP_ZIP}" ]; then
/usr/bin/sudo /bin/rm -rf ${MP_ZIP}
fi
/usr/bin/curl https://github.com/munki/munki-pkg/archive/${MP_SHA}.zip -L -o ${MP_ZIP}
if [ -d ${MP_BINDIR} ]; then
/usr/bin/sudo /bin/rm -rf ${MP_BINDIR}
fi
/usr/bin/unzip ${MP_ZIP} -d ${MP_BINDIR}
DL_RESULT="$?"
if [ "${DL_RESULT}" != "0" ]; then
echo "Error downloading munki-pkg tool: ${DL_RESULT}" 1>&2
exit 1
fi
# Create the json file for signed munkipkg hello pkg
/bin/cat << SIGNED_JSONFILE > "$HELLO_PKG_PATH/build-info.json"
{
"ownership": "recommended",
"suppress_bundle_relocation": true,
"identifier": "com.github.erikng.hello",
"postinstall_action": "none",
"distribution_style": true,
"version": "$AUTOMATED_HELLO_BUILD",
"name": "hello-$AUTOMATED_HELLO_BUILD.pkg",
"install_location": "/",
"signing_info": {
"identity": "$SIGNING_IDENTITY",
"timestamp": true
}
}
SIGNED_JSONFILE
/bin/cat << JSONFILE > "$HELLO_PKG_PATH/build-info.json"
{
"ownership": "recommended",
"suppress_bundle_relocation": true,
"identifier": "com.github.erikng.hello",
"postinstall_action": "none",
"distribution_style": true,
"version": "$AUTOMATED_HELLO_BUILD",
"name": "hello-$AUTOMATED_HELLO_BUILD.pkg",
"install_location": "/"
}
JSONFILE
# Create the signed pkg
"${MP_BINDIR}/munki-pkg-${MP_SHA}/munkipkg" "$HELLO_PKG_PATH"
PKG_RESULT="$?"
if [ "${PKG_RESULT}" != "0" ]; then
echo "Could not sign package: ${PKG_RESULT}" 1>&2
else
# Move the signed pkg
/bin/mv "$HELLO_PKG_PATH/build/hello-$AUTOMATED_HELLO_BUILD.pkg" "$OUTPUTSDIR"
fi