Chameleon

Chameleon Svn Source Tree

Root/branches/rewrite/package/buildpkg.sh

  • Property svn:executable set to *
Source at commit 1129 created 12 years 10 months ago.
By meklort, Change options.o so that it reloads the system config as well. Also change it so that it uses that config for variables (NOTE: if the calue exists in chameleonConfig, it's used instead.
1#!/bin/bash
2
3# $1 Path to store built package
4
5packagesidentity="org.chameleon"
6
7packagename="Chameleon"
8
9pkgroot="${0%/*}"
10
11#version=$( grep I386BOOT_CHAMELEONVERSION sym/i386/vers.h | awk '{ print $3 }' | tr -d '\"' )
12version=$( cat version )
13stage=${version##*-}
14revision=$( grep I386BOOT_CHAMELEONREVISION sym/i386/vers.h | awk '{ print $3 }' | tr -d '\"' )
15builddate=$( grep I386BOOT_BUILDDATE sym/i386/vers.h | awk '{ print $3,$4 }' | tr -d '\"' )
16timestamp=$( date -j -f "%Y-%m-%d %H:%M:%S" "${builddate}" "+%s" )
17
18distributioncount=0
19xmlindent=0
20
21indent[0]="\t"
22indent[1]="\t\t"
23indent[2]="\t\t\t"
24indent[3]="\t\t\t\t"
25
26main ()
27{
28
29# clean up the destination path
30
31rm -R -f "${1}"
32
33echo "Building $packagename Install Package v${version%%-*} $stage r$revision $builddate"
34
35outline[$((outlinecount++))]="${indent[$xmlindent]}<choices-outline>"
36
37# build core package
38
39mkdir -p ${1}/Core/Root/usr/sbin
40mkdir -p ${1}/Core/Root/usr/local/bin
41mkdir -p ${1}/Core/Root/usr/standalone/i386
42cp -f ${1%/*}/i386/boot ${1}/Core/Root/usr/standalone/i386
43cp -f ${1%/*}/i386/boot0 ${1}/Core/Root/usr/standalone/i386
44cp -f ${1%/*}/i386/boot1f32 ${1}/Core/Root/usr/standalone/i386
45cp -f ${1%/*}/i386/boot1h ${1}/Core/Root/usr/standalone/i386
46cp -f ${1%/*}/i386/boot1he ${1}/Core/Root/usr/standalone/i386
47cp -f ${1%/*}/i386/boot1hp ${1}/Core/Root/usr/standalone/i386
48cp -f ${1%/*}/i386/cdboot ${1}/Core/Root/usr/standalone/i386
49cp -f ${1%/*}/i386/chain0 ${1}/Core/Root/usr/standalone/i386
50fixperms "${1}/Core/Root/"
51cp -f ${pkgroot}/fdisk ${1}/Core/Root/usr/sbin
52local coresize=$( du -hkc "${1}/Core/Root" | tail -n1 | awk {'print $1'} )
53buildpackage "${1}/Core" "/" "0" "start_visible=\"false\" start_selected=\"true\""
54
55# build standard package
56
57mkdir -p ${1}/Standard/Root
58mkdir -p ${1}/Standard/Scripts/Tools
59cp -f ${pkgroot}/Scripts/Standard/* ${1}/Standard/Scripts
60ditto --arch i386 `which SetFile` ${1}/Standard/Scripts/Tools/SetFile
61buildpackage "${1}/Standard" "/" "${coresize}" "start_enabled=\"true\" start_selected=\"upgrade_allowed()\" selected=\"exclusive(choices['EnhancedHFS']) &amp;&amp; exclusive(choices['EnhancedFAT'])\""
62
63# build efi fat32 package
64
65mkdir -p ${1}/EnhancedFAT/Root
66mkdir -p ${1}/EnhancedFAT/Scripts/Tools
67cp -f ${pkgroot}/Scripts/FAT/* ${1}/EnhancedFAT/Scripts
68ditto --arch i386 `which SetFile` ${1}/EnhancedFAT/Scripts/Tools/SetFile
69buildpackage "${1}/EnhancedFAT" "/" "${coresize}" "start_visible=\"systemHasGPT()\" start_selected=\"false\" selected=\"exclusive(choices['Standard']) &amp;&amp; exclusive(choices['EnhancedHFS'])\""
70
71# build efi hfs package
72
73mkdir -p ${1}/EnhancedHFS/Root
74mkdir -p ${1}/EnhancedHFS/Scripts/Tools
75cp -f ${pkgroot}/Scripts/HFS/* ${1}/EnhancedHFS/Scripts
76ditto --arch i386 `which SetFile` ${1}/EnhancedHFS/Scripts/Tools/SetFile
77buildpackage "${1}/EnhancedHFS" "/" "${coresize}" "start_visible=\"systemHasGPT()\" start_selected=\"false\" selected=\"exclusive(choices['Standard']) &amp;&amp; exclusive(choices['EnhancedFAT'])\""
78
79# build options packages
80
81outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"Options\">"
82choices[$((choicescount++))]="<choice\n\tid=\"Options\"\n\ttitle=\"Options_title\"\n\tdescription=\"Options_description\"\n>\n</choice>\n"
83((xmlindent++))
84packagesidentity="org.chameleon"
85options=($( find "${pkgroot}/Scripts/Options" -type d -depth 1 -not -name '.svn' ))
86for (( i = 0 ; i < ${#options[@]} ; i++ ))
87do
88mkdir -p "${1}/${options[$i]##*/}/Root"
89mkdir -p "${1}/${options[$i]##*/}/Scripts"
90
91ditto --noextattr --noqtn "${options[$i]}/postinstall" "${1}/${options[$i]##*/}/Scripts/postinstall"
92
93buildpackage "${1}/${options[$i]##*/}" "/" "" "start_selected=\"false\""
94done
95((xmlindent--))
96outline[$((outlinecount++))]="${indent[$xmlindent]}\t</line>"
97
98# build theme packages
99
100outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"Themes\">"
101choices[$((choicescount++))]="<choice\n\tid=\"Themes\"\n\ttitle=\"Themes_title\"\n\tdescription=\"Themes_description\"\n>\n</choice>\n"
102((xmlindent++))
103packagesidentity="org.chameleon.theme"
104artwork="${1%/*}"
105themes=($( find "${artwork%/*}/artwork/themes" -type d -depth 1 -not -name '.svn' ))
106for (( i = 0 ; i < ${#themes[@]} ; i++ ))
107do
108theme=$( echo ${themes[$i]##*/} | awk 'BEGIN{OFS=FS=""}{$1=toupper($1);print}' )
109mkdir -p "${1}/${theme}/Root/"
110ditto --noextattr --noqtn "${themes[$i]}" "${1}/${themes[$i]##*/}/Root/${theme}"
111find "${1}/${themes[$i]##*/}" -name '.DS_Store' -or -name '.svn' -exec rm -R {} \+
112find "${1}/${themes[$i]##*/}" -type f -exec chmod 644 {} \+
113
114buildpackage "${1}/${theme}" "/.Chameleon/Extra/Themes" ""
115rm -R -f "${1}/${i##*/}"
116done
117
118((xmlindent--))
119outline[$((outlinecount++))]="${indent[$xmlindent]}\t</line>"
120
121outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"Extras\">"
122choices[$((choicescount++))]="<choice\n\tid=\"Extras\"\n\ttitle=\"Extras_title\"\n\tdescription=\"Extras_description\"\n>\n</choice>\n"
123
124((xmlindent++))
125
126# build kext packages
127
128outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"Kexts\">"
129choices[$((choicescount++))]="<choice\n\tid=\"Kexts\"\n\ttitle=\"Kexts_title\"\n\tdescription=\"Kexts_description\"\n>\n</choice>\n"
130((xmlindent++))
131packagesidentity="org.chameleon"
132kexts=($( find "${pkgroot}/Kexts" -type d -name '*.kext' -depth 1 ))
133for (( i = 0 ; i < ${#kexts[@]} ; i++ ))
134do
135filename="${kexts[$i]##*/}"
136mkdir -p "${1}/${filename%.kext}/Root/"
137ditto --noextattr --noqtn --arch i386 "${kexts[$i]}" "${1}/${filename%.kext}/Root/${filename}"
138find "${1}/${filename%.kext}" -name '.DS_Store' -or -name '.svn' -exec rm -R -f {} \; 2>/dev/null
139fixperms "${1}/${filename%.kext}/Root/"
140chown 501:20 "${1}/${filename%.kext}/Root/"
141buildpackage "${1}/${filename%.kext}" "/.Chameleon/Extra/Extensions" ""
142rm -R -f "${1}/${filename%.kext}"
143done
144
145((xmlindent--))
146outline[$((outlinecount++))]="${indent[$xmlindent]}\t</line>"
147
148((xmlindent--))
149outline[$((outlinecount++))]="${indent[$xmlindent]}\t</line>"
150
151# build post install package
152
153mkdir -p ${1}/Post/Root
154mkdir -p ${1}/Post/Scripts
155cp -f ${pkgroot}/Scripts/Post/* ${1}/Post/Scripts
156buildpackage "${1}/Post" "/" "" "start_visible=\"false\" start_selected=\"true\""
157outline[$((outlinecount++))]="${indent[$xmlindent]}</choices-outline>"
158
159# build meta package
160
161makedistribution "${1}" "${2}" "${3}" "${4}" "${5}"
162
163# clean up
164
165rm -R -f "${1}"
166
167}
168
169fixperms ()
170{
171# $1 path
172find "${1}" -type f -exec chmod 644 {} \;
173find "${1}" -type d -exec chmod 755 {} \;
174chown -R 0:0 "${1}"
175}
176
177buildpackage ()
178{
179# $1 Path to package to build containing Root and or Scripts
180# $2 Install Location
181# $3 Size
182# $4 Options
183
184if [ -d "${1}/Root" ] && [ "${1}/Scripts" ]; then
185
186local packagename="${1##*/}"
187local identifier=$( echo ${packagesidentity}.${packagename//_/.} | tr [:upper:] [:lower:] )
188find "${1}" -name '.DS_Store' -delete
189local filecount=$( find "${1}/Root" | wc -l )
190if [ "${3}" ]; then
191local installedsize="${3}"
192else
193local installedsize=$( du -hkc "${1}/Root" | tail -n1 | awk {'print $1'} )
194fi
195local header="<?xml version=\"1.0\"?>\n<pkg-info format-version=\"2\" "
196
197#[ "${3}" == "relocatable" ] && header+="relocatable=\"true\" "
198
199header+="identifier=\"${identifier}\" "
200header+="version=\"${version}\" "
201
202[ "${2}" != "relocatable" ] && header+="install-location=\"${2}\" "
203
204header+="auth=\"root\">\n"
205header+="\t<payload installKBytes=\"${installedsize##* }\" numberOfFiles=\"${filecount##* }\"/>\n"
206rm -R -f "${1}/Temp"
207
208[ -d "${1}/Temp" ] || mkdir -m 777 "${1}/Temp"
209[ -d "${1}/Root" ] && mkbom "${1}/Root" "${1}/Temp/Bom"
210
211if [ -d "${1}/Scripts" ]; then
212header+="\t<scripts>\n"
213for script in $( find "${1}/Scripts" -type f \( -name 'pre*' -or -name 'post*' \) )
214do
215header+="\t\t<${script##*/} file=\"./${script##*/}\"/>\n"
216done
217header+="\t</scripts>\n"
218chown -R 0:0 "${1}/Scripts"
219pushd "${1}/Scripts" >/dev/null
220find . -print | cpio -o -z -H cpio > "../Temp/Scripts"
221popd >/dev/null
222fi
223
224header+="</pkg-info>"
225echo -e "${header}" > "${1}/Temp/PackageInfo"
226pushd "${1}/Root" >/dev/null
227find . -print | cpio -o -z -H cpio > "../Temp/Payload"
228popd >/dev/null
229pushd "${1}/Temp" >/dev/null
230
231xar -c -f "${1%/*}/${packagename// /}.pkg" --compression none .
232
233popd >/dev/null
234
235outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"${packagename// /}\"/>"
236
237if [ "${4}" ]; then
238local choiceoptions="${indent[$xmlindent]}${4}\n"
239fi
240choices[$((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"
241
242rm -R -f "${1}"
243fi
244}
245
246makedistribution ()
247{
248rm -f "${1%/*}/${packagename// /}"*.pkg
249
250find "${1}" -type f -name '*.pkg' -depth 1 | while read component
251do
252mkdir -p "${1}/${packagename}/${component##*/}"
253pushd "${1}/${packagename}/${component##*/}" >/dev/null
254xar -x -f "${1%}/${component##*/}"
255popd >/dev/null
256done
257
258ditto --noextattr --noqtn "${pkgroot}/Distribution" "${1}/${packagename}/Distribution"
259ditto --noextattr --noqtn "${pkgroot}/Resources" "${1}/${packagename}/Resources"
260
261find "${1}/${packagename}/Resources" -type d -name '.svn' -exec rm -R -f {} \; 2>/dev/null
262
263for (( i=0; i < ${#outline[*]} ; i++));
264do
265echo -e "${outline[$i]}" >> "${1}/${packagename}/Distribution"
266done
267
268for (( i=0; i < ${#choices[*]} ; i++));
269do
270echo -e "${choices[$i]}" >> "${1}/${packagename}/Distribution"
271done
272
273echo "</installer-gui-script>" >> "${1}/${packagename}/Distribution"
274
275perl -i -p -e "s/%CHAMELEONVERSION%/${version%%-*}/g" `find "${1}/${packagename}/Resources" -type f`
276perl -i -p -e "s/%CHAMELEONREVISION%/${revision}/g" `find "${1}/${packagename}/Resources" -type f`
277
278stage=${stage/RC/Release Candidate }
279stage=${stage/FINAL/2.0 Final}
280perl -i -p -e "s/%CHAMELEONSTAGE%/${stage}/g" `find "${1}/${packagename}/Resources" -type f`
281
282find "${1}/${packagename}" -name '.DS_Store' -delete
283pushd "${1}/${packagename}" >/dev/null
284xar -c -f "${1%/*}/${packagename// /}-${version}-r${revision}.pkg" --compression none .
285popd >/dev/null
286
287md5=$( md5 "${1%/*}/${packagename// /}-${version}-r${revision}.pkg" | awk {'print $4'} )
288echo "MD5 (${packagename// /}-${version}-r${revision}.pkg) = ${md5}" > "${1%/*}/${packagename// /}-${version}-r${revision}.pkg.md5"
289}
290
291main "${1}" "${2}" "${3}" "${4}" "${5}"
292
293

Archive Download this file

Revision: 1129