Chameleon

View buildpkg.sh

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

Archive Download this file

Attachment to issue 391

Created: 9 years 20 days ago by FurtiF