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