Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Trunk/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 # klibc.dylib #
237 # Resolution.dylib #
238 # uClibcxx.dylib #
239 # Keylayout.dylib #
240 ###############################
241 if [ "$(ls -A "${1%/*}/i386/modules")" ]; then
242 {
243 outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"Module\">"
244 choices[$((choicescount++))]="\t<choice\n\t\tid=\"Module\"\n\t\ttitle=\"Module_title\"\n\t\tdescription=\"Module_description\">\n\t</choice>\n"
245 ((xmlindent++))
246
247# -
248 if [ -e ${1%/*}/i386/modules/klibc.dylib ]; then
249 {
250 # Start build klibc package module
251 choiceId="klibc"
252 mkdir -p ${1}/${choiceId}/Root
253 ditto --noextattr --noqtn ${1%/*}/i386/modules/${choiceId}.dylib ${1}/${choiceId}/Root
254 echo -e "\t[BUILD] ${choiceId} "
255 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
256 buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp/Extra/modules" # >/dev/null 2>&1
257 addChoice "${choiceId}" "start_selected=\"false\"" "$packageRefId"
258 # End build klibc package module
259 }
260 fi
261
262# -
263 if [ -e ${1%/*}/i386/modules/uClibcxx.dylib ]; then
264 {
265 # Start build uClibc package module
266 choiceId="uClibc"
267 mkdir -p ${1}/${choiceId}/Root
268 ditto --noextattr --noqtn ${1%/*}/i386/modules/uClibcxx.dylib ${1}/${choiceId}/Root
269 echo -e "\t[BUILD] ${choiceId} "
270 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
271 buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp/Extra/modules" # >/dev/null 2>&1
272 # Add the klibc package because the uClibc module is dependent of klibc module
273 addChoice "${choiceId}" "start_selected=\"false\"" \
274 "$packageRefId" $(getPackageRefId "${modules_packages_identity}" "klibc")
275 # End build uClibc package module
276 }
277 fi
278
279# -
280 if [ -e ${1%/*}/i386/modules/Resolution.dylib ]; then
281 {
282 # Start build Resolution package module
283 choiceId="AutoReso"
284 mkdir -p ${1}/${choiceId}/Root
285 ditto --noextattr --noqtn ${1%/*}/i386/modules/Resolution.dylib ${1}/${choiceId}/Root
286 echo -e "\t[BUILD] ${choiceId} "
287 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
288 buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp/Extra/modules" # >/dev/null 2>&1
289 addChoice "${choiceId}" "start_selected=\"false\"" "$packageRefId"
290 # End build Resolution package module
291 }
292 fi
293
294# -
295 # Warning Keylayout module need additional files
296 if [ -e ${1%/*}/i386/modules/Keylayout.dylib ]; then
297 {
298 # Start build Keylayout package module
299 choiceId="Keylayout"
300 mkdir -p ${1}/${choiceId}/Root/Extra/{modules,Keymaps}
301 mkdir -p ${1}/${choiceId}/Root/usr/local/bin
302 layout_src_dir="${1%/sym/*}/i386/modules/Keylayout/layouts/layouts-src"
303 if [ -d "$layout_src_dir" ];then
304 # Create a tar.gz from layout sources
305 (cd "$layout_src_dir"; \
306 tar czf "${1}/Keylayout/Root/Extra/Keymaps/layouts-src.tar.gz" README *.slt)
307 fi
308 # Adding module
309 ditto --noextattr --noqtn ${1%/*}/i386/modules/${choiceId}.dylib ${1}/${choiceId}/Root/Extra/modules
310 # Adding Keymaps
311 ditto --noextattr --noqtn ${1%/sym/*}/Keymaps ${1}/${choiceId}/Root/Extra/Keymaps
312 # Adding tools
313 ditto --noextattr --noqtn ${1%/*}/i386/cham-mklayout ${1}/${choiceId}/Root/usr/local/bin
314 echo -e "\t[BUILD] ${choiceId} "
315 packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")
316 buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp" # >/dev/null 2>&1
317
318 # Don't add a choice for Keylayout module
319 # addChoice "${choiceId}" "start_selected=\"false\"" "$packageRefId"
320 # End build Keylayout package module
321 }
322 fi
323
324 ((xmlindent--))
325 outline[$((outlinecount++))]="${indent[$xmlindent]}</line>"
326 }
327 else
328 {
329 echo " -= no modules to include =-"
330 }
331 fi
332# End build Modules packages
333
334# build Options packages
335
336 outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"Options\">"
337 choices[$((choicescount++))]="\t<choice\n\t\tid=\"Options\"\n\t\ttitle=\"Options_title\"\n\t\tdescription=\"Options_description\">\n\t</choice>\n"
338 ((xmlindent++))
339
340
341 # ------------------------------------------------------
342 # parse OptionalSettings folder to find files of boot options.
343 # ------------------------------------------------------
344 OptionalSettingsFolder="${pkgroot}/OptionalSettings"
345 OptionalSettingsFiles=($( find "${OptionalSettingsFolder}" -depth 1 ! -name '.svn' ! -name '.DS_Store' ))
346
347 for (( i = 0 ; i < ${#OptionalSettingsFiles[@]} ; i++ ))
348 do
349
350# Take filename and Strip .txt from end and path from front
351builtOptionsList=$( echo ${OptionalSettingsFiles[$i]%.txt} )
352builtOptionsList=$( echo ${builtOptionsList##*/} )
353echo "================= $builtOptionsList ================="
354outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"${builtOptionsList}\">"
355choices[$((choicescount++))]="\t<choice\n\t\tid=\"${builtOptionsList}\"\n\t\ttitle=\"${builtOptionsList}_title\"\n\t\tdescription=\"${builtOptionsList}_description\">\n\t</choice>\n"
356((xmlindent++))
357packagesidentity="org.chameleon.options.$builtOptionsList"
358
359# ------------------------------------------------------
360# Read boot option file into an array.
361# ------------------------------------------------------
362availableOptions=() # array to hold the list of boot options, per 'section'.
363exclusiveFlag=0 # used to indicate list has exclusive options
364count=0 # used as index for stepping through array.
365while read textLine; do
366# ignore lines in the file beginning with a # and Exclusive=False
367if [[ ${textLine} != \#* ]] && [[ ${textLine} != "Exclusive=False" ]];then
368# check for 'Exclusive=True' option in file
369if [[ ${textLine} == "Exclusive=True" ]];then
370exclusiveFlag=1
371else
372availableOptions[${#availableOptions[@]}]=$textLine
373fi
374fi
375done < ${OptionalSettingsFiles[$i]}
376
377# ------------------------------------------------------
378# Loop through options in array and process each in turn
379# ------------------------------------------------------
380allChoices="${availableOptions[@]//:*/}"
381for (( c = 0 ; c < ${#availableOptions[@]} ; c++ )); do
382textLine=${availableOptions[c]}
383# split line - taking all before ':' as option name
384# and all after ':' as key/value
385optionName=${textLine%:*}
386keyValue=${textLine##*:}
387
388# create folders required for each boot option
389mkdir -p "${1}/$optionName/Root/"
390
391# create dummy file with name of key/value
392echo "" > "${1}/$optionName/Root/${keyValue}"
393
394echo -e "\t[BUILD] ${optionName} "
395packageRefId=$(getPackageRefId "${packagesidentity}" "${optionName}")
396buildpackage "$packageRefId" "${optionName}" "${1}/${optionName}" "/$chamTemp/options" # >/dev/null 2>&1
397exclusiveSelect=""
398if [[ ${exclusiveFlag} -eq 1 ]];then
399exclusiveSelect="selected=\"$(exclusive_zero_or_one_choice "$optionName" "$allChoices")\""
400fi
401addChoice "${optionName}" "start_selected=\"false\" ${exclusiveSelect}" "$packageRefId"
402done
403
404((xmlindent--))
405outline[$((outlinecount++))]="${indent[$xmlindent]}</line>"
406done
407
408# build KeyLayout options packages
409echo "================= Keymaps Options ================="
410outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"KeyLayout\">"
411choices[$((choicescount++))]="\t<choice\n\t\tid=\"KeyLayout\"\n\t\ttitle=\"KeyLayout_title\"\n\t\tdescription=\"KeyLayout_description\">\n\t</choice>\n"
412((xmlindent++))
413packagesidentity="org.chameleon.options.keylayout"
414keylayoutPackageRefId=$(getPackageRefId "${modules_packages_identity}" "Keylayout")
415
416# ------------------------------------------------------
417# Available Keylayout boot options are discovered by
418# reading contents of /Keymaps folder after compilation
419# ------------------------------------------------------
420availableOptions=($( find "${1%/sym/*}/Keymaps" -type f -depth 1 -name '*.lyt' | sed 's|.*/||;s|\.lyt||' ))
421allChoices="${availableOptions[@]}"
422# Adjust array contents to match expected format
423# for boot options which is: name:key=value
424for (( i = 0 ; i < ${#availableOptions[@]} ; i++ )); do
425# availableOptions[i]=${availableOptions[i]}":KeyLayout="${availableOptions[i]}
426# Start build of a keymap package module
427choiceId="${availableOptions[i]}"
428mkdir -p ${1}/${choiceId}/Root
429
430# create dummy file with name of key/value
431echo "" > "${1}/${choiceId}/Root/KeyLayout=${availableOptions[i]}"
432
433echo -e "\t[BUILD] ${choiceId} "
434packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
435buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp/options" # >/dev/null 2>&1
436exclusiveChoice=$(exclusive_zero_or_one_choice "$choiceId" "$allChoices")
437# Add the Keylayout package because the Keylayout module is needed
438addChoice "${choiceId}" "start_selected=\"false\" selected=\"${exclusiveChoice}\"" \
439 "$packageRefId" "$keylayoutPackageRefId"
440# End build uClibc package module
441done
442
443((xmlindent--))
444outline[$((outlinecount++))]="${indent[$xmlindent]}</line>"
445
446# End build KeyLayout options packages
447
448((xmlindent--))
449outline[$((outlinecount++))]="${indent[$xmlindent]}</line>"
450# End build options packages
451
452# build theme packages
453echo "================= Themes ================="
454outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"Themes\">"
455choices[$((choicescount++))]="\t<choice\n\t\tid=\"Themes\"\n\t\ttitle=\"Themes_title\"\n\t\tdescription=\"Themes_description\">\n\t</choice>\n"
456((xmlindent++))
457
458# Using themes section from Azi's/package branch.
459packagesidentity="org.chameleon.themes"
460artwork="${1%/sym/package}/artwork/themes"
461themes=($( find "${artwork}" -type d -depth 1 -not -name '.svn' ))
462for (( i = 0 ; i < ${#themes[@]} ; i++ )); do
463theme=$( echo ${themes[$i]##*/} | awk 'BEGIN{OFS=FS=""}{$1=toupper($1);print}' )
464mkdir -p "${1}/${theme}/Root/"
465rsync -r --exclude=.svn "${themes[$i]}/" "${1}/${theme}/Root/${theme}"
466echo -e "\t[BUILD] ${theme}"
467packageRefId=$(getPackageRefId "${packagesidentity}" "${theme}")
468buildpackage "$packageRefId" "${theme}" "${1}/${theme}" "/$chamTemp/Extra/Themes" # >/dev/null 2>&1
469addChoice "${theme}" "start_selected=\"false\"" "$packageRefId"
470done
471
472((xmlindent--))
473outline[$((outlinecount++))]="${indent[$xmlindent]}</line>"
474# End build theme packages# End build Extras package
475
476# build post install package
477 echo "================= Post ================="
478 packagesidentity="org.chameleon"
479 choiceId="Post"
480 mkdir -p ${1}/${choiceId}/Root
481 mkdir -p ${1}/${choiceId}/Scripts
482 cp -f ${pkgroot}/Scripts/Main/postinstall ${1}/${choiceId}/Scripts
483 cp -f ${pkgroot}/Scripts/Sub/InstallLog.sh ${1}/${choiceId}/Scripts
484 cp -f ${pkgroot}/Scripts/Sub/UnMountEFIvolumes.sh ${1}/${choiceId}/Scripts
485 ditto --noextattr --noqtn ${1%/*/*}/revision ${1}/${choiceId}/Scripts/Resources/revision
486 ditto --noextattr --noqtn ${1%/*/*}/version ${1}/${choiceId}/Scripts/Resources/version
487 echo -e "\t[BUILD] ${choiceId} "
488 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
489 buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/" # >/dev/null 2>&1
490 addChoice "${choiceId}" "start_visible=\"false\" start_selected=\"true\"" "$packageRefId"
491# End build post install package
492
493((xmlindent--))
494outline[$((outlinecount++))]="${indent[$xmlindent]}</choices-outline>"
495
496# build meta package
497
498 makedistribution "${1}" "${2}" "${3}" "${4}" #"${5}"
499
500# clean up
501# rm -R -f "${1}"
502
503}
504
505buildpackage ()
506{
507# $1 Package Reference Id (ie: org.chameleon.themes.default)
508# $2 Package Name (ie: Default)
509# $3 Path to package to build containing Root and/or Scripts
510# $4 Target install location
511# $5 Size (optional)
512if [[ -d "${3}/Root" ]]; then
513local packageRefId="$1"
514local packageName="$2"
515local packagePath="$3"
516local targetPath="$4"
517local packageSize="$5"
518
519find "${packagePath}" -name '.DS_Store' -delete
520local filecount=$( find "${packagePath}/Root" | wc -l )
521if [ "${packageSize}" ]; then
522local installedsize="${packageSize}"
523else
524local installedsize=$( du -hkc "${packagePath}/Root" | tail -n1 | awk {'print $1'} )
525fi
526local header="<?xml version=\"1.0\"?>\n<pkg-info format-version=\"2\" "
527
528#[ "${3}" == "relocatable" ] && header+="relocatable=\"true\" "
529
530header+="identifier=\"${packageRefId}\" "
531header+="version=\"${version}\" "
532
533[ "${targetPath}" != "relocatable" ] && header+="install-location=\"${targetPath}\" "
534
535header+="auth=\"root\">\n"
536header+="\t<payload installKBytes=\"${installedsize##* }\" numberOfFiles=\"${filecount##* }\"/>\n"
537rm -R -f "${packagePath}/Temp"
538
539[ -d "${packagePath}/Temp" ] || mkdir -m 777 "${packagePath}/Temp"
540[ -d "${packagePath}/Root" ] && mkbom "${packagePath}/Root" "${packagePath}/Temp/Bom"
541
542if [ -d "${packagePath}/Scripts" ]; then
543header+="\t<scripts>\n"
544for script in $( find "${packagePath}/Scripts" -type f \( -name 'pre*' -or -name 'post*' \) ); do
545header+="\t\t<${script##*/} file=\"./${script##*/}\"/>\n"
546done
547header+="\t</scripts>\n"
548# Create the Script archive file (cpio format)
549(cd "${packagePath}/Scripts" && find . -print | cpio -o -z -R root:wheel --format cpio > "${packagePath}/Temp/Scripts") 2>&1 | \
550 grep -vE '^[0-9]+\s+blocks?$' # to remove cpio stderr messages
551 fi
552
553header+="</pkg-info>"
554echo -e "${header}" > "${packagePath}/Temp/PackageInfo"
555
556# Create the Payload file (cpio format)
557(cd "${packagePath}/Root" && find . -print | cpio -o -z -R root:wheel --format cpio > "${packagePath}/Temp/Payload") 2>&1 | \
558 grep -vE '^[0-9]+\s+blocks?$' # to remove cpio stderr messages
559
560# Create the package
561(cd "${packagePath}/Temp" && xar -c -f "${packagePath}/../${packageName}.pkg" --compression none .)
562
563# Add the package to the list of build packages
564pkgrefs[${#pkgrefs[*]}]="\t<pkg-ref id=\"${packageRefId}\" installKBytes='${installedsize}' version='${version}.0.0.${timestamp}'>#${packageName}.pkg</pkg-ref>"
565
566rm -rf "${packagePath}"
567fi
568}
569
570makedistribution ()
571{
572 distributionDestDir="${1%/*}"
573 distributionFilename="${packagename// /}-${version}-r${revision}.pkg"
574 distributionFilePath="${distributionDestDir}/${distributionFilename}"
575
576 rm -f "${distributionDestDir}/${packagename// /}"*.pkg
577
578 mkdir -p "${1}/${packagename}"
579
580 find "${1}" -type f -name '*.pkg' -depth 1 | while read component
581do
582 pkg="${component##*/}" # ie: EFI.pkg
583 pkgdir="${1}/${packagename}/${pkg}"
584 # expand individual packages
585 pkgutil --expand "${1%}/${pkg}" "$pkgdir"
586 rm -f "${1%}/${pkg}"
587 done
588
589# Create the Distribution file
590 ditto --noextattr --noqtn "${pkgroot}/Distribution" "${1}/${packagename}/Distribution"
591
592 for (( i=0; i < ${#outline[*]} ; i++)); do
593echo -e "${outline[$i]}" >> "${1}/${packagename}/Distribution"
594done
595
596 for (( i=0; i < ${#choices[*]} ; i++)); do
597echo -e "${choices[$i]}" >> "${1}/${packagename}/Distribution"
598done
599
600 for (( i=0; i < ${#pkgrefs[*]} ; i++)); do
601 echo -e "${pkgrefs[$i]}" >> "${1}/${packagename}/Distribution"
602 done
603
604 echo -e "\n</installer-gui-script>" >> "${1}/${packagename}/Distribution"
605
606# Create the Resources directory
607 ditto --noextattr --noqtn "${pkgroot}/Resources" "${1}/${packagename}/Resources"
608
609# CleanUp the directory
610 find "${1}/${packagename}" -type d -name '.svn' -exec rm -rf {} \; 2>/dev/null
611 find "${1}/${packagename}" -name '.DS_Store' -delete
612
613# Add Chameleon Version and Revision
614 perl -i -p -e "s/%CHAMELEONVERSION%/${version%%-*}/g" $( find "${1}/${packagename}/Resources" -type f )
615 perl -i -p -e "s/%CHAMELEONREVISION%/${revision}/g" $( find "${1}/${packagename}/Resources" -type f )
616
617# Add Chameleon Stage
618 stage=${stage/RC/Release Candidate }
619 stage=${stage/FINAL/2.0 Final}
620 perl -i -p -e "s/%CHAMELEONSTAGE%/${stage}/g" $( find "${1}/${packagename}/Resources" -type f )
621
622# Adding Developer and credits
623 perl -i -p -e "s/%DEVELOP%/${develop}/g" $( find "${1}/${packagename}/Resources" -type f )
624 perl -i -p -e "s/%CREDITS%/${credits}/g" $( find "${1}/${packagename}/Resources" -type f )
625 perl -i -p -e "s/%PKGDEV%/${pkgdev}/g" $( find "${1}/${packagename}/Resources" -type f )
626
627# Create the final package
628 pkgutil --flatten "${1}/${packagename}" "${distributionFilePath}"
629
630# Here is the place for assign a Icon to the pkg
631# command use to generate the file:
632# ditto -c -k --sequesterRsrc --keepParent Icon.icns Icon.zip
633# ----
634 ditto -xk "${pkgroot}/Icons/pkg.zip" "${1}/Icons/"
635 DeRez -only icns "${1}/Icons/Icons/pkg.icns" > "${1}/Icons/tempicns.rsrc"
636 Rez -append "${1}/Icons/tempicns.rsrc" -o "${distributionFilePath}"
637 SetFile -a C "${distributionFilePath}"
638 rm -rf "${1}/Icons"
639
640# End
641
642 md5=$( md5 "${distributionFilePath}" | awk {'print $4'} )
643 echo "MD5 (${distributionFilePath}) = ${md5}" > "${distributionFilePath}.md5"
644 echo ""
645
646 echo -e $COL_GREEN" --------------------------"$COL_RESET
647 echo -e $COL_GREEN" Building process complete!"$COL_RESET
648 echo -e $COL_GREEN" --------------------------"$COL_RESET
649 echo ""
650 echo -e $COL_GREEN" Build info."
651 echo -e $COL_GREEN" ==========="
652 echo -e $COL_BLUE" Package name: "$COL_RESET"${distributionFilename}"
653 echo -e $COL_BLUE" MD5: "$COL_RESET"$md5"
654 echo -e $COL_BLUE" Version: "$COL_RESET"$version"
655 echo -e $COL_BLUE" Stage: "$COL_RESET"$stage"
656 echo -e $COL_BLUE" Date/Time: "$COL_RESET"$builddate"
657 echo ""
658
659}
660
661main "${1}" "${2}" "${3}" "${4}" #"${5}"
662

Archive Download this file

Revision: 1755