Chameleon

Chameleon Svn Source Tree

Root/branches/blackosx/package/slimpkg.sh

  • Property svn:executable set to *
1#!/bin/bash
2
3# $1 Path to store built package
4
5packagesidentity="org.chameleon"
6
7packagename="Chameleon"
8
9pkgroot="${0%/*}"
10
11# blackosx to use /usr/local as a place for temporary files
12# taken from http://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard#cite_note-27
13chamTemp="usr/local/chamTemp"
14
15COL_BLACK="\x1b[30;01m"
16COL_RED="\x1b[31;01m"
17COL_GREEN="\x1b[32;01m"
18COL_YELLOW="\x1b[33;01m"
19COL_MAGENTA="\x1b[35;01m"
20COL_CYAN="\x1b[36;01m"
21COL_WHITE="\x1b[37;01m"
22COL_BLUE="\x1b[34;01m"
23COL_RESET="\x1b[39;49;00m"
24
25#version=$( grep I386BOOT_CHAMELEONVERSION vers.h | awk '{ print $3 }' | tr -d '\"' )
26version=$( cat version )
27stage=${version##*-}" (blackosx branch)"
28revision=$( grep I386BOOT_CHAMELEONREVISION vers.h | awk '{ print $3 }' | tr -d '\"' )
29builddate=$( grep I386BOOT_BUILDDATE vers.h | awk '{ print $3,$4 }' | tr -d '\"' )
30timestamp=$( date -j -f "%Y-%m-%d %H:%M:%S" "${builddate}" "+%s" )
31
32# =================
33
34develop=$(awk "NR==6{print;exit}" ${pkgroot}/../CREDITS)
35credits=$(awk "NR==10{print;exit}" ${pkgroot}/../CREDITS)
36pkgdev=$(awk "NR==14{print;exit}" ${pkgroot}/../CREDITS)
37
38# =================
39
40distributioncount=0
41xmlindent=0
42
43indent[0]="\t"
44indent[1]="\t\t"
45indent[2]="\t\t\t"
46indent[3]="\t\t\t\t"
47
48main ()
49{
50
51# clean up the destination path
52
53rm -R -f "${1}"
54echo ""
55echo -e $COL_CYAN"---------------------------------------"$COL_RESET
56echo -e $COL_CYAN"Building $packagename Slim Install Package"$COL_RESET
57echo -e $COL_CYAN"---------------------------------------"$COL_RESET
58echo ""
59
60outline[$((outlinecount++))]="${indent[$xmlindent]}<choices-outline>"
61
62# build core package
63echo "================= Core ================="
64((xmlindent++))
65packagesidentity="org.chameleon.core"
66mkdir -p ${1}/Core/Root/usr/local/bin
67mkdir -p ${1}/Core/Root/usr/standalone/i386
68ditto --noextattr --noqtn ${1%/*}/i386/boot ${1}/Core/Root/usr/standalone/i386
69ditto --noextattr --noqtn ${1%/*}/i386/boot0 ${1}/Core/Root/usr/standalone/i386
70ditto --noextattr --noqtn ${1%/*}/i386/boot0md ${1}/Core/Root/usr/standalone/i386
71ditto --noextattr --noqtn ${1%/*}/i386/boot1f32 ${1}/Core/Root/usr/standalone/i386
72ditto --noextattr --noqtn ${1%/*}/i386/boot1h ${1}/Core/Root/usr/standalone/i386
73ditto --noextattr --noqtn ${1%/*}/i386/boot1he ${1}/Core/Root/usr/standalone/i386
74ditto --noextattr --noqtn ${1%/*}/i386/boot1hp ${1}/Core/Root/usr/standalone/i386
75ditto --noextattr --noqtn ${1%/*}/i386/cdboot ${1}/Core/Root/usr/standalone/i386
76ditto --noextattr --noqtn ${1%/*}/i386/chain0 ${1}/Core/Root/usr/standalone/i386
77ditto --noextattr --noqtn ${1%/*}/i386/fdisk440 ${1}/Core/Root/usr/local/bin
78ditto --noextattr --noqtn ${1%/*}/i386/bdmesg ${1}/Core/Root/usr/local/bin
79local coresize=$( du -hkc "${1}/Core/Root" | tail -n1 | awk {'print $1'} )
80echo "[BUILD] i386 "
81buildpackage "${1}/Core" "/" "0" "start_visible=\"false\" start_selected=\"true\"" >/dev/null 2>&1
82
83# build Chameleon package
84echo "================= Chameleon ================="
85outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"Chameleon\">"
86choices[$((choicescount++))]="<choice\n\tid=\"Chameleon\"\n\ttitle=\"Chameleon_title\"\n\tdescription=\"Chameleon_description\"\n>\n</choice>\n"
87
88# build standard package
89mkdir -p ${1}/Standard/Root
90mkdir -p ${1}/Standard/Scripts/Resources
91cp -f ${pkgroot}/Scripts/Main/Standard/* ${1}/Standard/Scripts
92cp -f ${pkgroot}/Scripts/Sub/* ${1}/Standard/Scripts
93ditto --arch i386 `which SetFile` ${1}/Standard/Scripts/Resources/SetFile
94ditto --noextattr --noqtn ${1%/*/*}/revision ${1}/Standard/Scripts/Resources/revision
95ditto --noextattr --noqtn ${1%/*/*}/version ${1}/Standard/Scripts/Resources/version
96echo "[BUILD] Standard "
97buildpackage "${1}/Standard" "/" "${coresize}" "start_enabled=\"true\" start_selected=\"upgrade_allowed()\" selected=\"exclusive(choices['EFI']) &amp;&amp; exclusive(choices['noboot'])\"" >/dev/null 2>&1
98# End build standard package
99
100# build efi package
101mkdir -p ${1}/EFI/Root
102mkdir -p ${1}/EFI/Scripts/Resources
103cp -f ${pkgroot}/Scripts/Main/EFI/* ${1}/EFI/Scripts
104cp -f ${pkgroot}/Scripts/Sub/* ${1}/EFI/Scripts
105ditto --arch i386 `which SetFile` ${1}/EFI/Scripts/Resources/SetFile
106ditto --noextattr --noqtn ${1%/*/*}/revision ${1}/EFI/Scripts/Resources/revision
107ditto --noextattr --noqtn ${1%/*/*}/version ${1}/EFI/Scripts/Resources/version
108echo "[BUILD] EFI "
109buildpackage "${1}/EFI" "/" "${coresize}" "start_visible=\"systemHasGPT()\" start_selected=\"false\" selected=\"exclusive(choices['Standard']) &amp;&amp; exclusive(choices['noboot'])\"" >/dev/null 2>&1
110# End build efi package
111
112# build reset choice package
113mkdir -p ${1}/noboot/Root
114echo "[BUILD] Reset choice "
115buildpackage "${1}/noboot" "/$chamTemp" "" "start_visible=\"true\" start_selected=\"false\" selected=\"exclusive(choices['Standard']) &amp;&amp; exclusive(choices['EFI'])\"" >/dev/null 2>&1
116# End build reset choice package
117
118((xmlindent--))
119outline[$((outlinecount++))]="${indent[$xmlindent]}\t</line>"
120# End build Chameleon package
121
122# build Modules package
123echo "================= Modules ================="
124###############################
125# Supported Modules #
126###############################
127# klibc.dylib #
128# Resolution.dylib #
129# uClibcxx.dylib #
130# Keylayout.dylib #
131###############################
132if [ "$(ls -A "${1%/*}/i386/modules")" ]; then
133{
134outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"Module\">"
135choices[$((choicescount++))]="<choice\n\tid=\"Module\"\n\ttitle=\"Module_title\"\n\tdescription=\"Module_description\"\n>\n</choice>\n"
136((xmlindent++))
137packagesidentity="org.chameleon.modules"
138# -
139if [ -e ${1%/*}/i386/modules/klibc.dylib ]; then
140{
141mkdir -p ${1}/klibc/Root
142ditto --noextattr --noqtn ${1%/*}/i386/modules/klibc.dylib ${1}/klibc/Root
143echo "[BUILD] klibc "
144buildpackage "${1}/klibc" "/$chamTemp/Extra/modules" "" "start_selected=\"false\"" >/dev/null 2>&1
145}
146fi
147# -
148if [ -e ${1%/*}/i386/modules/Resolution.dylib ]; then
149{
150mkdir -p ${1}/AutoReso/Root
151ditto --noextattr --noqtn ${1%/*}/i386/modules/Resolution.dylib ${1}/AutoReso/Root
152echo "[BUILD] Resolution "
153buildpackage "${1}/AutoReso" "/$chamTemp/Extra/modules" "" "start_selected=\"false\"" >/dev/null 2>&1
154}
155fi
156# -
157if [ -e ${1%/*}/i386/modules/uClibcxx.dylib ]; then
158{
159mkdir -p ${1}/uClibc/Root
160ditto --noextattr --noqtn ${1%/*}/i386/modules/uClibcxx.dylib ${1}/uClibc/Root
161ditto --noextattr --noqtn ${1%/*}/i386/modules/klibc.dylib ${1}/uClibc/Root
162echo "[BUILD] uClibc++ "
163buildpackage "${1}/uClibc" "/$chamTemp/Extra/modules" "" "start_selected=\"false\"" >/dev/null 2>&1
164}
165fi
166# -
167if [ -e ${1%/*}/i386/modules/Keylayout.dylib ]; then
168{
169mkdir -p ${1}/Keylayout/Root
170ditto --noextattr --noqtn ${1%/*}/i386/modules/Keylayout.dylib ${1}/Keylayout/Root
171echo "[BUILD] Keylayout "
172buildpackage "${1}/Keylayout" "/$chamTemp/Extra/modules" "" "start_selected=\"false\"" >/dev/null 2>&1
173}
174fi
175
176((xmlindent--))
177outline[$((outlinecount++))]="${indent[$xmlindent]}\t</line>"
178}
179else
180{
181echo " -= no modules to include =-"
182}
183fi
184# End build Modules packages
185
186# build post install package
187echo "================= Post ================="
188mkdir -p ${1}/Post/Root
189mkdir -p ${1}/Post/Scripts
190cp -f ${pkgroot}/Scripts/Main/Post/* ${1}/Post/Scripts
191cp -f ${pkgroot}/Scripts/Sub/InstallLog.sh ${1}/Post/Scripts
192ditto --noextattr --noqtn ${1%/*/*}/revision ${1}/Post/Scripts/Resources/revision
193ditto --noextattr --noqtn ${1%/*/*}/version ${1}/Post/Scripts/Resources/version
194echo "[BUILD] Post "
195buildpackage "${1}/Post" "/" "" "start_visible=\"false\" start_selected=\"true\"" >/dev/null 2>&1
196outline[$((outlinecount++))]="${indent[$xmlindent]}</choices-outline>"
197
198# build meta package
199
200makedistribution "${1}" "${2}" "${3}" "${4}" "${5}"
201
202# clean up
203
204rm -R -f "${1}"
205
206}
207
208fixperms ()
209{
210# $1 path
211find "${1}" -type f -exec chmod 644 {} \;
212find "${1}" -type d -exec chmod 755 {} \;
213chown -R 0:0 "${1}"
214}
215
216buildpackage ()
217{
218# $1 Path to package to build containing Root and or Scripts
219# $2 Install Location
220# $3 Size
221# $4 Options
222
223if [ -d "${1}/Root" ] && [ "${1}/Scripts" ]; then
224
225local packagename="${1##*/}"
226local identifier=$( echo ${packagesidentity}.${packagename//_/.} | tr [:upper:] [:lower:] )
227find "${1}" -name '.DS_Store' -delete
228local filecount=$( find "${1}/Root" | wc -l )
229if [ "${3}" ]; then
230local installedsize="${3}"
231else
232local installedsize=$( du -hkc "${1}/Root" | tail -n1 | awk {'print $1'} )
233fi
234local header="<?xml version=\"1.0\"?>\n<pkg-info format-version=\"2\" "
235
236#[ "${3}" == "relocatable" ] && header+="relocatable=\"true\" "
237
238header+="identifier=\"${identifier}\" "
239header+="version=\"${version}\" "
240
241[ "${2}" != "relocatable" ] && header+="install-location=\"${2}\" "
242
243header+="auth=\"root\">\n"
244header+="\t<payload installKBytes=\"${installedsize##* }\" numberOfFiles=\"${filecount##* }\"/>\n"
245rm -R -f "${1}/Temp"
246
247[ -d "${1}/Temp" ] || mkdir -m 777 "${1}/Temp"
248[ -d "${1}/Root" ] && mkbom "${1}/Root" "${1}/Temp/Bom"
249
250if [ -d "${1}/Scripts" ]; then
251header+="\t<scripts>\n"
252for script in $( find "${1}/Scripts" -type f \( -name 'pre*' -or -name 'post*' \) )
253do
254header+="\t\t<${script##*/} file=\"./${script##*/}\"/>\n"
255done
256header+="\t</scripts>\n"
257chown -R 0:0 "${1}/Scripts"
258pushd "${1}/Scripts" >/dev/null
259find . -print | cpio -o -z -H cpio > "../Temp/Scripts"
260popd >/dev/null
261fi
262
263header+="</pkg-info>"
264echo -e "${header}" > "${1}/Temp/PackageInfo"
265pushd "${1}/Root" >/dev/null
266find . -print | cpio -o -z -H cpio > "../Temp/Payload"
267popd >/dev/null
268pushd "${1}/Temp" >/dev/null
269
270xar -c -f "${1%/*}/${packagename// /}.pkg" --compression none .
271
272popd >/dev/null
273
274outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"${packagename// /}\"/>"
275
276if [ "${4}" ]; then
277local choiceoptions="${indent[$xmlindent]}${4}\n"
278fi
279choices[$((choicescount++))]="<choice\n\tid=\"${packagename// /}\"\n\ttitle=\"${packagename}_title\"\n\tdescription=\"${packagename}_description\"\n${choiceoptions}>\n\t<pkg-ref id=\"${identifier}\" installKBytes='${installedsize}' version='${version}.0.0.${timestamp}' auth='root'>#${packagename// /}.pkg</pkg-ref>\n</choice>\n"
280
281rm -R -f "${1}"
282fi
283}
284
285makedistribution ()
286{
287rm -f "${1%/*}/${packagename// /}"*.pkg
288
289find "${1}" -type f -name '*.pkg' -depth 1 | while read component
290do
291mkdir -p "${1}/${packagename}/${component##*/}"
292pushd "${1}/${packagename}/${component##*/}" >/dev/null
293xar -x -f "${1%}/${component##*/}"
294popd >/dev/null
295done
296
297ditto --noextattr --noqtn "${pkgroot}/Distribution" "${1}/${packagename}/Distribution"
298ditto --noextattr --noqtn "${pkgroot}/Resources" "${1}/${packagename}/Resources"
299
300find "${1}/${packagename}/Resources" -type d -name '.svn' -exec rm -R -f {} \; 2>/dev/null
301
302for (( i=0; i < ${#outline[*]} ; i++));
303do
304echo -e "${outline[$i]}" >> "${1}/${packagename}/Distribution"
305done
306
307for (( i=0; i < ${#choices[*]} ; i++));
308do
309echo -e "${choices[$i]}" >> "${1}/${packagename}/Distribution"
310done
311
312echo "</installer-gui-script>" >> "${1}/${packagename}/Distribution"
313
314perl -i -p -e "s/%CHAMELEONVERSION%/${version%%-*}/g" `find "${1}/${packagename}/Resources" -type f`
315perl -i -p -e "s/%CHAMELEONREVISION%/${revision}/g" `find "${1}/${packagename}/Resources" -type f`
316
317# Adding Developer and credits
318perl -i -p -e "s/%DEVELOP%/${develop}/g" `find "${1}/${packagename}/Resources" -type f`
319perl -i -p -e "s/%CREDITS%/${credits}/g" `find "${1}/${packagename}/Resources" -type f`
320perl -i -p -e "s/%PKGDEV%/${pkgdev}/g" `find "${1}/${packagename}/Resources" -type f`
321
322stage=${stage/RC/Release Candidate }
323stage=${stage/FINAL/2.0 Final}
324perl -i -p -e "s/%CHAMELEONSTAGE%/${stage}/g" `find "${1}/${packagename}/Resources" -type f`
325
326find "${1}/${packagename}" -name '.DS_Store' -delete
327pushd "${1}/${packagename}" >/dev/null
328xar -c -f "${1%/*}/${packagename// /}-${version}-r${revision}.pkg" --compression none .
329popd >/dev/null
330
331# Here is the place for assign a Icon to the pkg
332ditto -xk "${pkgroot}/Icons/pkg.zip" "${pkgroot}/Icons/"
333DeRez -only icns "${pkgroot}/Icons/Icons/pkg.icns" > tempicns.rsrc
334Rez -append tempicns.rsrc -o "${1%/*}/$packagename-${version}-r$revision.pkg"
335SetFile -a C "${1%/*}/$packagename-${version}-r$revision.pkg"
336rm -f tempicns.rsrc
337rm -rf "${pkgroot}/Icons/Icons"
338# End
339
340echo ""
341
342echo -e $COL_GREEN"--------------------------"$COL_RESET
343echo -e $COL_GREEN"Building process complete!"$COL_RESET
344echo -e $COL_GREEN"--------------------------"$COL_RESET
345echo ""
346echo -e $COL_GREEN"Build info."
347echo -e $COL_GREEN"==========="
348echo -e $COL_BLUE"Package name:"$COL_RESET"$packagename-${version}-r$revision.pkg"
349echo -e $COL_BLUE"MD5:"$COL_RESET"$md5"
350echo -e $COL_BLUE"Version:"$COL_RESET"$version"
351echo -e $COL_BLUE"Stage:"$COL_RESET"$stage"
352echo -e $COL_BLUE"Date/Time:"$COL_RESET"$builddate"
353echo ""
354
355}
356
357main "${1}" "${2}" "${3}" "${4}" "${5}"
358
359

Archive Download this file

Revision: 1611