Chameleon

Chameleon Svn Source Tree

Root/trunk/package/buildpkg.sh

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

Archive Download this file

Revision: 1758