Chameleon

Chameleon Svn Source Tree

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

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

Archive Download this file

Revision: 2111