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