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

Archive Download this file

Revision: 1666