Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Enoch/package/buildpkg.sh

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