Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 2450