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

Archive Download this file

Revision: 1806