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

Archive Download this file

Revision: 1777