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