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

Archive Download this file

Revision: 1756