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