Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 1763