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

Archive Download this file

Revision: 1766