Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 1811