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

Archive Download this file

Revision: 1621