-
Notifications
You must be signed in to change notification settings - Fork 24
/
build-macos.sh
executable file
·169 lines (144 loc) · 4.92 KB
/
build-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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
#
# Modifications Copyright OpenSearch Contributors. See
# GitHub history for details.
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
PRODUCT="OpenSearchCLI"
DATE=`date +%Y-%m-%d`
TIME=`date +%H:%M:%S`
LOG_PREFIX="[$DATE $TIME]"
usage() {
echo ""
echo "This script is used to build the macos package for OpenSearch CLI."
echo "--------------------------------------------------------------------------"
echo "Usage: $0 [args]"
echo ""
echo "Required arguments:"
echo -e "-v VERSION\tSpecify the OpenSearch CLI version number that you are building, e.g. '1.0.0' or '1.0.0-beta1'."
echo -e "-a ARCHITECTURE\tSpecify the architecture type your signed binary is based on, e.g. 'x64,arm64'."
echo -e "-t TARGET DIRECTORY\tSpecify the location where you like to generate package artifact."
echo "--------------------------------------------------------------------------"
}
while getopts ":hv:a:t:" arg; do
case $arg in
h)
usage
exit 1
;;
v)
VERSION=$OPTARG
;;
a)
ARCHITECTURE=$OPTARG
;;
t)
TARGET_DIRECTORY=$OPTARG
;;
:)
echo "-${OPTARG} requires an argument"
usage
exit 1
;;
?)
echo "Invalid option: -${arg}"
exit 1
;;
esac
done
# Validate the required parameters to present
if [ -z "$VERSION" ] || [ -z "$ARCHITECTURE" ] || [ -z "$TARGET_DIRECTORY" ]; then
echo "You must specify '-v VERSION', '-a ARCHITECTURE', '-t TARGET_DIRECTORY'"
usage
exit 1
fi
if [ "$ARCHITECTURE" != "x64" ] && [ "$ARCHITECTURE" != "arm64" ]; then
echo "We only support 'x64' and 'arm64' as architecture name for -a parameter"
exit 1
fi
INSTALLER_NAME="opensearch-cli-${VERSION}-macos-${ARCHITECTURE}"
#Functions
go_to_dir() {
pushd $1 >/dev/null 2>&1
}
log_info() {
echo "${LOG_PREFIX}[INFO]" $1
}
log_error() {
echo "${LOG_PREFIX}[ERROR]" $1
}
deleteInstallationDirectory() {
log_info "Cleaning $TARGET_DIRECTORY directory."
rm -rf $TARGET_DIRECTORY
if [[ $? != 0 ]]; then
log_error "Failed to clean $TARGET_DIRECTORY directory" $?
exit 1
fi
}
createInstallationDirectory() {
if [ -d ${TARGET_DIRECTORY} ]; then
deleteInstallationDirectory
fi
mkdir $TARGET_DIRECTORY
if [[ $? != 0 ]]; then
log_error "Failed to create $TARGET_DIRECTORY directory" $?
exit 1
fi
}
copyDarwinDirectory(){
createInstallationDirectory
cp -r $SCRIPTPATH/darwin ${TARGET_DIRECTORY}/
chmod -R 755 ${TARGET_DIRECTORY}/darwin/scripts
chmod -R 755 ${TARGET_DIRECTORY}/darwin/Resources
chmod 755 ${TARGET_DIRECTORY}/darwin/Distribution
}
copyBuildDirectory() {
sed -i '' -e 's/__VERSION__/'${VERSION}'/g' ${TARGET_DIRECTORY}/darwin/scripts/postinstall
sed -i '' -e 's/__PRODUCT__/'${PRODUCT}'/g' ${TARGET_DIRECTORY}/darwin/scripts/postinstall
sed -i '' -e 's/__VERSION__/'${VERSION}'/g' ${TARGET_DIRECTORY}/darwin/Distribution
sed -i '' -e 's/__PRODUCT__/'${PRODUCT}'/g' ${TARGET_DIRECTORY}/darwin/Distribution
rm -rf ${TARGET_DIRECTORY}/darwinpkg
mkdir -p ${TARGET_DIRECTORY}/darwinpkg
#Copy opensearch-cli product to /Library/OpenSearchCLI
mkdir -p ${TARGET_DIRECTORY}/darwinpkg/Library/${PRODUCT}
cp -a $SCRIPTPATH/application/. ${TARGET_DIRECTORY}/darwinpkg/Library/${PRODUCT}
chmod -R 755 ${TARGET_DIRECTORY}/darwinpkg/Library/${PRODUCT}
rm -rf ${TARGET_DIRECTORY}/package
mkdir -p ${TARGET_DIRECTORY}/package
chmod -R 755 ${TARGET_DIRECTORY}/package
rm -rf ${TARGET_DIRECTORY}/pkg
mkdir -p ${TARGET_DIRECTORY}/pkg
chmod -R 755 ${TARGET_DIRECTORY}/pkg
}
buildPackage() {
log_info "Application installer package building started.(1/3)"
pkgbuild --identifier org.opensearch.${PRODUCT} \
--version ${VERSION} \
--scripts ${TARGET_DIRECTORY}/darwin/scripts \
--root ${TARGET_DIRECTORY}/darwinpkg \
${TARGET_DIRECTORY}/package/${PRODUCT}.pkg > /dev/null 2>&1
}
buildProduct() {
log_info "Application installer product building started.(2/3)"
productbuild --distribution ${TARGET_DIRECTORY}/darwin/Distribution \
--resources ${TARGET_DIRECTORY}/darwin/Resources \
--package-path ${TARGET_DIRECTORY}/package \
${TARGET_DIRECTORY}/pkg/$1 > /dev/null 2>&1
}
createInstaller() {
log_info "Application installer generation process started.(3 Steps)"
buildPackage
buildProduct ${INSTALLER_NAME}.pkg
log_info "Application installer generation steps finished."
}
#Main script
log_info "Installer generating process started."
copyDarwinDirectory
copyBuildDirectory
createInstaller
log_info "Installer generating process finished"
exit 0