Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Enoch/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"
12declare -r SCPT_TPL_DIR="${PKGROOT}/Scripts.templates"
13
14# Add by FurtiF fix patch of brew gettext
15export PATH=${PATH}:/usr/local/opt/gettext/bin
16
17if [[ $# -lt 3 ]];then
18 echo "Too few arguments. Aborting..." >&2 && exit 1
19fi
20
21if [[ ! -d "$SYMROOT" ]];then
22 echo "Directory ${SYMROOT} doesn't exit. Aborting..." >&2 && exit 1
23fi
24
25# Prevent the script from doing bad things
26set -u # Abort with unset variables
27#set -e # Abort with any error can be suppressed locally using EITHER cmd||true OR set -e;cmd;set +e
28
29# ====== LANGUAGE SETUP ======
30export LANG='en_US.UTF-8'
31export LC_COLLATE='C'
32export LC_CTYPE='C'
33
34# ====== CONFIGURATION ======
35CONFIG_MODULES=""
36CONFIG_ACPICODEC_MODULE=""
37CONFIG_AMDGE_MODULE=""
38CONFIG_GRAPHICSENABLER_MODULE=""
39CONFIG_GMAGE_MODULE=""
40CONFIG_NVIDIAGE_MODULE=""
41CONFIG_KERNELPATCHER_MODULE=""
42CONFIG_KEXTPATCHER_MODULE=""
43CONFIG_KEYLAYOUT_MODULE=""
44CONFIG_KLIBC_MODULE=""
45CONFIG_RESOLUTION_MODULE=""
46CONFIG_HDAENABLER_MODULE=""
47CONFIG_FILENVRAM_MODULE=""
48CONFIG_SATA_MODULE=""
49CONFIG_UCLIBCXX_MODULE=""
50source "${SRCROOT}/auto.conf"
51
52# ====== COLORS ======
53declare -r COL_BLACK="\x1b[30;01m"
54declare -r COL_RED="\x1b[31;01m"
55declare -r COL_GREEN="\x1b[32;01m"
56declare -r COL_YELLOW="\x1b[33;01m"
57declare -r COL_MAGENTA="\x1b[35;01m"
58declare -r COL_CYAN="\x1b[36;01m"
59declare -r COL_WHITE="\x1b[37;01m"
60declare -r COL_BLUE="\x1b[34;01m"
61declare -r COL_RESET="\x1b[39;49;00m"
62
63# ====== REVISION/VERSION ======
64declare -r CHAMELEON_VERSION=$( cat version )
65
66# stage
67CHAMELEON_STAGE=${CHAMELEON_VERSION##*-}
68CHAMELEON_STAGE=${CHAMELEON_STAGE/RC/Release Candidate }
69CHAMELEON_STAGE=${CHAMELEON_STAGE/FINAL/2.1 Final}
70declare -r CHAMELEON_STAGE
71
72declare -r CHAMELEON_REVISION=$( grep I386BOOT_CHAMELEONREVISION vers.h | awk '{ print $3 }' | tr -d '\"' )
73declare -r CHAMELEON_BUILDDATE=$( grep I386BOOT_BUILDDATE vers.h | awk '{ print $3,$4 }' | tr -d '\"' )
74declare -r CHAMELEON_TIMESTAMP=$( date -j -f "%Y-%m-%d %H:%M:%S" "${CHAMELEON_BUILDDATE}" "+%s" )
75
76# ====== CREDITS ======
77declare -r CHAMELEON_DEVELOP=$(awk "NR==6{print;exit}" ${PKGROOT}/../CREDITS)
78declare -r CHAMELEON_CREDITS=$(awk "NR==10{print;exit}" ${PKGROOT}/../CREDITS)
79declare -r CHAMELEON_PKGDEV=$(awk "NR==14{print;exit}" ${PKGROOT}/../CREDITS)
80declare -r CHAMELEON_CPRYEAR=$(awk "NR==18{print;exit}" ${PKGROOT}/../CREDITS)"-"$( date +"%Y" )
81if [[ $(whoami | awk '{print $1}' | cut -d ":" -f3) == "admin" ]];then
82 declare -r CHAMELEON_WHOBUILD="VoodooLabs BuildBot"
83else
84 declare -r CHAMELEON_WHOBUILD=$(whoami | awk '{print $1}' | cut -d ":" -f3)
85fi
86
87# ====== GLOBAL VARIABLES ======
88declare -r LOG_FILENAME="Chameleon_Installer_Log.txt"
89
90declare -a chameleonOptionType
91declare -a chameleonOptionKey
92declare -a chameleonOptionValues
93
94declare -a pkgrefs
95declare -a choice_key
96declare -a choice_options
97declare -a choice_pkgrefs
98declare -a choice_parent_group_index
99declare -a choice_group_items
100declare -a choice_group_exclusive
101
102# Init Main Group
103choice_key[0]=""
104choice_options[0]=""
105choices_pkgrefs[0]=""
106choice_group_items[0]=""
107choice_group_exclusive[0]=""
108
109# Package name
110declare -r packagename="Enoch"
111
112# Package identifiers
113declare -r chameleon_package_identity="org.chameleon"
114declare -r modules_packages_identity="${chameleon_package_identity}.modules"
115
116# Stages sub group name (contain options to skip installing one or all the bootloader stages)
117stages="Stages"
118# ====== FUNCTIONS ======
119trim () {
120 local result="${1#"${1%%[![:space:]]*}"}" # remove leading whitespace characters
121 echo "${result%"${result##*[![:space:]]}"}" # remove trailing whitespace characters
122}
123
124function makeSubstitutions () {
125 # Substition is like: Key=Value
126 #
127 # Optional arguments:
128 # --subst=<substition> : add a new substitution
129 #
130 # Last argument(s) is/are file(s) where substitutions must be made
131
132 local ownSubst=""
133
134 function addSubst () {
135 local mySubst="$1"
136 case "$mySubst" in
137*=*) keySubst=${mySubst%%=*}
138 valSubst=${mySubst#*=}
139 ownSubst=$(printf "%s\n%s" "$ownSubst" "s&@$keySubst@&$valSubst&g;t t")
140 ;;
141*) echo "Invalid substitution $mySubst" >&2
142 exit 1
143 ;;
144esac
145 }
146
147 # Check the arguments.
148 while [[ $# -gt 0 ]];do
149 local option="$1"
150 case "$option" in
151 --subst=*) shift; addSubst "${option#*=}" ;;
152 -*)
153 echo "Unrecognized makeSubstitutions option '$option'" >&2
154 exit 1
155 ;;
156 *) break ;;
157 esac
158 done
159
160 if [[ $# -lt 1 ]];then
161 echo "makeSubstitutions invalid number of arguments: at least one file needed" >&2
162 exit 1
163 fi
164
165 local chameleonSubsts="
166s&%CHAMELEONVERSION%&${CHAMELEON_VERSION%%-*}&g
167s&%CHAMELEONREVISION%&${CHAMELEON_REVISION}&g
168s&%CHAMELEONSTAGE%&${CHAMELEON_STAGE}&g
169s&%DEVELOP%&${CHAMELEON_DEVELOP}&g
170s&%CREDITS%&${CHAMELEON_CREDITS}&g
171s&%PKGDEV%&${CHAMELEON_PKGDEV}&g
172s&%CPRYEAR%&${CHAMELEON_CPRYEAR}&g
173s&%WHOBUILD%&${CHAMELEON_WHOBUILD}&g
174:t
175/@[a-zA-Z_][a-zA-Z_0-9]*@/!b
176s&@LOG_FILENAME@&${LOG_FILENAME}&g;t t"
177
178 local allSubst="
179$chameleonSubsts
180$ownSubst"
181
182 # HACK: Don't try to substitute in TIFF files!
183 for file in "$@";do
184 if [ -z `echo "$file" | grep tiff` ]
185 then
186 cp -pf "$file" "${file}.in"
187 sed "$allSubst" "${file}.in" > "${file}"
188 rm -f "${file}.in"
189 fi
190 done
191}
192
193addTemplateScripts () {
194 # Arguments:
195 # --pkg-rootdir=<pkg_rootdir> : path of the pkg root dir
196 #
197 # Optional arguments:
198 # --subst=<substition> : add a new substitution
199 #
200 # Substition is like: Key=Value
201 #
202 # $n : Name of template(s) (templates are in package/Scripts.templates
203
204 local pkgRootDir=""
205 declare -a allSubst
206
207 # Check the arguments.
208 while [[ $# -gt 0 ]];do
209 local option="$1"
210 case "$option" in
211 --pkg-rootdir=*) shift; pkgRootDir="${option#*=}" ;;
212 --subst=*) shift; allSubst[${#allSubst[*]}]="${option}" ;;
213 -*)
214 echo "Unrecognized addTemplateScripts option '$option'" >&2
215 exit 1
216 ;;
217 *) break ;;
218 esac
219 done
220 if [[ $# -lt 1 ]];then
221 echo "addTemplateScripts invalid number of arguments: you must specify a template name" >&2
222 exit 1
223 fi
224 [[ -z "$pkgRootDir" ]] && { echo "Error addTemplateScripts: --pkg-rootdir option is needed" >&2 ; exit 1; }
225 [[ ! -d "$pkgRootDir" ]] && { echo "Error addTemplateScripts: directory '$pkgRootDir' doesn't exists" >&2 ; exit 1; }
226
227 for templateName in "$@";do
228 local templateRootDir="${SCPT_TPL_DIR}/${templateName}"
229 [[ ! -d "$templateRootDir" ]] && {
230 echo "Error addTemplateScripts: template '$templateName' doesn't exists" >&2; exit 1; }
231
232 # Copy files to destination
233 rsync -pr --exclude=.svn --exclude="*~" "$templateRootDir/" "$pkgRootDir/Scripts/"
234 done
235
236 files=$( find "$pkgRootDir/Scripts/" -type f )
237 if [[ ${#allSubst[*]} -gt 0 ]];then
238 makeSubstitutions "${allSubst[@]}" $files
239 else
240 makeSubstitutions $files
241 fi
242}
243
244getPackageRefId () {
245 echo ${1//_/.}.${2//_/.} | tr [:upper:] [:lower:]
246}
247
248# Return index of a choice
249getChoiceIndex () {
250 # $1 Choice Id
251 local found=0
252 for (( idx=0 ; idx < ${#choice_key[*]}; idx++ ));do
253 if [[ "${1}" == "${choice_key[$idx]}" ]];then
254 found=1
255 break
256 fi
257 done
258 echo "$idx"
259 return $found
260}
261
262# Add a new choice
263addChoice () {
264 # Optional arguments:
265 # --group=<group> : Group Choice Id
266 # --start-selected=<javascript code> : Specifies whether this choice is initially selected or unselected
267 # --start-enabled=<javascript code> : Specifies the initial enabled state of this choice
268 # --start-visible=<javascript code> : Specifies whether this choice is initially visible
269 # --pkg-refs=<pkgrefs> : List of package reference(s) id (separate by spaces)
270 #
271 # $1 Choice Id
272
273 local option
274 local groupChoice=""
275 local choiceOptions=""
276 local pkgrefs=""
277
278 # Check the arguments.
279 for option in "${@}";do
280 case "$option" in
281 --group=*)
282 shift; groupChoice=${option#*=} ;;
283 --selected=*)
284 shift; choiceOptions="$choiceOptions selected=\"${option#*=}\"" ;;
285 --enabled=*)
286 shift; choiceOptions="$choiceOptions enabled=\"${option#*=}\"" ;;
287 --start-selected=*)
288 shift; choiceOptions="$choiceOptions start_selected=\"${option#*=}\"" ;;
289 --start-enabled=*)
290 shift; choiceOptions="$choiceOptions start_enabled=\"${option#*=}\"" ;;
291 --start-visible=*)
292 shift; choiceOptions="$choiceOptions start_visible=\"${option#*=}\"" ;;
293 --pkg-refs=*)
294 shift; pkgrefs=${option#*=} ;;
295 -*)
296 echo "Unrecognized addChoice option '$option'" >&2
297 exit 1
298 ;;
299 *) break ;;
300 esac
301 done
302
303 if [[ $# -ne 1 ]];then
304 echo "addChoice invalid number of arguments: ${@}" >&2
305 exit 1
306 fi
307
308 local choiceId="${1}"
309
310 # Add choice in the group
311 idx_group=$(getChoiceIndex "$groupChoice")
312 found_group=$?
313 if [[ $found_group -ne 1 ]];then
314 # No group exist
315 echo "Error can't add choice '$choiceId' to group '$groupChoice': group choice '$groupChoice' doesn't exists." >&2
316 exit 1
317 else
318 set +u; oldItems=${choice_group_items[$idx_group]}; set -u
319 choice_group_items[$idx_group]="$oldItems $choiceId"
320 fi
321
322 # Check that the choice doesn't already exists
323 idx=$(getChoiceIndex "$choiceId")
324 found=$?
325 if [[ $found -ne 0 ]];then
326 # Choice already exists
327 echo "Error can't add choice '$choiceId': a choice with same name already exists." >&2
328 exit 1
329 fi
330
331 # Record new node
332 choice_key[$idx]="$choiceId"
333 choice_options[$idx]=$(trim "${choiceOptions}") # Removing leading and trailing whitespace(s)
334 choice_parent_group_index[$idx]=$idx_group
335 choice_pkgrefs[$idx]="$pkgrefs"
336
337 return $idx
338}
339
340# Add a group choice
341addGroupChoices() {
342 # Optional arguments:
343 # --parent=<parent> : parent group choice id
344 # --exclusive_zero_or_one_choice : only zero or one choice can be selected in the group
345 # --exclusive_one_choice : only one choice can be selected in the group
346 #
347 # $1 Choice Id
348
349 local option
350 local groupChoice=""
351 local exclusive_function=""
352
353 for option in "${@}";do
354 case "$option" in
355 --exclusive_zero_or_one_choice)
356 shift; exclusive_function="exclusive_zero_or_one_choice" ;;
357 --exclusive_one_choice)
358 shift; exclusive_function="exclusive_one_choice" ;;
359 --parent=*)
360 shift; groupChoice=${option#*=} ;;
361 -*)
362 echo "Unrecognized addGroupChoices option '$option'" >&2
363 exit 1
364 ;;
365 *) break ;;
366 esac
367 done
368
369 if [[ $# -ne 1 ]];then
370 echo "addGroupChoices invalid number of arguments: ${@}" >&2
371 exit 1
372 fi
373
374 addChoice --group="$groupChoice" "${1}"
375 local idx=$? # index of the new created choice
376
377 choice_group_exclusive[$idx]="$exclusive_function"
378}
379
380exclusive_one_choice () {
381 # $1 Current choice (ie: test1)
382 # $2..$n Others choice(s) (ie: "test2" "test3"). Current can or can't be in the others choices
383 local myChoice="${1}"
384 local result="";
385 local separator=' || ';
386 for choice in ${@:2};do
387 if [[ "$choice" != "$myChoice" ]];then
388 result="${result}choices['$choice'].selected${separator}";
389 fi
390 done
391 if [[ -n "$result" ]];then
392 echo "!(${result%$separator})"
393 fi
394}
395
396exclusive_zero_or_one_choice () {
397 # $1 Current choice (ie: test1)
398 # $2..$n Others choice(s) (ie: "test2" "test3"). Current can or can't be in the others choices
399 local myChoice="${1}"
400 local result;
401 echo "(my.choice.selected &amp;&amp; $(exclusive_one_choice ${@}))"
402}
403
404recordChameleonOption () {
405 local type="$1"
406 local key="$2"
407 local value="$3"
408
409 # Search for an existing key
410 local found=0
411 for (( idx=0 ; idx < ${#chameleonOptionKey[@]}; idx++ ));do
412 if [[ "$key" == "${chameleonOptionKey[$idx]}" ]];then
413 found=1
414 break
415 fi
416 done
417
418 # idx contain the index of a new key or an existing one
419 if [[ $found -eq 0 ]]; then
420 # Create a new one
421 chameleonOptionKey[$idx]="$key"
422 chameleonOptionType[$idx]="$type"
423 chameleonOptionValues[$idx]=""
424 fi
425
426 case "$type" in
427 bool) ;;
428 text|list) chameleonOptionValues[$idx]="${chameleonOptionValues[$idx]} $value" ;;
429 *) echo "Error unknown type '$type' for '$key'" >&2
430 exit 1
431 ;;
432 esac
433}
434
435generate_options_yaml_file () {
436 local yamlFile="$1"
437 echo "---" > $yamlFile
438 for (( idx=0; idx < ${#chameleonOptionKey[@]}; idx++ ));do
439 printf "%s:\n type: %s\n" "${chameleonOptionKey[$idx]}" "${chameleonOptionType[$idx]}" >> $yamlFile
440 case ${chameleonOptionType[$idx]} in
441 text|list)
442 printf " values:\n" >> $yamlFile
443 for value in ${chameleonOptionValues[$idx]};do
444 printf " - %s\n" "$value" >> $yamlFile
445 done
446 ;;
447 esac
448 done
449}
450
451main ()
452{
453
454# clean up the destination path
455
456 rm -R -f "${PKG_BUILD_DIR}"
457 echo ""
458 echo -e $COL_CYAN" ----------------------------------"$COL_RESET
459 echo -e $COL_CYAN" Building $packagename Install Package"$COL_RESET
460 echo -e $COL_CYAN" ----------------------------------"$COL_RESET
461 echo ""
462
463# Add pre install choice
464 echo "================= Preinstall ================="
465 packagesidentity="${chameleon_package_identity}"
466 choiceId="Pre"
467
468 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
469 addChoice --start-visible="false" --start-selected="true" --pkg-refs="$packageRefId" "${choiceId}"
470
471 # Package will be built at the end
472# End pre install choice
473
474# build core package
475 echo "================= Core ================="
476 packagesidentity="${chameleon_package_identity}"
477 choiceId="Core"
478 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
479 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
480 ditto --noextattr --noqtn ${SYMROOT}/i386/boot ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
481 ditto --noextattr --noqtn ${SYMROOT}/i386/boot0 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
482 ditto --noextattr --noqtn ${SYMROOT}/i386/boot0md ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
483 ditto --noextattr --noqtn ${SYMROOT}/i386/boot0hfs ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
484 ditto --noextattr --noqtn ${SYMROOT}/i386/boot1f32 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
485 ditto --noextattr --noqtn ${SYMROOT}/i386/boot1h ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
486 ditto --noextattr --noqtn ${SYMROOT}/i386/boot1x ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
487 ditto --noextattr --noqtn ${SYMROOT}/i386/boot1he ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
488 ditto --noextattr --noqtn ${SYMROOT}/i386/boot1hp ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
489 ditto --noextattr --noqtn ${SYMROOT}/i386/cdboot ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
490 ditto --noextattr --noqtn ${SYMROOT}/i386/chain0 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
491 ditto --noextattr --noqtn ${SYMROOT}/i386/fdisk440 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
492 ditto --noextattr --noqtn ${SYMROOT}/i386/sectorsize ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
493 ditto --noextattr --noqtn ${SYMROOT}/i386/boot1-install ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
494 ditto --noextattr --noqtn ${SYMROOT}/i386/bdmesg ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
495
496 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
497 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
498 addChoice --start-visible="false" --selected="choices['boot'].selected" --pkg-refs="$packageRefId" "${choiceId}"
499# End build core package
500
501# build boot choice package
502 choiceId="boot"
503 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
504 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts
505 cp -f ${PKGROOT}/Scripts/Main/BootYES ${PKG_BUILD_DIR}/${choiceId}/Scripts/postinstall
506
507 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
508 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
509 addChoice --start-visible="false" --selected="!choices['BootNo'].selected" \
510 --pkg-refs="$packageRefId" "${choiceId}"
511# End build boot choice package
512
513# build Chameleon package
514 echo "================= Chameleon ================="
515 addGroupChoices "Chameleon"
516
517 # build BootNo choice package
518 choiceId="BootNo"
519 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
520 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts
521 cp -f ${PKGROOT}/Scripts/Main/${choiceId} ${PKG_BUILD_DIR}/${choiceId}/Scripts/postinstall
522
523 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
524 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
525 addChoice --group="Chameleon" --start-selected="false" --selected="!(choices['boot'].selected || choices['SkipStage0'].selected || choices['SkipStage1'].selected || choices['SkipActivePartition'].selected)" \
526 --pkg-refs="$packageRefId" "${choiceId}"
527# End build BootNo choice package
528
529# build SkipStage0 choice package
530 choiceId="SkipStage0"
531 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
532 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts
533 cp -f ${PKGROOT}/Scripts/Main/${choiceId} ${PKG_BUILD_DIR}/${choiceId}/Scripts/postinstall
534
535 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
536 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
537 addChoice --group="Chameleon" --start-selected="false" --selected="!choices['BootNo'].selected &amp;&amp; choices['SkipStage0'].selected" \
538 --pkg-refs="$packageRefId" "${choiceId}"
539# End build SkipStage0 choice package
540
541# build SkipStage1 choice package
542 choiceId="SkipStage1"
543 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
544 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts
545 cp -f ${PKGROOT}/Scripts/Main/${choiceId} ${PKG_BUILD_DIR}/${choiceId}/Scripts/postinstall
546
547 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
548 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
549 addChoice --group="Chameleon" --start-selected="false" --selected="!choices['BootNo'].selected &amp;&amp; choices['SkipStage10'].selected" \
550 --pkg-refs="$packageRefId" "${choiceId}"
551# End build SkipStage1 choice package
552
553# build SkipActivePartition choice package
554 choiceId="SkipActivePartition"
555 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
556 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts
557 cp -f ${PKGROOT}/Scripts/Main/${choiceId} ${PKG_BUILD_DIR}/${choiceId}/Scripts/postinstall
558
559 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
560 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
561 addChoice --group="Chameleon" --start-selected="false" --selected="!choices['BootNo'].selected &amp;&amp; choices['SkipActivePartition'].selected" \
562 --pkg-refs="$packageRefId" "${choiceId}"
563# End build SkipActivePartition choice package
564
565# End build Chameleon package
566
567if [[ "${CONFIG_MODULES}" == 'y' ]];then
568# build Modules package
569 echo "================= Modules ================="
570 ###############################
571 # Supported Modules #
572 ###############################
573 # ACPICodec.dylib #
574 # AMDGraphicsEnabler.dylib #
575 # GraphicsEnabler.dylib #
576 # ATiGraphicsEnabler.dylib #
577 # FileNVRAM.dylib #
578 # HDAEnabler.dylib #
579 # HelloWorld.dylib #
580 # IntelGraphicsEnabler.dylib #
581 # KernelPatcher.dylib #
582 # KextPatcher.dylib #
583 # Keylayout.dylib #
584 # klibc.dylib #
585 # NVDIAGraphicEnabler.dylib #
586 # Resolution.dylib #
587 # Sata.dylib #
588 # uClibcxx.dylib #
589 ###############################
590 if [ "$(ls -A "${SYMROOT}/i386/modules")" ]; then
591 {
592 addGroupChoices "Module"
593
594# -
595 if [[ "${CONFIG_ACPICODEC_MODULE}" == 'm' && -f "${SYMROOT}/i386/modules/ACPICodec.dylib" ]]; then
596 {
597 # Start build ACPICodec package module
598 choiceId="ACPICodec"
599 moduleFile="ACPICodec.dylib"
600 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
601 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
602 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
603 --subst="moduleName=$choiceId" \
604 --subst="moduleFile=$moduleFile" \
605 InstallModule
606
607 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
608 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
609 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
610 # End build ACPICodec package module
611 }
612 fi
613# -
614 if [[ "${CONFIG_GRAPHICSENABLER_MODULE}" == 'm' && -f "${SYMROOT}/i386/modules/GraphicsEnabler.dylib" ]]; then
615 {
616 # Start build GraphicsEnabler package module
617 choiceId="GraphicsEnablerModule"
618 moduleFile="GraphicsEnabler.dylib"
619 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
620 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
621 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
622 --subst="moduleName=$choiceId" \
623 --subst="moduleFile=$moduleFile" \
624 InstallModule
625
626 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
627 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
628 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
629 # End build GraphicsEnabler package module
630 }
631 fi
632# -
633 if [[ "${CONFIG_NVIDIAGE_MODULE}" == 'y' && -f "${SYMROOT}/i386/modules/NVIDIAGraphicsEnabler.dylib" ]]; then
634 {
635 # Start build NvidiaGraphicsEnabler package module
636 choiceId="NVIDIAGraphicsEnabler"
637 moduleFile="NVIDIAGraphicEnabler.dylib"
638 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
639 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
640 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
641 --subst="moduleName=$choiceId" \
642 --subst="moduleFile=$moduleFile" \
643 InstallModule
644
645 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
646 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
647 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
648 # End build NvidiaGraphicsEnabler package module
649 }
650 fi
651# -
652 if [[ "${CONFIG_AMDGE_MODULE}" == 'y' && -f "${SYMROOT}/i386/modules/AMDGraphicsEnabler.dylib" ]]; then
653 {
654 # Start build AMDGraphicsEnabler package module
655 choiceId="AMDGraphicsEnabler"
656 moduleFile="AMDGraphicsEnabler.dylib"
657 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
658 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
659 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
660 --subst="moduleName=$choiceId" \
661 --subst="moduleFile=$moduleFile" \
662 InstallModule
663
664 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
665 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
666 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
667 # End build AMDGraphicsEnabler package module
668 }
669 fi
670# -
671 if [[ "${CONFIG_GMAGE_MODULE}" == 'y' && -f "${SYMROOT}/i386/modules/IntelGraphicsEnabler.dylib" ]]; then
672 {
673 # Start build IntelGraphicsEnabler package module
674 choiceId="IntelGraphicsEnabler"
675 moduleFile="IntelGraphicsEnabler.dylib"
676 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
677 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
678 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
679 --subst="moduleName=$choiceId" \
680 --subst="moduleFile=$moduleFile" \
681 InstallModule
682
683 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
684 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
685 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
686 # End build IntelGraphicsEnabler package module
687 }
688 fi
689# -
690 if [[ "${CONFIG_KERNELPATCHER_MODULE}" == 'y' && -f "${SYMROOT}/i386/modules/KernelPatcher.dylib" ]]; then
691 {
692 # Start build KernelPatcher package module
693 choiceId="KernelPatcher"
694 moduleFile="KernelPatcher.dylib"
695 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
696 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
697 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
698 --subst="moduleName=$choiceId" \
699 --subst="moduleFile=$moduleFile" \
700 InstallModule
701
702 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
703 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
704 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
705 # End build KernelPatcher package module
706 }
707 fi
708# -
709 if [[ "${CONFIG_KEXTPATCHER_MODULE}" == 'y' && -f "${SYMROOT}/i386/modules/KextPatcher.dylib" ]]; then
710 {
711 # Start build KextPatcher package module
712 choiceId="KextPatcher"
713 moduleFile="KextPatcher.dylib"
714 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
715 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
716 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
717 --subst="moduleName=$choiceId" \
718 --subst="moduleFile=$moduleFile" \
719 InstallModule
720
721 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
722 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
723 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
724 # End build KextPatcher package module
725 }
726 fi
727# -
728 # Warning Keylayout module need additional files
729 if [[ "${CONFIG_KEYLAYOUT_MODULE}" = 'm' && -f "${SYMROOT}/i386/modules/Keylayout.dylib" ]]; then
730 {
731 # Start build Keylayout package module
732 choiceId="Keylayout"
733 moduleFile="${choiceId}.dylib"
734 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root/EXTRAROOTDIR/Extra/{modules,Keymaps}
735 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
736 layout_src_dir="${SRCROOT}/i386/modules/Keylayout/layouts/layouts-src"
737 if [ -d "$layout_src_dir" ];then
738 # Create a tar.gz from layout sources
739 (cd "$layout_src_dir"; \
740 tar czf "${PKG_BUILD_DIR}/${choiceId}/Root/EXTRAROOTDIR/Extra/Keymaps/layouts-src.tar.gz" README *.slt)
741 fi
742 # Adding module
743 ditto --noextattr --noqtn ${SYMROOT}/i386/modules/$moduleFile ${PKG_BUILD_DIR}/${choiceId}/Root/EXTRAROOTDIR/Extra/modules
744 # Adding Keymaps
745 ditto --noextattr --noqtn ${SRCROOT}/Keymaps ${PKG_BUILD_DIR}/${choiceId}/Root/EXTRAROOTDIR/Extra/Keymaps
746 # Adding tools
747 ditto --noextattr --noqtn ${SYMROOT}/i386/cham-mklayout ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
748 # Adding scripts
749 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
750 --subst="moduleName=$choiceId" \
751 --subst="moduleFile=$moduleFile" \
752 InstallModule
753
754 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
755 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
756
757 # Don't add a choice for Keylayout module
758 # addChoice "${choiceId}" "Module" --start-selected="false" "$packageRefId"
759 # End build Keylayout package module
760 }
761 fi
762# -
763 if [[ "${CONFIG_KLIBC_MODULE}" == 'm' && -f "${SYMROOT}/i386/modules/klibc.dylib" ]]; then
764 {
765 # Start build klibc package module
766 choiceId="klibc"
767 moduleFile="${choiceId}.dylib"
768 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
769 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" ${PKG_BUILD_DIR}/${choiceId}/Root
770 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
771 --subst="moduleName=$choiceId" \
772 --subst="moduleFile=$moduleFile" \
773 InstallModule
774
775 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
776 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
777 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
778 # End build klibc package module
779 }
780 fi
781# -
782 if [[ "${CONFIG_RESOLUTION_MODULE}" == 'm' && -f "${SYMROOT}/i386/modules/Resolution.dylib" ]]; then
783 {
784 # Start build Resolution package module
785 choiceId="AutoReso"
786 moduleFile="Resolution.dylib"
787 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
788 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
789 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
790 --subst="moduleName=$choiceId" \
791 --subst="moduleFile=$moduleFile" \
792 InstallModule
793
794 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
795 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
796 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
797 # End build Resolution package module
798 }
799 fi
800# -
801 if [[ "${CONFIG_HDAENABLER_MODULE}" == 'y' && -f "${SYMROOT}/i386/modules/HDAEnabler.dylib" ]]; then
802 {
803 # Start build HDAEnabler package module
804 choiceId="HDAEnabler"
805 moduleFile="HDAEnabler.dylib"
806 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
807 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
808 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
809 --subst="moduleName=$choiceId" \
810 --subst="moduleFile=$moduleFile" \
811 InstallModule
812
813 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
814 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
815 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
816 # End build HDAEnabler package module
817 }
818 fi
819# -
820 if [[ "${CONFIG_FILENVRAM_MODULE}" == 'y' && -f "${SYMROOT}/i386/modules/FileNVRAM.dylib" ]]; then
821 {
822 # Start build FileNVRAM package module
823 choiceId="FileNVRAM"
824 moduleFile="FileNVRAM.dylib"
825 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
826 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
827 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
828 --subst="moduleName=$choiceId" \
829 --subst="moduleFile=$moduleFile" \
830 InstallModule
831
832 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
833 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
834 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
835 # End build FileNVRAM package module
836 }
837 fi
838# -
839 if [[ "${CONFIG_SATA_MODULE}" == 'm' && -f "${SYMROOT}/i386/modules/Sata.dylib" ]]; then
840 {
841 # Start build Sata package module
842 choiceId="Sata"
843 moduleFile="Sata.dylib"
844 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
845 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
846 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
847 --subst="moduleName=$choiceId" \
848 --subst="moduleFile=$moduleFile" \
849 InstallModule
850
851 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
852 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
853 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
854 # End build Sata package module
855 }
856 fi
857# -
858 if [[ "${CONFIG_UCLIBCXX_MODULE}" = 'm' && -n "${CONFIG_KLIBC_MODULE}" && \
859 -f "${SYMROOT}/i386/modules/uClibcxx.dylib" ]]; then
860 {
861 klibcPackageRefId=""
862 if [[ "${CONFIG_KLIBC_MODULE}" == 'm' ]];then
863 klibcPackageRefId=$(getPackageRefId "${modules_packages_identity}" "klibc")
864 fi
865 # Start build uClibc package module
866 choiceId="uClibc"
867 moduleFile="uClibcxx.dylib"
868 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
869 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
870 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
871 --subst="moduleName=$choiceId" \
872 --subst="moduleFile=$moduleFile" \
873 InstallModule
874
875 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
876 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/EXTRAROOTDIR/Extra/modules"
877 # Add the klibc package because the uClibc module is dependent of klibc module
878 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId $klibcPackageRefId" "${choiceId}"
879 # End build uClibc package module
880 }
881 fi
882# -
883 }
884 else
885 {
886 echo " -= no modules to include =-"
887 }
888 fi
889# End build Modules packages
890fi
891
892# build Options packages
893
894 addGroupChoices "Options"
895
896 # ------------------------------------------------------
897 # parse OptionalSettings folder to find files of boot options.
898 # ------------------------------------------------------
899 OptionalSettingsFolder="${PKGROOT}/OptionalSettings"
900
901 while IFS= read -r -d '' OptionsFile; do
902
903 # Take filename and strip .txt from end and path from front
904 builtOptionsList=${OptionsFile%.txt}
905 builtOptionsList=${builtOptionsList##*/}
906 packagesidentity="${chameleon_package_identity}.options.$builtOptionsList"
907
908 echo "================= $builtOptionsList ================="
909
910 # ------------------------------------------------------
911 # Read boot option file into an array.
912 # ------------------------------------------------------
913 availableOptions=() # array to hold the list of boot options, per 'section'.
914 exclusiveFlag="" # used to indicate list has exclusive options
915 while read textLine; do
916 # ignore lines in the file beginning with a #
917 [[ $textLine = \#* ]] && continue
918 local optionName="" key="" value=""
919 case "$textLine" in
920 Exclusive=[Tt][Rr][Uu][Ee]) exclusiveFlag="--exclusive_zero_or_one_choice" ;;
921 Exclusive=*) continue ;;
922 *@*:*=*)
923 availableOptions[${#availableOptions[*]}]="$textLine" ;;
924 *) echo "Error: invalid line '$textLine' in file '$OptionsFile'" >&2
925 exit 1
926 ;;
927 esac
928 done < "$OptionsFile"
929
930 addGroupChoices --parent="Options" $exclusiveFlag "${builtOptionsList}"
931
932 # ------------------------------------------------------
933 # Loop through options in array and process each in turn
934 # ------------------------------------------------------
935 for textLine in "${availableOptions[@]}"; do
936 # split line - taking all before ':' as option name
937 # and all after ':' as key/value
938 type=$( echo "${textLine%%@*}" | tr '[:upper:]' '[:lower:]' )
939 tmp=${textLine#*@}
940 optionName=${tmp%%:*}
941 keyValue=${tmp##*:}
942 key=${keyValue%%=*}
943 value=${keyValue#*=}
944
945 # create folders required for each boot option
946 mkdir -p "${PKG_BUILD_DIR}/$optionName/Root/"
947
948 case "$type" in
949 bool) startSelected="check_chameleon_bool_option('$key','$value')" ;;
950 text) startSelected="check_chameleon_text_option('$key','$value')" ;;
951 list) startSelected="check_chameleon_list_option('$key','$value')" ;;
952 *) echo "Error: invalid type '$type' in line '$textLine' in '$OptionsFile'" >&2
953 exit 1
954 ;;
955 esac
956 recordChameleonOption "$type" "$key" "$value"
957 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/$optionName" \
958 --subst="optionType=$type" \
959 --subst="optionKey=$key" \
960 --subst="optionValue=$value" \
961 AddOption
962 packageRefId=$(getPackageRefId "${packagesidentity}" "${optionName}")
963 buildpackage "$packageRefId" "${optionName}" "${PKG_BUILD_DIR}/${optionName}" "/"
964 addChoice --group="${builtOptionsList}" \
965 --start-selected="$startSelected" \
966 --pkg-refs="$packageRefId" "${optionName}"
967 done
968
969 done < <( find "${OptionalSettingsFolder}" -depth 1 -type f -name '*.txt' -print0 )
970
971# End build options packages
972
973if [[ -n "${CONFIG_KEYLAYOUT_MODULE}" ]];then
974# build Keymaps options packages
975 echo "================= Keymaps Options ================="
976 addGroupChoices --exclusive_zero_or_one_choice "Keymaps"
977 packagesidentity="${chameleon_package_identity}.options.keymaps"
978 keylayoutPackageRefId=""
979 if [[ "${CONFIG_MODULES}" == 'y' && "${CONFIG_KEYLAYOUT_MODULE}" = 'm' ]];then
980 keylayoutPackageRefId=$(getPackageRefId "${modules_packages_identity}" "Keylayout")
981 fi
982
983 chameleon_keylayout_key="KeyLayout"
984 # ------------------------------------------------------
985 # Available Keylayout boot options are discovered by
986 # reading contents of /Keymaps folder after compilation
987 # ------------------------------------------------------
988 availableOptions=($( find "${SRCROOT}/Keymaps" -type f -depth 1 -name '*.lyt' | sed 's|.*/||;s|\.lyt||' ))
989 # Adjust array contents to match expected format
990 # for boot options which is: name:key=value
991 for (( i = 0 ; i < ${#availableOptions[@]} ; i++ )); do
992 # Start build of a keymap package module
993 choiceId="${availableOptions[i]}"
994 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
995
996 recordChameleonOption "text" "$chameleon_keylayout_key" "$choiceId"
997 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
998 --subst="optionType=text" \
999 --subst="optionKey=$chameleon_keylayout_key" \
1000 --subst="optionValue=$choiceId" \
1001 AddOption
1002 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
1003 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
1004 # Add the Keylayout package because the Keylayout module is needed
1005 addChoice --group="Keymaps" \
1006 --start-selected="check_chameleon_text_option('${chameleon_keylayout_key}','${choiceId}')" \
1007 --pkg-refs="$packageRefId $keylayoutPackageRefId" "${choiceId}"
1008 done
1009
1010# End build Keymaps options packages
1011fi
1012
1013# build theme packages
1014 echo "================= Themes ================="
1015 addGroupChoices "Themes"
1016
1017 # Using themes section from Azi's/package branch.
1018 packagesidentity="${chameleon_package_identity}.themes"
1019 artwork="${SRCROOT}/artwork/themes"
1020 themes=($( find "${artwork}" -type d -depth 1 -not -name '.svn' ))
1021 for (( i = 0 ; i < ${#themes[@]} ; i++ )); do
1022 themeName=$( echo ${themes[$i]##*/} | awk 'BEGIN{OFS=FS=""}{$1=toupper($1);print}' )
1023 themeDir="$themeName"
1024 mkdir -p "${PKG_BUILD_DIR}/${themeName}/Root/"
1025 rsync -r --exclude=.svn --exclude="*~" "${themes[$i]}/" "${PKG_BUILD_DIR}/${themeName}/Root/${themeName}"
1026 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${themeName}" \
1027 --subst="themeName=$themeName" \
1028 --subst="themeDir=$themeDir" \
1029 InstallTheme
1030
1031 packageRefId=$(getPackageRefId "${packagesidentity}" "${themeName}")
1032 buildpackage "$packageRefId" "${themeName}" "${PKG_BUILD_DIR}/${themeName}" "/EXTRAROOTDIR/Extra/Themes"
1033 addChoice --group="Themes" --start-selected="false" --pkg-refs="$packageRefId" "${themeName}"
1034 done
1035# End build theme packages# End build Extras package
1036
1037# build standard package
1038echo "================ standard ================"
1039 packagesidentity="${chameleon_package_identity}"
1040 choiceId="Standard"
1041 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
1042 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources
1043 local yamlFile="Resources/chameleon_options.yaml"
1044 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
1045 --subst="YAML_FILE=${yamlFile}" CleanOptions
1046 generate_options_yaml_file "${PKG_BUILD_DIR}/${choiceId}/Scripts/$yamlFile"
1047 cp -f ${PKGROOT}/Scripts/Main/${choiceId}postinstall ${PKG_BUILD_DIR}/${choiceId}/Scripts/postinstall
1048 ditto --arch i386 `which SetFile` ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources/SetFile
1049
1050 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
1051 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
1052 addChoice --group="Chameleon" --start-selected="true" --selected="!choices['EFI'].selected" \
1053 --pkg-refs="$packageRefId" "${choiceId}"
1054# End build standard package
1055
1056# build efi package
1057echo "================== EFI =================="
1058 packagesidentity="${chameleon_package_identity}"
1059 choiceId="EFI"
1060 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
1061 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources
1062 local yamlFile="Resources/chameleon_options.yaml"
1063 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
1064 --subst="YAML_FILE=${yamlFile}" CleanOptions
1065 generate_options_yaml_file "${PKG_BUILD_DIR}/${choiceId}/Scripts/$yamlFile"
1066 cp -f ${PKGROOT}/Scripts/Main/ESPpostinstall ${PKG_BUILD_DIR}/${choiceId}/Scripts/postinstall
1067 ditto --arch i386 `which SetFile` ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources/SetFile
1068
1069 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
1070 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
1071 addChoice --group="Chameleon" --enabled="systemHasGPT()" --start-selected="false" \
1072 --selected="!choices['Standard'].selected" \
1073 --pkg-refs="$packageRefId" "${choiceId}"
1074# End build efi package
1075
1076# build pre install package
1077 echo "================= Pre ================="
1078 packagesidentity="${chameleon_package_identity}"
1079 choiceId="Pre"
1080
1081 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
1082 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
1083 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" ${choiceId}
1084 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
1085# End build pre install package
1086
1087# build post install package
1088 echo "================= Post ================="
1089 packagesidentity="${chameleon_package_identity}"
1090 choiceId="Post"
1091 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
1092 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" ${choiceId}
1093
1094 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
1095 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
1096 addChoice --start-visible="false" --start-selected="true" --pkg-refs="$packageRefId" "${choiceId}"
1097# End build post install package
1098
1099}
1100
1101buildpackage ()
1102{
1103 # $1 Package Reference Id (ie: org.chameleon.themes.default)
1104 # $2 Package Name (ie: Default)
1105 # $3 Path to package to build containing Root and/or Scripts
1106 # $4 Target install location
1107 # $5 Size (optional)
1108 if [[ -d "${3}/Root" ]]; then
1109 local packageRefId="$1"
1110 local packageName="$2"
1111 local packagePath="$3"
1112 local targetPath="$4"
1113 set +u # packageSize is optional
1114 local packageSize="$5"
1115 set -u
1116
1117 echo -e "\t[BUILD] ${packageName}"
1118
1119 find "${packagePath}" -name '.DS_Store' -delete
1120 local filecount=$( find "${packagePath}/Root" | wc -l )
1121 if [ "${packageSize}" ]; then
1122 local installedsize="${packageSize}"
1123 else
1124 local installedsize=$( du -hkc "${packagePath}/Root" | tail -n1 | awk {'print $1'} )
1125 fi
1126 local header="<?xml version=\"1.0\"?>\n<pkg-info format-version=\"2\" "
1127
1128 #[ "${3}" == "relocatable" ] && header+="relocatable=\"true\" "
1129
1130 header+="identifier=\"${packageRefId}\" "
1131 header+="version=\"${CHAMELEON_VERSION}\" "
1132
1133 [ "${targetPath}" != "relocatable" ] && header+="install-location=\"${targetPath}\" "
1134
1135 header+="auth=\"root\">\n"
1136 header+="\t<payload installKBytes=\"${installedsize##* }\" numberOfFiles=\"${filecount##* }\"/>\n"
1137 rm -R -f "${packagePath}/Temp"
1138
1139 [ -d "${packagePath}/Temp" ] || mkdir -m 777 "${packagePath}/Temp"
1140 [ -d "${packagePath}/Root" ] && mkbom "${packagePath}/Root" "${packagePath}/Temp/Bom"
1141
1142 if [ -d "${packagePath}/Scripts" ]; then
1143 header+="\t<scripts>\n"
1144 for script in $( find "${packagePath}/Scripts" -type f \( -name 'pre*' -or -name 'post*' \) ); do
1145 header+="\t\t<${script##*/} file=\"./${script##*/}\"/>\n"
1146 done
1147 header+="\t</scripts>\n"
1148 # Create the Script archive file (cpio format)
1149 (cd "${packagePath}/Scripts" && find . -print | \
1150 cpio -o -z -R root:wheel --format cpio > "${packagePath}/Temp/Scripts") 2>&1 | \
1151 grep -vE '^[0-9]+\s+blocks?$' # to remove cpio stderr messages
1152 fi
1153
1154 header+="</pkg-info>"
1155 echo -e "${header}" > "${packagePath}/Temp/PackageInfo"
1156
1157 # Create the Payload file (cpio format)
1158 (cd "${packagePath}/Root" && find . -print | \
1159 cpio -o -z -R root:wheel --format cpio > "${packagePath}/Temp/Payload") 2>&1 | \
1160 grep -vE '^[0-9]+\s+blocks?$' # to remove cpio stderr messages
1161
1162 # Create the package
1163 (cd "${packagePath}/Temp" && xar -c -f "${packagePath}/../${packageName}.pkg" --compression none .)
1164
1165 # Add the package to the list of build packages
1166 pkgrefs[${#pkgrefs[*]}]="\t<pkg-ref id=\"${packageRefId}\" installKBytes='${installedsize}' version='${CHAMELEON_VERSION}.0.0.${CHAMELEON_TIMESTAMP}'>#${packageName}.pkg</pkg-ref>"
1167
1168 rm -rf "${packagePath}"
1169 fi
1170}
1171
1172generateOutlineChoices() {
1173 # $1 Main Choice
1174 # $2 indent level
1175 local idx=$(getChoiceIndex "$1")
1176 local indentLevel="$2"
1177 local indentString=""
1178 for ((level=1; level <= $indentLevel ; level++)); do
1179 indentString="\t$indentString"
1180 done
1181 set +u; subChoices="${choice_group_items[$idx]}"; set -u
1182 if [[ -n "${subChoices}" ]]; then
1183 # Sub choices exists
1184 echo -e "$indentString<line choice=\"$1\">"
1185 for subChoice in $subChoices;do
1186 case "$subChoice" in
1187 BootNo)
1188 echo -e "$indentString<line choice=\"${stages}\">"
1189 ;;
1190 Standard)
1191 echo -e "$indentString</line>"
1192 ;;
1193 esac
1194 generateOutlineChoices $subChoice $(($indentLevel+1))
1195 done
1196 echo -e "$indentString</line>"
1197 else
1198 echo -e "$indentString<line choice=\"$1\"/>"
1199 fi
1200}
1201
1202generateChoices() {
1203
1204 for (( idx=1; idx < ${#choice_key[*]} ; idx++)); do
1205 local choiceId=${choice_key[$idx]}
1206 local choiceOptions=${choice_options[$idx]}
1207 local choiceParentGroupIndex=${choice_parent_group_index[$idx]}
1208 set +u; local group_exclusive=${choice_group_exclusive[$choiceParentGroupIndex]}; set -u
1209
1210 # Create the node and standard attributes
1211 local choiceNode="\t<choice\n\t\tid=\"${choiceId}\"\n\t\ttitle=\"${choiceId}_title\"\n\t\tdescription=\"${choiceId}_description\""
1212
1213 # Add options like start_selected, etc...
1214 [[ -n "${choiceOptions}" ]] && choiceNode="${choiceNode}\n\t\t${choiceOptions}"
1215
1216 # Add the selected attribute if options are mutually exclusive
1217 if [[ -n "$group_exclusive" ]];then
1218 local group_items="${choice_group_items[$choiceParentGroupIndex]}"
1219 case $group_exclusive in
1220 exclusive_one_choice)
1221 local selected_option=$(exclusive_one_choice "$choiceId" "$group_items") ;;
1222 exclusive_zero_or_one_choice)
1223 local selected_option=$(exclusive_zero_or_one_choice "$choiceId" "$group_items") ;;
1224 *) echo "Error: unknown function to generate exclusive mode '$group_exclusive' for group '${choice_key[$choiceParentGroupIndex]}'" >&2
1225 exit 1
1226 ;;
1227 esac
1228 choiceNode="${choiceNode}\n\t\tselected=\"$selected_option\""
1229 fi
1230
1231 choiceNode="${choiceNode}>"
1232
1233 # Add the package references
1234 for pkgRefId in ${choice_pkgrefs[$idx]};do
1235 choiceNode="${choiceNode}\n\t\t<pkg-ref id=\"${pkgRefId}\"/>"
1236 done
1237
1238 # Close the node
1239 choiceNode="${choiceNode}\n\t</choice>\n"
1240 # Adding Stages subgroup
1241 if [[ "${choiceId}" = "Chameleon" ]];then
1242 choiceNode="${choiceNode}\t<choice\n\t\tid=\"${stages}\"\n\t\ttitle=\"${stages}_title\"\n\t\tdescription=\"${stages}_description\">\n\t</choice>\n\n"
1243 fi
1244
1245 echo -e "$choiceNode"
1246 done
1247}
1248
1249makedistribution ()
1250{
1251 declare -r distributionDestDir="${SYMROOT}"
1252 declare -r distributionFilename="${packagename// /}-rev.${CHAMELEON_REVISION}.pkg"
1253 declare -r distributionFilePath="${distributionDestDir}/${distributionFilename}"
1254
1255 rm -f "${distributionDestDir}/${packagename// /}"*.pkg
1256
1257 mkdir -p "${PKG_BUILD_DIR}/${packagename}"
1258
1259 find "${PKG_BUILD_DIR}" -type f -name '*.pkg' -depth 1 | while read component
1260 do
1261 pkg="${component##*/}" # ie: EFI.pkg
1262 pkgdir="${PKG_BUILD_DIR}/${packagename}/${pkg}"
1263 # expand individual packages
1264 pkgutil --expand "${PKG_BUILD_DIR}/${pkg}" "$pkgdir"
1265 rm -f "${PKG_BUILD_DIR}/${pkg}"
1266 done
1267
1268# Create the Distribution file
1269 ditto --noextattr --noqtn "${PKGROOT}/Distribution" "${PKG_BUILD_DIR}/${packagename}/Distribution"
1270
1271 local start_indent_level=2
1272 echo -e "\n\t<choices-outline>" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
1273
1274 for main_choice in ${choice_group_items[0]};do
1275 generateOutlineChoices $main_choice $start_indent_level >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
1276 done
1277 echo -e "\t</choices-outline>\n" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
1278
1279 generateChoices >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
1280
1281 for (( i=0; i < ${#pkgrefs[*]} ; i++)); do
1282 echo -e "${pkgrefs[$i]}" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
1283 done
1284
1285 echo -e "\n</installer-gui-script>" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
1286
1287# Create the Resources directory
1288 ditto --noextattr --noqtn "${PKGROOT}/Resources/distribution" "${PKG_BUILD_DIR}/${packagename}/Resources"
1289
1290# Make the translation
1291 echo ""
1292 echo "========= Translating Resources ========"
1293 (cd "${PKGROOT}" && PERLLIB=${PKGROOT}/bin/po4a/lib \
1294 bin/po4a/po4a \
1295 --package-name 'Chameleon' \
1296 --package-version "${CHAMELEON_VERSION}-r${CHAMELEON_REVISION}" \
1297 --msgmerge-opt '--lang=$lang' \
1298 --variable PODIR="po" \
1299 --variable TEMPLATES_DIR="Resources/templates" \
1300 --variable OUTPUT_DIR="${PKG_BUILD_DIR}/${packagename}/Resources" \
1301 ${PKGROOT}/po4a-chameleon.cfg)
1302
1303 # Copy common files in english localisation directory
1304 ditto --noextattr --noqtn "${PKGROOT}/Resources/common" "${PKG_BUILD_DIR}/${packagename}/Resources/en.lproj"
1305
1306 # CleanUp the directory
1307 find "${PKG_BUILD_DIR}/${packagename}" -name .svn -print0 | xargs -0 rm -rf
1308 find "${PKG_BUILD_DIR}/${packagename}" -name '*.DS_Store' -type f -delete
1309 find "${PKG_BUILD_DIR}/${packagename}" -type d -depth -empty -exec rmdir {} \; # Remove empty directories
1310
1311 # Make substitutions for version, revision, stage, developers, credits, etc..
1312 makeSubstitutions $( find "${PKG_BUILD_DIR}/${packagename}/Resources" -type f )
1313
1314# Create the final package
1315 pkgutil --flatten "${PKG_BUILD_DIR}/${packagename}" "${distributionFilePath}"
1316
1317##################################################################
1318# Here is the place to assign an icon to the pkg #
1319# command used to generate the file: #
1320# ditto -c -k --sequesterRsrc --keepParent Icon.icns Icon.zip #
1321##################################################################
1322 ditto -xk "${PKGROOT}/Icons/pkg.zip" "${PKG_BUILD_DIR}/Icons/"
1323 DeRez -only icns "${PKG_BUILD_DIR}/Icons/Icons/pkg.icns" > "${PKG_BUILD_DIR}/Icons/tempicns.rsrc"
1324 Rez -append "${PKG_BUILD_DIR}/Icons/tempicns.rsrc" -o "${distributionFilePath}"
1325 SetFile -a C "${distributionFilePath}"
1326 rm -rf "${PKG_BUILD_DIR}/Icons"
1327
1328# End
1329
1330 md5=$( md5 "${distributionFilePath}" | awk {'print $4'} )
1331 echo "MD5 (${distributionFilePath}) = ${md5}" > "${distributionFilePath}.md5"
1332 echo ""
1333
1334 echo -e $COL_GREEN" --------------------------"$COL_RESET
1335 echo -e $COL_GREEN" Building process complete!"$COL_RESET
1336 echo -e $COL_GREEN" --------------------------"$COL_RESET
1337 echo ""
1338 echo -e $COL_GREEN" Build info."
1339 echo -e $COL_GREEN" ==========="
1340 echo -e $COL_CYAN" Package name: "$COL_RESET"${distributionFilename}"
1341 echo -e $COL_CYAN" MD5: "$COL_RESET"$md5"
1342 echo -e $COL_CYAN" Version: "$COL_RESET"$CHAMELEON_VERSION"
1343 echo -e $COL_CYAN" Stage: "$COL_RESET"$CHAMELEON_STAGE"
1344 echo -e $COL_CYAN" Date/Time: "$COL_RESET"$CHAMELEON_BUILDDATE"
1345 echo -e $COL_CYAN" Built by: "$COL_RESET"$CHAMELEON_WHOBUILD"
1346 echo -e $COL_CYAN" Copyright $CHAMELEON_CPRYEAR ""$COL_RESET"
1347 echo ""
1348
1349}
1350
1351# build packages
1352main
1353
1354# build meta package
1355makedistribution
1356

Archive Download this file

Revision: 2679