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