Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 1802