Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Modules/package/buildpkg.sh

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

Archive Download this file

Revision: 1726