Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Modules/package/slimpkg.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 Slim 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 Chameleon package
92echo "================= Chameleon ================="
93outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"Chameleon\">"
94choices[$((choicescount++))]="\t<choice\n\t\tid=\"Chameleon\"\n\t\ttitle=\"Chameleon_title\"\n\t\tdescription=\"Chameleon_description\">\n\t</choice>\n"
95((xmlindent++))
96
97# build standard package
98mkdir -p ${1}/Standard/Root
99mkdir -p ${1}/Standard/Scripts/Resources
100cp -f ${pkgroot}/Scripts/Main/Standardpostinstall ${1}/Standard/Scripts/postinstall
101cp -f ${pkgroot}/Scripts/Sub/* ${1}/Standard/Scripts
102ditto --arch i386 `which SetFile` ${1}/Standard/Scripts/Resources/SetFile
103ditto --noextattr --noqtn ${1%/*/*}/revision ${1}/Standard/Scripts/Resources/revision
104ditto --noextattr --noqtn ${1%/*/*}/version ${1}/Standard/Scripts/Resources/version
105echo "[BUILD] Standard "
106 buildpackage "${1}/Standard" "/" "${coresize}" "start_enabled=\"true\" selected=\"exclusive(choices['EFI']) &amp;&amp; exclusive(choices['noboot'])\"" >/dev/null 2>&1
107# End build standard package
108
109# build efi package
110mkdir -p ${1}/EFI/Root
111mkdir -p ${1}/EFI/Scripts/Resources
112cp -f ${pkgroot}/Scripts/Main/ESPpostinstall ${1}/EFI/Scripts/postinstall
113cp -f ${pkgroot}/Scripts/Sub/* ${1}/EFI/Scripts
114ditto --arch i386 `which SetFile` ${1}/EFI/Scripts/Resources/SetFile
115ditto --noextattr --noqtn ${1%/*/*}/revision ${1}/EFI/Scripts/Resources/revision
116ditto --noextattr --noqtn ${1%/*/*}/version ${1}/EFI/Scripts/Resources/version
117echo "[BUILD] EFI "
118buildpackage "${1}/EFI" "/" "${coresize}" "start_visible=\"systemHasGPT()\" selected=\"exclusive(choices['Standard']) &amp;&amp; exclusive(choices['noboot'])\"" >/dev/null 2>&1
119# End build efi package
120
121# build reset choice package
122mkdir -p ${1}/noboot/Root
123echo "[BUILD] Reset choice "
124buildpackage "${1}/noboot" "/$chamTemp" "" "selected=\"exclusive(choices['Standard']) &amp;&amp; exclusive(choices['EFI'])\"" >/dev/null 2>&1
125# End build reset choice package
126
127 ((xmlindent--))
128 outline[$((outlinecount++))]="${indent[$xmlindent]}</line>"
129# End build Chameleon package
130
131# build Modules package
132echo "================= Modules ================="
133###############################
134# Supported Modules #
135###############################
136# AMDGraphicsEnabler.dylib #
137# ATiGraphicsEnabler.dylib #
138# IntelGraphicsEnabler.dylib #
139# klibc.dylib #
140# NVIDIAGraphicsEnabler.dylib #
141# Resolution.dylib #
142# uClibcxx.dylib #
143# Keylayout.dylib #
144###############################
145if [ "$(ls -A "${1%/*}/i386/modules")" ]; then
146{
147outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"Module\">"
148choices[$((choicescount++))]="\t<choice\n\t\tid=\"Module\"\n\t\ttitle=\"Module_title\"\n\t\tdescription=\"Module_description\">\n\t</choice>\n"
149((xmlindent++))
150packagesidentity="org.chameleon.modules"
151# -
152if [ -e ${1%/*}/i386/modules/klibc.dylib ]; then
153{
154mkdir -p ${1}/klibc/Root
155ditto --noextattr --noqtn ${1%/*}/i386/modules/klibc.dylib ${1}/klibc/Root
156echo "[BUILD] klibc "
157buildpackage "${1}/klibc" "/$chamTemp/Extra/modules" "" "start_selected=\"false\"" >/dev/null 2>&1
158}
159fi
160# -
161if [ -e ${1%/*}/i386/modules/uClibcxx.dylib ]; then
162{
163mkdir -p ${1}/uClibc/Root
164ditto --noextattr --noqtn ${1%/*}/i386/modules/uClibcxx.dylib ${1}/uClibc/Root
165ditto --noextattr --noqtn ${1%/*}/i386/modules/klibc.dylib ${1}/uClibc/Root
166echo "[BUILD] uClibc++ "
167buildpackage "${1}/uClibc" "/$chamTemp/Extra/modules" "" "start_selected=\"false\"" >/dev/null 2>&1
168}
169fi
170# -
171if [ -e ${1%/*}/i386/modules/Resolution.dylib ]; then
172{
173mkdir -p ${1}/AutoReso/Root
174ditto --noextattr --noqtn ${1%/*}/i386/modules/Resolution.dylib ${1}/AutoReso/Root
175echo "[BUILD] Resolution "
176buildpackage "${1}/AutoReso" "/$chamTemp/Extra/modules" "" "start_selected=\"false\"" >/dev/null 2>&1
177}
178fi
179# -
180if [ -e ${1%/*}/i386/modules/Keylayout.dylib ]; then
181{
182mkdir -p ${1}/Keylayout/Root
183ditto --noextattr --noqtn ${1%/*}/i386/modules/Keylayout.dylib ${1}/Keylayout/Root
184echo "[BUILD] Keylayout "
185buildpackage "${1}/Keylayout" "/$chamTemp/Extra/modules" "" "start_selected=\"false\"" >/dev/null 2>&1
186}
187fi
188# -
189if [ -e ${1%/*}/i386/modules/AMDGraphicsEnabler.dylib ]; then
190{
191mkdir -p ${1}/AMDGraphicsEnabler/Root
192ditto --noextattr --noqtn ${1%/*}/i386/modules/AMDGraphicsEnabler.dylib ${1}/AMDGraphicsEnabler/Root
193echo "[BUILD] AMDGraphicsEnabler "
194buildpackage "${1}/AMDGraphicsEnabler" "/$chamTemp/Extra/modules" "" "start_selected=\"false\"" >/dev/null 2>&1
195}
196fi
197# -
198if [ -e ${1%/*}/i386/modules/ATiGraphicsEnabler.dylib ]; then
199{
200mkdir -p ${1}/ATiGraphicsEnabler/Root
201ditto --noextattr --noqtn ${1%/*}/i386/modules/ATiGraphicsEnabler.dylib ${1}/ATiGraphicsEnabler/Root
202echo "[BUILD] ATiGraphicsEnabler "
203buildpackage "${1}/ATiGraphicsEnabler" "/$chamTemp/Extra/modules" "" "start_selected=\"false\"" >/dev/null 2>&1
204}
205fi
206# -
207if [ -e ${1%/*}/i386/modules/IntelGraphicsEnabler.dylib ]; then
208{
209mkdir -p ${1}/IntelGraphicsEnabler/Root
210ditto --noextattr --noqtn ${1%/*}/i386/modules/IntelGraphicsEnabler.dylib ${1}/IntelGraphicsEnabler/Root
211echo "[BUILD] IntelGraphicsEnabler "
212buildpackage "${1}/IntelGraphicsEnabler" "/$chamTemp/Extra/modules" "" "start_selected=\"false\"" >/dev/null 2>&1
213}
214fi
215# -
216if [ -e ${1%/*}/i386/modules/NVIDIAGraphicsEnabler.dylib ]; then
217{
218mkdir -p ${1}/NVIDIAGraphicsEnabler/Root
219ditto --noextattr --noqtn ${1%/*}/i386/modules/NVIDIAGraphicsEnabler.dylib ${1}/NVIDIAGraphicsEnabler/Root
220echo "[BUILD] NVIDIAGraphicsEnabler "
221buildpackage "${1}/NVIDIAGraphicsEnabler" "/$chamTemp/Extra/modules" "" "start_selected=\"false\"" >/dev/null 2>&1
222}
223fi
224
225((xmlindent--))
226outline[$((outlinecount++))]="${indent[$xmlindent]}</line>"
227}
228else
229{
230echo " -= no modules to include =-"
231}
232fi
233# End build Modules packages
234
235# build post install package
236echo "================= Post ================="
237packagesidentity="org.chameleon"
238mkdir -p ${1}/Post/Root
239mkdir -p ${1}/Post/Scripts
240cp -f ${pkgroot}/Scripts/Main/postinstall ${1}/Post/Scripts
241cp -f ${pkgroot}/Scripts/Sub/InstallLog.sh ${1}/Post/Scripts
242cp -f ${pkgroot}/Scripts/Sub/UnMountEFIvolumes.sh ${1}/Post/Scripts
243ditto --noextattr --noqtn ${1%/*/*}/revision ${1}/Post/Scripts/Resources/revision
244ditto --noextattr --noqtn ${1%/*/*}/version ${1}/Post/Scripts/Resources/version
245echo "[BUILD] Post "
246buildpackage "${1}/Post" "/" "" "start_visible=\"false\" start_selected=\"true\"" >/dev/null 2>&1
247# End build post install package
248
249#((xmlindent--))
250outline[$((outlinecount++))]="${indent[$xmlindent]}</choices-outline>"
251
252# build meta package
253
254makedistribution "${1}" "${2}" "${3}" "${4}" #"${5}"
255
256# clean up
257
258rm -R -f "${1}"
259
260}
261
262fixperms ()
263{
264# $1 path
265find "${1}" -type f -exec chmod 644 {} \;
266find "${1}" -type d -exec chmod 755 {} \;
267chown -R 0:0 "${1}"
268}
269
270buildpackage ()
271{
272# $1 Path to package to build containing Root and or Scripts
273# $2 Install Location
274# $3 Size
275# $4 Options
276
277if [ -d "${1}/Root" ] && [ "${1}/Scripts" ]; then
278
279local packagename="${1##*/}"
280local identifier=$( echo ${packagesidentity}.${packagename//_/.} | tr [:upper:] [:lower:] )
281find "${1}" -name '.DS_Store' -delete
282local filecount=$( find "${1}/Root" | wc -l )
283if [ "${3}" ]; then
284local installedsize="${3}"
285else
286local installedsize=$( du -hkc "${1}/Root" | tail -n1 | awk {'print $1'} )
287fi
288local header="<?xml version=\"1.0\"?>\n<pkg-info format-version=\"2\" "
289
290#[ "${3}" == "relocatable" ] && header+="relocatable=\"true\" "
291
292header+="identifier=\"${identifier}\" "
293header+="version=\"${version}\" "
294
295[ "${2}" != "relocatable" ] && header+="install-location=\"${2}\" "
296
297header+="auth=\"root\">\n"
298header+="\t<payload installKBytes=\"${installedsize##* }\" numberOfFiles=\"${filecount##* }\"/>\n"
299rm -R -f "${1}/Temp"
300
301[ -d "${1}/Temp" ] || mkdir -m 777 "${1}/Temp"
302[ -d "${1}/Root" ] && mkbom "${1}/Root" "${1}/Temp/Bom"
303
304if [ -d "${1}/Scripts" ]; then
305header+="\t<scripts>\n"
306for script in $( find "${1}/Scripts" -type f \( -name 'pre*' -or -name 'post*' \) )
307do
308header+="\t\t<${script##*/} file=\"./${script##*/}\"/>\n"
309done
310header+="\t</scripts>\n"
311chown -R 0:0 "${1}/Scripts"
312pushd "${1}/Scripts" >/dev/null
313find . -print | cpio -o -z -H cpio > "../Temp/Scripts"
314popd >/dev/null
315fi
316
317header+="</pkg-info>"
318echo -e "${header}" > "${1}/Temp/PackageInfo"
319pushd "${1}/Root" >/dev/null
320find . -print | cpio -o -z -H cpio > "../Temp/Payload"
321popd >/dev/null
322pushd "${1}/Temp" >/dev/null
323
324xar -c -f "${1%/*}/${packagename// /}.pkg" --compression none .
325
326popd >/dev/null
327
328outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"${packagename// /}\"/>"
329
330if [ "${4}" ]; then
331local choiceoptions="\t\t${4}"
332fi
333choices[$((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"
334rm -R -f "${1}"
335fi
336}
337
338makedistribution ()
339{
340rm -f "${1%/*}/${packagename// /}"*.pkg
341
342find "${1}" -type f -name '*.pkg' -depth 1 | while read component
343do
344mkdir -p "${1}/${packagename}/${component##*/}"
345pushd "${1}/${packagename}/${component##*/}" >/dev/null
346xar -x -f "${1%}/${component##*/}"
347popd >/dev/null
348done
349
350ditto --noextattr --noqtn "${pkgroot}/Distribution" "${1}/${packagename}/Distribution"
351ditto --noextattr --noqtn "${pkgroot}/Resources" "${1}/${packagename}/Resources"
352
353find "${1}/${packagename}/Resources" -type d -name '.svn' -exec rm -R -f {} \; 2>/dev/null
354
355for (( i=0; i < ${#outline[*]} ; i++));
356do
357echo -e "${outline[$i]}" >> "${1}/${packagename}/Distribution"
358done
359
360for (( i=0; i < ${#choices[*]} ; i++));
361do
362echo -e "${choices[$i]}" >> "${1}/${packagename}/Distribution"
363done
364
365echo "</installer-gui-script>" >> "${1}/${packagename}/Distribution"
366
367perl -i -p -e "s/%CHAMELEONVERSION%/${version%%-*}/g" `find "${1}/${packagename}/Resources" -type f`
368perl -i -p -e "s/%CHAMELEONREVISION%/${revision}/g" `find "${1}/${packagename}/Resources" -type f`
369
370# Adding Developer and credits
371perl -i -p -e "s/%DEVELOP%/${develop}/g" `find "${1}/${packagename}/Resources" -type f`
372perl -i -p -e "s/%CREDITS%/${credits}/g" `find "${1}/${packagename}/Resources" -type f`
373perl -i -p -e "s/%PKGDEV%/${pkgdev}/g" `find "${1}/${packagename}/Resources" -type f`
374
375stage=${stage/RC/Release Candidate }
376stage=${stage/FINAL/2.0 Final}
377perl -i -p -e "s/%CHAMELEONSTAGE%/${stage}/g" `find "${1}/${packagename}/Resources" -type f`
378
379find "${1}/${packagename}" -name '.DS_Store' -delete
380pushd "${1}/${packagename}" >/dev/null
381xar -c -f "${1%/*}/${packagename// /}-${version}-r${revision}.pkg" --compression none .
382popd >/dev/null
383
384# Here is the place for assign a Icon to the pkg
385# command use to generate the file:
386# ditto -c -k --sequesterRsrc --keepParent Icon.icns Icon.zip
387# ----
388 ditto -xk "${pkgroot}/Icons/pkg.zip" "${pkgroot}/Icons/"
389 DeRez -only icns "${pkgroot}/Icons/Icons/pkg.icns" > tempicns.rsrc
390 Rez -append tempicns.rsrc -o "${1%/*}/$packagename-${version}-r$revision.pkg"
391 SetFile -a C "${1%/*}/$packagename-${version}-r$revision.pkg"
392 rm -f tempicns.rsrc
393 rm -rf "${pkgroot}/Icons/Icons"
394# End
395
396echo ""
397
398echo -e $COL_GREEN"--------------------------"$COL_RESET
399echo -e $COL_GREEN"Building process complete!"$COL_RESET
400echo -e $COL_GREEN"--------------------------"$COL_RESET
401echo ""
402echo -e $COL_GREEN"Build info."
403echo -e $COL_GREEN"==========="
404echo -e $COL_BLUE"Package name:"$COL_RESET"$packagename-${version}-r$revision.pkg"
405echo -e $COL_BLUE"MD5:"$COL_RESET"$md5"
406echo -e $COL_BLUE"Version:"$COL_RESET"$version"
407echo -e $COL_BLUE"Stage:"$COL_RESET"$stage"
408echo -e $COL_BLUE"Date/Time:"$COL_RESET"$builddate"
409echo ""
410
411}
412
413main "${1}" "${2}" "${3}" "${4}" #"${5}"
414
415

Archive Download this file

Revision: 1651