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
458 ((xmlindent--))
459outline[${#outline[*]}]="${indent[$xmlindent]}</line>"
460# End build options packages
461
462if [[ -n "${CONFIG_KEYLAYOUT_MODULE}" ]];then
463# build KeyLayout options packages
464echo "================= Keymaps Options ================="
465outline[${#outline[*]}]="${indent[$xmlindent]}<line choice=\"KeyLayout\">"
466choices[${#choices[*]}]="\t<choice\n\t\tid=\"KeyLayout\"\n\t\ttitle=\"KeyLayout_title\"\n\t\tdescription=\"KeyLayout_description\">\n\t</choice>\n"
467((xmlindent++))
468packagesidentity="${chameleon_package_identity}.options.keylayout"
469 keylayoutPackageRefId=""
470 if [[ "${CONFIG_MODULES}" == 'y' && "${CONFIG_KEYLAYOUT_MODULE}" = 'm' ]];then
471 keylayoutPackageRefId=$(getPackageRefId "${modules_packages_identity}" "Keylayout")
472 fi
473
474# ------------------------------------------------------
475# Available Keylayout boot options are discovered by
476# reading contents of /Keymaps folder after compilation
477# ------------------------------------------------------
478availableOptions=($( find "${SRCROOT}/Keymaps" -type f -depth 1 -name '*.lyt' | sed 's|.*/||;s|\.lyt||' ))
479allChoices="${availableOptions[@]}"
480# Adjust array contents to match expected format
481# for boot options which is: name:key=value
482for (( i = 0 ; i < ${#availableOptions[@]} ; i++ )); do
483# availableOptions[i]=${availableOptions[i]}":KeyLayout="${availableOptions[i]}
484# Start build of a keymap package module
485choiceId="${availableOptions[i]}"
486mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
487
488# create dummy file with name of key/value
489echo "" > "${PKG_BUILD_DIR}/${choiceId}/Root/KeyLayout=${availableOptions[i]}"
490
491echo -e "\t[BUILD] ${choiceId} "
492packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
493buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/$chamTemp/options"
494exclusiveChoice=$(exclusive_zero_or_one_choice "$choiceId" "$allChoices")
495# Add the Keylayout package because the Keylayout module is needed
496addChoice "${choiceId}" "start_selected=\"false\" selected=\"${exclusiveChoice}\"" \
497 "$packageRefId" "$keylayoutPackageRefId"
498# End build uClibc package module
499done
500
501((xmlindent--))
502outline[${#outline[*]}]="${indent[$xmlindent]}</line>"
503
504# End build KeyLayout options packages
505fi
506
507# build theme packages
508echo "================= Themes ================="
509outline[${#outline[*]}]="${indent[$xmlindent]}<line choice=\"Themes\">"
510choices[${#choices[*]}]="\t<choice\n\t\tid=\"Themes\"\n\t\ttitle=\"Themes_title\"\n\t\tdescription=\"Themes_description\">\n\t</choice>\n"
511((xmlindent++))
512
513# Using themes section from Azi's/package branch.
514packagesidentity="${chameleon_package_identity}.themes"
515artwork="${SRCROOT}/artwork/themes"
516themes=($( find "${artwork}" -type d -depth 1 -not -name '.svn' ))
517for (( i = 0 ; i < ${#themes[@]} ; i++ )); do
518theme=$( echo ${themes[$i]##*/} | awk 'BEGIN{OFS=FS=""}{$1=toupper($1);print}' )
519mkdir -p "${PKG_BUILD_DIR}/${theme}/Root/"
520rsync -r --exclude=.svn "${themes[$i]}/" "${PKG_BUILD_DIR}/${theme}/Root/${theme}"
521echo -e "\t[BUILD] ${theme}"
522packageRefId=$(getPackageRefId "${packagesidentity}" "${theme}")
523buildpackage "$packageRefId" "${theme}" "${PKG_BUILD_DIR}/${theme}" "/$chamTemp/Extra/Themes"
524addChoice "${theme}" "start_selected=\"false\"" "$packageRefId"
525done
526
527((xmlindent--))
528outline[${#outline[*]}]="${indent[$xmlindent]}</line>"
529# End build theme packages# End build Extras package
530
531# build post install package
532 echo "================= Post ================="
533 packagesidentity="${chameleon_package_identity}"
534 choiceId="Post"
535 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Root
536 mkdir -p ${PKG_BUILD_DIR}/${choiceId}/Scripts
537 cp -f ${PKGROOT}/Scripts/Main/postinstall ${PKG_BUILD_DIR}/${choiceId}/Scripts
538 cp -f ${PKGROOT}/Scripts/Sub/InstallLog.sh ${PKG_BUILD_DIR}/${choiceId}/Scripts
539 cp -f ${PKGROOT}/Scripts/Sub/UnMountEFIvolumes.sh ${PKG_BUILD_DIR}/${choiceId}/Scripts
540 ditto --noextattr --noqtn ${SRCROOT}/revision ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources/revision
541 ditto --noextattr --noqtn ${SRCROOT}/version ${PKG_BUILD_DIR}/${choiceId}/Scripts/Resources/version
542 echo -e "\t[BUILD] ${choiceId} "
543 packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")
544 buildpackage "$packageRefId" "${choiceId}" "${PKG_BUILD_DIR}/${choiceId}" "/"
545 addChoice "${choiceId}" "start_visible=\"false\" start_selected=\"true\"" "$packageRefId"
546# End build post install package
547
548((xmlindent--))
549outline[${#outline[*]}]="${indent[$xmlindent]}</choices-outline>"
550
551}
552
553buildpackage ()
554{
555# $1 Package Reference Id (ie: org.chameleon.themes.default)
556# $2 Package Name (ie: Default)
557# $3 Path to package to build containing Root and/or Scripts
558# $4 Target install location
559# $5 Size (optional)
560if [[ -d "${3}/Root" ]]; then
561local packageRefId="$1"
562local packageName="$2"
563local packagePath="$3"
564local targetPath="$4"
565set +u # packageSize is optional
566 local packageSize="$5"
567 set -u
568
569find "${packagePath}" -name '.DS_Store' -delete
570local filecount=$( find "${packagePath}/Root" | wc -l )
571if [ "${packageSize}" ]; then
572local installedsize="${packageSize}"
573else
574local installedsize=$( du -hkc "${packagePath}/Root" | tail -n1 | awk {'print $1'} )
575fi
576local header="<?xml version=\"1.0\"?>\n<pkg-info format-version=\"2\" "
577
578#[ "${3}" == "relocatable" ] && header+="relocatable=\"true\" "
579
580header+="identifier=\"${packageRefId}\" "
581header+="version=\"${version}\" "
582
583[ "${targetPath}" != "relocatable" ] && header+="install-location=\"${targetPath}\" "
584
585header+="auth=\"root\">\n"
586header+="\t<payload installKBytes=\"${installedsize##* }\" numberOfFiles=\"${filecount##* }\"/>\n"
587rm -R -f "${packagePath}/Temp"
588
589[ -d "${packagePath}/Temp" ] || mkdir -m 777 "${packagePath}/Temp"
590[ -d "${packagePath}/Root" ] && mkbom "${packagePath}/Root" "${packagePath}/Temp/Bom"
591
592if [ -d "${packagePath}/Scripts" ]; then
593header+="\t<scripts>\n"
594for script in $( find "${packagePath}/Scripts" -type f \( -name 'pre*' -or -name 'post*' \) ); do
595header+="\t\t<${script##*/} file=\"./${script##*/}\"/>\n"
596done
597header+="\t</scripts>\n"
598# Create the Script archive file (cpio format)
599(cd "${packagePath}/Scripts" && find . -print | cpio -o -z -R 0:0 --format cpio > "${packagePath}/Temp/Scripts") 2>&1 | \
600 grep -vE '^[0-9]+\s+blocks?$' # to remove cpio stderr messages
601 fi
602
603header+="</pkg-info>"
604echo -e "${header}" > "${packagePath}/Temp/PackageInfo"
605
606# Create the Payload file (cpio format)
607(cd "${packagePath}/Root" && find . -print | cpio -o -z -R 0:0 --format cpio > "${packagePath}/Temp/Payload") 2>&1 | \
608 grep -vE '^[0-9]+\s+blocks?$' # to remove cpio stderr messages
609
610# Create the package
611(cd "${packagePath}/Temp" && xar -c -f "${packagePath}/../${packageName}.pkg" --compression none .)
612
613# Add the package to the list of build packages
614pkgrefs[${#pkgrefs[*]}]="\t<pkg-ref id=\"${packageRefId}\" installKBytes='${installedsize}' version='${version}.0.0.${timestamp}'>#${packageName}.pkg</pkg-ref>"
615
616rm -rf "${packagePath}"
617fi
618}
619
620makedistribution ()
621{
622 declare -r distributionDestDir="${SYMROOT}"
623 declare -r distributionFilename="${packagename// /}-${version}-r${revision}.pkg"
624 declare -r distributionFilePath="${distributionDestDir}/${distributionFilename}"
625
626 rm -f "${distributionDestDir}/${packagename// /}"*.pkg
627
628 mkdir -p "${PKG_BUILD_DIR}/${packagename}"
629
630 find "${PKG_BUILD_DIR}" -type f -name '*.pkg' -depth 1 | while read component
631do
632 pkg="${component##*/}" # ie: EFI.pkg
633 pkgdir="${PKG_BUILD_DIR}/${packagename}/${pkg}"
634 # expand individual packages
635 pkgutil --expand "${PKG_BUILD_DIR}/${pkg}" "$pkgdir"
636 rm -f "${PKG_BUILD_DIR}/${pkg}"
637 done
638
639# Create the Distribution file
640 ditto --noextattr --noqtn "${PKGROOT}/Distribution" "${PKG_BUILD_DIR}/${packagename}/Distribution"
641
642 for (( i=0; i < ${#outline[*]} ; i++)); do
643echo -e "${outline[$i]}" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
644done
645
646 for (( i=0; i < ${#choices[*]} ; i++)); do
647echo -e "${choices[$i]}" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
648done
649
650 for (( i=0; i < ${#pkgrefs[*]} ; i++)); do
651 echo -e "${pkgrefs[$i]}" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
652 done
653
654 echo -e "\n</installer-gui-script>" >> "${PKG_BUILD_DIR}/${packagename}/Distribution"
655
656# Create the Resources directory
657 ditto --noextattr --noqtn "${PKGROOT}/Resources" "${PKG_BUILD_DIR}/${packagename}/Resources"
658
659# CleanUp the directory
660 find "${PKG_BUILD_DIR}/${packagename}" \( -type d -name '.svn' \) -o -name '.DS_Store' -exec rm -rf {} \;
661
662# Add Chameleon Version and Revision
663 perl -i -p -e "s/%CHAMELEONVERSION%/${version%%-*}/g" $( find "${PKG_BUILD_DIR}/${packagename}/Resources" -type f )
664 perl -i -p -e "s/%CHAMELEONREVISION%/${revision}/g" $( find "${PKG_BUILD_DIR}/${packagename}/Resources" -type f )
665
666# Add Chameleon Stage
667 perl -i -p -e "s/%CHAMELEONSTAGE%/${stage}/g" $( find "${PKG_BUILD_DIR}/${packagename}/Resources" -type f )
668
669# Adding Developer and credits
670 perl -i -p -e "s/%DEVELOP%/${develop}/g" $( find "${PKG_BUILD_DIR}/${packagename}/Resources" -type f )
671 perl -i -p -e "s/%CREDITS%/${credits}/g" $( find "${PKG_BUILD_DIR}/${packagename}/Resources" -type f )
672 perl -i -p -e "s/%PKGDEV%/${pkgdev}/g" $( find "${PKG_BUILD_DIR}/${packagename}/Resources" -type f )
673
674# Create the final package
675 pkgutil --flatten "${PKG_BUILD_DIR}/${packagename}" "${distributionFilePath}"
676
677# Here is the place for assign a Icon to the pkg
678 ditto -xk "${PKGROOT}/Icons/pkg.zip" "${PKG_BUILD_DIR}/Icons/"
679 DeRez -only icns "${PKG_BUILD_DIR}/Icons/Icons/pkg.icns" > "${PKG_BUILD_DIR}/Icons/tempicns.rsrc"
680 Rez -append "${PKG_BUILD_DIR}/Icons/tempicns.rsrc" -o "${distributionFilePath}"
681 SetFile -a C "${distributionFilePath}"
682 rm -rf "${PKG_BUILD_DIR}/Icons"
683
684# End
685
686 md5=$( md5 "${distributionFilePath}" | awk {'print $4'} )
687 echo "MD5 (${distributionFilePath}) = ${md5}" > "${distributionFilePath}.md5"
688 echo ""
689
690 echo -e $COL_GREEN" --------------------------"$COL_RESET
691 echo -e $COL_GREEN" Building process complete!"$COL_RESET
692 echo -e $COL_GREEN" --------------------------"$COL_RESET
693 echo ""
694 echo -e $COL_GREEN" Build info."
695 echo -e $COL_GREEN" ==========="
696 echo -e $COL_BLUE" Package name: "$COL_RESET"${distributionFilename}"
697 echo -e $COL_BLUE" MD5: "$COL_RESET"$md5"
698 echo -e $COL_BLUE" Version: "$COL_RESET"$version"
699 echo -e $COL_BLUE" Stage: "$COL_RESET"$stage"
700 echo -e $COL_BLUE" Date/Time: "$COL_RESET"$builddate"
701 echo ""
702
703}
704
705# build packages
706main
707
708# build meta package
709makedistribution
710

Archive Download this file

Revision: 1759