Chameleon

Chameleon Svn Source Tree

Root/tags/2.3/package/slimpkg.sh

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

Archive Download this file

Revision: 2862