1 | #!/bin/bash␊ |
2 | ␊ |
3 | # $0 SRCROOT directory␊ |
4 | # $1 SYMROOT directory␊ |
5 | # $2 directory where pkgs will be created␊ |
6 | ␊ |
7 | # Directory paths␊ |
8 | declare -r PKGROOT="${0%/*}"␊ |
9 | declare -r SRCROOT="$1"␊ |
10 | declare -r SYMROOT="$2"␊ |
11 | declare -r PKG_BUILD_DIR="$3"␊ |
12 | ␊ |
13 | if [[ $# -lt 3 ]];then␊ |
14 | echo "Too few arguments. Aborting..." >&2 && exit 1␊ |
15 | fi␊ |
16 | ␊ |
17 | if [[ ! -d "$SYMROOT" ]];then␊ |
18 | ␉echo "Directory ${SYMROOT} doesn't exit. Aborting..." >&2 && exit 1␊ |
19 | fi␊ |
20 | ␊ |
21 | # Prevent the script from doing bad things␊ |
22 | set -u # Abort with unset variables␊ |
23 | #set -e # Abort with any error can be suppressed locally using EITHER cmd||true OR set -e;cmd;set +e␊ |
24 | ␊ |
25 | # ====== COLORS ======␊ |
26 | ␊ |
27 | declare -r COL_BLACK="\x1b[30;01m"␊ |
28 | declare -r COL_RED="\x1b[31;01m"␊ |
29 | declare -r COL_GREEN="\x1b[32;01m"␊ |
30 | declare -r COL_YELLOW="\x1b[33;01m"␊ |
31 | declare -r COL_MAGENTA="\x1b[35;01m"␊ |
32 | declare -r COL_CYAN="\x1b[36;01m"␊ |
33 | declare -r COL_WHITE="\x1b[37;01m"␊ |
34 | declare -r COL_BLUE="\x1b[34;01m"␊ |
35 | declare -r COL_RESET="\x1b[39;49;00m"␊ |
36 | ␊ |
37 | # ====== REVISION/VERSION ======␊ |
38 | ␊ |
39 | declare -r version=$( cat version )␊ |
40 | ␊ |
41 | # stage␊ |
42 | stage=${version##*-}␊ |
43 | stage=${stage/RC/Release Candidate }␊ |
44 | stage=${stage/FINAL/2.1 Final}␊ |
45 | declare -r stage␊ |
46 | ␊ |
47 | declare -r revision=$( grep I386BOOT_CHAMELEONREVISION vers.h | awk '{ print $3 }' | tr -d '\"' )␊ |
48 | declare -r builddate=$( grep I386BOOT_BUILDDATE vers.h | awk '{ print $3,$4 }' | tr -d '\"' )␊ |
49 | declare -r timestamp=$( date -j -f "%Y-%m-%d %H:%M:%S" "${builddate}" "+%s" )␊ |
50 | ␊ |
51 | # ====== CREDITS ======␊ |
52 | ␊ |
53 | declare -r develop=$(awk "NR==6{print;exit}" ${PKGROOT}/../CREDITS)␊ |
54 | declare -r credits=$(awk "NR==10{print;exit}" ${PKGROOT}/../CREDITS)␊ |
55 | declare -r pkgdev=$(awk "NR==14{print;exit}" ${PKGROOT}/../CREDITS)␊ |
56 | ␊ |
57 | # =================␊ |
58 | ␊ |
59 | xmlindent=0␊ |
60 | ␊ |
61 | indent[0]="\t"␊ |
62 | indent[1]="\t\t"␊ |
63 | indent[2]="\t\t\t"␊ |
64 | indent[3]="\t\t\t\t"␊ |
65 | ␊ |
66 | # ====== GLOBAL VARIABLES ======␊ |
67 | declare -a pkgrefs␊ |
68 | declare -a outline␊ |
69 | declare -a choices␊ |
70 | ␊ |
71 | # Package name␊ |
72 | declare -r packagename="Chameleon"␊ |
73 | ␊ |
74 | # Package identifiers␊ |
75 | declare -r chameleon_package_identity="org.chameleon"␊ |
76 | declare -r modules_packages_identity="${chameleon_package_identity}.modules"␊ |
77 | declare -r chamTemp="usr/local/chamTemp"␊ |
78 | ␊ |
79 | # ====== FUNCTIONS ======␊ |
80 | ␊ |
81 | getPackageRefId () {␊ |
82 | echo ${1//_/.}.${2//_/.} | tr [:upper:] [:lower:]␊ |
83 | }␊ |
84 | ␊ |
85 | addChoice () {␊ |
86 | # $1 Choice Id␊ |
87 | # $2 Choice Options␊ |
88 | # $3..$n Package reference id (optional)␊ |
89 | local choiceId="${1}"␊ |
90 | local choiceOptions="${2}"␊ |
91 | local choiceNode="\t<choice\n\t\tid=\"${choiceId}\"\n\t\ttitle=\"${choiceId}_title\"\n\t\tdescription=\"${choiceId}_description\""␊ |
92 | [[ -n "${choiceOptions}" ]] && choiceNode="${choiceNode}\n\t\t${choiceOptions}"␊ |
93 | choiceNode="${choiceNode}>"␊ |
94 | if [[ $# -ge 3 ]];then␊ |
95 | for pkgRefId in ${@:3};do␊ |
96 | choiceNode="${choiceNode}\n\t\t<pkg-ref id=\"${pkgRefId}\"/>"␊ |
97 | done␊ |
98 | fi␊ |
99 | choiceNode="${choiceNode}\n\t</choice>\n"␊ |
100 | ␊ |
101 | outline[${#outline[*]}]="${indent[$xmlindent]}<line choice=\"${choiceId}\"/>"␊ |
102 | choices[${#choices[*]}]="$choiceNode"␊ |
103 | }␊ |
104 | ␊ |
105 | exclusive_one_choice () {␊ |
106 | # $1 Current choice (ie: test1)␊ |
107 | # $2..$n Others choice(s) (ie: "test2" "test3"). Current can or can't be in the others choices␊ |
108 | local myChoice="${1}"␊ |
109 | local result="";␊ |
110 | local separator=' || ';␊ |
111 | for choice in ${@:2};do␊ |
112 | if [[ "$choice" != "$myChoice" ]];then␊ |
113 | result="${result}choices['$choice'].selected${separator}";␊ |
114 | fi␊ |
115 | done␊ |
116 | if [[ -n "$result" ]];then␊ |
117 | echo "!(${result%$separator})"␊ |
118 | fi␊ |
119 | }␊ |
120 | ␊ |
121 | exclusive_zero_or_one_choice () {␊ |
122 | # $1 Current choice (ie: test1)␊ |
123 | # $2..$n Others choice(s) (ie: "test2" "test3"). Current can or can't be in the others choices␊ |
124 | local myChoice="${1}"␊ |
125 | local result;␊ |
126 | echo "(my.choice.selected && $(exclusive_one_choice ${@}))"␊ |
127 | }␊ |
128 | ␊ |
129 | main ()␊ |
130 | {␊ |
131 | ␊ |
132 | # clean up the destination path␊ |
133 | ␊ |
134 | rm -R -f "${PKG_BUILD_DIR}"␊ |
135 | echo ""␊ |
136 | echo -e $COL_CYAN" ----------------------------------"$COL_RESET␊ |
137 | echo -e $COL_CYAN" Building $packagename Install Package"$COL_RESET␊ |
138 | echo -e $COL_CYAN" ----------------------------------"$COL_RESET␊ |
139 | echo ""␊ |
140 | ␊ |
141 | outline[${#outline[*]}]="${indent[$xmlindent]}<choices-outline>"␊ |
142 | ␊ |
143 | # build pre install package␊ |
144 | echo "================= Preinstall ================="␊ |
145 | ((xmlindent++))␊ |
146 | packagesidentity="${chameleon_package_identity}"␊ |
147 | choiceId="Pre"␊ |
148 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root␊ |
149 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts␊ |
150 | ditto --noextattr --noqtn ${SRCROOT}/revision ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources/revision␊ |
151 | ditto --noextattr --noqtn ${SRCROOT}/version ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources/version␊ |
152 | cp -f ${PKGROOT}/Scripts/Main/preinstall ${PKG_BUILD_DIR}/${choiceId}/Scripts␊ |
153 | cp -f ${PKGROOT}/Scripts/Sub/InstallLog.sh ${PKG_BUILD_DIR}/${choiceId}/Scripts␊ |
154 | echo -e "\t[BUILD] ${choiceId} "␊ |
155 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
156 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"␊ |
157 | addChoice "${choiceId}" "start_visible=\"false\" start_selected=\"true\"" "$packageRefId"␊ |
158 | # End build pre install package␊ |
159 | ␊ |
160 | # build core package␊ |
161 | echo "================= Core ================="␊ |
162 | packagesidentity="${chameleon_package_identity}"␊ |
163 | choiceId="Core"␊ |
164 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin␊ |
165 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386␊ |
166 | ditto --noextattr --noqtn ${SYMROOT}/i386/boot ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386␊ |
167 | ditto --noextattr --noqtn ${SYMROOT}/i386/boot0 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386␊ |
168 | ditto --noextattr --noqtn ${SYMROOT}/i386/boot0md ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386␊ |
169 | ditto --noextattr --noqtn ${SYMROOT}/i386/boot1f32 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386␊ |
170 | ditto --noextattr --noqtn ${SYMROOT}/i386/boot1h ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386␊ |
171 | ditto --noextattr --noqtn ${SYMROOT}/i386/boot1he ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386␊ |
172 | ditto --noextattr --noqtn ${SYMROOT}/i386/boot1hp ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386␊ |
173 | ditto --noextattr --noqtn ${SYMROOT}/i386/cdboot ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386␊ |
174 | ditto --noextattr --noqtn ${SYMROOT}/i386/chain0 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386␊ |
175 | ditto --noextattr --noqtn ${SYMROOT}/i386/fdisk440 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin␊ |
176 | ditto --noextattr --noqtn ${SYMROOT}/i386/bdmesg ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin␊ |
177 | echo -e "\t[BUILD] ${choiceId} "␊ |
178 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
179 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"␊ |
180 | addChoice "${choiceId}" "start_visible=\"false\" start_selected=\"true\"" "$packageRefId"␊ |
181 | # End build core package␊ |
182 | ␊ |
183 | # build install type␊ |
184 | echo "================= Chameleon ================="␊ |
185 | outline[${#outline[*]}]="${indent[$xmlindent]}<line choice=\"InstallType\">"␊ |
186 | choices[${#choices[*]}]="\t<choice\n\t\tid=\"InstallType\"\n\t\ttitle=\"InstallType_title\"\n\t\tdescription=\"InstallType_description\">\n\t</choice>\n"␊ |
187 | ((xmlindent++))␊ |
188 | packagesidentity="${chameleon_package_identity}.type"␊ |
189 | allChoices="New Upgrade"␊ |
190 | ␊ |
191 | # build new install package␊ |
192 | choiceId="New"␊ |
193 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root␊ |
194 | echo "" > "${PKG_BUILD_DIR}/${choiceId}/Root/install_type_new"␊ |
195 | echo -e "\t[BUILD] ${choiceId} "␊ |
196 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
197 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/$chamTemp"␊ |
198 | exclusiveChoice=$(exclusive_one_choice "$choiceId" "$allChoices")␊ |
199 | addChoice "${choiceId}" "start_selected=\"!choices['Upgrade'].selected\" selected=\"${exclusiveChoice}\"" "$packageRefId"␊ |
200 | # End build new install package␊ |
201 | ␊ |
202 | # build upgrade package␊ |
203 | choiceId="Upgrade"␊ |
204 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root␊ |
205 | echo "" > "${PKG_BUILD_DIR}/${choiceId}/Root/install_type_upgrade"␊ |
206 | echo -e "\t[BUILD] ${choiceId} "␊ |
207 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
208 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/$chamTemp"␊ |
209 | exclusiveChoice=$(exclusive_one_choice "$choiceId" "$allChoices")␊ |
210 | addChoice "${choiceId}" "start_selected=\"chameleon_boot_plist_exists()\" selected=\"${exclusiveChoice}\"" "$packageRefId"␊ |
211 | # End build upgrade package␊ |
212 | ␊ |
213 | ((xmlindent--))␊ |
214 | outline[${#outline[*]}]="${indent[$xmlindent]}</line>"␊ |
215 | # End build install type␊ |
216 | ␊ |
217 | # build Chameleon package␊ |
218 | echo "================= Chameleon ================="␊ |
219 | outline[${#outline[*]}]="${indent[$xmlindent]}<line choice=\"Chameleon\">"␊ |
220 | choices[${#choices[*]}]="\t<choice\n\t\tid=\"Chameleon\"\n\t\ttitle=\"Chameleon_title\"\n\t\tdescription=\"Chameleon_description\">\n\t</choice>\n"␊ |
221 | ((xmlindent++))␊ |
222 | ␊ |
223 | allChoices="Standard EFI noboot"␊ |
224 | ␊ |
225 | # build standard package␊ |
226 | choiceId="Standard"␊ |
227 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root␊ |
228 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources␊ |
229 | cp -f ${PKGROOT}/Scripts/Main/${choiceId}postinstall ${PKG_BUILD_DIR}/${choiceId}/Scripts/postinstall␊ |
230 | cp -f ${PKGROOT}/Scripts/Sub/* ${PKG_BUILD_DIR}/${choiceId}/Scripts␊ |
231 | ditto --arch i386 `which SetFile` ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources/SetFile␊ |
232 | echo -e "\t[BUILD] ${choiceId} "␊ |
233 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
234 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"␊ |
235 | exclusiveChoice=$(exclusive_one_choice "$choiceId" "$allChoices")␊ |
236 | addChoice "${choiceId}" "start_selected=\"true\" selected=\"${exclusiveChoice}\"" "$packageRefId"␊ |
237 | # End build standard package␊ |
238 | ␊ |
239 | # build efi package␊ |
240 | choiceId="EFI"␊ |
241 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root␊ |
242 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources␊ |
243 | cp -f ${PKGROOT}/Scripts/Main/ESPpostinstall ${PKG_BUILD_DIR}/${choiceId}/Scripts/postinstall␊ |
244 | cp -f ${PKGROOT}/Scripts/Sub/* ${PKG_BUILD_DIR}/${choiceId}/Scripts␊ |
245 | ditto --arch i386 `which SetFile` ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources/SetFile␊ |
246 | echo -e "\t[BUILD] ${choiceId} "␊ |
247 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
248 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"␊ |
249 | exclusiveChoice=$(exclusive_one_choice "$choiceId" "$allChoices")␊ |
250 | addChoice "${choiceId}" "start_visible=\"systemHasGPT()\" start_selected=\"false\" selected=\"${exclusiveChoice}\"" "$packageRefId"␊ |
251 | # End build efi package␊ |
252 | ␊ |
253 | # build no bootloader choice package␊ |
254 | choiceId="noboot"␊ |
255 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root␊ |
256 | echo -e "\t[BUILD] ${choiceId} "␊ |
257 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
258 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"␊ |
259 | exclusiveChoice=$(exclusive_one_choice "$choiceId" "$allChoices")␊ |
260 | addChoice "${choiceId}" "start_selected=\"false\" selected=\"${exclusiveChoice}\"" "$packageRefId"␊ |
261 | # End build no bootloader choice package␊ |
262 | ␊ |
263 | ((xmlindent--))␊ |
264 | outline[${#outline[*]}]="${indent[$xmlindent]}</line>"␊ |
265 | # End build Chameleon package␊ |
266 | ␊ |
267 | # build Modules package␊ |
268 | echo "================= Modules ================="␊ |
269 | ###############################␊ |
270 | # Supported Modules #␊ |
271 | ###############################␊ |
272 | # klibc.dylib #␊ |
273 | # Resolution.dylib #␊ |
274 | # uClibcxx.dylib #␊ |
275 | # Keylayout.dylib #␊ |
276 | ###############################␊ |
277 | if [ "$(ls -A "${SYMROOT}/i386/modules")" ]; then␊ |
278 | {␊ |
279 | outline[${#outline[*]}]="${indent[$xmlindent]}<line choice=\"Module\">"␊ |
280 | choices[${#choices[*]}]="\t<choice\n\t\tid=\"Module\"\n\t\ttitle=\"Module_title\"\n\t\tdescription=\"Module_description\">\n\t</choice>\n"␊ |
281 | ((xmlindent++))␊ |
282 | ␊ |
283 | # -␊ |
284 | if [ -e ${SYMROOT}/i386/modules/klibc.dylib ]; then␊ |
285 | {␊ |
286 | # Start build klibc package module␊ |
287 | choiceId="klibc"␊ |
288 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root␊ |
289 | ditto --noextattr --noqtn ${SYMROOT}/i386/modules/${choiceId}.dylib ${PKG_BUILD_DIR}/${choiceId}/Root␊ |
290 | echo -e "\t[BUILD] ${choiceId} "␊ |
291 | packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")␊ |
292 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/$chamTemp/Extra/modules"␊ |
293 | addChoice "${choiceId}" "start_selected=\"false\"" "$packageRefId"␊ |
294 | # End build klibc package module␊ |
295 | }␊ |
296 | fi␊ |
297 | ␊ |
298 | # -␊ |
299 | if [ -e ${SYMROOT}/i386/modules/Resolution.dylib ]; then␊ |
300 | {␊ |
301 | # Start build Resolution package module␊ |
302 | choiceId="AutoReso"␊ |
303 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root␊ |
304 | ditto --noextattr --noqtn ${SYMROOT}/i386/modules/Resolution.dylib ${PKG_BUILD_DIR}/${choiceId}/Root␊ |
305 | echo -e "\t[BUILD] ${choiceId} "␊ |
306 | packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")␊ |
307 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/$chamTemp/Extra/modules"␊ |
308 | addChoice "${choiceId}" "start_selected=\"false\"" "$packageRefId"␊ |
309 | # End build Resolution package module␊ |
310 | }␊ |
311 | fi␊ |
312 | ␊ |
313 | # -␊ |
314 | if [ -e ${SYMROOT}/i386/modules/uClibcxx.dylib ]; then␊ |
315 | {␊ |
316 | # Start build uClibc package module␊ |
317 | choiceId="uClibc"␊ |
318 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root␊ |
319 | ditto --noextattr --noqtn ${SYMROOT}/i386/modules/uClibcxx.dylib ${PKG_BUILD_DIR}/${choiceId}/Root␊ |
320 | echo -e "\t[BUILD] ${choiceId} "␊ |
321 | packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")␊ |
322 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/$chamTemp/Extra/modules"␊ |
323 | # Add the klibc package because the uClibc module is dependent of klibc module␊ |
324 | addChoice "${choiceId}" "start_selected=\"false\"" \␊ |
325 | "$packageRefId" $(getPackageRefId "${modules_packages_identity}" "klibc")␊ |
326 | # End build uClibc package module␊ |
327 | }␊ |
328 | fi␊ |
329 | ␊ |
330 | # -␊ |
331 | # Warning Keylayout module need additional files␊ |
332 | if [ -e ${SYMROOT}/i386/modules/Keylayout.dylib ]; then␊ |
333 | {␊ |
334 | # Start build Keylayout package module␊ |
335 | choiceId="Keylayout"␊ |
336 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root/Extra/{modules,Keymaps}␊ |
337 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin␊ |
338 | layout_src_dir="${SRCROOT}/i386/modules/Keylayout/layouts/layouts-src"␊ |
339 | if [ -d "$layout_src_dir" ];then␊ |
340 | # Create a tar.gz from layout sources␊ |
341 | (cd "$layout_src_dir"; \␊ |
342 | tar czf "${PKG_BUILD_DIR}/${choiceId}/Root/Extra/Keymaps/layouts-src.tar.gz" README *.slt)␊ |
343 | fi␊ |
344 | # Adding module␊ |
345 | ditto --noextattr --noqtn ${SYMROOT}/i386/modules/${choiceId}.dylib ${PKG_BUILD_DIR}/${choiceId}/Root/Extra/modules␊ |
346 | # Adding Keymaps␊ |
347 | ditto --noextattr --noqtn ${SRCROOT}/Keymaps ${PKG_BUILD_DIR}/${choiceId}/Root/Extra/Keymaps␊ |
348 | # Adding tools␊ |
349 | ditto --noextattr --noqtn ${SYMROOT}/i386/cham-mklayout ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin␊ |
350 | echo -e "\t[BUILD] ${choiceId} "␊ |
351 | packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")␊ |
352 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/$chamTemp"␊ |
353 | ␊ |
354 | # Don't add a choice for Keylayout module␊ |
355 | # addChoice "${choiceId}" "start_selected=\"false\"" "$packageRefId"␊ |
356 | # End build Keylayout package module␊ |
357 | }␊ |
358 | fi␊ |
359 | ␊ |
360 | ((xmlindent--))␊ |
361 | outline[${#outline[*]}]="${indent[$xmlindent]}</line>"␊ |
362 | }␊ |
363 | else␊ |
364 | {␊ |
365 | echo " -= no modules to include =-"␊ |
366 | }␊ |
367 | fi␊ |
368 | # End build Modules packages␊ |
369 | ␊ |
370 | # build Options packages␊ |
371 | ␊ |
372 | outline[${#outline[*]}]="${indent[$xmlindent]}<line choice=\"Options\">"␊ |
373 | choices[${#choices[*]}]="\t<choice\n\t\tid=\"Options\"\n\t\ttitle=\"Options_title\"\n\t\tdescription=\"Options_description\">\n\t</choice>\n"␊ |
374 | ((xmlindent++))␊ |
375 | ␊ |
376 | ␊ |
377 | # ------------------------------------------------------␊ |
378 | # parse OptionalSettings folder to find files of boot options.␊ |
379 | # ------------------------------------------------------␊ |
380 | OptionalSettingsFolder="${PKGROOT}/OptionalSettings"␊ |
381 | OptionalSettingsFiles=($( find "${OptionalSettingsFolder}" -depth 1 ! -name '.svn' ! -name '.DS_Store' ))␊ |
382 | ␊ |
383 | for (( i = 0 ; i < ${#OptionalSettingsFiles[@]} ; i++ ))␊ |
384 | do␊ |
385 | ␊ |
386 | ␉␉# Take filename and Strip .txt from end and path from front␊ |
387 | ␉␉builtOptionsList=$( echo ${OptionalSettingsFiles[$i]%.txt} )␊ |
388 | ␉␉builtOptionsList=$( echo ${builtOptionsList##*/} )␊ |
389 | ␉␉echo "================= $builtOptionsList ================="␊ |
390 | ␉␉outline[${#outline[*]}]="${indent[$xmlindent]}<line choice=\"${builtOptionsList}\">"␊ |
391 | ␉␉choices[${#choices[*]}]="\t<choice\n\t\tid=\"${builtOptionsList}\"\n\t\ttitle=\"${builtOptionsList}_title\"\n\t\tdescription=\"${builtOptionsList}_description\">\n\t</choice>\n"␊ |
392 | ␉␉((xmlindent++))␊ |
393 | ␉␉packagesidentity="${chameleon_package_identity}.options.$builtOptionsList"␊ |
394 | ␊ |
395 | ␉␉# ------------------------------------------------------␊ |
396 | ␉␉# Read boot option file into an array.␊ |
397 | ␉␉# ------------------------------------------------------␊ |
398 | ␉␉availableOptions=() # array to hold the list of boot options, per 'section'.␊ |
399 | ␉␉exclusiveFlag=0 # used to indicate list has exclusive options␊ |
400 | ␉␉count=0 # used as index for stepping through array.␊ |
401 | ␉␉while read textLine; do␊ |
402 | ␉␉␉# ignore lines in the file beginning with a # and Exclusive=False␊ |
403 | ␉␉␉if [[ ${textLine} != \#* ]] && [[ ${textLine} != "Exclusive=False" ]];then␊ |
404 | ␉␉␉␉# check for 'Exclusive=True' option in file␊ |
405 | ␉␉␉␉if [[ ${textLine} == "Exclusive=True" ]];then␊ |
406 | ␉␉␉␉␉exclusiveFlag=1␊ |
407 | ␉␉␉␉else␊ |
408 | ␉␉␉␉␉availableOptions[${#availableOptions[@]}]=$textLine␊ |
409 | ␉␉␉␉fi␊ |
410 | ␉␉␉fi␊ |
411 | ␉␉done < ${OptionalSettingsFiles[$i]}␊ |
412 | ␊ |
413 | ␉␉# ------------------------------------------------------␊ |
414 | ␉␉# Loop through options in array and process each in turn␊ |
415 | ␉␉# ------------------------------------------------------␊ |
416 | ␉␉allChoices="${availableOptions[@]//:*/}"␊ |
417 | ␉␉for (( c = 0 ; c < ${#availableOptions[@]} ; c++ )); do␊ |
418 | ␉␉␉textLine=${availableOptions[c]}␊ |
419 | ␉␉␉# split line - taking all before ':' as option name␊ |
420 | ␉␉␉# and all after ':' as key/value␊ |
421 | ␉␉␉optionName=${textLine%:*}␊ |
422 | ␉␉␉keyValue=${textLine##*:}␊ |
423 | ␊ |
424 | ␉␉␉# create folders required for each boot option␊ |
425 | ␉␉␉mkdir -p "${PKG_BUILD_DIR}/$optionName/Root/"␊ |
426 | ␊ |
427 | ␉␉␉# create dummy file with name of key/value␊ |
428 | ␉␉␉echo "" > "${PKG_BUILD_DIR}/$optionName/Root/${keyValue}"␊ |
429 | ␊ |
430 | ␉␉␉echo -e "\t[BUILD] ${optionName} "␊ |
431 | ␉␉␉packageRefId=$(getPackageRefId "${packagesidentity}" "${optionName}")␊ |
432 | ␉␉␉buildpackage "$packageRefId" "${optionName}" "${PKG_BUILD_DIR}/${optionName}" "/$chamTemp/options"␊ |
433 | ␉␉␉exclusiveSelect=""␊ |
434 | ␉␉␉if [[ ${exclusiveFlag} -eq 1 ]];then␊ |
435 | ␉␉␉␉exclusiveSelect="selected=\"$(exclusive_zero_or_one_choice "$optionName" "$allChoices")\""␊ |
436 | ␉␉␉fi␊ |
437 | ␉␉␉addChoice "${optionName}" "start_selected=\"false\" ${exclusiveSelect}" "$packageRefId"␊ |
438 | ␉␉done␊ |
439 | ␊ |
440 | ␉␉((xmlindent--))␊ |
441 | ␉␉outline[${#outline[*]}]="${indent[$xmlindent]}</line>"␊ |
442 | ␉done␊ |
443 | ␊ |
444 | ␉# build KeyLayout options packages␊ |
445 | ␉echo "================= Keymaps Options ================="␊ |
446 | ␉outline[${#outline[*]}]="${indent[$xmlindent]}<line choice=\"KeyLayout\">"␊ |
447 | ␉choices[${#choices[*]}]="\t<choice\n\t\tid=\"KeyLayout\"\n\t\ttitle=\"KeyLayout_title\"\n\t\tdescription=\"KeyLayout_description\">\n\t</choice>\n"␊ |
448 | ␉((xmlindent++))␊ |
449 | ␉packagesidentity="${chameleon_package_identity}.options.keylayout"␊ |
450 | ␉keylayoutPackageRefId=$(getPackageRefId "${modules_packages_identity}" "Keylayout")␊ |
451 | ␊ |
452 | ␉# ------------------------------------------------------␊ |
453 | ␉# Available Keylayout boot options are discovered by␊ |
454 | ␉# reading contents of /Keymaps folder after compilation␊ |
455 | ␉# ------------------------------------------------------␊ |
456 | ␉availableOptions=($( find "${SRCROOT}/Keymaps" -type f -depth 1 -name '*.lyt' | sed 's|.*/||;s|\.lyt||' ))␊ |
457 | ␉allChoices="${availableOptions[@]}"␊ |
458 | ␉# Adjust array contents to match expected format␊ |
459 | ␉# for boot options which is: name:key=value␊ |
460 | ␉for (( i = 0 ; i < ${#availableOptions[@]} ; i++ )); do␊ |
461 | ␉␉# availableOptions[i]=${availableOptions[i]}":KeyLayout="${availableOptions[i]}␊ |
462 | ␉␉# Start build of a keymap package module␊ |
463 | ␉␉choiceId="${availableOptions[i]}"␊ |
464 | ␉␉mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root␊ |
465 | ␊ |
466 | ␉␉# create dummy file with name of key/value␊ |
467 | ␉␉echo "" > "${PKG_BUILD_DIR}/${choiceId}/Root/KeyLayout=${availableOptions[i]}"␊ |
468 | ␊ |
469 | ␉␉echo -e "\t[BUILD] ${choiceId} "␊ |
470 | ␉␉packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
471 | ␉␉buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/$chamTemp/options"␊ |
472 | ␉␉exclusiveChoice=$(exclusive_zero_or_one_choice "$choiceId" "$allChoices")␊ |
473 | ␉␉# Add the Keylayout package because the Keylayout module is needed␊ |
474 | ␉␉addChoice "${choiceId}" "start_selected=\"false\" selected=\"${exclusiveChoice}\"" \␊ |
475 | ␉␉ "$packageRefId" "$keylayoutPackageRefId"␊ |
476 | ␉␉# End build uClibc package module␊ |
477 | ␉done␊ |
478 | ␊ |
479 | ␉((xmlindent--))␊ |
480 | ␉outline[${#outline[*]}]="${indent[$xmlindent]}</line>"␊ |
481 | ␊ |
482 | ␉# End build KeyLayout options packages␊ |
483 | ␊ |
484 | ␉((xmlindent--))␊ |
485 | ␉outline[${#outline[*]}]="${indent[$xmlindent]}</line>"␊ |
486 | # End build options packages␊ |
487 | ␊ |
488 | # build theme packages␊ |
489 | ␉echo "================= Themes ================="␊ |
490 | ␉outline[${#outline[*]}]="${indent[$xmlindent]}<line choice=\"Themes\">"␊ |
491 | ␉choices[${#choices[*]}]="\t<choice\n\t\tid=\"Themes\"\n\t\ttitle=\"Themes_title\"\n\t\tdescription=\"Themes_description\">\n\t</choice>\n"␊ |
492 | ␉((xmlindent++))␊ |
493 | ␊ |
494 | ␉# Using themes section from Azi's/package branch.␊ |
495 | ␉packagesidentity="${chameleon_package_identity}.themes"␊ |
496 | ␉artwork="${SRCROOT}/artwork/themes"␊ |
497 | ␉themes=($( find "${artwork}" -type d -depth 1 -not -name '.svn' ))␊ |
498 | ␉for (( i = 0 ; i < ${#themes[@]} ; i++ )); do␊ |
499 | ␉␉theme=$( echo ${themes[$i]##*/} | awk 'BEGIN{OFS=FS=""}{$1=toupper($1);print}' )␊ |
500 | ␉␉mkdir -p "${PKG_BUILD_DIR}/${theme}/Root/"␊ |
501 | ␉␉rsync -r --exclude=.svn "${themes[$i]}/" "${PKG_BUILD_DIR}/${theme}/Root/${theme}"␊ |
502 | ␉␉echo -e "\t[BUILD] ${theme}"␊ |
503 | ␉␉packageRefId=$(getPackageRefId "${packagesidentity}" "${theme}")␊ |
504 | ␉␉buildpackage "$packageRefId" "${theme}" "${PKG_BUILD_DIR}/${theme}" "/$chamTemp/Extra/Themes"␊ |
505 | ␉␉addChoice "${theme}" "start_selected=\"false\"" "$packageRefId"␊ |
506 | ␉done␊ |
507 | ␊ |
508 | ␉((xmlindent--))␊ |
509 | ␉outline[${#outline[*]}]="${indent[$xmlindent]}</line>"␊ |
510 | # End build theme packages# End build Extras package␊ |
511 | ␊ |
512 | # build post install package␊ |
513 | echo "================= Post ================="␊ |
514 | packagesidentity="${chameleon_package_identity}"␊ |
515 | choiceId="Post"␊ |
516 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root␊ |
517 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts␊ |
518 | cp -f ${PKGROOT}/Scripts/Main/postinstall ${PKG_BUILD_DIR}/${choiceId}/Scripts␊ |
519 | cp -f ${PKGROOT}/Scripts/Sub/InstallLog.sh ${PKG_BUILD_DIR}/${choiceId}/Scripts␊ |
520 | cp -f ${PKGROOT}/Scripts/Sub/UnMountEFIvolumes.sh ${PKG_BUILD_DIR}/${choiceId}/Scripts␊ |
521 | ditto --noextattr --noqtn ${SRCROOT}/revision ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources/revision␊ |
522 | ditto --noextattr --noqtn ${SRCROOT}/version ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources/version␊ |
523 | echo -e "\t[BUILD] ${choiceId} "␊ |
524 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
525 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"␊ |
526 | addChoice "${choiceId}" "start_visible=\"false\" start_selected=\"true\"" "$packageRefId"␊ |
527 | # End build post install package␊ |
528 | ␊ |
529 | ␉((xmlindent--))␊ |
530 | ␉outline[${#outline[*]}]="${indent[$xmlindent]}</choices-outline>"␊ |
531 | ␊ |
532 | }␊ |
533 | ␊ |
534 | buildpackage ()␊ |
535 | {␊ |
536 | ␉# $1 Package Reference Id (ie: org.chameleon.themes.default)␊ |
537 | ␉# $2 Package Name (ie: Default)␊ |
538 | ␉# $3 Path to package to build containing Root and/or Scripts␊ |
539 | ␉# $4 Target install location␊ |
540 | ␉# $5 Size (optional)␊ |
541 | ␉if [[ -d "${3}/Root" ]]; then␊ |
542 | ␉␉local packageRefId="$1"␊ |
543 | ␉␉local packageName="$2"␊ |
544 | ␉␉local packagePath="$3"␊ |
545 | ␉␉local targetPath="$4"␊ |
546 | ␉␉set +u # packageSize is optional␊ |
547 | local packageSize="$5"␊ |
548 | set -u␊ |
549 | ␊ |
550 | ␉␉find "${packagePath}" -name '.DS_Store' -delete␊ |
551 | ␉␉local filecount=$( find "${packagePath}/Root" | wc -l )␊ |
552 | ␉␉if [ "${packageSize}" ]; then␊ |
553 | ␉␉␉local installedsize="${packageSize}"␊ |
554 | ␉␉else␊ |
555 | ␉␉␉local installedsize=$( du -hkc "${packagePath}/Root" | tail -n1 | awk {'print $1'} )␊ |
556 | ␉␉fi␊ |
557 | ␉␉local header="<?xml version=\"1.0\"?>\n<pkg-info format-version=\"2\" "␊ |
558 | ␊ |
559 | ␉␉#[ "${3}" == "relocatable" ] && header+="relocatable=\"true\" "␊ |
560 | ␊ |
561 | ␉␉header+="identifier=\"${packageRefId}\" "␊ |
562 | ␉␉header+="version=\"${version}\" "␊ |
563 | ␊ |
564 | ␉␉[ "${targetPath}" != "relocatable" ] && header+="install-location=\"${targetPath}\" "␊ |
565 | ␊ |
566 | ␉␉header+="auth=\"root\">\n"␊ |
567 | ␉␉header+="\t<payload installKBytes=\"${installedsize##* }\" numberOfFiles=\"${filecount##* }\"/>\n"␊ |
568 | ␉␉rm -R -f "${packagePath}/Temp"␊ |
569 | ␊ |
570 | ␉␉[ -d "${packagePath}/Temp" ] || mkdir -m 777 "${packagePath}/Temp"␊ |
571 | ␉␉[ -d "${packagePath}/Root" ] && mkbom "${packagePath}/Root" "${packagePath}/Temp/Bom"␊ |
572 | ␊ |
573 | ␉␉if [ -d "${packagePath}/Scripts" ]; then␊ |
574 | ␉␉␉header+="\t<scripts>\n"␊ |
575 | ␉␉␉for script in $( find "${packagePath}/Scripts" -type f \( -name 'pre*' -or -name 'post*' \) ); do␊ |
576 | ␉␉␉␉header+="\t\t<${script##*/} file=\"./${script##*/}\"/>\n"␊ |
577 | ␉␉␉done␊ |
578 | ␉␉␉header+="\t</scripts>\n"␊ |
579 | ␉␉␉# Create the Script archive file (cpio format)␊ |
580 | ␉␉␉(cd "${packagePath}/Scripts" && find . -print | cpio -o -z -R 0:0 --format cpio > "${packagePath}/Temp/Scripts") 2>&1 | \␊ |
581 | ␉␉␉ grep -vE '^[0-9]+\s+blocks?$' # to remove cpio stderr messages␊ |
582 | fi␊ |
583 | ␊ |
584 | ␉␉header+="</pkg-info>"␊ |
585 | ␉␉echo -e "${header}" > "${packagePath}/Temp/PackageInfo"␊ |
586 | ␊ |
587 | ␉␉# Create the Payload file (cpio format)␊ |
588 | ␉␉(cd "${packagePath}/Root" && find . -print | cpio -o -z -R 0:0 --format cpio > "${packagePath}/Temp/Payload") 2>&1 | \␊ |
589 | ␉ grep -vE '^[0-9]+\s+blocks?$' # to remove cpio stderr messages␊ |
590 | ␊ |
591 | ␉␉# Create the package␊ |
592 | ␉␉(cd "${packagePath}/Temp" && xar -c -f "${packagePath}/../${packageName}.pkg" --compression none .)␊ |
593 | ␊ |
594 | ␉␉# Add the package to the list of build packages␊ |
595 | ␉␉pkgrefs[${#pkgrefs[*]}]="\t<pkg-ref id=\"${packageRefId}\" installKBytes='${installedsize}' version='${version}.0.0.${timestamp}'>#${packageName}.pkg</pkg-ref>"␊ |
596 | ␊ |
597 | ␉␉rm -rf "${packagePath}"␊ |
598 | ␉fi␊ |
599 | }␊ |
600 | ␊ |
601 | makedistribution ()␊ |
602 | {␊ |
603 | declare -r distributionDestDir="${SYMROOT}"␊ |
604 | declare -r distributionFilename="${packagename// /}-${version}-r${revision}.pkg"␊ |
605 | declare -r distributionFilePath="${distributionDestDir}/${distributionFilename}"␊ |
606 | ␊ |
607 | rm -f "${distributionDestDir}/${packagename// /}"*.pkg␊ |
608 | ␊ |
609 | mkdir -p "${PKG_BUILD_DIR}/${packagename}"␊ |
610 | ␊ |
611 | find "${PKG_BUILD_DIR}" -type f -name '*.pkg' -depth 1 | while read component␊ |
612 | ␉do␊ |
613 | pkg="${component##*/}" # ie: EFI.pkg␊ |
614 | pkgdir="${PKG_BUILD_DIR}/${packagename}/${pkg}"␊ |
615 | # expand individual packages␊ |
616 | pkgutil --expand "${PKG_BUILD_DIR}/${pkg}" "$pkgdir"␊ |
617 | rm -f "${PKG_BUILD_DIR}/${pkg}"␊ |
618 | done␊ |
619 | ␊ |
620 | # Create the Distribution file␊ |
621 | ditto --noextattr --noqtn "${PKGROOT}/Distribution" "${PKG_BUILD_DIR}/${packagename}/Distribution"␊ |
622 | ␊ |
623 | for (( i=0; i < ${#outline[*]} ; i++)); do␊ |
624 | ␉␉echo -e "${outline[$i]}" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"␊ |
625 | ␉done␊ |
626 | ␊ |
627 | for (( i=0; i < ${#choices[*]} ; i++)); do␊ |
628 | ␉␉echo -e "${choices[$i]}" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"␊ |
629 | ␉done␊ |
630 | ␊ |
631 | for (( i=0; i < ${#pkgrefs[*]} ; i++)); do␊ |
632 | echo -e "${pkgrefs[$i]}" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"␊ |
633 | done␊ |
634 | ␊ |
635 | echo -e "\n</installer-gui-script>" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"␊ |
636 | ␊ |
637 | # Create the Resources directory␊ |
638 | ditto --noextattr --noqtn "${PKGROOT}/Resources" "${PKG_BUILD_DIR}/${packagename}/Resources"␊ |
639 | ␊ |
640 | # CleanUp the directory␊ |
641 | find "${PKG_BUILD_DIR}/${packagename}" \( -type d -name '.svn' \) -o -name '.DS_Store' -exec rm -rf {} \;␊ |
642 | ␊ |
643 | # Add Chameleon Version and Revision␊ |
644 | perl -i -p -e "s/%CHAMELEONVERSION%/${version%%-*}/g" $( find "${PKG_BUILD_DIR}/${packagename}/Resources" -type f )␊ |
645 | perl -i -p -e "s/%CHAMELEONREVISION%/${revision}/g" $( find "${PKG_BUILD_DIR}/${packagename}/Resources" -type f )␊ |
646 | ␊ |
647 | # Add Chameleon Stage␊ |
648 | perl -i -p -e "s/%CHAMELEONSTAGE%/${stage}/g" $( find "${PKG_BUILD_DIR}/${packagename}/Resources" -type f )␊ |
649 | ␊ |
650 | # Adding Developer and credits␊ |
651 | perl -i -p -e "s/%DEVELOP%/${develop}/g" $( find "${PKG_BUILD_DIR}/${packagename}/Resources" -type f )␊ |
652 | perl -i -p -e "s/%CREDITS%/${credits}/g" $( find "${PKG_BUILD_DIR}/${packagename}/Resources" -type f )␊ |
653 | perl -i -p -e "s/%PKGDEV%/${pkgdev}/g" $( find "${PKG_BUILD_DIR}/${packagename}/Resources" -type f )␊ |
654 | ␊ |
655 | # Create the final package␊ |
656 | pkgutil --flatten "${PKG_BUILD_DIR}/${packagename}" "${distributionFilePath}"␊ |
657 | ␊ |
658 | # Here is the place for assign a Icon to the pkg␊ |
659 | ditto -xk "${PKGROOT}/Icons/pkg.zip" "${PKG_BUILD_DIR}/Icons/"␊ |
660 | DeRez -only icns "${PKG_BUILD_DIR}/Icons/Icons/pkg.icns" > "${PKG_BUILD_DIR}/Icons/tempicns.rsrc"␊ |
661 | Rez -append "${PKG_BUILD_DIR}/Icons/tempicns.rsrc" -o "${distributionFilePath}"␊ |
662 | SetFile -a C "${distributionFilePath}"␊ |
663 | rm -rf "${PKG_BUILD_DIR}/Icons"␊ |
664 | ␊ |
665 | # End␊ |
666 | ␊ |
667 | md5=$( md5 "${distributionFilePath}" | awk {'print $4'} )␊ |
668 | echo "MD5 (${distributionFilePath}) = ${md5}" > "${distributionFilePath}.md5"␊ |
669 | echo ""␊ |
670 | ␊ |
671 | echo -e $COL_GREEN" --------------------------"$COL_RESET␊ |
672 | echo -e $COL_GREEN" Building process complete!"$COL_RESET␊ |
673 | echo -e $COL_GREEN" --------------------------"$COL_RESET␊ |
674 | echo ""␊ |
675 | echo -e $COL_GREEN" Build info."␊ |
676 | echo -e $COL_GREEN" ==========="␊ |
677 | echo -e $COL_BLUE" Package name: "$COL_RESET"${distributionFilename}"␊ |
678 | echo -e $COL_BLUE" MD5: "$COL_RESET"$md5"␊ |
679 | echo -e $COL_BLUE" Version: "$COL_RESET"$version"␊ |
680 | echo -e $COL_BLUE" Stage: "$COL_RESET"$stage"␊ |
681 | echo -e $COL_BLUE" Date/Time: "$COL_RESET"$builddate"␊ |
682 | echo ""␊ |
683 | ␊ |
684 | }␊ |
685 | ␊ |
686 | # build packages␊ |
687 | main␊ |
688 | ␊ |
689 | # build meta package␊ |
690 | makedistribution␊ |
691 | |