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) == "cmorton" ]];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="Chameleon"␊ |
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 | local pkgTemplateType=""␊ |
182 | declare -a allSubst␊ |
183 | ␊ |
184 | # Check the arguments.␊ |
185 | while [[ $# -gt 0 ]];do␊ |
186 | local option="$1"␊ |
187 | case "$option" in␊ |
188 | --pkg-rootdir=*) shift; pkgRootDir="${option#*=}" ;;␊ |
189 | --subst=*) shift; allSubst[${#allSubst[*]}]="${option}" ;;␊ |
190 | --type=*) shift; pkgTemplateType=$pkgRootDir"/${option#*=}" ;;␊ |
191 | -*)␊ |
192 | echo "Unrecognized addTemplateScripts option '$option'" >&2␊ |
193 | exit 1␊ |
194 | ;;␊ |
195 | *) break ;;␊ |
196 | esac␊ |
197 | done␊ |
198 | if [[ $# -lt 1 ]];then␊ |
199 | echo "addTemplateScripts invalid number of arguments: you must specify a template name" >&2␊ |
200 | exit 1␊ |
201 | fi␊ |
202 | [[ -z "$pkgRootDir" ]] && { echo "Error addTemplateScripts: --pkg-rootdir option is needed" >&2 ; exit 1; }␊ |
203 | [[ ! -d "$pkgRootDir" ]] && { echo "Error addTemplateScripts: directory '$pkgRootDir' doesn't exists" >&2 ; exit 1; }␊ |
204 | ␊ |
205 | for templateName in "$@";do␊ |
206 | local templateRootDir="${SCPT_TPL_DIR}/${templateName}"␊ |
207 | [[ ! -d "$templateRootDir" ]] && {␊ |
208 | echo "Error addTemplateScripts: template '$templateName' doesn't exists" >&2; exit 1; }␊ |
209 | ␊ |
210 | # Copy files to destination␊ |
211 | rsync -pr --exclude=.svn --exclude="*~" "$templateRootDir/" "$pkgTemplateType"␊ |
212 | done␊ |
213 | ␊ |
214 | files=$( find "$pkgTemplateType" -type f )␊ |
215 | if [[ ${#allSubst[*]} -gt 0 ]];then␊ |
216 | makeSubstitutions "${allSubst[@]}" $files␊ |
217 | else␊ |
218 | makeSubstitutions $files␊ |
219 | fi␊ |
220 | }␊ |
221 | ␊ |
222 | getPackageRefId () {␊ |
223 | echo ${1//_/.}.${2//_/.} | tr [:upper:] [:lower:]␊ |
224 | }␊ |
225 | ␊ |
226 | # Return index of a choice␊ |
227 | getChoiceIndex () {␊ |
228 | # $1 Choice Id␊ |
229 | local found=0␊ |
230 | for (( idx=0 ; idx < ${#choice_key[*]}; idx++ ));do␊ |
231 | if [[ "${1}" == "${choice_key[$idx]}" ]];then␊ |
232 | found=1␊ |
233 | break␊ |
234 | fi␊ |
235 | done␊ |
236 | echo "$idx"␊ |
237 | return $found␊ |
238 | }␊ |
239 | ␊ |
240 | # Add a new choice␊ |
241 | addChoice () {␊ |
242 | # Optional arguments:␊ |
243 | # --group=<group> : Group Choice Id␊ |
244 | # --start-selected=<javascript code> : Specifies whether this choice is initially selected or unselected␊ |
245 | # --start-enabled=<javascript code> : Specifies the initial enabled state of this choice␊ |
246 | # --start-visible=<javascript code> : Specifies whether this choice is initially visible␊ |
247 | # --pkg-refs=<pkgrefs> : List of package reference(s) id (separate by spaces)␊ |
248 | #␊ |
249 | # $1 Choice Id␊ |
250 | ␊ |
251 | local option␊ |
252 | local groupChoice=""␊ |
253 | local choiceOptions=""␊ |
254 | local pkgrefs=""␊ |
255 | ␊ |
256 | # Check the arguments.␊ |
257 | for option in "${@}";do␊ |
258 | case "$option" in␊ |
259 | --group=*)␊ |
260 | shift; groupChoice=${option#*=} ;;␊ |
261 | --start-selected=*)␊ |
262 | shift; choiceOptions="$choiceOptions start_selected=\"${option#*=}\"" ;;␊ |
263 | --start-enabled=*)␊ |
264 | shift; choiceOptions="$choiceOptions start_enabled=\"${option#*=}\"" ;;␊ |
265 | --start-visible=*)␊ |
266 | shift; choiceOptions="$choiceOptions start_visible=\"${option#*=}\"" ;;␊ |
267 | --pkg-refs=*)␊ |
268 | shift; pkgrefs=${option#*=} ;;␊ |
269 | -*)␊ |
270 | echo "Unrecognized addChoice option '$option'" >&2␊ |
271 | exit 1␊ |
272 | ;;␊ |
273 | *) break ;;␊ |
274 | esac␊ |
275 | done␊ |
276 | ␊ |
277 | if [[ $# -ne 1 ]];then␊ |
278 | echo "addChoice invalid number of arguments: ${@}" >&2␊ |
279 | exit 1␊ |
280 | fi␊ |
281 | ␊ |
282 | local choiceId="${1}"␊ |
283 | ␊ |
284 | # Add choice in the group␊ |
285 | idx_group=$(getChoiceIndex "$groupChoice")␊ |
286 | found_group=$?␊ |
287 | if [[ $found_group -ne 1 ]];then␊ |
288 | # No group exist␊ |
289 | echo "Error can't add choice '$choiceId' to group '$groupChoice': group choice '$groupChoice' doesn't exists." >&2␊ |
290 | exit 1␊ |
291 | else␊ |
292 | set +u; oldItems=${choice_group_items[$idx_group]}; set -u␊ |
293 | choice_group_items[$idx_group]="$oldItems $choiceId"␊ |
294 | fi␊ |
295 | ␊ |
296 | # Check that the choice doesn't already exists␊ |
297 | idx=$(getChoiceIndex "$choiceId")␊ |
298 | found=$?␊ |
299 | if [[ $found -ne 0 ]];then␊ |
300 | # Choice already exists␊ |
301 | echo "Error can't add choice '$choiceId': a choice with same name already exists." >&2␊ |
302 | exit 1␊ |
303 | fi␊ |
304 | ␊ |
305 | # Record new node␊ |
306 | choice_key[$idx]="$choiceId"␊ |
307 | choice_options[$idx]=$(trim "${choiceOptions}") # Removing leading and trailing whitespace(s)␊ |
308 | choice_parent_group_index[$idx]=$idx_group␊ |
309 | choice_pkgrefs[$idx]="$pkgrefs"␊ |
310 | ␊ |
311 | return $idx␊ |
312 | }␊ |
313 | ␊ |
314 | # Add a group choice␊ |
315 | addGroupChoices() {␊ |
316 | # Optional arguments:␊ |
317 | # --parent=<parent> : parent group choice id␊ |
318 | # --exclusive_zero_or_one_choice : only zero or one choice can be selected in the group␊ |
319 | # --exclusive_one_choice : only one choice can be selected in the group␊ |
320 | #␊ |
321 | # $1 Choice Id␊ |
322 | ␊ |
323 | local option␊ |
324 | local groupChoice=""␊ |
325 | local exclusive_function=""␊ |
326 | ␊ |
327 | for option in "${@}";do␊ |
328 | case "$option" in␊ |
329 | --exclusive_zero_or_one_choice)␊ |
330 | shift; exclusive_function="exclusive_zero_or_one_choice" ;;␊ |
331 | --exclusive_one_choice)␊ |
332 | shift; exclusive_function="exclusive_one_choice" ;;␊ |
333 | --parent=*)␊ |
334 | shift; groupChoice=${option#*=} ;;␊ |
335 | -*)␊ |
336 | echo "Unrecognized addGroupChoices option '$option'" >&2␊ |
337 | exit 1␊ |
338 | ;;␊ |
339 | *) break ;;␊ |
340 | esac␊ |
341 | done␊ |
342 | ␊ |
343 | if [[ $# -ne 1 ]];then␊ |
344 | echo "addGroupChoices invalid number of arguments: ${@}" >&2␊ |
345 | exit 1␊ |
346 | fi␊ |
347 | ␊ |
348 | addChoice --group="$groupChoice" "${1}"␊ |
349 | local idx=$? # index of the new created choice␊ |
350 | ␊ |
351 | choice_group_exclusive[$idx]="$exclusive_function"␊ |
352 | }␊ |
353 | ␊ |
354 | exclusive_one_choice () {␊ |
355 | # $1 Current choice (ie: test1)␊ |
356 | # $2..$n Others choice(s) (ie: "test2" "test3"). Current can or can't be in the others choices␊ |
357 | local myChoice="${1}"␊ |
358 | local result="";␊ |
359 | local separator=' || ';␊ |
360 | for choice in ${@:2};do␊ |
361 | if [[ "$choice" != "$myChoice" ]];then␊ |
362 | result="${result}choices['$choice'].selected${separator}";␊ |
363 | fi␊ |
364 | done␊ |
365 | if [[ -n "$result" ]];then␊ |
366 | echo "!(${result%$separator})"␊ |
367 | fi␊ |
368 | }␊ |
369 | ␊ |
370 | exclusive_zero_or_one_choice () {␊ |
371 | # $1 Current choice (ie: test1)␊ |
372 | # $2..$n Others choice(s) (ie: "test2" "test3"). Current can or can't be in the others choices␊ |
373 | local myChoice="${1}"␊ |
374 | local result;␊ |
375 | echo "(my.choice.selected && $(exclusive_one_choice ${@}))"␊ |
376 | }␊ |
377 | ␊ |
378 | recordChameleonOption () {␊ |
379 | local type="$1"␊ |
380 | local key="$2"␊ |
381 | local value="$3"␊ |
382 | ␊ |
383 | # Search for an existing key␊ |
384 | local found=0␊ |
385 | for (( idx=0 ; idx < ${#chameleonOptionKey[@]}; idx++ ));do␊ |
386 | if [[ "$key" == "${chameleonOptionKey[$idx]}" ]];then␊ |
387 | found=1␊ |
388 | break␊ |
389 | fi␊ |
390 | done␊ |
391 | ␊ |
392 | # idx contain the index of a new key or an existing one␊ |
393 | if [[ $found -eq 0 ]]; then␊ |
394 | # Create a new one␊ |
395 | chameleonOptionKey[$idx]="$key"␊ |
396 | chameleonOptionType[$idx]="$type"␊ |
397 | chameleonOptionValues[$idx]=""␊ |
398 | fi␊ |
399 | ␊ |
400 | case "$type" in␊ |
401 | bool) ;;␊ |
402 | text|list) chameleonOptionValues[$idx]="${chameleonOptionValues[$idx]} $value" ;;␊ |
403 | *) echo "Error unknown type '$type' for '$key'" >&2␊ |
404 | exit 1␊ |
405 | ;;␊ |
406 | esac␊ |
407 | }␊ |
408 | ␊ |
409 | generate_options_yaml_file () {␊ |
410 | local yamlFile="$1"␊ |
411 | echo "---" > $yamlFile␊ |
412 | for (( idx=0; idx < ${#chameleonOptionKey[@]}; idx++ ));do␊ |
413 | printf "%s:\n type: %s\n" "${chameleonOptionKey[$idx]}" "${chameleonOptionType[$idx]}" >> $yamlFile␊ |
414 | case ${chameleonOptionType[$idx]} in␊ |
415 | text|list)␊ |
416 | printf " values:\n" >> $yamlFile␊ |
417 | for value in ${chameleonOptionValues[$idx]};do␊ |
418 | printf " - %s\n" "$value" >> $yamlFile␊ |
419 | done␊ |
420 | ;;␊ |
421 | esac␊ |
422 | done␊ |
423 | }␊ |
424 | ␊ |
425 | main ()␊ |
426 | {␊ |
427 | ␊ |
428 | # clean up the destination path␊ |
429 | ␊ |
430 | rm -R -f "${PKG_BUILD_DIR}"␊ |
431 | echo ""␊ |
432 | echo -e $COL_CYAN" ----------------------------------"$COL_RESET␊ |
433 | echo -e $COL_CYAN" Building $packagename Install Package"$COL_RESET␊ |
434 | echo -e $COL_CYAN" ----------------------------------"$COL_RESET␊ |
435 | echo ""␊ |
436 | ␊ |
437 | # Add pre install choice␊ |
438 | echo "================= Preinstall ================="␊ |
439 | packagesidentity="${chameleon_package_identity}"␊ |
440 | choiceId="Pre"␊ |
441 | ␊ |
442 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
443 | addChoice --start-visible="false" --start-selected="true" --pkg-refs="$packageRefId" "${choiceId}"␊ |
444 | ␊ |
445 | # Package will be built at the end␊ |
446 | # End pre install choice␊ |
447 | ␊ |
448 | # build core package␊ |
449 | echo "================= Core ================="␊ |
450 | packagesidentity="${chameleon_package_identity}"␊ |
451 | choiceId="Core"␊ |
452 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin␊ |
453 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386␊ |
454 | ditto --noextattr --noqtn ${SYMROOT}/i386/boot ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386␊ |
455 | ditto --noextattr --noqtn ${SYMROOT}/i386/boot0 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386␊ |
456 | ditto --noextattr --noqtn ${SYMROOT}/i386/boot0md ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386␊ |
457 | ditto --noextattr --noqtn ${SYMROOT}/i386/boot1f32 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386␊ |
458 | ditto --noextattr --noqtn ${SYMROOT}/i386/boot1h ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386␊ |
459 | ditto --noextattr --noqtn ${SYMROOT}/i386/boot1he ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386␊ |
460 | ditto --noextattr --noqtn ${SYMROOT}/i386/boot1hp ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386␊ |
461 | ditto --noextattr --noqtn ${SYMROOT}/i386/cdboot ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386␊ |
462 | ditto --noextattr --noqtn ${SYMROOT}/i386/chain0 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386␊ |
463 | ditto --noextattr --noqtn ${SYMROOT}/i386/fdisk440 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin␊ |
464 | ditto --noextattr --noqtn ${SYMROOT}/i386/bdmesg ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin␊ |
465 | ␊ |
466 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
467 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"␊ |
468 | addChoice --start-visible="false" --start-selected="true" --pkg-refs="$packageRefId" "${choiceId}"␊ |
469 | # End build core package␊ |
470 | ␊ |
471 | # build Chameleon package␊ |
472 | echo "================= Chameleon ================="␊ |
473 | addGroupChoices --exclusive_one_choice "Chameleon"␊ |
474 | ␊ |
475 | # build standard package␊ |
476 | choiceId="Standard"␊ |
477 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root␊ |
478 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources␊ |
479 | addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" --type="Scripts" InstallerLog␊ |
480 | addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" --type="Scripts" UnMount␊ |
481 | cp -f ${PKGROOT}/Scripts/Main/${choiceId}postinstall ${PKG_BUILD_DIR}/${choiceId}/Scripts/postinstall␊ |
482 | cp -f ${PKGROOT}/Scripts/Sub/* ${PKG_BUILD_DIR}/${choiceId}/Scripts␊ |
483 | ditto --arch i386 `which SetFile` ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources/SetFile␊ |
484 | ␊ |
485 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
486 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"␊ |
487 | addChoice --group="Chameleon" --start-selected="true" --pkg-refs="$packageRefId" "${choiceId}"␊ |
488 | # End build standard package␊ |
489 | ␊ |
490 | # build efi package␊ |
491 | if [[ 1 -eq 0 ]];then␊ |
492 | # Only standard installation is currently supported␊ |
493 | # We need to update the script to be able to install␊ |
494 | # Chameleon on EFI partition␊ |
495 | choiceId="EFI"␊ |
496 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root␊ |
497 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources␊ |
498 | addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" InstallerLog␊ |
499 | cp -f ${PKGROOT}/Scripts/Main/ESPpostinstall ${PKG_BUILD_DIR}/${choiceId}/Scripts/postinstall␊ |
500 | cp -f ${PKGROOT}/Scripts/Sub/* ${PKG_BUILD_DIR}/${choiceId}/Scripts␊ |
501 | ditto --arch i386 `which SetFile` ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources/SetFile␊ |
502 | ␊ |
503 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
504 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"␊ |
505 | addChoice --group="Chameleon" --start-visible="systemHasGPT()" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"␊ |
506 | # End build efi package␊ |
507 | fi␊ |
508 | # build no bootloader choice package␊ |
509 | choiceId="noboot"␊ |
510 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root␊ |
511 | ␊ |
512 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
513 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"␊ |
514 | addChoice --group="Chameleon" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"␊ |
515 | # End build no bootloader choice package␊ |
516 | ␊ |
517 | # End build Chameleon package␊ |
518 | ␊ |
519 | if [[ "${CONFIG_MODULES}" == 'y' ]];then␊ |
520 | # build Modules package␊ |
521 | echo "================= Modules ================="␊ |
522 | ###############################␊ |
523 | # Supported Modules #␊ |
524 | ###############################␊ |
525 | # klibc.dylib #␊ |
526 | # Resolution.dylib #␊ |
527 | # uClibcxx.dylib #␊ |
528 | # Keylayout.dylib #␊ |
529 | ###############################␊ |
530 | if [ "$(ls -A "${SYMROOT}/i386/modules")" ]; then␊ |
531 | {␊ |
532 | addGroupChoices "Module"␊ |
533 | ␊ |
534 | # -␊ |
535 | if [[ "${CONFIG_RESOLUTION_MODULE}" == 'm' && -f "${SYMROOT}/i386/modules/Resolution.dylib" ]]; then␊ |
536 | {␊ |
537 | # Start build Resolution package module␊ |
538 | choiceId="AutoReso"␊ |
539 | moduleFile="Resolution.dylib"␊ |
540 | mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"␊ |
541 | ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"␊ |
542 | addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \␊ |
543 | --subst="moduleName=$choiceId" \␊ |
544 | --subst="moduleFile=$moduleFile" \␊ |
545 | --type="Scripts" \␊ |
546 | InstallModule␊ |
547 | ␊ |
548 | packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")␊ |
549 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"␊ |
550 | addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"␊ |
551 | # End build Resolution package module␊ |
552 | }␊ |
553 | fi␊ |
554 | ␊ |
555 | # -␊ |
556 | if [[ "${CONFIG_KLIBC_MODULE}" == 'm' && -f "${SYMROOT}/i386/modules/klibc.dylib" ]]; then␊ |
557 | {␊ |
558 | # Start build klibc package module␊ |
559 | choiceId="klibc"␊ |
560 | moduleFile="${choiceId}.dylib"␊ |
561 | mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"␊ |
562 | ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" ${PKG_BUILD_DIR}/${choiceId}/Root␊ |
563 | addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \␊ |
564 | --subst="moduleName=$choiceId" \␊ |
565 | --subst="moduleFile=$moduleFile" \␊ |
566 | --type="Scripts" \␊ |
567 | InstallModule␊ |
568 | ␊ |
569 | packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")␊ |
570 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"␊ |
571 | addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId" "${choiceId}"␊ |
572 | # End build klibc package module␊ |
573 | }␊ |
574 | fi␊ |
575 | ␊ |
576 | # -␊ |
577 | if [[ "${CONFIG_UCLIBCXX_MODULE}" = 'm' && -n "${CONFIG_KLIBC_MODULE}" && \␊ |
578 | -f "${SYMROOT}/i386/modules/uClibcxx.dylib" ]]; then␊ |
579 | {␊ |
580 | klibcPackageRefId=""␊ |
581 | if [[ "${CONFIG_KLIBC_MODULE}" == 'm' ]];then␊ |
582 | klibcPackageRefId=$(getPackageRefId "${modules_packages_identity}" "klibc")␊ |
583 | fi␊ |
584 | # Start build uClibc package module␊ |
585 | choiceId="uClibc"␊ |
586 | moduleFile="uClibcxx.dylib"␊ |
587 | mkdir -p "${PKG_BUILD_DIR}/${choiceId}/Root"␊ |
588 | ditto --noextattr --noqtn "${SYMROOT}/i386/modules/$moduleFile" "${PKG_BUILD_DIR}/${choiceId}/Root"␊ |
589 | addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \␊ |
590 | --subst="moduleName=$choiceId" \␊ |
591 | --subst="moduleFile=$moduleFile" \␊ |
592 | --type="Scripts" \␊ |
593 | InstallModule␊ |
594 | ␊ |
595 | packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")␊ |
596 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/Extra/modules"␊ |
597 | # Add the klibc package because the uClibc module is dependent of klibc module␊ |
598 | addChoice --group="Module" --start-selected="false" --pkg-refs="$packageRefId $klibcPackageRefId" "${choiceId}"␊ |
599 | # End build uClibc package module␊ |
600 | }␊ |
601 | fi␊ |
602 | ␊ |
603 | # -␊ |
604 | # Warning Keylayout module need additional files␊ |
605 | if [[ "${CONFIG_KEYLAYOUT_MODULE}" = 'm' && -f "${SYMROOT}/i386/modules/Keylayout.dylib" ]]; then␊ |
606 | {␊ |
607 | # Start build Keylayout package module␊ |
608 | choiceId="Keylayout"␊ |
609 | moduleFile="${choiceId}.dylib"␊ |
610 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root/Extra/{modules,Keymaps}␊ |
611 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin␊ |
612 | layout_src_dir="${SRCROOT}/i386/modules/Keylayout/layouts/layouts-src"␊ |
613 | if [ -d "$layout_src_dir" ];then␊ |
614 | # Create a tar.gz from layout sources␊ |
615 | (cd "$layout_src_dir"; \␊ |
616 | tar czf "${PKG_BUILD_DIR}/${choiceId}/Root/Extra/Keymaps/layouts-src.tar.gz" README *.slt)␊ |
617 | fi␊ |
618 | # Adding module␊ |
619 | ditto --noextattr --noqtn ${SYMROOT}/i386/modules/$moduleFile ${PKG_BUILD_DIR}/${choiceId}/Root/Extra/modules␊ |
620 | # Adding Keymaps␊ |
621 | ditto --noextattr --noqtn ${SRCROOT}/Keymaps ${PKG_BUILD_DIR}/${choiceId}/Root/Extra/Keymaps␊ |
622 | # Adding tools␊ |
623 | ditto --noextattr --noqtn ${SYMROOT}/i386/cham-mklayout ${PKG_BUILD_DIR}/${choiceId}/Root/usr/local/bin␊ |
624 | # Adding scripts␊ |
625 | addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \␊ |
626 | --subst="moduleName=$choiceId" \␊ |
627 | --subst="moduleFile=$moduleFile" \␊ |
628 | --type="Scripts" \␊ |
629 | InstallModule␊ |
630 | ␊ |
631 | packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")␊ |
632 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"␊ |
633 | ␊ |
634 | # Don't add a choice for Keylayout module␊ |
635 | # addChoice "${choiceId}" "Module" --start-selected="false" "$packageRefId"␊ |
636 | # End build Keylayout package module␊ |
637 | }␊ |
638 | fi␊ |
639 | ␊ |
640 | }␊ |
641 | else␊ |
642 | {␊ |
643 | echo " -= no modules to include =-"␊ |
644 | }␊ |
645 | fi␊ |
646 | # End build Modules packages␊ |
647 | fi␊ |
648 | ␊ |
649 | # build Options packages␊ |
650 | ␊ |
651 | addGroupChoices "Options"␊ |
652 | ␊ |
653 | # ------------------------------------------------------␊ |
654 | # parse OptionalSettings folder to find files of boot options.␊ |
655 | # ------------------------------------------------------␊ |
656 | OptionalSettingsFolder="${PKGROOT}/OptionalSettings"␊ |
657 | ␊ |
658 | while IFS= read -r -d '' OptionsFile; do␊ |
659 | ␊ |
660 | # Take filename and strip .txt from end and path from front␊ |
661 | builtOptionsList=${OptionsFile%.txt}␊ |
662 | builtOptionsList=${builtOptionsList##*/}␊ |
663 | packagesidentity="${chameleon_package_identity}.options.$builtOptionsList"␊ |
664 | ␊ |
665 | echo "================= $builtOptionsList ================="␊ |
666 | ␊ |
667 | # ------------------------------------------------------␊ |
668 | # Read boot option file into an array.␊ |
669 | # ------------------------------------------------------␊ |
670 | availableOptions=() # array to hold the list of boot options, per 'section'.␊ |
671 | exclusiveFlag="" # used to indicate list has exclusive options␊ |
672 | while read textLine; do␊ |
673 | # ignore lines in the file beginning with a #␊ |
674 | [[ $textLine = \#* ]] && continue␊ |
675 | local optionName="" key="" value=""␊ |
676 | case "$textLine" in␊ |
677 | Exclusive=[Tt][Rr][Uu][Ee]) exclusiveFlag="--exclusive_zero_or_one_choice" ;;␊ |
678 | Exclusive=*) continue ;;␊ |
679 | *@*:*=*)␊ |
680 | availableOptions[${#availableOptions[*]}]="$textLine" ;;␊ |
681 | *) echo "Error: invalid line '$textLine' in file '$OptionsFile'" >&2␊ |
682 | exit 1␊ |
683 | ;;␊ |
684 | esac␊ |
685 | done < "$OptionsFile"␊ |
686 | ␊ |
687 | addGroupChoices --parent="Options" $exclusiveFlag "${builtOptionsList}"␊ |
688 | ␊ |
689 | # ------------------------------------------------------␊ |
690 | # Loop through options in array and process each in turn␊ |
691 | # ------------------------------------------------------␊ |
692 | for textLine in "${availableOptions[@]}"; do␊ |
693 | # split line - taking all before ':' as option name␊ |
694 | # and all after ':' as key/value␊ |
695 | type=$( echo "${textLine%%@*}" | tr '[:upper:]' '[:lower:]' )␊ |
696 | tmp=${textLine#*@}␊ |
697 | optionName=${tmp%%:*}␊ |
698 | keyValue=${tmp##*:}␊ |
699 | key=${keyValue%%=*}␊ |
700 | value=${keyValue#*=}␊ |
701 | ␊ |
702 | # create folders required for each boot option␊ |
703 | mkdir -p "${PKG_BUILD_DIR}/$optionName/Root/"␊ |
704 | ␊ |
705 | case "$type" in␊ |
706 | bool) startSelected="check_chameleon_bool_option('$key','$value')" ;;␊ |
707 | text) startSelected="check_chameleon_text_option('$key','$value')" ;;␊ |
708 | list) startSelected="check_chameleon_list_option('$key','$value')" ;;␊ |
709 | *) echo "Error: invalid type '$type' in line '$textLine' in '$OptionsFile'" >&2␊ |
710 | exit 1␊ |
711 | ;;␊ |
712 | esac␊ |
713 | recordChameleonOption "$type" "$key" "$value"␊ |
714 | addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/$optionName" \␊ |
715 | --subst="optionType=$type" \␊ |
716 | --subst="optionKey=$key" \␊ |
717 | --subst="optionValue=$value" \␊ |
718 | --type="Scripts" \␊ |
719 | AddOption␊ |
720 | packageRefId=$(getPackageRefId "${packagesidentity}" "${optionName}")␊ |
721 | buildpackage "$packageRefId" "${optionName}" "${PKG_BUILD_DIR}/${optionName}" "/"␊ |
722 | addChoice --group="${builtOptionsList}" \␊ |
723 | --start-selected="$startSelected" \␊ |
724 | --pkg-refs="$packageRefId" "${optionName}"␊ |
725 | done␊ |
726 | ␊ |
727 | done < <( find "${OptionalSettingsFolder}" -depth 1 -type f -name '*.txt' -print0 )␊ |
728 | ␊ |
729 | # End build options packages␊ |
730 | ␊ |
731 | if [[ -n "${CONFIG_KEYLAYOUT_MODULE}" ]];then␊ |
732 | # build Keymaps options packages␊ |
733 | echo "================= Keymaps Options ================="␊ |
734 | addGroupChoices --exclusive_zero_or_one_choice "Keymaps"␊ |
735 | packagesidentity="${chameleon_package_identity}.options.keymaps"␊ |
736 | keylayoutPackageRefId=""␊ |
737 | if [[ "${CONFIG_MODULES}" == 'y' && "${CONFIG_KEYLAYOUT_MODULE}" = 'm' ]];then␊ |
738 | keylayoutPackageRefId=$(getPackageRefId "${modules_packages_identity}" "Keylayout")␊ |
739 | fi␊ |
740 | ␊ |
741 | chameleon_keylayout_key="KeyLayout"␊ |
742 | # ------------------------------------------------------␊ |
743 | # Available Keylayout boot options are discovered by␊ |
744 | # reading contents of /Keymaps folder after compilation␊ |
745 | # ------------------------------------------------------␊ |
746 | availableOptions=($( find "${SRCROOT}/Keymaps" -type f -depth 1 -name '*.lyt' | sed 's|.*/||;s|\.lyt||' ))␊ |
747 | # Adjust array contents to match expected format␊ |
748 | # for boot options which is: name:key=value␊ |
749 | for (( i = 0 ; i < ${#availableOptions[@]} ; i++ )); do␊ |
750 | # Start build of a keymap package module␊ |
751 | choiceId="${availableOptions[i]}"␊ |
752 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root␊ |
753 | ␊ |
754 | recordChameleonOption "text" "$chameleon_keylayout_key" "$choiceId"␊ |
755 | addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \␊ |
756 | --subst="optionType=text" \␊ |
757 | --subst="optionKey=$chameleon_keylayout_key" \␊ |
758 | --subst="optionValue=$choiceId" \␊ |
759 | --type="Scripts" \␊ |
760 | AddOption␊ |
761 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
762 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"␊ |
763 | # Add the Keylayout package because the Keylayout module is needed␊ |
764 | addChoice --group="Keymaps" \␊ |
765 | --start-selected="check_chameleon_text_option('${chameleon_keylayout_key}','${choiceId}')" \␊ |
766 | --pkg-refs="$packageRefId $keylayoutPackageRefId" "${choiceId}"␊ |
767 | done␊ |
768 | ␊ |
769 | # End build Keymaps options packages␊ |
770 | fi␊ |
771 | ␊ |
772 | # build theme packages␊ |
773 | echo "================= Themes ================="␊ |
774 | addGroupChoices "Themes"␊ |
775 | ␊ |
776 | # Using themes section from Azi's/package branch.␊ |
777 | packagesidentity="${chameleon_package_identity}.themes"␊ |
778 | artwork="${SRCROOT}/artwork/themes"␊ |
779 | themes=($( find "${artwork}" -type d -depth 1 -not -name '.svn' ))␊ |
780 | for (( i = 0 ; i < ${#themes[@]} ; i++ )); do␊ |
781 | themeName=$( echo ${themes[$i]##*/} | awk 'BEGIN{OFS=FS=""}{$1=toupper($1);print}' )␊ |
782 | themeDir="$themeName"␊ |
783 | mkdir -p "${PKG_BUILD_DIR}/${themeName}/Root/"␊ |
784 | rsync -r --exclude=.svn --exclude="*~" "${themes[$i]}/" "${PKG_BUILD_DIR}/${themeName}/Root/${themeName}"␊ |
785 | addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${themeName}" \␊ |
786 | --subst="themeName=$themeName" \␊ |
787 | --subst="themeDir=$themeDir" \␊ |
788 | --type="Scripts" \␊ |
789 | InstallTheme␊ |
790 | ␊ |
791 | packageRefId=$(getPackageRefId "${packagesidentity}" "${themeName}")␊ |
792 | buildpackage "$packageRefId" "${themeName}" "${PKG_BUILD_DIR}/${themeName}" "/Extra/Themes"␊ |
793 | addChoice --group="Themes" --start-selected="false" --pkg-refs="$packageRefId" "${themeName}"␊ |
794 | done␊ |
795 | # End build theme packages# End build Extras package␊ |
796 | ␊ |
797 | # build pre install package␊ |
798 | echo "================= Pre ================="␊ |
799 | packagesidentity="${chameleon_package_identity}"␊ |
800 | choiceId="Pre"␊ |
801 | ␊ |
802 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
803 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root␊ |
804 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources␊ |
805 | local yamlFile="Resources/chameleon_options.yaml"␊ |
806 | addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" \␊ |
807 | --type="Scripts" \␊ |
808 | --subst="YAML_FILE=${yamlFile}" ${choiceId}␊ |
809 | generate_options_yaml_file "${PKG_BUILD_DIR}/${choiceId}/Scripts/$yamlFile"␊ |
810 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"␊ |
811 | # End build pre install package␊ |
812 | ␊ |
813 | # build post install package␊ |
814 | echo "================= Post ================="␊ |
815 | packagesidentity="${chameleon_package_identity}"␊ |
816 | choiceId="Post"␊ |
817 | mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root␊ |
818 | addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" --type="Scripts" ${choiceId}␊ |
819 | addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" --type="Scripts" InstallerLog␊ |
820 | addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${choiceId}" --type="Scripts" UnMount␊ |
821 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
822 | buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"␊ |
823 | addChoice --start-visible="false" --start-selected="true" --pkg-refs="$packageRefId" "${choiceId}"␊ |
824 | # End build post install package␊ |
825 | ␊ |
826 | }␊ |
827 | ␊ |
828 | buildpackage () {␊ |
829 | # $1 Package Reference Id (ie: org.chameleon.themes.default)␊ |
830 | # $2 Package Name (ie: Default)␊ |
831 | # $3 Path to package to build containing Root and/or Scripts␊ |
832 | # $4 Target install location␊ |
833 | # $5 Size (optional)␊ |
834 | if [[ -d "${3}/Root" ]]; then␊ |
835 | local packageRefId="$1"␊ |
836 | local packageName="$2"␊ |
837 | local packagePath="$3"␊ |
838 | local targetPath="$4"␊ |
839 | set +u # packageSize is optional␊ |
840 | local packageSize="$5"␊ |
841 | set -u␊ |
842 | ␊ |
843 | echo -e "\t[BUILD] ${packageName}"␊ |
844 | ␊ |
845 | find "${packagePath}" -name '.DS_Store' -delete␊ |
846 | local filecount=$( find "${packagePath}/Root" | wc -l )␊ |
847 | if [ "${packageSize}" ]; then␊ |
848 | local installedsize="${packageSize}"␊ |
849 | else␊ |
850 | local installedsize=$( du -hkc "${packagePath}/Root" | tail -n1 | awk {'print $1'} )␊ |
851 | fi␊ |
852 | local header="<?xml version=\"1.0\"?>\n<pkg-info format-version=\"2\" "␊ |
853 | ␊ |
854 | #[ "${3}" == "relocatable" ] && header+="relocatable=\"true\" "␊ |
855 | ␊ |
856 | header+="identifier=\"${packageRefId}\" "␊ |
857 | header+="version=\"${CHAMELEON_VERSION}\" "␊ |
858 | ␊ |
859 | [ "${targetPath}" != "relocatable" ] && header+="install-location=\"${targetPath}\" "␊ |
860 | ␊ |
861 | header+="auth=\"root\">\n"␊ |
862 | header+="\t<payload installKBytes=\"${installedsize##* }\" numberOfFiles=\"${filecount##* }\"/>\n"␊ |
863 | rm -R -f "${packagePath}/Temp"␊ |
864 | ␊ |
865 | [ -d "${packagePath}/Temp" ] || mkdir -m 777 "${packagePath}/Temp"␊ |
866 | [ -d "${packagePath}/Root" ] && mkbom "${packagePath}/Root" "${packagePath}/Temp/Bom"␊ |
867 | ␊ |
868 | if [ -d "${packagePath}/Scripts" ]; then␊ |
869 | header+="\t<scripts>\n"␊ |
870 | for script in $( find "${packagePath}/Scripts" -type f \( -name 'pre*' -or -name 'post*' \) ); do␊ |
871 | header+="\t\t<${script##*/} file=\"./${script##*/}\"/>\n"␊ |
872 | done␊ |
873 | header+="\t</scripts>\n"␊ |
874 | # Create the Script archive file (cpio format)␊ |
875 | # Note: Use root:wheel instead of 0:0 otherwise it errors on Snow Leopard.␊ |
876 | (cd "${packagePath}/Scripts" && find . -print | cpio -o -z -R root:wheel --format cpio > "${packagePath}/Temp/Scripts") 2>&1 | \␊ |
877 | grep -E '^[0-9]+\s+blocks?$' # to remove cpio stderr messages #blackosx removed -v from -vE␊ |
878 | fi␊ |
879 | ␊ |
880 | header+="</pkg-info>"␊ |
881 | echo -e "${header}" > "${packagePath}/Temp/PackageInfo"␊ |
882 | ␊ |
883 | # Create the Payload file (cpio format)␊ |
884 | # Note: Use root:wheel instead of 0:0 otherwise it errors on Snow Leopard.␊ |
885 | (cd "${packagePath}/Root" && find . -print | cpio -o -z -R root:wheel --format cpio > "${packagePath}/Temp/Payload") 2>&1 | \␊ |
886 | grep -E '^[0-9]+\s+blocks?$' # to remove cpio stderr messages #blackosx removed -v from -vE␊ |
887 | ␊ |
888 | # Create the package␊ |
889 | (cd "${packagePath}/Temp" && xar -c -f "${packagePath}/../${packageName}.pkg" --compression none .)␊ |
890 | ␊ |
891 | # Add the package to the list of build packages␊ |
892 | pkgrefs[${#pkgrefs[*]}]="\t<pkg-ref id=\"${packageRefId}\" installKBytes='${installedsize}' version='${CHAMELEON_VERSION}.0.0.${CHAMELEON_TIMESTAMP}'>#${packageName}.pkg</pkg-ref>"␊ |
893 | ␊ |
894 | rm -rf "${packagePath}"␊ |
895 | fi␊ |
896 | }␊ |
897 | ␊ |
898 | generateOutlineChoices() {␊ |
899 | # $1 Main Choice␊ |
900 | # $2 indent level␊ |
901 | local idx=$(getChoiceIndex "$1")␊ |
902 | local indentLevel="$2"␊ |
903 | local indentString=""␊ |
904 | for ((level=1; level <= $indentLevel ; level++)); do␊ |
905 | indentString="\t$indentString"␊ |
906 | done␊ |
907 | set +u; subChoices="${choice_group_items[$idx]}"; set -u␊ |
908 | if [[ -n "${subChoices}" ]]; then␊ |
909 | # Sub choices exists␊ |
910 | echo -e "$indentString<line choice=\"$1\">"␊ |
911 | for subChoice in $subChoices;do␊ |
912 | generateOutlineChoices $subChoice $(($indentLevel+1))␊ |
913 | done␊ |
914 | echo -e "$indentString</line>"␊ |
915 | else␊ |
916 | echo -e "$indentString<line choice=\"$1\"/>"␊ |
917 | fi␊ |
918 | }␊ |
919 | ␊ |
920 | generateChoices() {␊ |
921 | for (( idx=1; idx < ${#choice_key[*]} ; idx++)); do␊ |
922 | local choiceId=${choice_key[$idx]}␊ |
923 | local choiceOptions=${choice_options[$idx]}␊ |
924 | local choiceParentGroupIndex=${choice_parent_group_index[$idx]}␊ |
925 | set +u; local group_exclusive=${choice_group_exclusive[$choiceParentGroupIndex]}; set -u␊ |
926 | ␊ |
927 | # Create the node and standard attributes␊ |
928 | local choiceNode="\t<choice\n\t\tid=\"${choiceId}\"\n\t\ttitle=\"${choiceId}_title\"\n\t\tdescription=\"${choiceId}_description\""␊ |
929 | ␊ |
930 | # Add options like start_selected, etc...␊ |
931 | [[ -n "${choiceOptions}" ]] && choiceNode="${choiceNode}\n\t\t${choiceOptions}"␊ |
932 | ␊ |
933 | # Add the selected attribute if options are mutually exclusive␊ |
934 | if [[ -n "$group_exclusive" ]];then␊ |
935 | local group_items="${choice_group_items[$choiceParentGroupIndex]}"␊ |
936 | case $group_exclusive in␊ |
937 | exclusive_one_choice)␊ |
938 | local selected_option=$(exclusive_one_choice "$choiceId" "$group_items") ;;␊ |
939 | exclusive_zero_or_one_choice)␊ |
940 | local selected_option=$(exclusive_zero_or_one_choice "$choiceId" "$group_items") ;;␊ |
941 | *) echo "Error: unknown function to generate exclusive mode '$group_exclusive' for group '${choice_key[$choiceParentGroupIndex]}'" >&2␊ |
942 | exit 1␊ |
943 | ;;␊ |
944 | esac␊ |
945 | choiceNode="${choiceNode}\n\t\tselected=\"$selected_option\""␊ |
946 | fi␊ |
947 | ␊ |
948 | choiceNode="${choiceNode}>"␊ |
949 | ␊ |
950 | # Add the package references␊ |
951 | for pkgRefId in ${choice_pkgrefs[$idx]};do␊ |
952 | choiceNode="${choiceNode}\n\t\t<pkg-ref id=\"${pkgRefId}\"/>"␊ |
953 | done␊ |
954 | ␊ |
955 | # Close the node␊ |
956 | choiceNode="${choiceNode}\n\t</choice>\n"␊ |
957 | ␊ |
958 | echo -e "$choiceNode"␊ |
959 | done␊ |
960 | }␊ |
961 | ␊ |
962 | resetVars() {␊ |
963 | foundCode=""␊ |
964 | foundMessageName=""␊ |
965 | foundObjectName=""␊ |
966 | foundObjectTitle=""␊ |
967 | foundDescription=""␊ |
968 | ␊ |
969 | resourceToUse=""␊ |
970 | ␊ |
971 | buildCodes=()␊ |
972 | templateStrings=()␊ |
973 | }␊ |
974 | ␊ |
975 | buildresources() {␊ |
976 | ResourcesSourceFolder="${PKGROOT}/Resources.source"␊ |
977 | ResourcesSourceFile="ResourcesSourceFile.txt"␊ |
978 | ␊ |
979 | # Check for ResourcesSourceFile.txt.␊ |
980 | # It now won't exist, so call perl script to download the published␊ |
981 | # Google docs spreadsheet as UTF-8 .tsv file and make another one.␊ |
982 | if [ ! -f "${PKG_BUILD_DIR}/${ResourcesSourceFile}" ]; then␊ |
983 | "${ResourcesSourceFolder}/ConvertResourcesTextFile.pl" "${PKG_BUILD_DIR}" "${ResourcesSourceFile}"␊ |
984 | fi␊ |
985 | ␊ |
986 | #Initialise Variables␊ |
987 | foundLanguage=""␊ |
988 | resetVars␊ |
989 | ␊ |
990 | # begin␊ |
991 | if [ -f "${PKG_BUILD_DIR}/${ResourcesSourceFile}" ]; then␊ |
992 | while read -r line␊ |
993 | do␊ |
994 | case "${line%%:*}" in␊ |
995 | ␊ |
996 | "language" ) ␊ |
997 | foundLanguage="${line#*: }"␊ |
998 | if [ ! -d "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage" ]; then␊ |
999 | echo -e "\tCreating Language Resource Folder: $foundLanguage"␊ |
1000 | mkdir -p "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage"␊ |
1001 | fi␊ |
1002 | ␊ |
1003 | ## Add License.rtf file to Language folder␊ |
1004 | if [ ! -f "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage/License.rtf" ]; then␊ |
1005 | echo -e "\t\tAdding License.rtf file"␊ |
1006 | ditto --noextattr --noqtn "${ResourcesSourceFolder}/License.rtf" "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage"␊ |
1007 | fi␊ |
1008 | ␊ |
1009 | resetVars␊ |
1010 | ;;␊ |
1011 | ␊ |
1012 | "file" )␊ |
1013 | # Have we already built an array of codes for the Welcome, Conclusion or Description Resource files?␊ |
1014 | if [ ${#buildCodes[@]} -ne 0 ]; then␊ |
1015 | for (( n=0; n<${#buildCodes[@]}; n++ ))␊ |
1016 | do␊ |
1017 | templateStrings[${#templateStrings[*]}]="--subst=${buildCodes[$n]}"␊ |
1018 | done␊ |
1019 | # Send the pre-built arrays to addTemplateResources() for completing template.␊ |
1020 | addTemplateScripts --pkg-rootdir="${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage" \␊ |
1021 | "${templateStrings[@]}" \␊ |
1022 | --type="" \␊ |
1023 | "$resourceToUse"␊ |
1024 | fi␊ |
1025 | ␊ |
1026 | resourceToUse="${line#*: }"␊ |
1027 | echo -e "\t\tComposing $resourceToUse File" ␊ |
1028 | ;;␊ |
1029 | ␊ |
1030 | "codeID" ) foundCode="${line#*: }" ;;␊ |
1031 | "messageName" ) foundMessageName="${line#*: }" ;;␊ |
1032 | "objectName" ) foundObjectName="${line#*: }"; foundObjectName="${foundObjectName%%_title*}" ;;␊ |
1033 | "objectTitle" ) foundObjectTitle="${line#*: }" ;;␊ |
1034 | "description" ) foundDescription="${line#*: }" ;;␊ |
1035 | esac␊ |
1036 | ␊ |
1037 | if [[ "$foundLanguage" != "" ]]; then␊ |
1038 | # Build an array for each the Welcome, Conclusion and Description Resource files per language.␊ |
1039 | if [[ "$foundCode" != "" ]] && [[ "$foundDescription" != "" ]]; then␊ |
1040 | if [[ "$resourceToUse" == "Welcome" ]] || [[ "$resourceToUse" == "Conclusion" ]]; then ␊ |
1041 | ␊ |
1042 | # Convert description from UFT8 to raw unicode markup␊ |
1043 | # ************************************************************␊ |
1044 | # FIX ME:␊ |
1045 | # This ony works on Lion. ␊ |
1046 | # The command on Snow Leopard yields different results??␊ |
1047 | # ************************************************************␊ |
1048 | convertedFoundDescription=$( echo $foundDescription | textutil -convert rtf -encoding UTF-8 -stdin -stdout )␊ |
1049 | ␊ |
1050 | # Strip away unicode text up to and including '\f0\fs24 \cf0' - take what's after.␊ |
1051 | strippedConvertedFoundDescription="${convertedFoundDescription#*\\f0\\fs24 \\cf0 }"␊ |
1052 | # Remove last three characters from string and replace all backslashes with a double backslash.␊ |
1053 | fixStrippedConvertedFoundDescription=$( echo "${strippedConvertedFoundDescription%???}" | sed -e 's/\\/\\\\/g' ) ␊ |
1054 | buildCodes[${#buildCodes[*]}]="$foundCode=$fixStrippedConvertedFoundDescription"␊ |
1055 | fi␊ |
1056 | if [[ "$resourceToUse" == "Description" ]]; then␊ |
1057 | # No need to convert the text for the Description file as it's not RTF.␊ |
1058 | buildCodes[${#buildCodes[*]}]="$foundCode=$foundDescription"␊ |
1059 | fi␊ |
1060 | foundCode=""; foundDescription=""␊ |
1061 | fi␊ |
1062 | ␊ |
1063 | # No need for an array for Localizable.strings. These can be written straight to file.␊ |
1064 | if [[ "$resourceToUse" == "LocalizableStrings" ]]; then␊ |
1065 | if [[ "$foundMessageName" != "" ]] && [[ "$foundDescription" != "" ]]; then␊ |
1066 | echo "\"${foundMessageName}\" = \"${foundDescription}\";" >> "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage/Localizable.strings"␊ |
1067 | echo "" >> "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage/Localizable.strings"␊ |
1068 | foundMessageName=""; foundDescription=""␊ |
1069 | fi␊ |
1070 | if [[ "$foundObjectName" != "" ]] && [[ "$foundObjectTitle" != "" ]] && [[ "$foundDescription" != "" ]]; then␊ |
1071 | echo "\"${foundObjectName}_title\" = \"${foundObjectTitle}\";" >> "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage/Localizable.strings"␊ |
1072 | echo "\"${foundObjectName}_description\" = \"${foundDescription}\";" >> "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage/Localizable.strings" ␊ |
1073 | echo "" >> "${PKG_BUILD_DIR}/${packagename}/Resources/$foundLanguage/Localizable.strings"␊ |
1074 | foundObjectName=""; foundObjectTitle=""; foundDescription=""␊ |
1075 | fi␊ |
1076 | fi␊ |
1077 | fi␊ |
1078 | done < "${PKG_BUILD_DIR}/${ResourcesSourceFile}"␊ |
1079 | rm "${PKG_BUILD_DIR}/${ResourcesSourceFile}"␊ |
1080 | else␊ |
1081 | echo -e "\tError. ${ResourcesLanguageFile} not created."␊ |
1082 | exit 1␊ |
1083 | fi␊ |
1084 | ␊ |
1085 | echo -e "\tAdding background.tiff file"␊ |
1086 | ditto --noextattr --noqtn "${ResourcesSourceFolder}/background.tiff" "${PKG_BUILD_DIR}/${packagename}/Resources"␊ |
1087 | echo -e "\tBuild Resources Completed."␊ |
1088 | }␊ |
1089 | ␊ |
1090 | makedistribution () {␊ |
1091 | declare -r distributionDestDir="${SYMROOT}"␊ |
1092 | declare -r distributionFilename="${packagename// /}-${CHAMELEON_VERSION}-r${CHAMELEON_REVISION}.pkg"␊ |
1093 | declare -r distributionFilePath="${distributionDestDir}/${distributionFilename}"␊ |
1094 | ␊ |
1095 | rm -f "${distributionDestDir}/${packagename// /}"*.pkg␊ |
1096 | ␊ |
1097 | mkdir -p "${PKG_BUILD_DIR}/${packagename}"␊ |
1098 | find "${PKG_BUILD_DIR}" -type f -name '*.pkg' -depth 1 | while read component␊ |
1099 | do␊ |
1100 | pkg="${component##*/}" # ie: EFI.pkg␊ |
1101 | pkgdir="${PKG_BUILD_DIR}/${packagename}/${pkg}"␊ |
1102 | # expand individual packages␊ |
1103 | pkgutil --expand "${PKG_BUILD_DIR}/${pkg}" "$pkgdir"␊ |
1104 | rm -f "${PKG_BUILD_DIR}/${pkg}"␊ |
1105 | done␊ |
1106 | ␊ |
1107 | # Create the Distribution file␊ |
1108 | ditto --noextattr --noqtn "${PKGROOT}/Distribution" "${PKG_BUILD_DIR}/${packagename}/Distribution"␊ |
1109 | ␊ |
1110 | local start_indent_level=2␊ |
1111 | echo -e "\n\t<choices-outline>" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"␊ |
1112 | for main_choice in ${choice_group_items[0]};do␊ |
1113 | generateOutlineChoices $main_choice $start_indent_level >> "${PKG_BUILD_DIR}/${packagename}/Distribution"␊ |
1114 | done␊ |
1115 | echo -e "\t</choices-outline>\n" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"␊ |
1116 | ␊ |
1117 | generateChoices >> "${PKG_BUILD_DIR}/${packagename}/Distribution"␊ |
1118 | ␊ |
1119 | for (( i=0; i < ${#pkgrefs[*]} ; i++)); do␊ |
1120 | echo -e "${pkgrefs[$i]}" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"␊ |
1121 | done␊ |
1122 | ␊ |
1123 | echo -e "\n</installer-gui-script>" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"␊ |
1124 | ␊ |
1125 | # Create the Resources directory␊ |
1126 | buildresources␊ |
1127 | ␊ |
1128 | # CleanUp the directory␊ |
1129 | # this next line should work but it doesn't - not sure why.␊ |
1130 | #find "${PKG_BUILD_DIR}/${packagename}" \( -type d -name '.svn' \) -o -name '.DS_Store' -exec rm -rf {} \;␊ |
1131 | ␊ |
1132 | # instead, doing it this way works.␊ |
1133 | find "${PKG_BUILD_DIR}/${packagename}/Resources" -name ".svn" -type d -o -name ".DS_Store" -type f | while read component␊ |
1134 | do␊ |
1135 | ␉␉rm -rf "${component}"␊ |
1136 | done␊ |
1137 | ␊ |
1138 | # Make substitutions for version, revision, stage, developers, credits, etc..␊ |
1139 | makeSubstitutions $( find "${PKG_BUILD_DIR}/${packagename}/Resources" -type f )␊ |
1140 | ␊ |
1141 | # Create the final package␊ |
1142 | pkgutil --flatten "${PKG_BUILD_DIR}/${packagename}" "${distributionFilePath}"␊ |
1143 | ␊ |
1144 | # Here is the place to assign an icon to the pkg␊ |
1145 | ditto -xk "${PKGROOT}/Icons/pkg.zip" "${PKG_BUILD_DIR}/Icons/"␊ |
1146 | DeRez -only icns "${PKG_BUILD_DIR}/Icons/Icons/pkg.icns" > "${PKG_BUILD_DIR}/Icons/tempicns.rsrc"␊ |
1147 | Rez -append "${PKG_BUILD_DIR}/Icons/tempicns.rsrc" -o "${distributionFilePath}"␊ |
1148 | SetFile -a C "${distributionFilePath}"␊ |
1149 | rm -rf "${PKG_BUILD_DIR}/Icons"␊ |
1150 | ␊ |
1151 | # End␊ |
1152 | ␊ |
1153 | md5=$( md5 "${distributionFilePath}" | awk {'print $4'} )␊ |
1154 | echo "MD5 (${distributionFilePath}) = ${md5}" > "${distributionFilePath}.md5"␊ |
1155 | echo ""␊ |
1156 | ␊ |
1157 | echo -e $COL_GREEN" --------------------------"$COL_RESET␊ |
1158 | echo -e $COL_GREEN" Building process complete!"$COL_RESET␊ |
1159 | echo -e $COL_GREEN" --------------------------"$COL_RESET␊ |
1160 | echo ""␊ |
1161 | echo -e $COL_GREEN" Build info."␊ |
1162 | echo -e $COL_GREEN" ==========="␊ |
1163 | echo -e $COL_CYAN" Package name: "$COL_RESET"${distributionFilename}"␊ |
1164 | echo -e $COL_CYAN" MD5: "$COL_RESET"$md5"␊ |
1165 | echo -e $COL_CYAN" Version: "$COL_RESET"$CHAMELEON_VERSION"␊ |
1166 | echo -e $COL_CYAN" Stage: "$COL_RESET"$CHAMELEON_STAGE"␊ |
1167 | echo -e $COL_CYAN" Date/Time: "$COL_RESET"$CHAMELEON_BUILDDATE"␊ |
1168 | echo -e $COL_CYAN" Built by: "$COL_RESET"$CHAMELEON_WHOBUILD"␊ |
1169 | echo -e $COL_CYAN" Copyright $CHAMELEON_CPRYEAR ""$COL_RESET"␊ |
1170 | echo ""␊ |
1171 | ␊ |
1172 | }␊ |
1173 | ␊ |
1174 | # build packages␊ |
1175 | main␊ |
1176 | ␊ |
1177 | # build meta package␊ |
1178 | makedistribution␊ |
1179 | |