-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathbuild.bash
More file actions
executable file
·226 lines (194 loc) · 7.28 KB
/
build.bash
File metadata and controls
executable file
·226 lines (194 loc) · 7.28 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/bin/bash
# Script to build OS X package install from installpkg core source code
#
# Copyright (C)2011 - Henri Shustak
# Released under the GUN GPL v3 or later
# Lucid Information Systems
# http://www.lucidsystems.org
#
# v1.1 : initial release
#
# establish some varibles
package_version="${1}"
parent_directory=`dirname "${0}"`
parent_direcotry_uid=`ls -nld "${parent_directory}" | awk '{print $3}'`
input_package="${parent_directory}/InstallPKG.pkg"
tmp_working_directory=`mktemp -d /tmp/build_installpkg_XXXXXXXX`
tmp_installpkg_build_dir="${tmp_working_directory}/installpkg"
disk_image_src_dir="${tmp_installpkg_build_dir}"
output_package="${tmp_installpkg_build_dir}/InstallPKG.pkg"
make_file_template_for_package_building="${parent_directory}/Makefile_template"
make_file_for_package_building="${parent_directory}/Makefile"
output_diskimage_name="installpkg"
output_diskimage_path="${parent_directory}/builds/${output_diskimage_name}_v${package_version}.dmg"
realitive_output_diskimage_path="./builds/${output_diskimage_name}_v${package_version}.dmg"
clean_up_pkg_file="YES"
export exit_value=0
# list of additional files to copy to the disk image
additional_files_to_include_within_diskimage=( "InstallPKG-Uninstall.bash" "extras" )
# functions
function clean_exit {
rm -rf "${tmp_working_directory}"
rm -f "${make_file_for_package_building}"
if [ -e "${input_package}" ] && [ "${clean_up_pkg_file}" == "YES" ] ; then
rm -rf "${input_package}"
fi
exit ${exit_value}
}
# perform some basic checks
# -------------------------
if [ "$1" == "" ] ; then
echo "Usage : build.bash <build_version_number>"
echo " eg. : ./build.bash 0.0.9"
exit -1
fi
# check we are running as root
current_user=`whoami`
if [ "${current_user}" != "root" ] ; then
echo "Luggage requires superuser privileges to build the package."
echo "Please run this script as root."
export exit_value=-1
clean_exit
fi
# check that luggage (maybe installed) - must be a better approach
if ! [ -d /usr/local/share/luggage ] ; then
echo "This script requires that you have luggage installed on your system."
echo "Download luggage from : https://github.com/unixorn/luggage"
echo "For more information : http://luggage.apesseekingknowledge.net"
export exit_value=-1
clean_exit
fi
# prepare to build the package the package
cd "${parent_directory}"
if [ $? != 0 ] ; then
echo " ERROR : Unable to change working directory to the parent directory of this script."
echo " Build has been canceled."
export exit_value=-1
clean_exit
fi
# if a previous package build exits (from previous run) then remove this
if [ -e "${input_package}" ] ; then
rm -R "${input_package}"
if [ $? != 0 ] ; then
echo ""
echo " ERROR! : Failed during removal of previous package."
echo ""
export exit_value=-1
clean_exit
fi
fi
# perform check incase an existing disk image already exists.
if [ -e "${output_diskimage_path}" ] ; then
echo ""
echo -n "Overwrite exiting disk image? [y/N] : "
read instructions
if [ "${instructions}" != "y" ] && [ "${instructions}" != "yes" ] && [ "${instructions}" != "YES" ] ; then
echo "Disk image creation aborted."
export exit_value=-1
clean_exit
fi
echo -n "Removing exiting disk image..."
rm $output_diskimage_path
if [ $? != 0 ] ; then
echo " ERROR!: Unable to remove the old disk image!"
export exit_value=-1
clean_exit
fi
echo "done."
echo ""
fi
# remove any exisiting make file....
if [ -f "${make_file_for_package_building}" ] ; then
rm "${make_file_for_package_building}"
if [ $? != 0 ] ; then
echo " ERROR! : Unable to remove package make file (do not worry template is not being removed)"
export exit_value=-1
clean_exit
fi
fi
# create the make file from the template
sed s/XXXXXXXXX/${package_version}/g "${make_file_template_for_package_building}" > "${make_file_for_package_building}"
if [ $? != 0 ] ; then
echo " ERROR!: InstallPGK setting version in make file failed!"
export exit_value=-1
clean_exit
fi
# make the package (using the luggage)
# -------------------------
# make pkg-dist - this may be required for modern operating systems
# for now we keep using 'make pkg' until it breaks
make pkg
if [ $? != 0 ] ; then
echo ""
echo " ERROR! : Failed during new package creation."
echo ""
export exit_value=-1
clean_exit
fi
echo ""
echo "---------------------------------------------------------------------------------------"
echo " Package for InstallPKG was successfully created from the InstallPKG core source code. "
echo "---------------------------------------------------------------------------------------"
echo ""
# prepare for disk image building
# --------------------------------
# allow anyone to look inside the tempoary building directory.
chmod 755 "${tmp_working_directory}"
# generate the dmg output directory
mkdir -p "${tmp_installpkg_build_dir}"
if [ $? != 0 ] ; then
echo " ERROR!: Unable to generate the dmg output directory!"
export exit_value=-1
clean_exit
fi
# copy the package from the build directory into the output directory
echo "Copying package...."
cp -r "${input_package}" "${output_package}"
if [ $? != 0 ] ; then
echo " ERROR!: Unable to copy the install package to the dmg build directory!"
export exit_value=-1
clean_exit
fi
echo "Coping extras...."
# copy each items listed in the settings from the install_components directory
for to_copy in "${additional_files_to_include_within_diskimage[@]}" ; do
cp -r "${parent_directory}/install_components/${to_copy}" "${tmp_installpkg_build_dir}/"
if [ $? != 0 ] ; then
echo " ERROR!: Unable to copy the additional component \" ${to_copy} \" to the dmg build directory!"
export exit_value=-1
clean_exit
fi
done
# generate disk image from the temporary build directory
echo -n "Building disk image"
hdiutil create -srcfolder "${disk_image_src_dir}" -fs HFS+ -volname installpkg -uid 99 -gid 99 -mode 755 -partitionType Apple_HFS -format UDZO -copyuid root "${output_diskimage_path}"
return_value=$?
if [ $return_value -ne 0 ] ; then
echo "ERROR! : Creating disk image!"
echo ""
exit $retrun_value
fi
# set the owner for this disk image to be the same as the parent directory
chown ${parent_direcotry_uid} "${output_diskimage_path}"
if [ $? != 0 ] ; then
echo " ERROR!: Unable to set the ownership of the output .dmg"
export exit_value=-1
clean_exit
fi
# generate latest version link
rm -f ./installpkg_latest.dmg
ln -s "${realitive_output_diskimage_path}" ./installpkg_latest.dmg
if [ $? != 0 ] ; then
echo " ERROR!: while generating latest version link"
export exit_value=-1
clean_exit
fi
echo ""
echo "---------------------------------------------------------------------------------------"
echo " Output image \"installpkg_v${package_version}.dmg\" is ready for collection from the builds direcotry "
echo "---------------------------------------------------------------------------------------"
echo ""
# exit cleanly
# --------------------------------
export exit_value=0
clean_exit