Chameleon

Chameleon Svn Source Tree

Root/branches/blackosx/package/buildpkg.sh

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

Archive Download this file

Revision: 1769