Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 1628