Chameleon

Chameleon Svn Source Tree

Root/trunk/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/boot0xg ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
474 ditto --noextattr --noqtn ${SYMROOT}/i386/boot1f32 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
475 ditto --noextattr --noqtn ${SYMROOT}/i386/boot1h ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
476# ditto --noextattr --noqtn ${SYMROOT}/i386/boot1x ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
477 ditto --noextattr --noqtn ${SYMROOT}/i386/boot1he ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
478 ditto --noextattr --noqtn ${SYMROOT}/i386/boot1hp ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
479 ditto --noextattr --noqtn ${SYMROOT}/i386/cdboot ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
480 ditto --noextattr --noqtn ${SYMROOT}/i386/chain0 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
481 ditto --noextattr --noqtn ${SYMROOT}/i386/fdisk440 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
482 ditto --noextattr --noqtn ${SYMROOT}/i386/boot1-install ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
483 ditto --noextattr --noqtn ${SYMROOT}/i386/bdmesg ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
484
485 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
486 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
487 addChoice --start-visible="false" --start-selected="true" --pkg-refs="$packageRefId" "${choiceId}"
488# End build core package
489
490# build Chameleon package
491 echo "================= Chameleon ================="
492 addGroupChoices --exclusive_one_choice "Chameleon"
493
494 # build standard package
495 choiceId="Standard"
496 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
497 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources
498 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" InstallerLog
499 cp -f ${PKGROOT}/Scripts/Main/${choiceId}postinstall ${PKG_BUILD_DIR}/${choiceId}/Scripts/postinstall
500 cp -f ${PKGROOT}/Scripts/Sub/* ${PKG_BUILD_DIR}/${choiceId}/Scripts
501 ditto --arch i386 `which SetFile` ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources/SetFile
502
503 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
504 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
505 addChoice --group="Chameleon" --start-selected="true" --pkg-refs="$packageRefId" "${choiceId}"
506 # End build standard package
507
508 # build efi package
509if [[ 1 -eq 0 ]];then
510 # Only standard installation is currently supported
511 # We need to update the script to be able to install
512 # Chameleon on EFI partition
513 choiceId="EFI"
514 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
515 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources
516 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" InstallerLog
517 cp -f ${PKGROOT}/Scripts/Main/ESPpostinstall ${PKG_BUILD_DIR}/${choiceId}/Scripts/postinstall
518 cp -f ${PKGROOT}/Scripts/Sub/* ${PKG_BUILD_DIR}/${choiceId}/Scripts
519 ditto --arch i386 `which SetFile` ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources/SetFile
520
521 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
522 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
523 addChoice --group="Chameleon" --start-visible="systemHasGPT()" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
524 # End build efi package
525fi
526 # build no bootloader choice package
527 choiceId="noboot"
528 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
529
530 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
531 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
532 addChoice --group="Chameleon" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
533 # End build no bootloader choice package
534
535# End build Chameleon package
536
537if [[ "${CONFIG_MODULES}" == 'y' ]];then
538# build Modules package
539 echo "================= Modules ================="
540 ###############################
541 # Supported Modules #
542 ###############################
543 # ACPICodec.dylib #
544 # AMDGraphicsEnabler.dylib #
545 # ATiGraphicsEnabler.dylib #
546 # FileNVRAM.dylib #
547 # HDAEnabler.dylib #
548 # HelloWorld.dylib #
549 # IntelGraphicsEnabler.dylib #
550 # KernelPatcher.dylib #
551 # KextPatcher.dylib #
552 # Keylayout.dylib #
553 # klibc.dylib #
554 # NVDIAGraphicEnabler.dylib #
555 # Resolution.dylib #
556 # Sata.dylib #
557 # uClibcxx.dylib #
558 ###############################
559 if [ "$(ls -A "${SYMROOT}/i386/modules")" ]; then
560 {
561 addGroupChoices "Module"
562
563# -
564 if [[ "${CONFIG_ACPICODEC_MODULE}" == 'm' && -f "${SYMROOT}/i386/modules/ACPICodec.dylib" ]]; then
565 {
566 # Start build ACPICodec package module
567 choiceId="ACPICodec"
568 moduleFile="ACPICodec.dylib"
569 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
570 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
571 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
572 --subst="moduleName=$choiceId" \
573 --subst="moduleFile=$moduleFile" \
574 InstallModule
575
576 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
577 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
578 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
579 # End build ACPICodec package module
580 }
581 fi
582# -
583 if [[ "${CONFIG_NVIDIAGE_MODULE}" == 'y' && -f "${SYMROOT}/i386/modules/NVIDIAGraphicEnabler.dylib" ]]; then
584 {
585 # Start build NvidiaGraphicsEnabler package module
586 choiceId="NVIDIAGraphicsEnabler"
587 moduleFile="NVIDIAGraphicEnabler.dylib"
588 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
589 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
590 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
591 --subst="moduleName=$choiceId" \
592 --subst="moduleFile=$moduleFile" \
593 InstallModule
594
595 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
596 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
597 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
598 # End build NvidiaGraphicsEnabler package module
599 }
600 fi
601# -
602 if [[ "${CONFIG_AMDGE_MODULE}" == 'y' && -f "${SYMROOT}/i386/modules/AMDGraphicsEnabler.dylib" ]]; then
603 {
604 # Start build AMDGraphicsEnabler package module
605 choiceId="AMDGraphicsEnabler"
606 moduleFile="AMDGraphicsEnabler_title.dylib"
607 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
608 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
609 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
610 --subst="moduleName=$choiceId" \
611 --subst="moduleFile=$moduleFile" \
612 InstallModule
613
614 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
615 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
616 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
617 # End build AMDGraphicsEnabler package module
618 }
619 fi
620# -
621 if [[ "${CONFIG_GMAGE_MODULE}" == 'y' && -f "${SYMROOT}/i386/modules/IntelGraphicsEnabler.dylib" ]]; then
622 {
623 # Start build IntelGraphicsEnabler package module
624 choiceId="IntelGraphicsEnabler"
625 moduleFile="IntelGraphicsEnabler_title.dylib"
626 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
627 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
628 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
629 --subst="moduleName=$choiceId" \
630 --subst="moduleFile=$moduleFile" \
631 InstallModule
632
633 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
634 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
635 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
636 # End build IntelGraphicsEnabler package module
637 }
638 fi
639# -
640 if [[ "${CONFIG_KERNELPATCHER_MODULE}" == 'y' && -f "${SYMROOT}/i386/modules/KernelPatcher.dylib" ]]; then
641 {
642 # Start build KernelPatcher package module
643 choiceId="KernelPatcher"
644 moduleFile="KernelPatcher.dylib"
645 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
646 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
647 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
648 --subst="moduleName=$choiceId" \
649 --subst="moduleFile=$moduleFile" \
650 InstallModule
651
652 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
653 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
654 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
655 # End build KernelPatcher package module
656 }
657 fi
658# -
659 if [[ "${CONFIG_KEXTPATCHER_MODULE}" == 'y' && -f "${SYMROOT}/i386/modules/KextPatcher.dylib" ]]; then
660 {
661 # Start build KextPatcher package module
662 choiceId="KextPatcher"
663 moduleFile="KextPatcher.dylib"
664 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
665 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
666 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
667 --subst="moduleName=$choiceId" \
668 --subst="moduleFile=$moduleFile" \
669 InstallModule
670
671 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
672 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
673 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
674 # End build KextPatcher package module
675 }
676 fi
677# -
678 # Warning Keylayout module need additional files
679 if [[ "${CONFIG_KEYLAYOUT_MODULE}" = 'm' && -f "${SYMROOT}/i386/modules/Keylayout.dylib" ]]; then
680 {
681 # Start build Keylayout package module
682 choiceId="Keylayout"
683 moduleFile="${choiceId}.dylib"
684 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root/Extra/{modules,Keymaps}
685 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
686 layout_src_dir="${SRCROOT}/i386/modules/Keylayout/layouts/layouts-src"
687 if [ -d "$layout_src_dir" ];then
688 # Create a tar.gz from layout sources
689 (cd "$layout_src_dir"; \
690 tar czf "${PKG_BUILD_DIR}/${choiceId}/Root/Extra/Keymaps/layouts-src.tar.gz" README *.slt)
691 fi
692 # Adding module
693 ditto --noextattr --noqtn ${SYMROOT}/i386/modules/$moduleFile ${PKG_BUILD_DIR}/${choiceId}/Root/Extra/modules
694 # Adding Keymaps
695 ditto --noextattr --noqtn ${SRCROOT}/Keymaps ${PKG_BUILD_DIR}/${choiceId}/Root/Extra/Keymaps
696 # Adding tools
697 ditto --noextattr --noqtn ${SYMROOT}/i386/cham-mklayout ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
698 # Adding scripts
699 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
700 --subst="moduleName=$choiceId" \
701 --subst="moduleFile=$moduleFile" \
702 InstallModule
703
704 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
705 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
706
707 # Don't add a choice for Keylayout module
708 # addChoice "${choiceId}" "Module" --start-selected="false" "$packageRefId"
709 # End build Keylayout package module
710 }
711 fi
712# -
713 if [[ "${CONFIG_KLIBC_MODULE}" == 'm' && -f "${SYMROOT}/i386/modules/klibc.dylib" ]]; then
714 {
715 # Start build klibc package module
716 choiceId="klibc"
717 moduleFile="${choiceId}.dylib"
718 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
719 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" ${PKG_BUILD_DIR}/${choiceId}/Root
720 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
721 --subst="moduleName=$choiceId" \
722 --subst="moduleFile=$moduleFile" \
723 InstallModule
724
725 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
726 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
727 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
728 # End build klibc package module
729 }
730 fi
731# -
732 if [[ "${CONFIG_RESOLUTION_MODULE}" == 'm' && -f "${SYMROOT}/i386/modules/Resolution.dylib" ]]; then
733 {
734 # Start build Resolution package module
735 choiceId="AutoReso"
736 moduleFile="Resolution.dylib"
737 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
738 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
739 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
740 --subst="moduleName=$choiceId" \
741 --subst="moduleFile=$moduleFile" \
742 InstallModule
743
744 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
745 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
746 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
747 # End build Resolution package module
748 }
749 fi
750# -
751 if [[ "${CONFIG_HDAENABLER_MODULE}" == 'y' && -f "${SYMROOT}/i386/modules/HDAEnabler.dylib" ]]; then
752 {
753 # Start build HDAEnabler package module
754 choiceId="HDAEnabler"
755 moduleFile="HDAEnabler.dylib"
756 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
757 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
758 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
759 --subst="moduleName=$choiceId" \
760 --subst="moduleFile=$moduleFile" \
761 InstallModule
762
763 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
764 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
765 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
766 # End build HDAEnabler package module
767 }
768 fi
769# -
770 if [[ "${CONFIG_FILENVRAM_MODULE}" == 'y' && -f "${SYMROOT}/i386/modules/FileNVRAM.dylib" ]]; then
771 {
772 # Start build FileNVRAM package module
773 choiceId="FileNVRAM"
774 moduleFile="FileNVRAM.dylib"
775 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
776 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
777 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
778 --subst="moduleName=$choiceId" \
779 --subst="moduleFile=$moduleFile" \
780 InstallModule
781
782 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
783 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
784 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
785 # End build FileNVRAM package module
786 }
787 fi
788# -
789 if [[ "${CONFIG_SATA_MODULE}" == 'm' && -f "${SYMROOT}/i386/modules/Sata.dylib" ]]; then
790 {
791 # Start build Sata package module
792 choiceId="Sata"
793 moduleFile="Sata.dylib"
794 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
795 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
796 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
797 --subst="moduleName=$choiceId" \
798 --subst="moduleFile=$moduleFile" \
799 InstallModule
800
801 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
802 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
803 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
804 # End build Sata package module
805 }
806 fi
807# -
808 if [[ "${CONFIG_UCLIBCXX_MODULE}" = 'm' && -n "${CONFIG_KLIBC_MODULE}" && \
809 -f "${SYMROOT}/i386/modules/uClibcxx.dylib" ]]; then
810 {
811 klibcPackageRefId=""
812 if [[ "${CONFIG_KLIBC_MODULE}" == 'm' ]];then
813 klibcPackageRefId=$(getPackageRefId "${modules_packages_identity}" "klibc")
814 fi
815 # Start build uClibc package module
816 choiceId="uClibc"
817 moduleFile="uClibcxx.dylib"
818 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
819 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
820 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
821 --subst="moduleName=$choiceId" \
822 --subst="moduleFile=$moduleFile" \
823 InstallModule
824
825 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
826 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
827 # Add the klibc package because the uClibc module is dependent of klibc module
828 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId $klibcPackageRefId" "${choiceId}"
829 # End build uClibc package module
830 }
831 fi
832# -
833 }
834 else
835 {
836 echo " -= no modules to include =-"
837 }
838 fi
839# End build Modules packages
840fi
841
842# build Options packages
843
844 addGroupChoices "Options"
845
846 # ------------------------------------------------------
847 # parse OptionalSettings folder to find files of boot options.
848 # ------------------------------------------------------
849 OptionalSettingsFolder="${PKGROOT}/OptionalSettings"
850
851 while IFS= read -r -d '' OptionsFile; do
852
853 # Take filename and strip .txt from end and path from front
854 builtOptionsList=${OptionsFile%.txt}
855 builtOptionsList=${builtOptionsList##*/}
856 packagesidentity="${chameleon_package_identity}.options.$builtOptionsList"
857
858 echo "================= $builtOptionsList ================="
859
860 # ------------------------------------------------------
861 # Read boot option file into an array.
862 # ------------------------------------------------------
863 availableOptions=() # array to hold the list of boot options, per 'section'.
864 exclusiveFlag="" # used to indicate list has exclusive options
865 while read textLine; do
866 # ignore lines in the file beginning with a #
867 [[ $textLine = \#* ]] && continue
868 local optionName="" key="" value=""
869 case "$textLine" in
870 Exclusive=[Tt][Rr][Uu][Ee]) exclusiveFlag="--exclusive_zero_or_one_choice" ;;
871 Exclusive=*) continue ;;
872 *@*:*=*)
873 availableOptions[${#availableOptions[*]}]="$textLine" ;;
874 *) echo "Error: invalid line '$textLine' in file '$OptionsFile'" >&2
875 exit 1
876 ;;
877 esac
878 done < "$OptionsFile"
879
880 addGroupChoices --parent="Options" $exclusiveFlag "${builtOptionsList}"
881
882 # ------------------------------------------------------
883 # Loop through options in array and process each in turn
884 # ------------------------------------------------------
885 for textLine in "${availableOptions[@]}"; do
886 # split line - taking all before ':' as option name
887 # and all after ':' as key/value
888 type=$( echo "${textLine%%@*}" | tr '[:upper:]' '[:lower:]' )
889 tmp=${textLine#*@}
890 optionName=${tmp%%:*}
891 keyValue=${tmp##*:}
892 key=${keyValue%%=*}
893 value=${keyValue#*=}
894
895 # create folders required for each boot option
896 mkdir -p "${PKG_BUILD_DIR}/$optionName/Root/"
897
898 case "$type" in
899 bool) startSelected="check_chameleon_bool_option('$key','$value')" ;;
900 text) startSelected="check_chameleon_text_option('$key','$value')" ;;
901 list) startSelected="check_chameleon_list_option('$key','$value')" ;;
902 *) echo "Error: invalid type '$type' in line '$textLine' in '$OptionsFile'" >&2
903 exit 1
904 ;;
905 esac
906 recordChameleonOption "$type" "$key" "$value"
907 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/$optionName" \
908 --subst="optionType=$type" \
909 --subst="optionKey=$key" \
910 --subst="optionValue=$value" \
911 AddOption
912 packageRefId=$(getPackageRefId "${packagesidentity}" "${optionName}")
913 buildpackage "$packageRefId" "${optionName}" "${PKG_BUILD_DIR}/${optionName}" "/"
914 addChoice --group="${builtOptionsList}" \
915 --start-selected="$startSelected" \
916 --pkg-refs="$packageRefId" "${optionName}"
917 done
918
919 done < <( find "${OptionalSettingsFolder}" -depth 1 -type f -name '*.txt' -print0 )
920
921# End build options packages
922
923if [[ -n "${CONFIG_KEYLAYOUT_MODULE}" ]];then
924# build Keymaps options packages
925 echo "================= Keymaps Options ================="
926 addGroupChoices --exclusive_zero_or_one_choice "Keymaps"
927 packagesidentity="${chameleon_package_identity}.options.keymaps"
928 keylayoutPackageRefId=""
929 if [[ "${CONFIG_MODULES}" == 'y' && "${CONFIG_KEYLAYOUT_MODULE}" = 'm' ]];then
930 keylayoutPackageRefId=$(getPackageRefId "${modules_packages_identity}" "Keylayout")
931 fi
932
933 chameleon_keylayout_key="KeyLayout"
934 # ------------------------------------------------------
935 # Available Keylayout boot options are discovered by
936 # reading contents of /Keymaps folder after compilation
937 # ------------------------------------------------------
938 availableOptions=($( find "${SRCROOT}/Keymaps" -type f -depth 1 -name '*.lyt' | sed 's|.*/||;s|\.lyt||' ))
939 # Adjust array contents to match expected format
940 # for boot options which is: name:key=value
941 for (( i = 0 ; i < ${#availableOptions[@]} ; i++ )); do
942 # Start build of a keymap package module
943 choiceId="${availableOptions[i]}"
944 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
945
946 recordChameleonOption "text" "$chameleon_keylayout_key" "$choiceId"
947 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
948 --subst="optionType=text" \
949 --subst="optionKey=$chameleon_keylayout_key" \
950 --subst="optionValue=$choiceId" \
951 AddOption
952 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
953 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
954 # Add the Keylayout package because the Keylayout module is needed
955 addChoice --group="Keymaps" \
956 --start-selected="check_chameleon_text_option('${chameleon_keylayout_key}','${choiceId}')" \
957 --pkg-refs="$packageRefId $keylayoutPackageRefId" "${choiceId}"
958 done
959
960# End build Keymaps options packages
961fi
962
963# build theme packages
964 echo "================= Themes ================="
965 addGroupChoices "Themes"
966
967 # Using themes section from Azi's/package branch.
968 packagesidentity="${chameleon_package_identity}.themes"
969 artwork="${SRCROOT}/artwork/themes"
970 themes=($( find "${artwork}" -type d -depth 1 -not -name '.svn' ))
971 for (( i = 0 ; i < ${#themes[@]} ; i++ )); do
972 themeName=$( echo ${themes[$i]##*/} | awk 'BEGIN{OFS=FS=""}{$1=toupper($1);print}' )
973 themeDir="$themeName"
974 mkdir -p "${PKG_BUILD_DIR}/${themeName}/Root/"
975 rsync -r --exclude=.svn --exclude="*~" "${themes[$i]}/" "${PKG_BUILD_DIR}/${themeName}/Root/${themeName}"
976 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${themeName}" \
977 --subst="themeName=$themeName" \
978 --subst="themeDir=$themeDir" \
979 InstallTheme
980
981 packageRefId=$(getPackageRefId "${packagesidentity}" "${themeName}")
982 buildpackage "$packageRefId" "${themeName}" "${PKG_BUILD_DIR}/${themeName}" "/Extra/Themes"
983 addChoice --group="Themes" --start-selected="false" --pkg-refs="$packageRefId" "${themeName}"
984 done
985# End build theme packages# End build Extras package
986
987# build pre install package
988 echo "================= Pre ================="
989 packagesidentity="${chameleon_package_identity}"
990 choiceId="Pre"
991
992 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
993 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
994 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources
995 local yamlFile="Resources/chameleon_options.yaml"
996 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
997 --subst="YAML_FILE=${yamlFile}" ${choiceId}
998 generate_options_yaml_file "${PKG_BUILD_DIR}/${choiceId}/Scripts/$yamlFile"
999 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
1000# End build pre install package
1001
1002# build post install package
1003 echo "================= Post ================="
1004 packagesidentity="${chameleon_package_identity}"
1005 choiceId="Post"
1006 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
1007 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" ${choiceId}
1008 cp -f ${PKGROOT}/Scripts/Sub/UnMountEFIvolumes.sh ${PKG_BUILD_DIR}/${choiceId}/Scripts
1009
1010 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
1011 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
1012 addChoice --start-visible="false" --start-selected="true" --pkg-refs="$packageRefId" "${choiceId}"
1013# End build post install package
1014
1015}
1016
1017buildpackage ()
1018{
1019 # $1 Package Reference Id (ie: org.chameleon.themes.default)
1020 # $2 Package Name (ie: Default)
1021 # $3 Path to package to build containing Root and/or Scripts
1022 # $4 Target install location
1023 # $5 Size (optional)
1024 if [[ -d "${3}/Root" ]]; then
1025 local packageRefId="$1"
1026 local packageName="$2"
1027 local packagePath="$3"
1028 local targetPath="$4"
1029 set +u # packageSize is optional
1030 local packageSize="$5"
1031 set -u
1032
1033 echo -e "\t[BUILD] ${packageName}"
1034
1035 find "${packagePath}" -name '.DS_Store' -delete
1036 local filecount=$( find "${packagePath}/Root" | wc -l )
1037 if [ "${packageSize}" ]; then
1038 local installedsize="${packageSize}"
1039 else
1040 local installedsize=$( du -hkc "${packagePath}/Root" | tail -n1 | awk {'print $1'} )
1041 fi
1042 local header="<?xml version=\"1.0\"?>\n<pkg-info format-version=\"2\" "
1043
1044 #[ "${3}" == "relocatable" ] && header+="relocatable=\"true\" "
1045
1046 header+="identifier=\"${packageRefId}\" "
1047 header+="version=\"${CHAMELEON_VERSION}\" "
1048
1049 [ "${targetPath}" != "relocatable" ] && header+="install-location=\"${targetPath}\" "
1050
1051 header+="auth=\"root\">\n"
1052 header+="\t<payload installKBytes=\"${installedsize##* }\" numberOfFiles=\"${filecount##* }\"/>\n"
1053 rm -R -f "${packagePath}/Temp"
1054
1055 [ -d "${packagePath}/Temp" ] || mkdir -m 777 "${packagePath}/Temp"
1056 [ -d "${packagePath}/Root" ] && mkbom "${packagePath}/Root" "${packagePath}/Temp/Bom"
1057
1058 if [ -d "${packagePath}/Scripts" ]; then
1059 header+="\t<scripts>\n"
1060 for script in $( find "${packagePath}/Scripts" -type f \( -name 'pre*' -or -name 'post*' \) ); do
1061 header+="\t\t<${script##*/} file=\"./${script##*/}\"/>\n"
1062 done
1063 header+="\t</scripts>\n"
1064 # Create the Script archive file (cpio format)
1065 (cd "${packagePath}/Scripts" && find . -print | \
1066 cpio -o -z -R root:wheel --format cpio > "${packagePath}/Temp/Scripts") 2>&1 | \
1067 grep -vE '^[0-9]+\s+blocks?$' # to remove cpio stderr messages
1068 fi
1069
1070 header+="</pkg-info>"
1071 echo -e "${header}" > "${packagePath}/Temp/PackageInfo"
1072
1073 # Create the Payload file (cpio format)
1074 (cd "${packagePath}/Root" && find . -print | \
1075 cpio -o -z -R root:wheel --format cpio > "${packagePath}/Temp/Payload") 2>&1 | \
1076 grep -vE '^[0-9]+\s+blocks?$' # to remove cpio stderr messages
1077
1078 # Create the package
1079 (cd "${packagePath}/Temp" && xar -c -f "${packagePath}/../${packageName}.pkg" --compression none .)
1080
1081 # Add the package to the list of build packages
1082 pkgrefs[${#pkgrefs[*]}]="\t<pkg-ref id=\"${packageRefId}\" installKBytes='${installedsize}' version='${CHAMELEON_VERSION}.0.0.${CHAMELEON_TIMESTAMP}'>#${packageName}.pkg</pkg-ref>"
1083
1084 rm -rf "${packagePath}"
1085 fi
1086}
1087
1088generateOutlineChoices() {
1089 # $1 Main Choice
1090 # $2 indent level
1091 local idx=$(getChoiceIndex "$1")
1092 local indentLevel="$2"
1093 local indentString=""
1094 for ((level=1; level <= $indentLevel ; level++)); do
1095 indentString="\t$indentString"
1096 done
1097 set +u; subChoices="${choice_group_items[$idx]}"; set -u
1098 if [[ -n "${subChoices}" ]]; then
1099 # Sub choices exists
1100 echo -e "$indentString<line choice=\"$1\">"
1101 for subChoice in $subChoices;do
1102 generateOutlineChoices $subChoice $(($indentLevel+1))
1103 done
1104 echo -e "$indentString</line>"
1105 else
1106 echo -e "$indentString<line choice=\"$1\"/>"
1107 fi
1108}
1109
1110generateChoices() {
1111 for (( idx=1; idx < ${#choice_key[*]} ; idx++)); do
1112 local choiceId=${choice_key[$idx]}
1113 local choiceOptions=${choice_options[$idx]}
1114 local choiceParentGroupIndex=${choice_parent_group_index[$idx]}
1115 set +u; local group_exclusive=${choice_group_exclusive[$choiceParentGroupIndex]}; set -u
1116
1117 # Create the node and standard attributes
1118 local choiceNode="\t<choice\n\t\tid=\"${choiceId}\"\n\t\ttitle=\"${choiceId}_title\"\n\t\tdescription=\"${choiceId}_description\""
1119
1120 # Add options like start_selected, etc...
1121 [[ -n "${choiceOptions}" ]] && choiceNode="${choiceNode}\n\t\t${choiceOptions}"
1122
1123 # Add the selected attribute if options are mutually exclusive
1124 if [[ -n "$group_exclusive" ]];then
1125 local group_items="${choice_group_items[$choiceParentGroupIndex]}"
1126 case $group_exclusive in
1127 exclusive_one_choice)
1128 local selected_option=$(exclusive_one_choice "$choiceId" "$group_items") ;;
1129 exclusive_zero_or_one_choice)
1130 local selected_option=$(exclusive_zero_or_one_choice "$choiceId" "$group_items") ;;
1131 *) echo "Error: unknown function to generate exclusive mode '$group_exclusive' for group '${choice_key[$choiceParentGroupIndex]}'" >&2
1132 exit 1
1133 ;;
1134 esac
1135 choiceNode="${choiceNode}\n\t\tselected=\"$selected_option\""
1136 fi
1137
1138 choiceNode="${choiceNode}>"
1139
1140 # Add the package references
1141 for pkgRefId in ${choice_pkgrefs[$idx]};do
1142 choiceNode="${choiceNode}\n\t\t<pkg-ref id=\"${pkgRefId}\"/>"
1143 done
1144
1145 # Close the node
1146 choiceNode="${choiceNode}\n\t</choice>\n"
1147
1148 echo -e "$choiceNode"
1149 done
1150}
1151
1152makedistribution ()
1153{
1154 declare -r distributionDestDir="${SYMROOT}"
1155 declare -r distributionFilename="${packagename// /}-${CHAMELEON_VERSION}-r${CHAMELEON_REVISION}.pkg"
1156 declare -r distributionFilePath="${distributionDestDir}/${distributionFilename}"
1157
1158 rm -f "${distributionDestDir}/${packagename// /}"*.pkg
1159
1160 mkdir -p "${PKG_BUILD_DIR}/${packagename}"
1161
1162 find "${PKG_BUILD_DIR}" -type f -name '*.pkg' -depth 1 | while read component
1163 do
1164 pkg="${component##*/}" # ie: EFI.pkg
1165 pkgdir="${PKG_BUILD_DIR}/${packagename}/${pkg}"
1166 # expand individual packages
1167 pkgutil --expand "${PKG_BUILD_DIR}/${pkg}" "$pkgdir"
1168 rm -f "${PKG_BUILD_DIR}/${pkg}"
1169 done
1170
1171# Create the Distribution file
1172 ditto --noextattr --noqtn "${PKGROOT}/Distribution" "${PKG_BUILD_DIR}/${packagename}/Distribution"
1173
1174 local start_indent_level=2
1175 echo -e "\n\t<choices-outline>" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
1176 for main_choice in ${choice_group_items[0]};do
1177 generateOutlineChoices $main_choice $start_indent_level >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
1178 done
1179 echo -e "\t</choices-outline>\n" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
1180
1181 generateChoices >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
1182
1183 for (( i=0; i < ${#pkgrefs[*]} ; i++)); do
1184 echo -e "${pkgrefs[$i]}" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
1185 done
1186
1187 echo -e "\n</installer-gui-script>" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
1188
1189# Create the Resources directory
1190 ditto --noextattr --noqtn "${PKGROOT}/Resources/distribution" "${PKG_BUILD_DIR}/${packagename}/Resources"
1191
1192# Make the translation
1193 echo ""
1194 echo "========= Translating Resources ========"
1195 (cd "${PKGROOT}" && PERLLIB=${PKGROOT}/bin/po4a/lib \
1196 bin/po4a/po4a \
1197 --package-name 'Chameleon' \
1198 --package-version "${CHAMELEON_VERSION}-r${CHAMELEON_REVISION}" \
1199 --msgmerge-opt '--lang=$lang' \
1200 --variable PODIR="po" \
1201 --variable TEMPLATES_DIR="Resources/templates" \
1202 --variable OUTPUT_DIR="${PKG_BUILD_DIR}/${packagename}/Resources" \
1203 ${PKGROOT}/po4a-chameleon.cfg)
1204
1205 # Copy common files in english localisation directory
1206 ditto --noextattr --noqtn "${PKGROOT}/Resources/common" "${PKG_BUILD_DIR}/${packagename}/Resources/en.lproj"
1207
1208 # CleanUp the directory
1209 find "${PKG_BUILD_DIR}/${packagename}" \( -type d -name '.svn' \) -o -name '.DS_Store' -depth -exec rm -rf {} \;
1210 find "${PKG_BUILD_DIR}/${packagename}" -type d -depth -empty -exec rmdir {} \; # Remove empty directories
1211
1212 # Make substitutions for version, revision, stage, developers, credits, etc..
1213 makeSubstitutions $( find "${PKG_BUILD_DIR}/${packagename}/Resources" -type f )
1214
1215# Create the final package
1216 pkgutil --flatten "${PKG_BUILD_DIR}/${packagename}" "${distributionFilePath}"
1217
1218##################################################################
1219# Here is the place to assign an icon to the pkg #
1220# command used to generate the file: #
1221# ditto -c -k --sequesterRsrc --keepParent Icon.icns Icon.zip #
1222##################################################################
1223 ditto -xk "${PKGROOT}/Icons/pkg.zip" "${PKG_BUILD_DIR}/Icons/"
1224 DeRez -only icns "${PKG_BUILD_DIR}/Icons/Icons/pkg.icns" > "${PKG_BUILD_DIR}/Icons/tempicns.rsrc"
1225 Rez -append "${PKG_BUILD_DIR}/Icons/tempicns.rsrc" -o "${distributionFilePath}"
1226 SetFile -a C "${distributionFilePath}"
1227 rm -rf "${PKG_BUILD_DIR}/Icons"
1228
1229# End
1230
1231 md5=$( md5 "${distributionFilePath}" | awk {'print $4'} )
1232 echo "MD5 (${distributionFilePath}) = ${md5}" > "${distributionFilePath}.md5"
1233 echo ""
1234
1235 echo -e $COL_GREEN" --------------------------"$COL_RESET
1236 echo -e $COL_GREEN" Building process complete!"$COL_RESET
1237 echo -e $COL_GREEN" --------------------------"$COL_RESET
1238 echo ""
1239 echo -e $COL_GREEN" Build info."
1240 echo -e $COL_GREEN" ==========="
1241 echo -e $COL_BLUE" Package name: "$COL_RESET"${distributionFilename}"
1242 echo -e $COL_BLUE" MD5: "$COL_RESET"$md5"
1243 echo -e $COL_BLUE" Version: "$COL_RESET"$CHAMELEON_VERSION"
1244 echo -e $COL_BLUE" Stage: "$COL_RESET"$CHAMELEON_STAGE"
1245 echo -e $COL_BLUE" Date/Time: "$COL_RESET"$CHAMELEON_BUILDDATE"
1246 echo -e $COL_BLUE" Built by: "$COL_RESET"$CHAMELEON_WHOBUILD"
1247 echo -e $COL_BLUE" Copyright $CHAMELEON_CPRYEAR "$COL_RESET
1248 echo ""
1249
1250}
1251
1252# build packages
1253main
1254
1255# build meta package
1256makedistribution
1257

Archive Download this file

Revision: 2495