Chameleon

Chameleon Svn Source Tree

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

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

Archive Download this file

Revision: 1836