Chameleon

Chameleon Svn Source Tree

Root/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
26# ====== CONFIGURATION ======
27CONFIG_MODULES=""
28CONFIG_KLIBC_MODULE=""
29CONFIG_UCLIBCXX_MODULE=""
30CONFIG_SATA_MODULE=""
31CONFIG_ACPICODEC_MODULE=""
32CONFIG_RESOLUTION_MODULE=""
33CONFIG_KEYLAYOUT_MODULE=""
34source "${SRCROOT}/auto.conf"
35
36# ====== COLORS ======
37declare -r COL_BLACK="\x1b[30;01m"
38declare -r COL_RED="\x1b[31;01m"
39declare -r COL_GREEN="\x1b[32;01m"
40declare -r COL_YELLOW="\x1b[33;01m"
41declare -r COL_MAGENTA="\x1b[35;01m"
42declare -r COL_CYAN="\x1b[36;01m"
43declare -r COL_WHITE="\x1b[37;01m"
44declare -r COL_BLUE="\x1b[34;01m"
45declare -r COL_RESET="\x1b[39;49;00m"
46
47# ====== REVISION/VERSION ======
48declare -r CHAMELEON_VERSION=$( cat version )
49
50# stage
51CHAMELEON_STAGE=${CHAMELEON_VERSION##*-}
52CHAMELEON_STAGE=${CHAMELEON_STAGE/RC/Release Candidate }
53CHAMELEON_STAGE=${CHAMELEON_STAGE/FINAL/2.1 Final}
54declare -r CHAMELEON_STAGE
55
56declare -r CHAMELEON_REVISION=$( grep I386BOOT_CHAMELEONREVISION vers.h | awk '{ print $3 }' | tr -d '\"' )
57declare -r CHAMELEON_BUILDDATE=$( grep I386BOOT_BUILDDATE vers.h | awk '{ print $3,$4 }' | tr -d '\"' )
58declare -r CHAMELEON_TIMESTAMP=$( date -j -f "%Y-%m-%d %H:%M:%S" "${CHAMELEON_BUILDDATE}" "+%s" )
59
60# ====== CREDITS ======
61declare -r CHAMELEON_DEVELOP=$(awk "NR==6{print;exit}" ${PKGROOT}/../CREDITS)
62declare -r CHAMELEON_CREDITS=$(awk "NR==10{print;exit}" ${PKGROOT}/../CREDITS)
63declare -r CHAMELEON_PKGDEV=$(awk "NR==14{print;exit}" ${PKGROOT}/../CREDITS)
64declare -r CHAMELEON_CPRYEAR=$(awk "NR==18{print;exit}" ${PKGROOT}/../CREDITS)
65if [[ $(whoami | awk '{print $1}' | cut -d ":" -f3) == "admin" ]];then
66 declare -r CHAMELEON_WHOBUILD="VoodooLabs BuildBot"
67else
68 declare -r CHAMELEON_WHOBUILD=$(whoami | awk '{print $1}' | cut -d ":" -f3)
69fi
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 ======
101trim () {
102 local result="${1#"${1%%[![:space:]]*}"}" # remove leading whitespace characters
103 echo "${result%"${result##*[![:space:]]}"}" # remove trailing whitespace characters
104}
105
106function makeSubstitutions () {
107 # Substition is like: Key=Value
108 #
109 # Optional arguments:
110 # --subst=<substition> : add a new substitution
111 #
112 # Last argument(s) is/are file(s) where substitutions must be made
113
114 local ownSubst=""
115
116 function addSubst () {
117 local mySubst="$1"
118 case "$mySubst" in
119*=*) keySubst=${mySubst%%=*}
120 valSubst=${mySubst#*=}
121 ownSubst=$(printf "%s\n%s" "$ownSubst" "s&@$keySubst@&$valSubst&g;t t")
122 ;;
123*) echo "Invalid substitution $mySubst" >&2
124 exit 1
125 ;;
126esac
127 }
128
129 # Check the arguments.
130 while [[ $# -gt 0 ]];do
131 local option="$1"
132 case "$option" in
133 --subst=*) shift; addSubst "${option#*=}" ;;
134 -*)
135 echo "Unrecognized makeSubstitutions option '$option'" >&2
136 exit 1
137 ;;
138 *) break ;;
139 esac
140 done
141
142 if [[ $# -lt 1 ]];then
143 echo "makeSubstitutions invalid number of arguments: at least one file needed" >&2
144 exit 1
145 fi
146
147 local chameleonSubsts="
148s&%CHAMELEONVERSION%&${CHAMELEON_VERSION%%-*}&g
149s&%CHAMELEONREVISION%&${CHAMELEON_REVISION}&g
150s&%CHAMELEONSTAGE%&${CHAMELEON_STAGE}&g
151s&%DEVELOP%&${CHAMELEON_DEVELOP}&g
152s&%CREDITS%&${CHAMELEON_CREDITS}&g
153s&%PKGDEV%&${CHAMELEON_PKGDEV}&g
154s&%CPRYEAR%&${CHAMELEON_CPRYEAR}&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 # Optional 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 # Optional 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 # Optional 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 built 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 # ACPICodec.dylib #
525 # KernelPatcher.dylib #
526 # KextPatcher.dylib #
527 # Keylayout.dylib #
528 # klibc.dylib #
529 # Resolution.dylib #
530 # Sata.dylib #
531 # uClibcxx.dylib #
532 ###############################
533 if [ "$(ls -A "${SYMROOT}/i386/modules")" ]; then
534 {
535 addGroupChoices "Module"
536
537# -
538 if [[ "${CONFIG_ACPICODEC_MODULE}" == 'm' && -f "${SYMROOT}/i386/modules/ACPICodec.dylib" ]]; then
539 {
540 # Start build ACPICodec package module
541 choiceId="ACPICodec"
542 moduleFile="ACPICodec.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 ACPICodec package module
554 }
555 fi
556# -
557 if [[ "${CONFIG_RESOLUTION_MODULE}" == 'm' && -f "${SYMROOT}/i386/modules/KernelPatcher.dylib" ]]; then
558 {
559 # Start build KernelPatcher package module
560 choiceId="KernelPatcher"
561 moduleFile="KernelPatcher.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}" "/Extra/modules"
571 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
572 # End build KernelPatcher package module
573 }
574 fi
575# -
576 if [[ "${CONFIG_RESOLUTION_MODULE}" == 'm' && -f "${SYMROOT}/i386/modules/KextPatcher.dylib" ]]; then
577 {
578 # Start build KextPatcher package module
579 choiceId="KextPatcher"
580 moduleFile="KextPatcher.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}" "/Extra/modules"
590 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
591 # End build KextPatcher package module
592 }
593 fi
594# -
595 # Warning Keylayout module need additional files
596 if [[ "${CONFIG_KEYLAYOUT_MODULE}" = 'm' && -f "${SYMROOT}/i386/modules/Keylayout.dylib" ]]; then
597 {
598 # Start build Keylayout package module
599 choiceId="Keylayout"
600 moduleFile="${choiceId}.dylib"
601 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root/Extra/{modules,Keymaps}
602 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
603 layout_src_dir="${SRCROOT}/i386/modules/Keylayout/layouts/layouts-src"
604 if [ -d "$layout_src_dir" ];then
605 # Create a tar.gz from layout sources
606 (cd "$layout_src_dir"; \
607 tar czf "${PKG_BUILD_DIR}/${choiceId}/Root/Extra/Keymaps/layouts-src.tar.gz" README *.slt)
608 fi
609 # Adding module
610 ditto --noextattr --noqtn ${SYMROOT}/i386/modules/$moduleFile ${PKG_BUILD_DIR}/${choiceId}/Root/Extra/modules
611 # Adding Keymaps
612 ditto --noextattr --noqtn ${SRCROOT}/Keymaps ${PKG_BUILD_DIR}/${choiceId}/Root/Extra/Keymaps
613 # Adding tools
614 ditto --noextattr --noqtn ${SYMROOT}/i386/cham-mklayout ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
615 # Adding scripts
616 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
617 --subst="moduleName=$choiceId" \
618 --subst="moduleFile=$moduleFile" \
619 InstallModule
620
621 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
622 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
623
624 # Don't add a choice for Keylayout module
625 # addChoice "${choiceId}" "Module" --start-selected="false" "$packageRefId"
626 # End build Keylayout package module
627 }
628 fi
629# -
630 if [[ "${CONFIG_KLIBC_MODULE}" == 'm' && -f "${SYMROOT}/i386/modules/klibc.dylib" ]]; then
631 {
632 # Start build klibc package module
633 choiceId="klibc"
634 moduleFile="${choiceId}.dylib"
635 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
636 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" ${PKG_BUILD_DIR}/${choiceId}/Root
637 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
638 --subst="moduleName=$choiceId" \
639 --subst="moduleFile=$moduleFile" \
640 InstallModule
641
642 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
643 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
644 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
645 # End build klibc package module
646 }
647 fi
648# -
649 if [[ "${CONFIG_RESOLUTION_MODULE}" == 'm' && -f "${SYMROOT}/i386/modules/Resolution.dylib" ]]; then
650 {
651 # Start build Resolution package module
652 choiceId="AutoReso"
653 moduleFile="Resolution.dylib"
654 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
655 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
656 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
657 --subst="moduleName=$choiceId" \
658 --subst="moduleFile=$moduleFile" \
659 InstallModule
660
661 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
662 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
663 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
664 # End build Resolution package module
665 }
666 fi
667# -
668 if [[ "${CONFIG_SATA_MODULE}" == 'm' && -f "${SYMROOT}/i386/modules/Sata.dylib" ]]; then
669 {
670 # Start build Sata package module
671 choiceId="Sata"
672 moduleFile="Sata.dylib"
673 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
674 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
675 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
676 --subst="moduleName=$choiceId" \
677 --subst="moduleFile=$moduleFile" \
678 InstallModule
679
680 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
681 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
682 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
683 # End build Sata package module
684 }
685 fi
686# -
687 if [[ "${CONFIG_UCLIBCXX_MODULE}" = 'm' && -n "${CONFIG_KLIBC_MODULE}" && \
688 -f "${SYMROOT}/i386/modules/uClibcxx.dylib" ]]; then
689 {
690 klibcPackageRefId=""
691 if [[ "${CONFIG_KLIBC_MODULE}" == 'm' ]];then
692 klibcPackageRefId=$(getPackageRefId "${modules_packages_identity}" "klibc")
693 fi
694 # Start build uClibc package module
695 choiceId="uClibc"
696 moduleFile="uClibcxx.dylib"
697 mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
698 ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"
699 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
700 --subst="moduleName=$choiceId" \
701 --subst="moduleFile=$moduleFile" \
702 InstallModule
703
704 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
705 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"
706 # Add the klibc package because the uClibc module is dependent of klibc module
707 addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId $klibcPackageRefId" "${choiceId}"
708 # End build uClibc package module
709 }
710 fi
711# -
712 }
713 else
714 {
715 echo " -= no modules to include =-"
716 }
717 fi
718# End build Modules packages
719fi
720
721# build Options packages
722
723 addGroupChoices "Options"
724
725 # ------------------------------------------------------
726 # parse OptionalSettings folder to find files of boot options.
727 # ------------------------------------------------------
728 OptionalSettingsFolder="${PKGROOT}/OptionalSettings"
729
730 while IFS= read -r -d '' OptionsFile; do
731
732 # Take filename and strip .txt from end and path from front
733 builtOptionsList=${OptionsFile%.txt}
734 builtOptionsList=${builtOptionsList##*/}
735 packagesidentity="${chameleon_package_identity}.options.$builtOptionsList"
736
737 echo "================= $builtOptionsList ================="
738
739 # ------------------------------------------------------
740 # Read boot option file into an array.
741 # ------------------------------------------------------
742 availableOptions=() # array to hold the list of boot options, per 'section'.
743 exclusiveFlag="" # used to indicate list has exclusive options
744 while read textLine; do
745 # ignore lines in the file beginning with a #
746 [[ $textLine = \#* ]] && continue
747 local optionName="" key="" value=""
748 case "$textLine" in
749 Exclusive=[Tt][Rr][Uu][Ee]) exclusiveFlag="--exclusive_zero_or_one_choice" ;;
750 Exclusive=*) continue ;;
751 *@*:*=*)
752 availableOptions[${#availableOptions[*]}]="$textLine" ;;
753 *) echo "Error: invalid line '$textLine' in file '$OptionsFile'" >&2
754 exit 1
755 ;;
756 esac
757 done < "$OptionsFile"
758
759 addGroupChoices --parent="Options" $exclusiveFlag "${builtOptionsList}"
760
761 # ------------------------------------------------------
762 # Loop through options in array and process each in turn
763 # ------------------------------------------------------
764 for textLine in "${availableOptions[@]}"; do
765 # split line - taking all before ':' as option name
766 # and all after ':' as key/value
767 type=$( echo "${textLine%%@*}" | tr '[:upper:]' '[:lower:]' )
768 tmp=${textLine#*@}
769 optionName=${tmp%%:*}
770 keyValue=${tmp##*:}
771 key=${keyValue%%=*}
772 value=${keyValue#*=}
773
774 # create folders required for each boot option
775 mkdir -p "${PKG_BUILD_DIR}/$optionName/Root/"
776
777 case "$type" in
778 bool) startSelected="check_chameleon_bool_option('$key','$value')" ;;
779 text) startSelected="check_chameleon_text_option('$key','$value')" ;;
780 list) startSelected="check_chameleon_list_option('$key','$value')" ;;
781 *) echo "Error: invalid type '$type' in line '$textLine' in '$OptionsFile'" >&2
782 exit 1
783 ;;
784 esac
785 recordChameleonOption "$type" "$key" "$value"
786 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/$optionName" \
787 --subst="optionType=$type" \
788 --subst="optionKey=$key" \
789 --subst="optionValue=$value" \
790 AddOption
791 packageRefId=$(getPackageRefId "${packagesidentity}" "${optionName}")
792 buildpackage "$packageRefId" "${optionName}" "${PKG_BUILD_DIR}/${optionName}" "/"
793 addChoice --group="${builtOptionsList}" \
794 --start-selected="$startSelected" \
795 --pkg-refs="$packageRefId" "${optionName}"
796 done
797
798 done < <( find "${OptionalSettingsFolder}" -depth 1 -type f -name '*.txt' -print0 )
799
800# End build options packages
801
802if [[ -n "${CONFIG_KEYLAYOUT_MODULE}" ]];then
803# build Keymaps options packages
804 echo "================= Keymaps Options ================="
805 addGroupChoices --exclusive_zero_or_one_choice "Keymaps"
806 packagesidentity="${chameleon_package_identity}.options.keymaps"
807 keylayoutPackageRefId=""
808 if [[ "${CONFIG_MODULES}" == 'y' && "${CONFIG_KEYLAYOUT_MODULE}" = 'm' ]];then
809 keylayoutPackageRefId=$(getPackageRefId "${modules_packages_identity}" "Keylayout")
810 fi
811
812 chameleon_keylayout_key="KeyLayout"
813 # ------------------------------------------------------
814 # Available Keylayout boot options are discovered by
815 # reading contents of /Keymaps folder after compilation
816 # ------------------------------------------------------
817 availableOptions=($( find "${SRCROOT}/Keymaps" -type f -depth 1 -name '*.lyt' | sed 's|.*/||;s|\.lyt||' ))
818 # Adjust array contents to match expected format
819 # for boot options which is: name:key=value
820 for (( i = 0 ; i < ${#availableOptions[@]} ; i++ )); do
821 # Start build of a keymap package module
822 choiceId="${availableOptions[i]}"
823 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
824
825 recordChameleonOption "text" "$chameleon_keylayout_key" "$choiceId"
826 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
827 --subst="optionType=text" \
828 --subst="optionKey=$chameleon_keylayout_key" \
829 --subst="optionValue=$choiceId" \
830 AddOption
831 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
832 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
833 # Add the Keylayout package because the Keylayout module is needed
834 addChoice --group="Keymaps" \
835 --start-selected="check_chameleon_text_option('${chameleon_keylayout_key}','${choiceId}')" \
836 --pkg-refs="$packageRefId $keylayoutPackageRefId" "${choiceId}"
837 done
838
839# End build Keymaps options packages
840fi
841
842# build theme packages
843 echo "================= Themes ================="
844 addGroupChoices "Themes"
845
846 # Using themes section from Azi's/package branch.
847 packagesidentity="${chameleon_package_identity}.themes"
848 artwork="${SRCROOT}/artwork/themes"
849 themes=($( find "${artwork}" -type d -depth 1 -not -name '.svn' ))
850 for (( i = 0 ; i < ${#themes[@]} ; i++ )); do
851 themeName=$( echo ${themes[$i]##*/} | awk 'BEGIN{OFS=FS=""}{$1=toupper($1);print}' )
852 themeDir="$themeName"
853 mkdir -p "${PKG_BUILD_DIR}/${themeName}/Root/"
854 rsync -r --exclude=.svn --exclude="*~" "${themes[$i]}/" "${PKG_BUILD_DIR}/${themeName}/Root/${themeName}"
855 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${themeName}" \
856 --subst="themeName=$themeName" \
857 --subst="themeDir=$themeDir" \
858 InstallTheme
859
860 packageRefId=$(getPackageRefId "${packagesidentity}" "${themeName}")
861 buildpackage "$packageRefId" "${themeName}" "${PKG_BUILD_DIR}/${themeName}" "/Extra/Themes"
862 addChoice --group="Themes" --start-selected="false" --pkg-refs="$packageRefId" "${themeName}"
863 done
864# End build theme packages# End build Extras package
865
866# build pre install package
867 echo "================= Pre ================="
868 packagesidentity="${chameleon_package_identity}"
869 choiceId="Pre"
870
871 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
872 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
873 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources
874 local yamlFile="Resources/chameleon_options.yaml"
875 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \
876 --subst="YAML_FILE=${yamlFile}" ${choiceId}
877 generate_options_yaml_file "${PKG_BUILD_DIR}/${choiceId}/Scripts/$yamlFile"
878 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
879# End build pre install package
880
881# build post install package
882 echo "================= Post ================="
883 packagesidentity="${chameleon_package_identity}"
884 choiceId="Post"
885 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
886 addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" ${choiceId}
887 cp -f ${PKGROOT}/Scripts/Sub/UnMountEFIvolumes.sh ${PKG_BUILD_DIR}/${choiceId}/Scripts
888
889 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
890 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
891 addChoice --start-visible="false" --start-selected="true" --pkg-refs="$packageRefId" "${choiceId}"
892# End build post install package
893
894}
895
896buildpackage ()
897{
898 # $1 Package Reference Id (ie: org.chameleon.themes.default)
899 # $2 Package Name (ie: Default)
900 # $3 Path to package to build containing Root and/or Scripts
901 # $4 Target install location
902 # $5 Size (optional)
903 if [[ -d "${3}/Root" ]]; then
904 local packageRefId="$1"
905 local packageName="$2"
906 local packagePath="$3"
907 local targetPath="$4"
908 set +u # packageSize is optional
909 local packageSize="$5"
910 set -u
911
912 echo -e "\t[BUILD] ${packageName}"
913
914 find "${packagePath}" -name '.DS_Store' -delete
915 local filecount=$( find "${packagePath}/Root" | wc -l )
916 if [ "${packageSize}" ]; then
917 local installedsize="${packageSize}"
918 else
919 local installedsize=$( du -hkc "${packagePath}/Root" | tail -n1 | awk {'print $1'} )
920 fi
921 local header="<?xml version=\"1.0\"?>\n<pkg-info format-version=\"2\" "
922
923 #[ "${3}" == "relocatable" ] && header+="relocatable=\"true\" "
924
925 header+="identifier=\"${packageRefId}\" "
926 header+="version=\"${CHAMELEON_VERSION}\" "
927
928 [ "${targetPath}" != "relocatable" ] && header+="install-location=\"${targetPath}\" "
929
930 header+="auth=\"root\">\n"
931 header+="\t<payload installKBytes=\"${installedsize##* }\" numberOfFiles=\"${filecount##* }\"/>\n"
932 rm -R -f "${packagePath}/Temp"
933
934 [ -d "${packagePath}/Temp" ] || mkdir -m 777 "${packagePath}/Temp"
935 [ -d "${packagePath}/Root" ] && mkbom "${packagePath}/Root" "${packagePath}/Temp/Bom"
936
937 if [ -d "${packagePath}/Scripts" ]; then
938 header+="\t<scripts>\n"
939 for script in $( find "${packagePath}/Scripts" -type f \( -name 'pre*' -or -name 'post*' \) ); do
940 header+="\t\t<${script##*/} file=\"./${script##*/}\"/>\n"
941 done
942 header+="\t</scripts>\n"
943 # Create the Script archive file (cpio format)
944 (cd "${packagePath}/Scripts" && find . -print | \
945 cpio -o -z -R root:wheel --format cpio > "${packagePath}/Temp/Scripts") 2>&1 | \
946 grep -vE '^[0-9]+\s+blocks?$' # to remove cpio stderr messages
947 fi
948
949 header+="</pkg-info>"
950 echo -e "${header}" > "${packagePath}/Temp/PackageInfo"
951
952 # Create the Payload file (cpio format)
953 (cd "${packagePath}/Root" && find . -print | \
954 cpio -o -z -R root:wheel --format cpio > "${packagePath}/Temp/Payload") 2>&1 | \
955 grep -vE '^[0-9]+\s+blocks?$' # to remove cpio stderr messages
956
957 # Create the package
958 (cd "${packagePath}/Temp" && xar -c -f "${packagePath}/../${packageName}.pkg" --compression none .)
959
960 # Add the package to the list of build packages
961 pkgrefs[${#pkgrefs[*]}]="\t<pkg-ref id=\"${packageRefId}\" installKBytes='${installedsize}' version='${CHAMELEON_VERSION}.0.0.${CHAMELEON_TIMESTAMP}'>#${packageName}.pkg</pkg-ref>"
962
963 rm -rf "${packagePath}"
964 fi
965}
966
967generateOutlineChoices() {
968 # $1 Main Choice
969 # $2 indent level
970 local idx=$(getChoiceIndex "$1")
971 local indentLevel="$2"
972 local indentString=""
973 for ((level=1; level <= $indentLevel ; level++)); do
974 indentString="\t$indentString"
975 done
976 set +u; subChoices="${choice_group_items[$idx]}"; set -u
977 if [[ -n "${subChoices}" ]]; then
978 # Sub choices exists
979 echo -e "$indentString<line choice=\"$1\">"
980 for subChoice in $subChoices;do
981 generateOutlineChoices $subChoice $(($indentLevel+1))
982 done
983 echo -e "$indentString</line>"
984 else
985 echo -e "$indentString<line choice=\"$1\"/>"
986 fi
987}
988
989generateChoices() {
990 for (( idx=1; idx < ${#choice_key[*]} ; idx++)); do
991 local choiceId=${choice_key[$idx]}
992 local choiceOptions=${choice_options[$idx]}
993 local choiceParentGroupIndex=${choice_parent_group_index[$idx]}
994 set +u; local group_exclusive=${choice_group_exclusive[$choiceParentGroupIndex]}; set -u
995
996 # Create the node and standard attributes
997 local choiceNode="\t<choice\n\t\tid=\"${choiceId}\"\n\t\ttitle=\"${choiceId}_title\"\n\t\tdescription=\"${choiceId}_description\""
998
999 # Add options like start_selected, etc...
1000 [[ -n "${choiceOptions}" ]] && choiceNode="${choiceNode}\n\t\t${choiceOptions}"
1001
1002 # Add the selected attribute if options are mutually exclusive
1003 if [[ -n "$group_exclusive" ]];then
1004 local group_items="${choice_group_items[$choiceParentGroupIndex]}"
1005 case $group_exclusive in
1006 exclusive_one_choice)
1007 local selected_option=$(exclusive_one_choice "$choiceId" "$group_items") ;;
1008 exclusive_zero_or_one_choice)
1009 local selected_option=$(exclusive_zero_or_one_choice "$choiceId" "$group_items") ;;
1010 *) echo "Error: unknown function to generate exclusive mode '$group_exclusive' for group '${choice_key[$choiceParentGroupIndex]}'" >&2
1011 exit 1
1012 ;;
1013 esac
1014 choiceNode="${choiceNode}\n\t\tselected=\"$selected_option\""
1015 fi
1016
1017 choiceNode="${choiceNode}>"
1018
1019 # Add the package references
1020 for pkgRefId in ${choice_pkgrefs[$idx]};do
1021 choiceNode="${choiceNode}\n\t\t<pkg-ref id=\"${pkgRefId}\"/>"
1022 done
1023
1024 # Close the node
1025 choiceNode="${choiceNode}\n\t</choice>\n"
1026
1027 echo -e "$choiceNode"
1028 done
1029}
1030
1031makedistribution ()
1032{
1033 declare -r distributionDestDir="${SYMROOT}"
1034 declare -r distributionFilename="${packagename// /}-${CHAMELEON_VERSION}-r${CHAMELEON_REVISION}.pkg"
1035 declare -r distributionFilePath="${distributionDestDir}/${distributionFilename}"
1036
1037 rm -f "${distributionDestDir}/${packagename// /}"*.pkg
1038
1039 mkdir -p "${PKG_BUILD_DIR}/${packagename}"
1040
1041 find "${PKG_BUILD_DIR}" -type f -name '*.pkg' -depth 1 | while read component
1042 do
1043 pkg="${component##*/}" # ie: EFI.pkg
1044 pkgdir="${PKG_BUILD_DIR}/${packagename}/${pkg}"
1045 # expand individual packages
1046 pkgutil --expand "${PKG_BUILD_DIR}/${pkg}" "$pkgdir"
1047 rm -f "${PKG_BUILD_DIR}/${pkg}"
1048 done
1049
1050# Create the Distribution file
1051 ditto --noextattr --noqtn "${PKGROOT}/Distribution" "${PKG_BUILD_DIR}/${packagename}/Distribution"
1052
1053 local start_indent_level=2
1054 echo -e "\n\t<choices-outline>" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
1055 for main_choice in ${choice_group_items[0]};do
1056 generateOutlineChoices $main_choice $start_indent_level >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
1057 done
1058 echo -e "\t</choices-outline>\n" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
1059
1060 generateChoices >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
1061
1062 for (( i=0; i < ${#pkgrefs[*]} ; i++)); do
1063 echo -e "${pkgrefs[$i]}" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
1064 done
1065
1066 echo -e "\n</installer-gui-script>" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
1067
1068# Create the Resources directory
1069 ditto --noextattr --noqtn "${PKGROOT}/Resources/distribution" "${PKG_BUILD_DIR}/${packagename}/Resources"
1070
1071# Make the translation
1072 echo ""
1073 echo "========= Translating Resources ========"
1074 (cd "${PKGROOT}" && PERLLIB=${PKGROOT}/bin/po4a/lib \
1075 bin/po4a/po4a \
1076 --package-name 'Chameleon' \
1077 --package-version "${CHAMELEON_VERSION}-r${CHAMELEON_REVISION}" \
1078 --msgmerge-opt '--lang=$lang' \
1079 --variable PODIR="po" \
1080 --variable TEMPLATES_DIR="Resources/templates" \
1081 --variable OUTPUT_DIR="${PKG_BUILD_DIR}/${packagename}/Resources" \
1082 ${PKGROOT}/po4a-chameleon.cfg)
1083
1084 # Copy common files in english localisation directory
1085 ditto --noextattr --noqtn "${PKGROOT}/Resources/common" "${PKG_BUILD_DIR}/${packagename}/Resources/en.lproj"
1086
1087 # CleanUp the directory
1088 find "${PKG_BUILD_DIR}/${packagename}" \( -type d -name '.svn' \) -o -name '.DS_Store' -depth -exec rm -rf {} \;
1089 find "${PKG_BUILD_DIR}/${packagename}" -type d -depth -empty -exec rmdir {} \; # Remove empty directories
1090
1091 # Make substitutions for version, revision, stage, developers, credits, etc..
1092 makeSubstitutions $( find "${PKG_BUILD_DIR}/${packagename}/Resources" -type f )
1093
1094# Create the final package
1095 pkgutil --flatten "${PKG_BUILD_DIR}/${packagename}" "${distributionFilePath}"
1096
1097# Here is the place to assign an icon to the pkg
1098 ditto -xk "${PKGROOT}/Icons/pkg.zip" "${PKG_BUILD_DIR}/Icons/"
1099 DeRez -only icns "${PKG_BUILD_DIR}/Icons/Icons/pkg.icns" > "${PKG_BUILD_DIR}/Icons/tempicns.rsrc"
1100 Rez -append "${PKG_BUILD_DIR}/Icons/tempicns.rsrc" -o "${distributionFilePath}"
1101 SetFile -a C "${distributionFilePath}"
1102 rm -rf "${PKG_BUILD_DIR}/Icons"
1103
1104# End
1105
1106 md5=$( md5 "${distributionFilePath}" | awk {'print $4'} )
1107 echo "MD5 (${distributionFilePath}) = ${md5}" > "${distributionFilePath}.md5"
1108 echo ""
1109
1110 echo -e $COL_GREEN" --------------------------"$COL_RESET
1111 echo -e $COL_GREEN" Building process complete!"$COL_RESET
1112 echo -e $COL_GREEN" --------------------------"$COL_RESET
1113 echo ""
1114 echo -e $COL_GREEN" Build info."
1115 echo -e $COL_GREEN" ==========="
1116 echo -e $COL_BLUE" Package name: "$COL_RESET"${distributionFilename}"
1117 echo -e $COL_BLUE" MD5: "$COL_RESET"$md5"
1118 echo -e $COL_BLUE" Version: "$COL_RESET"$CHAMELEON_VERSION"
1119 echo -e $COL_BLUE" Stage: "$COL_RESET"$CHAMELEON_STAGE"
1120 echo -e $COL_BLUE" Date/Time: "$COL_RESET"$CHAMELEON_BUILDDATE"
1121 echo -e $COL_BLUE" Built by: "$COL_RESET"$CHAMELEON_WHOBUILD"
1122 echo -e $COL_BLUE" Copyright $CHAMELEON_CPRYEAR ""$COL_RESET"
1123 echo ""
1124
1125}
1126
1127# build packages
1128main
1129
1130# build meta package
1131makedistribution
1132

Archive Download this file

Revision: 2110