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