Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: HEAD