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

Archive Download this file

Revision: 1784