Chameleon

Chameleon Commit Details

Date:2011-12-31 18:53:38 (12 years 3 months ago)
Author:JrCs
Commit:1765
Parents: 1764
Message:Improved buildpkg script - Simplify the construction of options menu - Add a lot of checks to avoid the construction of a bad XML file
Changes:
M/trunk/package/buildpkg.sh

File differences

trunk/package/buildpkg.sh
1515
1616
1717
18
18
1919
2020
2121
......
6262
6363
6464
65
66
67
68
69
70
71
72
73
7465
7566
76
77
67
68
69
70
71
72
7873
74
75
76
77
78
79
80
7981
8082
8183
......
8688
8789
8890
91
92
93
94
95
8996
9097
9198
9299
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
93115
116
117
118
119
120
121
122
94123
95
96
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
97156
98
99
100
101
102
103
104
105
157
158
159
160
161
162
163
164
165
166
167
106168
107
108169
109
110
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
111186
112187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
113227
114228
115229
......
146260
147261
148262
149
150
151263
152264
153
154265
155266
156267
......
159270
160271
161272
162
273
163274
164275
165
276
166277
167278
168279
......
182293
183294
184295
185
296
186297
187298
188
299
189300
190301
191302
192303
193
194
195
304
196305
197
198306
199307
200308
201309
202310
203
311
204312
205313
206
207
314
208315
209316
210317
211318
212319
213320
214
321
215322
216323
217
218
324
219325
220326
221
222
223327
224328
225329
226330
227
228
229
331
230332
231
232
233333
234334
235335
......
237337
238338
239339
240
340
241341
242342
243
244
343
245344
246345
247346
......
251350
252351
253352
254
353
255354
256355
257
258
356
259357
260358
261359
262360
263361
264
362
265363
266364
267
268
365
269366
270367
271
272
273368
274369
275370
......
285380
286381
287382
288
289
290
383
291384
292385
293386
......
296389
297390
298391
299
392
300393
301394
302
395
303396
304397
305398
......
311404
312405
313406
314
407
315408
316409
317
410
318411
319412
320413
......
331424
332425
333426
334
427
335428
336429
337430
338
431
339432
340433
341434
......
360453
361454
362455
363
456
364457
365458
366459
367460
368
461
369462
370463
371464
372465
373
374
375466
376467
377468
......
383474
384475
385476
386
387
388
477
389478
390
391479
392480
393481
......
397485
398486
399487
400
401
402
403
404
405
406
407
488
489
490
408491
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
492
426493
427
428
429
430
431
432
433
434
435
436
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
437510
438
439
511
512
440513
441
442
514
515
516
517
518
519
520
521
522
523
524
443525
444
445
446
447
448
449
450
451
452
526
527
453528
454
455
456
529
530
457531
458
459
532
533
534
535
536
537
538
460539
461540
462541
463542
464
465
466
467
468
543
544
545
469546
470547
471548
472549
473550
474
475
476
477
478
479
480
481
482
483
484
485
486
551
552
553
554
555
556
557
558
559
560
561
562
487563
488
489
564
565
490566
491
492
493
494
495
496
497
498
499
567
568
569
570
571
500572
501
502
503
504573
505574
506575
507576
508
509
510
511
577
578
512579
513
514
515
516
517
518
519
520
521
522
523
524
525
580
581
582
583
584
585
586
587
526588
527
528
589
590
591
592
529593
530594
531595
......
539603
540604
541605
542
606
543607
544608
545
609
546610
547611
548
549
550
551612
552613
553614
554615
555
556
557
558
559
560
561
562
563
564
565
616
617
618
619
620
621
622
623
624
625
626
566627
567628
568629
569
570
571
572
573
574
575
576
630
577631
578
632
633
634
635
636
637
638
639
579640
580
581
641
582642
583
643
644
584645
585
586
587
646
588647
589
590
648
649
650
591651
592
593
594
595
596
597
598
599
600
652
653
654
655
656
657
658
659
660
661
662
663
601664
602665
603
604
666
667
605668
606
607
608
669
670
671
609672
610
611
673
674
612675
613
614
676
677
615678
616
617
679
680
618681
619682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
620747
621748
622749
......
628755
629756
630757
631
758
632759
633760
634761
......
639766
640767
641768
642
643
644
769
770
771
772
773
774
645775
646
647
648
776
649777
650778
651779
fi
if [[ ! -d "$SYMROOT" ]];then
echo "Directory ${SYMROOT} doesn't exit. Aborting..." >&2 && exit 1
echo "Directory ${SYMROOT} doesn't exit. Aborting..." >&2 && exit 1
fi
# Prevent the script from doing bad things
declare -r credits=$(awk "NR==10{print;exit}" ${PKGROOT}/../CREDITS)
declare -r pkgdev=$(awk "NR==14{print;exit}" ${PKGROOT}/../CREDITS)
# =================
xmlindent=0
indent[0]="\t"
indent[1]="\t\t"
indent[2]="\t\t\t"
indent[3]="\t\t\t\t"
# ====== GLOBAL VARIABLES ======
declare -a pkgrefs
declare -a outline
declare -a choices
declare -a choice_key
declare -a choice_options
declare -a choice_pkgrefs
declare -a choice_parent_group_index
declare -a choice_group_items
declare -a choice_group_exclusive
# Init Main Group
choice_key[0]=""
choice_options[0]=""
choices_pkgrefs[0]=""
choice_group_items[0]=""
choice_group_exclusive[0]=""
# Package name
declare -r packagename="Chameleon"
# ====== FUNCTIONS ======
trim () {
local result="${1#"${1%%[![:space:]]*}"}" # remove leading whitespace characters
echo "${result%"${result##*[![:space:]]}"}" # remove trailing whitespace characters
}
getPackageRefId () {
echo ${1//_/.}.${2//_/.} | tr [:upper:] [:lower:]
}
# Return index of a choice
getChoiceIndex () {
# $1 Choice Id
local found=0
for (( idx=0 ; idx < ${#choice_key[*]}; idx++ ));do
if [[ "${1}" == "${choice_key[$idx]}" ]];then
found=1
break
fi
done
echo "$idx"
return $found
}
# Add a new choice
addChoice () {
# Optionnal arguments:
# --group=<group> : Group Choice Id
# --start-selected=<javascript code> : Specifies whether this choice is initially selected or unselected
# --start-enabled=<javascript code> : Specifies the initial enabled state of this choice
# --start-visible=<javascript code> : Specifies whether this choice is initially visible
# --pkg-refs=<pkgrefs> : List of package reference(s) id (separate by spaces)
#
# $1 Choice Id
# $2 Choice Options
# $3..$n Package reference id (optional)
local option
local groupChoice=""
local choiceOptions=""
local pkgrefs=""
# Check the arguments.
for option in "${@}";do
case "$option" in
--group=*)
shift; groupChoice=${option#*=} ;;
--start-selected=*)
shift; choiceOptions="$choiceOptions start_selected=\"${option#*=}\"" ;;
--start-enabled=*)
shift; choiceOptions="$choiceOptions start_enabled=\"${option#*=}\"" ;;
--start-visible=*)
shift; choiceOptions="$choiceOptions start_visible=\"${option#*=}\"" ;;
--pkg-refs=*)
shift; pkgrefs=${option#*=} ;;
-*)
echo "Unrecognized addChoice option '$option'" >&2
exit 1
;;
*) break ;;
esac
done
if [[ $# -ne 1 ]];then
echo "addChoice invalid number of arguments: ${@}" >&2
exit 1
fi
local choiceId="${1}"
local choiceOptions="${2}"
local choiceNode="\t<choice\n\t\tid=\"${choiceId}\"\n\t\ttitle=\"${choiceId}_title\"\n\t\tdescription=\"${choiceId}_description\""
[[ -n "${choiceOptions}" ]] && choiceNode="${choiceNode}\n\t\t${choiceOptions}"
choiceNode="${choiceNode}>"
if [[ $# -ge 3 ]];then
for pkgRefId in ${@:3};do
choiceNode="${choiceNode}\n\t\t<pkg-ref id=\"${pkgRefId}\"/>"
done
# Add choice in the group
idx_group=$(getChoiceIndex "$groupChoice")
found_group=$?
if [[ $found_group -ne 1 ]];then
# No group exist
echo "Error can't add choice '$choiceId' to group '$groupChoice': group choice '$groupChoice' doesn't exists." >&2
exit 1
else
set +u; oldItems=${choice_group_items[$idx_group]}; set -u
choice_group_items[$idx_group]="$oldItems $choiceId"
fi
choiceNode="${choiceNode}\n\t</choice>\n"
outline[${#outline[*]}]="${indent[$xmlindent]}<line choice=\"${choiceId}\"/>"
choices[${#choices[*]}]="$choiceNode"
# Check that the choice doesn't already exists
idx=$(getChoiceIndex "$choiceId")
found=$?
if [[ $found -ne 0 ]];then
# Choice already exists
echo "Error can't add choice '$choiceId': a choice with same name already exists." >&2
exit 1
fi
# Record new node
choice_key[$idx]="$choiceId"
choice_options[$idx]=$(trim "${choiceOptions}") # Removing leading and trailing whitespace(s)
choice_parent_group_index[$idx]=$idx_group
choice_pkgrefs[$idx]="$pkgrefs"
return $idx
}
# Add a group choice
addGroupChoices() {
# $1 Choice Id
# $2 Parent group choice Id (empty if main group)
# $3 Exclusive mode (optional):
# exclusive_zero_or_one_choice
# exclusive_one_choice
# Check the arguments.
local option
local groupChoice=""
local exclusive_function=""
for option in "${@}";do
case "$option" in
--exclusive_zero_or_one_choice)
shift; exclusive_function="exclusive_zero_or_one_choice" ;;
--exclusive_one_choice)
shift; exclusive_function="exclusive_one_choice" ;;
--group=*)
shift; groupChoice=${option#*=} ;;
-*)
echo "Unrecognized addGroupChoices option '$option'" >&2
exit 1
;;
*) break ;;
esac
done
if [[ $# -ne 1 ]];then
echo "addGroupChoices invalid number of arguments: ${@}" >&2
exit 1
fi
addChoice --group="$groupChoice" "${1}"
local idx=$? # index of the new created choice
choice_group_exclusive[$idx]="$exclusive_function"
}
exclusive_one_choice () {
# $1 Current choice (ie: test1)
# $2..$n Others choice(s) (ie: "test2" "test3"). Current can or can't be in the others choices
echo -e $COL_CYAN" ----------------------------------"$COL_RESET
echo ""
outline[${#outline[*]}]="${indent[$xmlindent]}<choices-outline>"
# build pre install package
echo "================= Preinstall ================="
((xmlindent++))
packagesidentity="${chameleon_package_identity}"
choiceId="Pre"
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
ditto --noextattr --noqtn ${SRCROOT}/version ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources/version
cp -f ${PKGROOT}/Scripts/Main/preinstall ${PKG_BUILD_DIR}/${choiceId}/Scripts
cp -f ${PKGROOT}/Scripts/Sub/InstallLog.sh ${PKG_BUILD_DIR}/${choiceId}/Scripts
echo -e "\t[BUILD] ${choiceId} "
packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
addChoice "${choiceId}" "start_visible=\"false\" start_selected=\"true\"" "$packageRefId"
addChoice --start-visible="false" --start-selected="true" --pkg-refs="$packageRefId" "${choiceId}"
# End build pre install package
# build core package
ditto --noextattr --noqtn ${SYMROOT}/i386/chain0 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/fdisk440 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
ditto --noextattr --noqtn ${SYMROOT}/i386/bdmesg ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
echo -e "\t[BUILD] ${choiceId} "
packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
addChoice "${choiceId}" "start_visible=\"false\" start_selected=\"true\"" "$packageRefId"
addChoice --start-visible="false" --start-selected="true" --pkg-refs="$packageRefId" "${choiceId}"
# End build core package
# build install type
echo "================= Chameleon ================="
outline[${#outline[*]}]="${indent[$xmlindent]}<line choice=\"InstallType\">"
choices[${#choices[*]}]="\t<choice\n\t\tid=\"InstallType\"\n\t\ttitle=\"InstallType_title\"\n\t\tdescription=\"InstallType_description\">\n\t</choice>\n"
((xmlindent++))
addGroupChoices --exclusive_one_choice "InstallType"
packagesidentity="${chameleon_package_identity}.type"
allChoices="New Upgrade"
# build new install package
choiceId="New"
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
echo "" > "${PKG_BUILD_DIR}/${choiceId}/Root/install_type_new"
echo -e "\t[BUILD] ${choiceId} "
packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/$chamTemp"
exclusiveChoice=$(exclusive_one_choice "$choiceId" "$allChoices")
addChoice "${choiceId}" "start_selected=\"!choices['Upgrade'].selected\" selected=\"${exclusiveChoice}\"" "$packageRefId"
addChoice --group="InstallType" --start-selected="!choices['Upgrade'].selected" --pkg-refs="$packageRefId" "${choiceId}"
# End build new install package
# build upgrade package
choiceId="Upgrade"
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
echo "" > "${PKG_BUILD_DIR}/${choiceId}/Root/install_type_upgrade"
echo -e "\t[BUILD] ${choiceId} "
packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/$chamTemp"
exclusiveChoice=$(exclusive_one_choice "$choiceId" "$allChoices")
addChoice "${choiceId}" "start_selected=\"chameleon_boot_plist_exists()\" selected=\"${exclusiveChoice}\"" "$packageRefId"
addChoice --group="InstallType" --start-selected="chameleon_boot_plist_exists()" --pkg-refs="$packageRefId" "${choiceId}"
# End build upgrade package
((xmlindent--))
outline[${#outline[*]}]="${indent[$xmlindent]}</line>"
# End build install type
# build Chameleon package
echo "================= Chameleon ================="
outline[${#outline[*]}]="${indent[$xmlindent]}<line choice=\"Chameleon\">"
choices[${#choices[*]}]="\t<choice\n\t\tid=\"Chameleon\"\n\t\ttitle=\"Chameleon_title\"\n\t\tdescription=\"Chameleon_description\">\n\t</choice>\n"
((xmlindent++))
addGroupChoices --exclusive_one_choice "Chameleon"
allChoices="Standard EFI noboot"
# build standard package
choiceId="Standard"
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
cp -f ${PKGROOT}/Scripts/Main/${choiceId}postinstall ${PKG_BUILD_DIR}/${choiceId}/Scripts/postinstall
cp -f ${PKGROOT}/Scripts/Sub/* ${PKG_BUILD_DIR}/${choiceId}/Scripts
ditto --arch i386 `which SetFile` ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources/SetFile
echo -e "\t[BUILD] ${choiceId} "
packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
exclusiveChoice=$(exclusive_one_choice "$choiceId" "$allChoices")
addChoice "${choiceId}" "start_selected=\"true\" selected=\"${exclusiveChoice}\"" "$packageRefId"
addChoice --group="Chameleon" --start-selected="true" --pkg-refs="$packageRefId" "${choiceId}"
# End build standard package
# build efi package
cp -f ${PKGROOT}/Scripts/Main/ESPpostinstall ${PKG_BUILD_DIR}/${choiceId}/Scripts/postinstall
cp -f ${PKGROOT}/Scripts/Sub/* ${PKG_BUILD_DIR}/${choiceId}/Scripts
ditto --arch i386 `which SetFile` ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources/SetFile
echo -e "\t[BUILD] ${choiceId} "
packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
exclusiveChoice=$(exclusive_one_choice "$choiceId" "$allChoices")
addChoice "${choiceId}" "start_visible=\"systemHasGPT()\" start_selected=\"false\" selected=\"${exclusiveChoice}\"" "$packageRefId"
addChoice --group="Chameleon" --start-visible="systemHasGPT()" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
# End build efi package
# build no bootloader choice package
choiceId="noboot"
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
echo -e "\t[BUILD] ${choiceId} "
packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
exclusiveChoice=$(exclusive_one_choice "$choiceId" "$allChoices")
addChoice "${choiceId}" "start_selected=\"false\" selected=\"${exclusiveChoice}\"" "$packageRefId"
addChoice --group="Chameleon" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
# End build no bootloader choice package
((xmlindent--))
outline[${#outline[*]}]="${indent[$xmlindent]}</line>"
# End build Chameleon package
if [[ "${CONFIG_MODULES}" == 'y' ]];then
###############################
if [ "$(ls -A "${SYMROOT}/i386/modules")" ]; then
{
outline[${#outline[*]}]="${indent[$xmlindent]}<line choice=\"Module\">"
choices[${#choices[*]}]="\t<choice\n\t\tid=\"Module\"\n\t\ttitle=\"Module_title\"\n\t\tdescription=\"Module_description\">\n\t</choice>\n"
((xmlindent++))
addGroupChoices "Module"
# -
if [[ "${CONFIG_RESOLUTION_MODULE}" == 'm' && -f "${SYMROOT}/i386/modules/Resolution.dylib" ]]; then
choiceId="AutoReso"
mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
ditto --noextattr --noqtn "${SYMROOT}/i386/modules/Resolution.dylib" "${PKG_BUILD_DIR}/${choiceId}/Root"
echo -e "\t[BUILD] ${choiceId} "
packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/$chamTemp/Extra/modules"
addChoice "${choiceId}" "start_selected=\"false\"" "$packageRefId"
addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
# End build Resolution package module
}
fi
choiceId="klibc"
mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
ditto --noextattr --noqtn "${SYMROOT}/i386/modules/${choiceId}.dylib" ${PKG_BUILD_DIR}/${choiceId}/Root
echo -e "\t[BUILD] ${choiceId} "
packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/$chamTemp/Extra/modules"
addChoice "${choiceId}" "start_selected=\"false\"" "$packageRefId"
addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"
# End build klibc package module
}
fi
choiceId="uClibc"
mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"
ditto --noextattr --noqtn "${SYMROOT}/i386/modules/uClibcxx.dylib" "${PKG_BUILD_DIR}/${choiceId}/Root"
echo -e "\t[BUILD] ${choiceId} "
packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/$chamTemp/Extra/modules"
# Add the klibc package because the uClibc module is dependent of klibc module
addChoice "${choiceId}" "start_selected=\"false\"" "$packageRefId" "$klibcPackageRefId"
addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId $klibcPackageRefId" "${choiceId}"
# End build uClibc package module
}
fi
ditto --noextattr --noqtn ${SRCROOT}/Keymaps ${PKG_BUILD_DIR}/${choiceId}/Root/Extra/Keymaps
# Adding tools
ditto --noextattr --noqtn ${SYMROOT}/i386/cham-mklayout ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin
echo -e "\t[BUILD] ${choiceId} "
packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/$chamTemp"
# Don't add a choice for Keylayout module
# addChoice "${choiceId}" "start_selected=\"false\"" "$packageRefId"
# addChoice "${choiceId}" "Module" --start-selected="false" "$packageRefId"
# End build Keylayout package module
}
fi
((xmlindent--))
outline[${#outline[*]}]="${indent[$xmlindent]}</line>"
}
else
{
# build Options packages
outline[${#outline[*]}]="${indent[$xmlindent]}<line choice=\"Options\">"
choices[${#choices[*]}]="\t<choice\n\t\tid=\"Options\"\n\t\ttitle=\"Options_title\"\n\t\tdescription=\"Options_description\">\n\t</choice>\n"
((xmlindent++))
addGroupChoices "Options"
# ------------------------------------------------------
# parse OptionalSettings folder to find files of boot options.
# ------------------------------------------------------
for (( i = 0 ; i < ${#OptionalSettingsFiles[@]} ; i++ ))
do
# Take filename and Strip .txt from end and path from front
builtOptionsList=$( echo ${OptionalSettingsFiles[$i]%.txt} )
builtOptionsList=$( echo ${builtOptionsList##*/} )
echo "================= $builtOptionsList ================="
outline[${#outline[*]}]="${indent[$xmlindent]}<line choice=\"${builtOptionsList}\">"
choices[${#choices[*]}]="\t<choice\n\t\tid=\"${builtOptionsList}\"\n\t\ttitle=\"${builtOptionsList}_title\"\n\t\tdescription=\"${builtOptionsList}_description\">\n\t</choice>\n"
((xmlindent++))
packagesidentity="${chameleon_package_identity}.options.$builtOptionsList"
# Take filename and Strip .txt from end and path from front
builtOptionsList=$( echo ${OptionalSettingsFiles[$i]%.txt} )
builtOptionsList=$( echo ${builtOptionsList##*/} )
# ------------------------------------------------------
# Read boot option file into an array.
# ------------------------------------------------------
availableOptions=() # array to hold the list of boot options, per 'section'.
exclusiveFlag=0 # used to indicate list has exclusive options
count=0 # used as index for stepping through array.
while read textLine; do
# ignore lines in the file beginning with a # and Exclusive=False
if [[ ${textLine} != \#* ]] && [[ ${textLine} != "Exclusive=False" ]];then
# check for 'Exclusive=True' option in file
if [[ ${textLine} == "Exclusive=True" ]];then
exclusiveFlag=1
else
availableOptions[${#availableOptions[@]}]=$textLine
fi
fi
done < ${OptionalSettingsFiles[$i]}
echo "================= $builtOptionsList ================="
# ------------------------------------------------------
# Loop through options in array and process each in turn
# ------------------------------------------------------
allChoices="${availableOptions[@]//:*/}"
for (( c = 0 ; c < ${#availableOptions[@]} ; c++ )); do
textLine=${availableOptions[c]}
# split line - taking all before ':' as option name
# and all after ':' as key/value
optionName=${textLine%:*}
keyValue=${textLine##*:}
# ------------------------------------------------------
# Read boot option file into an array.
# ------------------------------------------------------
availableOptions=() # array to hold the list of boot options, per 'section'.
exclusiveFlag="" # used to indicate list has exclusive options
while read textLine; do
# ignore lines in the file beginning with a # and Exclusive=False
if [[ ${textLine} != \#* ]] && [[ ${textLine} != "Exclusive=False" ]];then
# check for 'Exclusive=True' option in file
if [[ ${textLine} == "Exclusive=True" ]];then
exclusiveFlag="--exclusive_zero_or_one_choice"
else
availableOptions[${#availableOptions[@]}]=$textLine
fi
fi
done < ${OptionalSettingsFiles[$i]}
# create folders required for each boot option
mkdir -p "${PKG_BUILD_DIR}/$optionName/Root/"
addGroupChoices --group="Options" $exclusiveFlag "${builtOptionsList}"
packagesidentity="${chameleon_package_identity}.options.$builtOptionsList"
# create dummy file with name of key/value
echo "" > "${PKG_BUILD_DIR}/$optionName/Root/${keyValue}"
# ------------------------------------------------------
# Loop through options in array and process each in turn
# ------------------------------------------------------
for (( c = 0 ; c < ${#availableOptions[@]} ; c++ )); do
textLine=${availableOptions[c]}
# split line - taking all before ':' as option name
# and all after ':' as key/value
optionName=${textLine%:*}
keyValue=${textLine##*:}
key=${keyValue%%=*}
value=${keyValue#*=}
echo -e "\t[BUILD] ${optionName} "
packageRefId=$(getPackageRefId "${packagesidentity}" "${optionName}")
buildpackage "$packageRefId" "${optionName}" "${PKG_BUILD_DIR}/${optionName}" "/$chamTemp/options"
exclusiveSelect=""
if [[ ${exclusiveFlag} -eq 1 ]];then
exclusiveSelect="selected=\"$(exclusive_zero_or_one_choice "$optionName" "$allChoices")\""
fi
addChoice "${optionName}" "start_selected=\"false\" ${exclusiveSelect}" "$packageRefId"
done
# create folders required for each boot option
mkdir -p "${PKG_BUILD_DIR}/$optionName/Root/"
((xmlindent--))
outline[${#outline[*]}]="${indent[$xmlindent]}</line>"
done
# create dummy file with name of key/value
echo "" > "${PKG_BUILD_DIR}/$optionName/Root/${keyValue}"
((xmlindent--))
outline[${#outline[*]}]="${indent[$xmlindent]}</line>"
packageRefId=$(getPackageRefId "${packagesidentity}" "${optionName}")
buildpackage "$packageRefId" "${optionName}" "${PKG_BUILD_DIR}/${optionName}" "/$chamTemp/options"
addChoice --group="${builtOptionsList}" --start-selected="false" --pkg-refs="$packageRefId" "${optionName}"
done
done
# End build options packages
if [[ -n "${CONFIG_KEYLAYOUT_MODULE}" ]];then
# build KeyLayout options packages
echo "================= Keymaps Options ================="
outline[${#outline[*]}]="${indent[$xmlindent]}<line choice=\"KeyLayout\">"
choices[${#choices[*]}]="\t<choice\n\t\tid=\"KeyLayout\"\n\t\ttitle=\"KeyLayout_title\"\n\t\tdescription=\"KeyLayout_description\">\n\t</choice>\n"
((xmlindent++))
packagesidentity="${chameleon_package_identity}.options.keylayout"
echo "================= Keymaps Options ================="
addGroupChoices --exclusive_zero_or_one_choice "KeyLayout"
packagesidentity="${chameleon_package_identity}.options.keylayout"
keylayoutPackageRefId=""
if [[ "${CONFIG_MODULES}" == 'y' && "${CONFIG_KEYLAYOUT_MODULE}" = 'm' ]];then
keylayoutPackageRefId=$(getPackageRefId "${modules_packages_identity}" "Keylayout")
fi
# ------------------------------------------------------
# Available Keylayout boot options are discovered by
# reading contents of /Keymaps folder after compilation
# ------------------------------------------------------
availableOptions=($( find "${SRCROOT}/Keymaps" -type f -depth 1 -name '*.lyt' | sed 's|.*/||;s|\.lyt||' ))
allChoices="${availableOptions[@]}"
# Adjust array contents to match expected format
# for boot options which is: name:key=value
for (( i = 0 ; i < ${#availableOptions[@]} ; i++ )); do
# availableOptions[i]=${availableOptions[i]}":KeyLayout="${availableOptions[i]}
# Start build of a keymap package module
choiceId="${availableOptions[i]}"
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
# ------------------------------------------------------
# Available Keylayout boot options are discovered by
# reading contents of /Keymaps folder after compilation
# ------------------------------------------------------
availableOptions=($( find "${SRCROOT}/Keymaps" -type f -depth 1 -name '*.lyt' | sed 's|.*/||;s|\.lyt||' ))
# Adjust array contents to match expected format
# for boot options which is: name:key=value
for (( i = 0 ; i < ${#availableOptions[@]} ; i++ )); do
# availableOptions[i]=${availableOptions[i]}":KeyLayout="${availableOptions[i]}
# Start build of a keymap package module
choiceId="${availableOptions[i]}"
mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
# create dummy file with name of key/value
echo "" > "${PKG_BUILD_DIR}/${choiceId}/Root/KeyLayout=${availableOptions[i]}"
# create dummy file with name of key/value
echo "" > "${PKG_BUILD_DIR}/${choiceId}/Root/KeyLayout=${availableOptions[i]}"
echo -e "\t[BUILD] ${choiceId} "
packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/$chamTemp/options"
exclusiveChoice=$(exclusive_zero_or_one_choice "$choiceId" "$allChoices")
# Add the Keylayout package because the Keylayout module is needed
addChoice "${choiceId}" "start_selected=\"false\" selected=\"${exclusiveChoice}\"" \
"$packageRefId" "$keylayoutPackageRefId"
# End build uClibc package module
done
packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/$chamTemp/options"
# Add the Keylayout package because the Keylayout module is needed
addChoice --group="KeyLayout" --start-selected="false" --pkg-refs="$packageRefId $keylayoutPackageRefId" "${choiceId}"
done
((xmlindent--))
outline[${#outline[*]}]="${indent[$xmlindent]}</line>"
# End build KeyLayout options packages
fi
# build theme packages
echo "================= Themes ================="
outline[${#outline[*]}]="${indent[$xmlindent]}<line choice=\"Themes\">"
choices[${#choices[*]}]="\t<choice\n\t\tid=\"Themes\"\n\t\ttitle=\"Themes_title\"\n\t\tdescription=\"Themes_description\">\n\t</choice>\n"
((xmlindent++))
echo "================= Themes ================="
addGroupChoices "Themes"
# Using themes section from Azi's/package branch.
packagesidentity="${chameleon_package_identity}.themes"
artwork="${SRCROOT}/artwork/themes"
themes=($( find "${artwork}" -type d -depth 1 -not -name '.svn' ))
for (( i = 0 ; i < ${#themes[@]} ; i++ )); do
theme=$( echo ${themes[$i]##*/} | awk 'BEGIN{OFS=FS=""}{$1=toupper($1);print}' )
mkdir -p "${PKG_BUILD_DIR}/${theme}/Root/"
rsync -r --exclude=.svn "${themes[$i]}/" "${PKG_BUILD_DIR}/${theme}/Root/${theme}"
echo -e "\t[BUILD] ${theme}"
packageRefId=$(getPackageRefId "${packagesidentity}" "${theme}")
buildpackage "$packageRefId" "${theme}" "${PKG_BUILD_DIR}/${theme}" "/$chamTemp/Extra/Themes"
addChoice "${theme}" "start_selected=\"false\"" "$packageRefId"
done
# Using themes section from Azi's/package branch.
packagesidentity="${chameleon_package_identity}.themes"
artwork="${SRCROOT}/artwork/themes"
themes=($( find "${artwork}" -type d -depth 1 -not -name '.svn' ))
for (( i = 0 ; i < ${#themes[@]} ; i++ )); do
theme=$( echo ${themes[$i]##*/} | awk 'BEGIN{OFS=FS=""}{$1=toupper($1);print}' )
mkdir -p "${PKG_BUILD_DIR}/${theme}/Root/"
rsync -r --exclude=.svn "${themes[$i]}/" "${PKG_BUILD_DIR}/${theme}/Root/${theme}"
((xmlindent--))
outline[${#outline[*]}]="${indent[$xmlindent]}</line>"
packageRefId=$(getPackageRefId "${packagesidentity}" "${theme}")
buildpackage "$packageRefId" "${theme}" "${PKG_BUILD_DIR}/${theme}" "/$chamTemp/Extra/Themes"
addChoice --group="Themes" --start-selected="false" --pkg-refs="$packageRefId" "${theme}"
done
# End build theme packages# End build Extras package
# build post install package
cp -f ${PKGROOT}/Scripts/Sub/UnMountEFIvolumes.sh ${PKG_BUILD_DIR}/${choiceId}/Scripts
ditto --noextattr --noqtn ${SRCROOT}/revision ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources/revision
ditto --noextattr --noqtn ${SRCROOT}/version ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources/version
echo -e "\t[BUILD] ${choiceId} "
packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
addChoice "${choiceId}" "start_visible=\"false\" start_selected=\"true\"" "$packageRefId"
addChoice --start-visible="false" --start-selected="true" --pkg-refs="$packageRefId" "${choiceId}"
# End build post install package
((xmlindent--))
outline[${#outline[*]}]="${indent[$xmlindent]}</choices-outline>"
}
buildpackage ()
{
# $1 Package Reference Id (ie: org.chameleon.themes.default)
# $2 Package Name (ie: Default)
# $3 Path to package to build containing Root and/or Scripts
# $4 Target install location
# $5 Size (optional)
if [[ -d "${3}/Root" ]]; then
local packageRefId="$1"
local packageName="$2"
local packagePath="$3"
local targetPath="$4"
set +u # packageSize is optional
# $1 Package Reference Id (ie: org.chameleon.themes.default)
# $2 Package Name (ie: Default)
# $3 Path to package to build containing Root and/or Scripts
# $4 Target install location
# $5 Size (optional)
if [[ -d "${3}/Root" ]]; then
local packageRefId="$1"
local packageName="$2"
local packagePath="$3"
local targetPath="$4"
set +u # packageSize is optional
local packageSize="$5"
set -u
find "${packagePath}" -name '.DS_Store' -delete
local filecount=$( find "${packagePath}/Root" | wc -l )
if [ "${packageSize}" ]; then
local installedsize="${packageSize}"
else
local installedsize=$( du -hkc "${packagePath}/Root" | tail -n1 | awk {'print $1'} )
fi
local header="<?xml version=\"1.0\"?>\n<pkg-info format-version=\"2\" "
echo -e "\t[BUILD] ${packageName}"
#[ "${3}" == "relocatable" ] && header+="relocatable=\"true\" "
find "${packagePath}" -name '.DS_Store' -delete
local filecount=$( find "${packagePath}/Root" | wc -l )
if [ "${packageSize}" ]; then
local installedsize="${packageSize}"
else
local installedsize=$( du -hkc "${packagePath}/Root" | tail -n1 | awk {'print $1'} )
fi
local header="<?xml version=\"1.0\"?>\n<pkg-info format-version=\"2\" "
header+="identifier=\"${packageRefId}\" "
header+="version=\"${version}\" "
#[ "${3}" == "relocatable" ] && header+="relocatable=\"true\" "
[ "${targetPath}" != "relocatable" ] && header+="install-location=\"${targetPath}\" "
header+="identifier=\"${packageRefId}\" "
header+="version=\"${version}\" "
header+="auth=\"root\">\n"
header+="\t<payload installKBytes=\"${installedsize##* }\" numberOfFiles=\"${filecount##* }\"/>\n"
rm -R -f "${packagePath}/Temp"
[ "${targetPath}" != "relocatable" ] && header+="install-location=\"${targetPath}\" "
[ -d "${packagePath}/Temp" ] || mkdir -m 777 "${packagePath}/Temp"
[ -d "${packagePath}/Root" ] && mkbom "${packagePath}/Root" "${packagePath}/Temp/Bom"
header+="auth=\"root\">\n"
header+="\t<payload installKBytes=\"${installedsize##* }\" numberOfFiles=\"${filecount##* }\"/>\n"
rm -R -f "${packagePath}/Temp"
if [ -d "${packagePath}/Scripts" ]; then
header+="\t<scripts>\n"
for script in $( find "${packagePath}/Scripts" -type f \( -name 'pre*' -or -name 'post*' \) ); do
header+="\t\t<${script##*/} file=\"./${script##*/}\"/>\n"
done
header+="\t</scripts>\n"
# Create the Script archive file (cpio format)
(cd "${packagePath}/Scripts" && find . -print | cpio -o -z -R 0:0 --format cpio > "${packagePath}/Temp/Scripts") 2>&1 | \
grep -vE '^[0-9]+\s+blocks?$' # to remove cpio stderr messages
[ -d "${packagePath}/Temp" ] || mkdir -m 777 "${packagePath}/Temp"
[ -d "${packagePath}/Root" ] && mkbom "${packagePath}/Root" "${packagePath}/Temp/Bom"
if [ -d "${packagePath}/Scripts" ]; then
header+="\t<scripts>\n"
for script in $( find "${packagePath}/Scripts" -type f \( -name 'pre*' -or -name 'post*' \) ); do
header+="\t\t<${script##*/} file=\"./${script##*/}\"/>\n"
done
header+="\t</scripts>\n"
# Create the Script archive file (cpio format)
(cd "${packagePath}/Scripts" && find . -print | cpio -o -z -R 0:0 --format cpio > "${packagePath}/Temp/Scripts") 2>&1 | \
grep -vE '^[0-9]+\s+blocks?$' # to remove cpio stderr messages
fi
header+="</pkg-info>"
echo -e "${header}" > "${packagePath}/Temp/PackageInfo"
header+="</pkg-info>"
echo -e "${header}" > "${packagePath}/Temp/PackageInfo"
# Create the Payload file (cpio format)
(cd "${packagePath}/Root" && find . -print | cpio -o -z -R 0:0 --format cpio > "${packagePath}/Temp/Payload") 2>&1 | \
grep -vE '^[0-9]+\s+blocks?$' # to remove cpio stderr messages
# Create the Payload file (cpio format)
(cd "${packagePath}/Root" && find . -print | cpio -o -z -R 0:0 --format cpio > "${packagePath}/Temp/Payload") 2>&1 | \
grep -vE '^[0-9]+\s+blocks?$' # to remove cpio stderr messages
# Create the package
(cd "${packagePath}/Temp" && xar -c -f "${packagePath}/../${packageName}.pkg" --compression none .)
# Create the package
(cd "${packagePath}/Temp" && xar -c -f "${packagePath}/../${packageName}.pkg" --compression none .)
# Add the package to the list of build packages
pkgrefs[${#pkgrefs[*]}]="\t<pkg-ref id=\"${packageRefId}\" installKBytes='${installedsize}' version='${version}.0.0.${timestamp}'>#${packageName}.pkg</pkg-ref>"
# Add the package to the list of build packages
pkgrefs[${#pkgrefs[*]}]="\t<pkg-ref id=\"${packageRefId}\" installKBytes='${installedsize}' version='${version}.0.0.${timestamp}'>#${packageName}.pkg</pkg-ref>"
rm -rf "${packagePath}"
fi
rm -rf "${packagePath}"
fi
}
generateOutlineChoices() {
# $1 Main Choice
# $2 indent level
local idx=$(getChoiceIndex "$1")
local indentLevel="$2"
local indentString=""
for ((level=1; level <= $indentLevel ; level++)); do
indentString="\t$indentString"
done
set +u; subChoices="${choice_group_items[$idx]}"; set -u
if [[ -n "${subChoices}" ]]; then
# Sub choices exists
echo -e "$indentString<line choice=\"$1\">"
for subChoice in $subChoices;do
generateOutlineChoices $subChoice $(($indentLevel+1))
done
echo -e "$indentString</line>"
else
echo -e "$indentString<line choice=\"$1\"/>"
fi
}
generateChoices() {
for (( idx=1; idx < ${#choice_key[*]} ; idx++)); do
local choiceId=${choice_key[$idx]}
local choiceOptions=${choice_options[$idx]}
local choiceParentGroupIndex=${choice_parent_group_index[$idx]}
set +u; local group_exclusive=${choice_group_exclusive[$choiceParentGroupIndex]}; set -u
# Create the node and standard attributes
local choiceNode="\t<choice\n\t\tid=\"${choiceId}\"\n\t\ttitle=\"${choiceId}_title\"\n\t\tdescription=\"${choiceId}_description\""
# Add options like start_selected, etc...
[[ -n "${choiceOptions}" ]] && choiceNode="${choiceNode}\n\t\t${choiceOptions}"
# Add the selected attribute if options are mutually exclusive
if [[ -n "$group_exclusive" ]];then
local group_items="${choice_group_items[$choiceParentGroupIndex]}"
case $group_exclusive in
exclusive_one_choice)
local selected_option=$(exclusive_one_choice "$choiceId" "$group_items") ;;
exclusive_zero_or_one_choice)
local selected_option=$(exclusive_zero_or_one_choice "$choiceId" "$group_items") ;;
*) echo "Error: unknown function to generate exclusive mode '$group_exclusive' for group '${choice_key[$choiceParentGroupIndex]}'" >&2
exit 1
;;
esac
choiceNode="${choiceNode}\n\t\tselected=\"$selected_option\""
fi
choiceNode="${choiceNode}>"
# Add the package references
for pkgRefId in ${choice_pkgrefs[$idx]};do
choiceNode="${choiceNode}\n\t\t<pkg-ref id=\"${pkgRefId}\"/>"
done
# Close the node
choiceNode="${choiceNode}\n\t</choice>\n"
echo -e "$choiceNode"
done
}
makedistribution ()
{
declare -r distributionDestDir="${SYMROOT}"
mkdir -p "${PKG_BUILD_DIR}/${packagename}"
find "${PKG_BUILD_DIR}" -type f -name '*.pkg' -depth 1 | while read component
do
do
pkg="${component##*/}" # ie: EFI.pkg
pkgdir="${PKG_BUILD_DIR}/${packagename}/${pkg}"
# expand individual packages
# Create the Distribution file
ditto --noextattr --noqtn "${PKGROOT}/Distribution" "${PKG_BUILD_DIR}/${packagename}/Distribution"
for (( i=0; i < ${#outline[*]} ; i++)); do
echo -e "${outline[$i]}" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
done
local start_indent_level=2
echo -e "\n\t<choices-outline>" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
for main_choice in ${choice_group_items[0]};do
generateOutlineChoices $main_choice $start_indent_level >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
done
echo -e "\t</choices-outline>\n" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
for (( i=0; i < ${#choices[*]} ; i++)); do
echo -e "${choices[$i]}" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
done
generateChoices >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
for (( i=0; i < ${#pkgrefs[*]} ; i++)); do
echo -e "${pkgrefs[$i]}" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"

Archive Download the corresponding diff file

Revision: 1765