Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 2238