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