Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Modules/package/buildpkg.sh

  • Property svn:executable set to *
1#!/bin/bash
2
3# $1 Path to store built package
4
5packagesidentity="org.chameleon"
6packagename="Chameleon"
7pkgroot="${0%/*}"
8chamTemp="usr/local/chamTemp"
9
10COL_BLACK="\x1b[30;01m"
11COL_RED="\x1b[31;01m"
12COL_GREEN="\x1b[32;01m"
13COL_YELLOW="\x1b[33;01m"
14COL_MAGENTA="\x1b[35;01m"
15COL_CYAN="\x1b[36;01m"
16COL_WHITE="\x1b[37;01m"
17COL_BLUE="\x1b[34;01m"
18COL_RESET="\x1b[39;49;00m"
19
20version=$( cat version )
21stage=${version##*-}
22revision=$( grep I386BOOT_CHAMELEONREVISION vers.h | awk '{ print $3 }' | tr -d '\"' )
23builddate=$( grep I386BOOT_BUILDDATE vers.h | awk '{ print $3,$4 }' | tr -d '\"' )
24timestamp=$( date -j -f "%Y-%m-%d %H:%M:%S" "${builddate}" "+%s" )
25
26# =================
27
28develop=$(awk "NR==6{print;exit}" ${pkgroot}/../CREDITS)
29credits=$(awk "NR==10{print;exit}" ${pkgroot}/../CREDITS)
30pkgdev=$(awk "NR==14{print;exit}" ${pkgroot}/../CREDITS)
31
32# =================
33
34distributioncount=0
35xmlindent=0
36
37indent[0]="\t"
38indent[1]="\t\t"
39indent[2]="\t\t\t"
40indent[3]="\t\t\t\t"
41
42declare -a pkgrefs
43
44# Package identifiers
45modules_packages_identity="org.chameleon.modules"
46
47getPackageRefId () {
48 echo ${1//_/.}.${2//_/.} | tr [:upper:] [:lower:]
49}
50
51addChoice () {
52 # $1 Choice Id
53 # $2 Choice Options
54 # $3..$n Package reference id (optional)
55 local choiceId="${1}"
56 local choiceOptions="${2}"
57 local choiceNode="\t<choice\n\t\tid=\"${choiceId}\"\n\t\ttitle=\"${choiceId}_title\"\n\t\tdescription=\"${choiceId}_description\""
58 [[ -n "${choiceOptions}" ]] && choiceNode="${choiceNode}\n\t\t${choiceOptions}"
59 choiceNode="${choiceNode}>"
60 if [[ $# -ge 3 ]];then
61 for pkgRefId in ${@:3};do
62 choiceNode="${choiceNode}\n\t\t<pkg-ref id=\"${pkgRefId}\"/>"
63 done
64 fi
65 choiceNode="${choiceNode}\n\t</choice>\n"
66
67 outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"${choiceId}\"/>"
68 choices[$((choicescount++))]="$choiceNode"
69}
70
71exclusive_one_choice () {
72 # $1 Current choice (ie: test1)
73 # $2..$n Others choice(s) (ie: "test2" "test3"). Current can or can't be in the others choices
74 local myChoice="${1}"
75 local result;
76 local separator=' || ';
77 for choice in ${@:2};do
78 if [[ "$choice" != "$myChoice" ]];then
79 result="${result}choices['$choice'].selected${separator}";
80 fi
81 done
82 echo "!(${result%$separator})"
83}
84
85exclusive_zero_or_one_choice () {
86 # $1 Current choice (ie: test1)
87 # $2..$n Others choice(s) (ie: "test2" "test3"). Current can or can't be in the others choices
88 local myChoice="${1}"
89 local result;
90 echo "(my.choice.selected &amp;&amp; $(exclusive_one_choice ${@}))"
91}
92
93main ()
94{
95
96# clean up the destination path
97
98 rm -R -f "${1}"
99 echo ""
100 echo -e $COL_CYAN" ----------------------------------"$COL_RESET
101 echo -e $COL_CYAN" Building $packagename Install Package"$COL_RESET
102 echo -e $COL_CYAN" ----------------------------------"$COL_RESET
103 echo ""
104
105 outline[$((outlinecount++))]="${indent[$xmlindent]}<choices-outline>"
106
107# build pre install package
108 echo "================= Preinstall ================="
109 ((xmlindent++))
110 packagesidentity="org.chameleon"
111 choiceId="Pre"
112 mkdir -p ${1}/${choiceId}/Root
113 mkdir -p ${1}/${choiceId}/Scripts
114 ditto --noextattr --noqtn ${1%/*/*}/revision ${1}/${choiceId}/Scripts/Resources/revision
115 ditto --noextattr --noqtn ${1%/*/*}/version ${1}/${choiceId}/Scripts/Resources/version
116 cp -f ${pkgroot}/Scripts/Main/preinstall ${1}/${choiceId}/Scripts
117 cp -f ${pkgroot}/Scripts/Sub/InstallLog.sh ${1}/${choiceId}/Scripts
118 echo -e "\t[BUILD] ${choiceId} "
119 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
120 buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/" >/dev/null 2>&1
121 addChoice "${choiceId}" "start_visible=\"false\" start_selected=\"true\"" "$packageRefId"
122# End build pre install package
123
124# build core package
125 echo "================= Core ================="
126 packagesidentity="org.chameleon"
127 choiceId="Core"
128 mkdir -p ${1}/${choiceId}/Root/usr/local/bin
129 mkdir -p ${1}/${choiceId}/Root/usr/standalone/i386
130 ditto --noextattr --noqtn ${1%/*}/i386/boot ${1}/${choiceId}/Root/usr/standalone/i386
131 ditto --noextattr --noqtn ${1%/*}/i386/boot0 ${1}/${choiceId}/Root/usr/standalone/i386
132 ditto --noextattr --noqtn ${1%/*}/i386/boot0md ${1}/${choiceId}/Root/usr/standalone/i386
133 ditto --noextattr --noqtn ${1%/*}/i386/boot1f32 ${1}/${choiceId}/Root/usr/standalone/i386
134 ditto --noextattr --noqtn ${1%/*}/i386/boot1h ${1}/${choiceId}/Root/usr/standalone/i386
135 ditto --noextattr --noqtn ${1%/*}/i386/boot1he ${1}/${choiceId}/Root/usr/standalone/i386
136 ditto --noextattr --noqtn ${1%/*}/i386/boot1hp ${1}/${choiceId}/Root/usr/standalone/i386
137 ditto --noextattr --noqtn ${1%/*}/i386/cdboot ${1}/${choiceId}/Root/usr/standalone/i386
138 ditto --noextattr --noqtn ${1%/*}/i386/chain0 ${1}/${choiceId}/Root/usr/standalone/i386
139 ditto --noextattr --noqtn ${1%/*}/i386/fdisk440 ${1}/${choiceId}/Root/usr/local/bin
140 ditto --noextattr --noqtn ${1%/*}/i386/bdmesg ${1}/${choiceId}/Root/usr/local/bin
141 echo -e "\t[BUILD] ${choiceId} "
142 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
143 buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/" >/dev/null 2>&1
144 addChoice "${choiceId}" "start_visible=\"false\" start_selected=\"true\"" "$packageRefId"
145# End build core package
146
147# build install type
148 echo "================= Chameleon ================="
149 outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"InstallType\">"
150 choices[$((choicescount++))]="\t<choice\n\t\tid=\"InstallType\"\n\t\ttitle=\"InstallType_title\"\n\t\tdescription=\"InstallType_description\">\n\t</choice>\n"
151 ((xmlindent++))
152 packagesidentity="org.chameleon.type"
153 allChoices="New Upgrade"
154
155 # build new install package
156 choiceId="New"
157 mkdir -p ${1}/${choiceId}/Root
158 echo "" > "${1}/${choiceId}/Root/install_type_new"
159 echo -e "\t[BUILD] ${choiceId} "
160 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
161 buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp" >/dev/null 2>&1
162 exclusiveChoice=$(exclusive_one_choice "$choiceId" "$allChoices")
163 addChoice "${choiceId}" "start_selected=\"!choices['Upgrade'].selected\" selected=\"${exclusiveChoice}\"" "$packageRefId"
164 # End build new install package
165
166 # build upgrade package
167 choiceId="Upgrade"
168 mkdir -p ${1}/${choiceId}/Root
169 echo "" > "${1}/${choiceId}/Root/install_type_upgrade"
170 echo -e "\t[BUILD] ${choiceId} "
171 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
172 buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp" >/dev/null 2>&1
173 exclusiveChoice=$(exclusive_one_choice "$choiceId" "$allChoices")
174 addChoice "${choiceId}" "start_selected=\"chameleon_boot_plist_exists()\" selected=\"${exclusiveChoice}\"" "$packageRefId"
175 # End build upgrade package
176
177 ((xmlindent--))
178 outline[$((outlinecount++))]="${indent[$xmlindent]}</line>"
179# End build install type
180
181# build Chameleon package
182 echo "================= Chameleon ================="
183 outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"Chameleon\">"
184 choices[$((choicescount++))]="\t<choice\n\t\tid=\"Chameleon\"\n\t\ttitle=\"Chameleon_title\"\n\t\tdescription=\"Chameleon_description\">\n\t</choice>\n"
185 ((xmlindent++))
186
187 allChoices="Standard EFI noboot"
188
189 # build standard package
190 choiceId="Standard"
191 mkdir -p ${1}/${choiceId}/Root
192 mkdir -p ${1}/${choiceId}/Scripts/Resources
193 cp -f ${pkgroot}/Scripts/Main/${choiceId}postinstall ${1}/${choiceId}/Scripts/postinstall
194 cp -f ${pkgroot}/Scripts/Sub/* ${1}/${choiceId}/Scripts
195 ditto --arch i386 `which SetFile` ${1}/${choiceId}/Scripts/Resources/SetFile
196 echo -e "\t[BUILD] ${choiceId} "
197 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
198 buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/" >/dev/null 2>&1
199 exclusiveChoice=$(exclusive_one_choice "$choiceId" "$allChoices")
200 addChoice "${choiceId}" "start_selected=\"true\" selected=\"${exclusiveChoice}\"" "$packageRefId"
201 # End build standard package
202
203 # build efi package
204 choiceId="EFI"
205 mkdir -p ${1}/${choiceId}/Root
206 mkdir -p ${1}/${choiceId}/Scripts/Resources
207 cp -f ${pkgroot}/Scripts/Main/ESPpostinstall ${1}/${choiceId}/Scripts/postinstall
208 cp -f ${pkgroot}/Scripts/Sub/* ${1}/${choiceId}/Scripts
209 ditto --arch i386 `which SetFile` ${1}/${choiceId}/Scripts/Resources/SetFile
210 echo -e "\t[BUILD] ${choiceId} "
211 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
212 buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/" >/dev/null 2>&1
213 exclusiveChoice=$(exclusive_one_choice "$choiceId" "$allChoices")
214 addChoice "${choiceId}" "start_visible=\"systemHasGPT()\" start_selected=\"false\" selected=\"${exclusiveChoice}\"" "$packageRefId"
215 # End build efi package
216
217 # build no bootloader choice package
218 choiceId="noboot"
219 mkdir -p ${1}/${choiceId}/Root
220 echo -e "\t[BUILD] ${choiceId} "
221 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
222 buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/" >/dev/null 2>&1
223 exclusiveChoice=$(exclusive_one_choice "$choiceId" "$allChoices")
224 addChoice "${choiceId}" "start_selected=\"false\" selected=\"${exclusiveChoice}\"" "$packageRefId"
225 # End build no bootloader choice package
226
227 ((xmlindent--))
228 outline[$((outlinecount++))]="${indent[$xmlindent]}</line>"
229# End build Chameleon package
230
231# build Modules package
232 echo "================= Modules ================="
233 ###############################
234 # Supported Modules #
235 ###############################
236 # AMDGraphicsEnabler.dylib #
237 # ATiGraphicsEnabler.dylib #
238 # IntelGraphicsEnabler.dylib #
239 # klibc.dylib #
240 # NVIDIAGraphicsEnabler.dylib #
241 # Resolution.dylib #
242 # uClibcxx.dylib #
243 # Keylayout.dylib #
244 ###############################
245 if [ "$(ls -A "${1%/*}/i386/modules")" ]; then
246 {
247 outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"Module\">"
248 choices[$((choicescount++))]="\t<choice\n\t\tid=\"Module\"\n\t\ttitle=\"Module_title\"\n\t\tdescription=\"Module_description\">\n\t</choice>\n"
249 ((xmlindent++))
250
251# -
252 if [ -e ${1%/*}/i386/modules/klibc.dylib ]; then
253 {
254 # Start build klibc package module
255 choiceId="klibc"
256 mkdir -p ${1}/${choiceId}/Root
257 ditto --noextattr --noqtn ${1%/*}/i386/modules/${choiceId}.dylib ${1}/${choiceId}/Root
258 echo -e "\t[BUILD] ${choiceId} "
259 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
260 buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp/Extra/modules" >/dev/null 2>&1
261 addChoice "${choiceId}" "start_selected=\"false\"" "$packageRefId"
262 # End build klibc package module
263 }
264 fi
265
266# -
267 if [ -e ${1%/*}/i386/modules/uClibcxx.dylib ]; then
268 {
269 # Start build uClibc package module
270 choiceId="uClibc"
271 mkdir -p ${1}/${choiceId}/Root
272 ditto --noextattr --noqtn ${1%/*}/i386/modules/uClibcxx.dylib ${1}/${choiceId}/Root
273 echo -e "\t[BUILD] ${choiceId} "
274 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
275 buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp/Extra/modules" >/dev/null 2>&1
276 # Add the klibc package because the uClibc module is dependent of klibc module
277 addChoice "${choiceId}" "start_selected=\"false\"" \
278 "$packageRefId" $(getPackageRefId "${modules_packages_identity}" "klibc")
279 # End build uClibc package module
280 }
281 fi
282
283# -
284 if [ -e ${1%/*}/i386/modules/Resolution.dylib ]; then
285 {
286 # Start build Resolution package module
287 choiceId="AutoReso"
288 mkdir -p ${1}/${choiceId}/Root
289 ditto --noextattr --noqtn ${1%/*}/i386/modules/Resolution.dylib ${1}/${choiceId}/Root
290 echo -e "\t[BUILD] ${choiceId} "
291 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
292 buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp/Extra/modules" >/dev/null 2>&1
293 addChoice "${choiceId}" "start_selected=\"false\"" "$packageRefId"
294 # End build Resolution package module
295 }
296 fi
297
298# -
299 # Warning Keylayout module need additional files
300 if [ -e ${1%/*}/i386/modules/Keylayout.dylib ]; then
301 {
302 # Start build Keylayout package module
303 choiceId="Keylayout"
304 mkdir -p ${1}/${choiceId}/Root/Extra/{modules,Keymaps}
305 mkdir -p ${1}/${choiceId}/Root/usr/local/bin
306 layout_src_dir="${1%/sym/*}/i386/modules/Keylayout/layouts/layouts-src"
307 if [ -d "$layout_src_dir" ];then
308 # Create a tar.gz from layout sources
309 (cd "$layout_src_dir"; \
310 tar czf "${1}/Keylayout/Root/Extra/Keymaps/layouts-src.tar.gz" README *.slt)
311 fi
312 # Adding module
313 ditto --noextattr --noqtn ${1%/*}/i386/modules/${choiceId}.dylib ${1}/${choiceId}/Root/Extra/modules
314 # Adding Keymaps
315 ditto --noextattr --noqtn ${1%/sym/*}/Keymaps ${1}/${choiceId}/Root/Extra/Keymaps
316 # Adding tools
317 ditto --noextattr --noqtn ${1%/*}/i386/cham-mklayout ${1}/${choiceId}/Root/usr/local/bin
318 echo -e "\t[BUILD] ${choiceId} "
319 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
320 buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp" >/dev/null 2>&1
321
322 # Don't add a choice for Keylayout module
323 # addChoice "${choiceId}" "start_selected=\"false\"" "$packageRefId"
324 # End build Keylayout package module
325 }
326 fi
327
328# -
329
330 if [ -e ${1%/*}/i386/modules/AMDGraphicsEnabler.dylib ]; then
331 {
332 # Start build AMDGraphicsEnabler package module
333 choiceId="AMDGraphicsEnabler"
334 mkdir -p ${1}/${choiceId}/Root
335 ditto --noextattr --noqtn ${1%/*}/i386/modules/AMDGraphicsEnabler.dylib ${1}/${choiceId}/Root
336 echo -e "\t[BUILD] ${choiceId} "
337 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
338 buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp/Extra/modules" >/dev/null 2>&1
339 addChoice "${choiceId}" "start_selected=\"false\"" "$packageRefId"
340 # End build AMDGraphicsEnabler package module
341 }
342 fi
343
344# -
345
346 if [ -e ${1%/*}/i386/modules/ATiGraphicsEnabler.dylib ]; then
347 {
348 # Start build ATiGraphicsEnabler package module
349 choiceId="AMDGraphicsEnabler"
350 mkdir -p ${1}/${choiceId}/Root
351 ditto --noextattr --noqtn ${1%/*}/i386/modules/ATiGraphicsEnabler.dylib ${1}/${choiceId}/Root
352 echo -e "\t[BUILD] ${choiceId} "
353 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
354 buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp/Extra/modules" >/dev/null 2>&1
355 addChoice "${choiceId}" "start_selected=\"false\"" "$packageRefId"
356 # End build ATiGraphicsEnabler package module
357 }
358 fi
359
360# -
361
362 if [ -e ${1%/*}/i386/modules/IntelGraphicsEnabler.dylib ]; then
363 {
364 # Start build ATiGraphicsEnabler package module
365 choiceId="IntelGraphicsEnabler"
366 mkdir -p ${1}/${choiceId}/Root
367 ditto --noextattr --noqtn ${1%/*}/i386/modules/IntelGraphicsEnabler.dylib ${1}/${choiceId}/Root
368 echo -e "\t[BUILD] ${choiceId} "
369 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
370 buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp/Extra/modules" >/dev/null 2>&1
371 addChoice "${choiceId}" "start_selected=\"false\"" "$packageRefId"
372 # End build IntelGraphicsEnabler package module
373 }
374 fi
375
376# -
377
378 if [ -e ${1%/*}/i386/modules/NVIDIAGraphicsEnabler.dylib ]; then
379 {
380 # Start build NVIDIAGraphicsEnabler package module
381 choiceId="NVIDIAGraphicsEnabler"
382 mkdir -p ${1}/${choiceId}/Root
383 ditto --noextattr --noqtn ${1%/*}/i386/modules/NVIDIAGraphicsEnabler.dylib ${1}/${choiceId}/Root
384 echo -e "\t[BUILD] ${choiceId} "
385 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
386 buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp/Extra/modules" >/dev/null 2>&1
387 addChoice "${choiceId}" "start_selected=\"false\"" "$packageRefId"
388 # End build NVIDIAGraphicsEnabler package module
389 }
390 fi
391
392 ((xmlindent--))
393 outline[$((outlinecount++))]="${indent[$xmlindent]}</line>"
394 }
395 else
396 {
397 echo " -= no modules to include =-"
398 }
399 fi
400# End build Modules packages
401
402# build Options packages
403
404 outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"Options\">"
405 choices[$((choicescount++))]="\t<choice\n\t\tid=\"Options\"\n\t\ttitle=\"Options_title\"\n\t\tdescription=\"Options_description\">\n\t</choice>\n"
406 ((xmlindent++))
407
408
409 # ------------------------------------------------------
410 # parse OptionalSettings folder to find files of boot options.
411 # ------------------------------------------------------
412 OptionalSettingsFolder="${pkgroot}/OptionalSettings"
413 OptionalSettingsFiles=($( find "${OptionalSettingsFolder}" -depth 1 ! -name '.svn' ! -name '.DS_Store' ))
414
415 for (( i = 0 ; i < ${#OptionalSettingsFiles[@]} ; i++ ))
416 do
417
418# Take filename and Strip .txt from end and path from front
419builtOptionsList=$( echo ${OptionalSettingsFiles[$i]%.txt} )
420builtOptionsList=$( echo ${builtOptionsList##*/} )
421echo "================= $builtOptionsList ================="
422outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"${builtOptionsList}\">"
423choices[$((choicescount++))]="\t<choice\n\t\tid=\"${builtOptionsList}\"\n\t\ttitle=\"${builtOptionsList}_title\"\n\t\tdescription=\"${builtOptionsList}_description\">\n\t</choice>\n"
424((xmlindent++))
425packagesidentity="org.chameleon.options.$builtOptionsList"
426
427# ------------------------------------------------------
428# Read boot option file into an array.
429# ------------------------------------------------------
430availableOptions=() # array to hold the list of boot options, per 'section'.
431exclusiveFlag=0 # used to indicate list has exclusive options
432count=0 # used as index for stepping through array.
433while read textLine; do
434# ignore lines in the file beginning with a # and Exclusive=False
435if [[ ${textLine} != \#* ]] && [[ ${textLine} != "Exclusive=False" ]];then
436# check for 'Exclusive=True' option in file
437if [[ ${textLine} == "Exclusive=True" ]];then
438exclusiveFlag=1
439else
440availableOptions[${#availableOptions[@]}]=$textLine
441fi
442fi
443done < ${OptionalSettingsFiles[$i]}
444
445# ------------------------------------------------------
446# Loop through options in array and process each in turn
447# ------------------------------------------------------
448allChoices="${availableOptions[@]//:*/}"
449for (( c = 0 ; c < ${#availableOptions[@]} ; c++ )); do
450textLine=${availableOptions[c]}
451# split line - taking all before ':' as option name
452# and all after ':' as key/value
453optionName=${textLine%:*}
454keyValue=${textLine##*:}
455
456# create folders required for each boot option
457mkdir -p "${1}/$optionName/Root/"
458
459# create dummy file with name of key/value
460echo "" > "${1}/$optionName/Root/${keyValue}"
461
462echo -e "\t[BUILD] ${optionName} "
463packageRefId=$(getPackageRefId "${packagesidentity}" "${optionName}")
464buildpackage "$packageRefId" "${optionName}" "${1}/${optionName}" "/$chamTemp/options" >/dev/null 2>&1
465exclusiveSelect=""
466if [[ ${exclusiveFlag} -eq 1 ]];then
467exclusiveSelect="selected=\"$(exclusive_zero_or_one_choice "$optionName" "$allChoices")\""
468fi
469addChoice "${optionName}" "start_selected=\"false\" ${exclusiveSelect}" "$packageRefId"
470done
471
472((xmlindent--))
473outline[$((outlinecount++))]="${indent[$xmlindent]}</line>"
474done
475
476# build KeyLayout options packages
477echo "================= Keymaps Options ================="
478outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"KeyLayout\">"
479choices[$((choicescount++))]="\t<choice\n\t\tid=\"KeyLayout\"\n\t\ttitle=\"KeyLayout_title\"\n\t\tdescription=\"KeyLayout_description\">\n\t</choice>\n"
480((xmlindent++))
481packagesidentity="org.chameleon.options.keylayout"
482keylayoutPackageRefId=$(getPackageRefId "${modules_packages_identity}" "Keylayout")
483
484# ------------------------------------------------------
485# Available Keylayout boot options are discovered by
486# reading contents of /Keymaps folder after compilation
487# ------------------------------------------------------
488availableOptions=($( find "${1%/sym/*}/Keymaps" -type f -depth 1 -name '*.lyt' | sed 's|.*/||;s|\.lyt||' ))
489allChoices="${availableOptions[@]}"
490# Adjust array contents to match expected format
491# for boot options which is: name:key=value
492for (( i = 0 ; i < ${#availableOptions[@]} ; i++ )); do
493# availableOptions[i]=${availableOptions[i]}":KeyLayout="${availableOptions[i]}
494# Start build of a keymap package module
495choiceId="${availableOptions[i]}"
496mkdir -p ${1}/${choiceId}/Root
497
498# create dummy file with name of key/value
499echo "" > "${1}/${choiceId}/Root/KeyLayout=${availableOptions[i]}"
500
501echo -e "\t[BUILD] ${choiceId} "
502packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
503buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp/options" >/dev/null 2>&1
504exclusiveChoice=$(exclusive_zero_or_one_choice "$choiceId" "$allChoices")
505# Add the Keylayout package because the Keylayout module is needed
506addChoice "${choiceId}" "start_selected=\"false\" selected=\"${exclusiveChoice}\"" \
507 "$packageRefId" "$keylayoutPackageRefId"
508# End build uClibc package module
509done
510
511((xmlindent--))
512outline[$((outlinecount++))]="${indent[$xmlindent]}</line>"
513
514# End build KeyLayout options packages
515
516((xmlindent--))
517outline[$((outlinecount++))]="${indent[$xmlindent]}</line>"
518# End build options packages
519
520# build theme packages
521echo "================= Themes ================="
522outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"Themes\">"
523choices[$((choicescount++))]="\t<choice\n\t\tid=\"Themes\"\n\t\ttitle=\"Themes_title\"\n\t\tdescription=\"Themes_description\">\n\t</choice>\n"
524((xmlindent++))
525
526# Using themes section from Azi's/package branch.
527packagesidentity="org.chameleon.themes"
528artwork="${1%/sym/package}/artwork/themes"
529themes=($( find "${artwork}" -type d -depth 1 -not -name '.svn' ))
530for (( i = 0 ; i < ${#themes[@]} ; i++ )); do
531theme=$( echo ${themes[$i]##*/} | awk 'BEGIN{OFS=FS=""}{$1=toupper($1);print}' )
532mkdir -p "${1}/${theme}/Root/"
533rsync -r --exclude=.svn "${themes[$i]}/" "${1}/${theme}/Root/${theme}"
534echo -e "\t[BUILD] ${theme}"
535packageRefId=$(getPackageRefId "${packagesidentity}" "${theme}")
536buildpackage "$packageRefId" "${theme}" "${1}/${theme}" "/$chamTemp/Extra/Themes" >/dev/null 2>&1
537addChoice "${theme}" "start_selected=\"false\"" "$packageRefId"
538done
539
540((xmlindent--))
541outline[$((outlinecount++))]="${indent[$xmlindent]}</line>"
542# End build theme packages# End build Extras package
543
544# build post install package
545 echo "================= Post ================="
546 packagesidentity="org.chameleon"
547 choiceId="Post"
548 mkdir -p ${1}/${choiceId}/Root
549 mkdir -p ${1}/${choiceId}/Scripts
550 cp -f ${pkgroot}/Scripts/Main/postinstall ${1}/${choiceId}/Scripts
551 cp -f ${pkgroot}/Scripts/Sub/InstallLog.sh ${1}/${choiceId}/Scripts
552 cp -f ${pkgroot}/Scripts/Sub/UnMountEFIvolumes.sh ${1}/${choiceId}/Scripts
553 ditto --noextattr --noqtn ${1%/*/*}/revision ${1}/${choiceId}/Scripts/Resources/revision
554 ditto --noextattr --noqtn ${1%/*/*}/version ${1}/${choiceId}/Scripts/Resources/version
555 echo -e "\t[BUILD] ${choiceId} "
556 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
557 buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/" >/dev/null 2>&1
558 addChoice "${choiceId}" "start_visible=\"false\" start_selected=\"true\"" "$packageRefId"
559# End build post install package
560
561((xmlindent--))
562outline[$((outlinecount++))]="${indent[$xmlindent]}</choices-outline>"
563
564# build meta package
565
566 makedistribution "${1}" "${2}" "${3}" "${4}" #"${5}"
567
568# clean up
569# rm -R -f "${1}"
570
571}
572
573buildpackage ()
574{
575# $1 Package Reference Id (ie: org.chameleon.themes.default)
576# $2 Package Name (ie: Default)
577# $3 Path to package to build containing Root and/or Scripts
578# $4 Target install location
579# $5 Size (optional)
580if [[ -d "${3}/Root" ]]; then
581local packageRefId="$1"
582local packageName="$2"
583local packagePath="$3"
584local targetPath="$4"
585local packageSize="$5"
586
587find "${packagePath}" -name '.DS_Store' -delete
588local filecount=$( find "${packagePath}/Root" | wc -l )
589if [ "${packageSize}" ]; then
590local installedsize="${packageSize}"
591else
592local installedsize=$( du -hkc "${packagePath}/Root" | tail -n1 | awk {'print $1'} )
593fi
594local header="<?xml version=\"1.0\"?>\n<pkg-info format-version=\"2\" "
595
596#[ "${3}" == "relocatable" ] && header+="relocatable=\"true\" "
597
598header+="identifier=\"${packageRefId}\" "
599header+="version=\"${version}\" "
600
601[ "${targetPath}" != "relocatable" ] && header+="install-location=\"${targetPath}\" "
602
603header+="auth=\"root\">\n"
604header+="\t<payload installKBytes=\"${installedsize##* }\" numberOfFiles=\"${filecount##* }\"/>\n"
605rm -R -f "${packagePath}/Temp"
606
607[ -d "${packagePath}/Temp" ] || mkdir -m 777 "${packagePath}/Temp"
608[ -d "${packagePath}/Root" ] && mkbom "${packagePath}/Root" "${packagePath}/Temp/Bom"
609
610if [ -d "${packagePath}/Scripts" ]; then
611header+="\t<scripts>\n"
612for script in $( find "${packagePath}/Scripts" -type f \( -name 'pre*' -or -name 'post*' \) ); do
613header+="\t\t<${script##*/} file=\"./${script##*/}\"/>\n"
614done
615header+="\t</scripts>\n"
616# Create the Script archive file (cpio format)
617(cd "${packagePath}/Scripts" && find . -print | cpio -o -z -R root:wheel --format cpio > "${packagePath}/Temp/Scripts") 2>&1 | \
618 grep -vE '^[0-9]+\s+blocks?$' # to remove cpio stderr messages
619 fi
620
621header+="</pkg-info>"
622echo -e "${header}" > "${packagePath}/Temp/PackageInfo"
623
624# Create the Payload file (cpio format)
625(cd "${packagePath}/Root" && find . -print | cpio -o -z -R root:wheel --format cpio > "${packagePath}/Temp/Payload") 2>&1 | \
626 grep -vE '^[0-9]+\s+blocks?$' # to remove cpio stderr messages
627
628# Create the package
629(cd "${packagePath}/Temp" && xar -c -f "${packagePath}/../${packageName}.pkg" --compression none .)
630
631# Add the package to the list of build packages
632pkgrefs[${#pkgrefs[*]}]="\t<pkg-ref id=\"${packageRefId}\" installKBytes='${installedsize}' version='${version}.0.0.${timestamp}'>#${packageName}.pkg</pkg-ref>"
633
634rm -rf "${packagePath}"
635fi
636}
637
638makedistribution ()
639{
640 distributionDestDir="${1%/*}"
641 distributionFilename="${packagename// /}-${version}-r${revision}.pkg"
642 distributionFilePath="${distributionDestDir}/${distributionFilename}"
643
644 rm -f "${distributionDestDir}/${packagename// /}"*.pkg
645
646 mkdir -p "${1}/${packagename}"
647
648 find "${1}" -type f -name '*.pkg' -depth 1 | while read component
649do
650 pkg="${component##*/}" # ie: EFI.pkg
651 pkgdir="${1}/${packagename}/${pkg}"
652 # expand individual packages
653 pkgutil --expand "${1%}/${pkg}" "$pkgdir"
654 rm -f "${1%}/${pkg}"
655 done
656
657# Create the Distribution file
658 ditto --noextattr --noqtn "${pkgroot}/Distribution" "${1}/${packagename}/Distribution"
659
660 for (( i=0; i < ${#outline[*]} ; i++)); do
661echo -e "${outline[$i]}" >> "${1}/${packagename}/Distribution"
662done
663
664 for (( i=0; i < ${#choices[*]} ; i++)); do
665echo -e "${choices[$i]}" >> "${1}/${packagename}/Distribution"
666done
667
668 for (( i=0; i < ${#pkgrefs[*]} ; i++)); do
669 echo -e "${pkgrefs[$i]}" >> "${1}/${packagename}/Distribution"
670 done
671
672 echo -e "\n</installer-gui-script>" >> "${1}/${packagename}/Distribution"
673
674# Create the Resources directory
675 ditto --noextattr --noqtn "${pkgroot}/Resources" "${1}/${packagename}/Resources"
676
677# CleanUp the directory
678 find "${1}/${packagename}" -type d -name '.svn' -exec rm -rf {} \; 2>/dev/null
679 find "${1}/${packagename}" -name '.DS_Store' -delete
680
681# Add Chameleon Version and Revision
682 perl -i -p -e "s/%CHAMELEONVERSION%/${version%%-*}/g" $( find "${1}/${packagename}/Resources" -type f )
683 perl -i -p -e "s/%CHAMELEONREVISION%/${revision}/g" $( find "${1}/${packagename}/Resources" -type f )
684
685# Add Chameleon Stage
686 stage=${stage/RC/Release Candidate }
687 stage=${stage/FINAL/2.0 Final}
688 perl -i -p -e "s/%CHAMELEONSTAGE%/${stage}/g" $( find "${1}/${packagename}/Resources" -type f )
689
690# Adding Developer and credits
691 perl -i -p -e "s/%DEVELOP%/${develop}/g" $( find "${1}/${packagename}/Resources" -type f )
692 perl -i -p -e "s/%CREDITS%/${credits}/g" $( find "${1}/${packagename}/Resources" -type f )
693 perl -i -p -e "s/%PKGDEV%/${pkgdev}/g" $( find "${1}/${packagename}/Resources" -type f )
694
695# Create the final package
696 pkgutil --flatten "${1}/${packagename}" "${distributionFilePath}"
697
698# Here is the place for assign a Icon to the pkg
699# command use to generate the file:
700# ditto -c -k --sequesterRsrc --keepParent Icon.icns Icon.zip
701# ----
702 ditto -xk "${pkgroot}/Icons/pkg.zip" "${1}/Icons/"
703 DeRez -only icns "${1}/Icons/Icons/pkg.icns" > "${1}/Icons/tempicns.rsrc"
704 Rez -append "${1}/Icons/tempicns.rsrc" -o "${distributionFilePath}"
705 SetFile -a C "${distributionFilePath}"
706 rm -rf "${1}/Icons"
707
708# End
709
710 md5=$( md5 "${distributionFilePath}" | awk {'print $4'} )
711 echo "MD5 (${distributionFilePath}) = ${md5}" > "${distributionFilePath}.md5"
712 echo ""
713
714 echo -e $COL_GREEN" --------------------------"$COL_RESET
715 echo -e $COL_GREEN" Building process complete!"$COL_RESET
716 echo -e $COL_GREEN" --------------------------"$COL_RESET
717 echo ""
718 echo -e $COL_GREEN" Build info."
719 echo -e $COL_GREEN" ==========="
720 echo -e $COL_BLUE" Package name: "$COL_RESET"${distributionFilename}"
721 echo -e $COL_BLUE" MD5: "$COL_RESET"$md5"
722 echo -e $COL_BLUE" Version: "$COL_RESET"$version"
723 echo -e $COL_BLUE" Stage: "$COL_RESET"$stage"
724 echo -e $COL_BLUE" Date/Time: "$COL_RESET"$builddate"
725 echo ""
726
727}
728
729main "${1}" "${2}" "${3}" "${4}" #"${5}"
730

Archive Download this file

Revision: 1751