Chameleon Applications

Chameleon Applications Svn Source Tree

Root/branches/iFabio/Chameleon/package/slimpkg.sh

  • Property svn:executable set to *
Source at commit 333 created 12 years 8 months ago.
By ifabio, Add a control for module dir (check if the modules folder sym/i386/modules is empty or not) before copy the modules folder into the "core" package and build the modules choices. TODO: now for each module need a similar check. This avoids the creation of choices, that does not exist
1#!/bin/bash
2
3# $1 Path to store built package
4
5packagesidentity="org.chameleon"
6
7packagename="Chameleon"
8
9pkgroot="${0%/*}"
10
11COL_BLACK="\x1b[30;01m"
12COL_RED="\x1b[31;01m"
13COL_GREEN="\x1b[32;01m"
14COL_YELLOW="\x1b[33;01m"
15COL_MAGENTA="\x1b[35;01m"
16COL_CYAN="\x1b[36;01m"
17COL_WHITE="\x1b[37;01m"
18COL_BLUE="\x1b[34;01m"
19COL_RESET="\x1b[39;49;00m"
20
21#version=$( grep I386BOOT_CHAMELEONVERSION sym/i386/vers.h | awk '{ print $3 }' | tr -d '\"' )
22version=$( cat version )
23stage=${version##*-}
24revision=$( grep I386BOOT_CHAMELEONREVISION sym/i386/vers.h | awk '{ print $3 }' | tr -d '\"' )
25builddate=$( grep I386BOOT_BUILDDATE sym/i386/vers.h | awk '{ print $3,$4 }' | tr -d '\"' )
26timestamp=$( date -j -f "%Y-%m-%d %H:%M:%S" "${builddate}" "+%s" )
27
28# =================
29
30develop=" Crazor, Dense, fassl, fxtentacle, iNDi, JrCs, Kabyl, kaitek, mackerintel, mercurysquad, munky, Slice, meklort, mozodojo, rekursor, Turbo, cparm, valv & zef "
31
32credits=" andyvand, asereBLN, Azimut, bumby, cosmo1t, dfe, Galaxy, kalyway, Krazubu, MasterChief, netkas, sckevyn, smith@@, THeKiNG, blackosx, .: ErmaC :., scrax, DutchHockeyPro & Andy"
33
34# =================
35
36distributioncount=0
37xmlindent=0
38
39indent[0]="\t"
40indent[1]="\t\t"
41indent[2]="\t\t\t"
42indent[3]="\t\t\t\t"
43
44main ()
45{
46
47# clean up the destination path
48
49rm -R -f "${1}"
50echo ""
51echo -e $COL_BLACK"---------------------"$COL_RESET
52echo -e $COL_BLACK"Building Slim Package"$COL_RESET
53echo -e $COL_BLACK"---------------------"$COL_RESET
54echo ""
55
56outline[$((outlinecount++))]="${indent[$xmlindent]}<choices-outline>"
57
58# build core package
59echo "================= Core ================="
60((xmlindent++))
61packagesidentity="org.chameleon.core"
62mkdir -p ${1}/Core/Root/usr/sbin
63mkdir -p ${1}/Core/Root/usr/local/bin
64mkdir -p ${1}/Core/Root/usr/standalone/i386
65 if [ "$(ls -A ${1%/*}/i386/modules)" ]; then
66 echo "Found Module :)"
67 mkdir -p ${1}/Core/Root/usr/standalone/i386/modules
68 cp -R ${1%/*}/i386/modules ${1}/Core/Root/usr/standalone/i386
69 else
70 echo "No found module into dir module"
71 fi
72cp -f ${1%/*}/i386/boot ${1}/Core/Root/usr/standalone/i386
73cp -f ${1%/*}/i386/boot0 ${1}/Core/Root/usr/standalone/i386
74cp -f ${1%/*}/i386/boot0md ${1}/Core/Root/usr/standalone/i386
75cp -f ${1%/*}/i386/boot1f32 ${1}/Core/Root/usr/standalone/i386
76cp -f ${1%/*}/i386/boot1h ${1}/Core/Root/usr/standalone/i386
77cp -f ${1%/*}/i386/boot1he ${1}/Core/Root/usr/standalone/i386
78cp -f ${1%/*}/i386/boot1hp ${1}/Core/Root/usr/standalone/i386
79fixperms "${1}/Core/Root/"
80cp -f ${1%/*}/i386/fdisk440 ${1}/Core/Root/usr/sbin
81cp -f ${1%/*}/i386/bdmesg ${1}/Core/Root/usr/sbin
82local coresize=$( du -hkc "${1}/Core/Root" | tail -n1 | awk {'print $1'} )
83echo "[BUILD] i386 "
84buildpackage "${1}/Core" "/" "0" "start_visible=\"false\" start_selected=\"true\"" >/dev/null 2>&1
85
86# build Chameleon package
87echo "================= Chameleon ================="
88outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"Chameleon\">"
89choices[$((choicescount++))]="<choice\n\tid=\"Chameleon\"\n\ttitle=\"Chameleon_title\"\n\tdescription=\"Chameleon_description\"\n>\n</choice>\n"
90
91# build standard package
92mkdir -p ${1}/Standard/Root
93mkdir -p ${1}/Standard/Scripts/Tools
94cp -f ${pkgroot}/Scripts/Standard/* ${1}/Standard/Scripts
95# ditto --arch i386 `which SetFile` ${1}/Standard/Scripts/Tools/SetFile
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/Tools
103cp -f ${pkgroot}/Scripts/EFI/* ${1}/EFI/Scripts
104# ditto --arch i386 `which SetFile` ${1}/EFI/Scripts/Tools/SetFile
105echo "[BUILD] EFI "
106buildpackage "${1}/EFI" "/" "${coresize}" "start_visible=\"systemHasGPT()\" start_selected=\"false\" selected=\"exclusive(choices['Standard']) &amp;&amp; exclusive(choices['noboot'])\"" >/dev/null 2>&1
107# End build efi package
108
109# build reset choice package
110mkdir -p ${1}/noboot/Root
111echo "[BUILD] Reset choice "
112buildpackage "${1}/noboot" "/tmpcham" "" "start_visible=\"true\" start_selected=\"false\" selected=\"exclusive(choices['Standard']) &amp;&amp; exclusive(choices['EFI'])\"" >/dev/null 2>&1
113# End build reset choice package
114
115# build Modules package
116 echo "================= Modules ================="
117 if [ "$(ls -A ${1%/*}/i386/modules)" ]; then
118 outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"Module\">"
119 choices[$((choicescount++))]="<choice\n\tid=\"Module\"\n\ttitle=\"Module_title\"\n\tdescription=\"Module_description\"\n>\n</choice>\n"
120 ((xmlindent++))
121 packagesidentity="org.chameleon.module"
122 modules=($( find "${pkgroot}/Scripts/Modules" -type d -depth 1 -not -name '.svn' ))
123 for (( i = 0 ; i < ${#modules[@]} ; i++ ))
124 do
125 mkdir -p "${1}/${modules[$i]##*/}/Root"
126 mkdir -p "${1}/${modules[$i]##*/}/Scripts"
127 ditto --noextattr --noqtn "${modules[$i]}/postinstall" "${1}/${modules[$i]##*/}/Scripts/postinstall"
128 echo "[BUILD] ${modules[$i]##*/} "
129 buildpackage "${1}/${modules[$i]##*/}" "/" "" "start_selected=\"false\"" >/dev/null 2>&1
130 rm -R -f "${1}/${i##*/}"
131 done
132 ((xmlindent--))
133 outline[$((outlinecount++))]="${indent[$xmlindent]}\t</line>"
134 else
135 echo " -= no module/s to include =-"
136 fi
137# End build Modules packages
138
139((xmlindent--))
140outline[$((outlinecount++))]="${indent[$xmlindent]}\t</line>"
141# End build Chameleon package
142
143# build post install package
144echo "================= Post ================="
145mkdir -p ${1}/Post/Root
146mkdir -p ${1}/Post/Scripts
147cp -f ${pkgroot}/Scripts/Post/* ${1}/Post/Scripts
148echo "[BUILD] Post "
149buildpackage "${1}/Post" "/" "" "start_visible=\"false\" start_selected=\"true\"" >/dev/null 2>&1
150outline[$((outlinecount++))]="${indent[$xmlindent]}</choices-outline>"
151
152# build meta package
153
154makedistribution "${1}" "${2}" "${3}" "${4}" "${5}"
155
156# clean up
157
158rm -R -f "${1}"
159
160}
161
162fixperms ()
163{
164# $1 path
165find "${1}" -type f -exec chmod 644 {} \;
166find "${1}" -type d -exec chmod 755 {} \;
167chown -R 0:0 "${1}"
168}
169
170buildpackage ()
171{
172# $1 Path to package to build containing Root and or Scripts
173# $2 Install Location
174# $3 Size
175# $4 Options
176
177if [ -d "${1}/Root" ] && [ "${1}/Scripts" ]; then
178
179local packagename="${1##*/}"
180local identifier=$( echo ${packagesidentity}.${packagename//_/.} | tr [:upper:] [:lower:] )
181find "${1}" -name '.DS_Store' -delete
182local filecount=$( find "${1}/Root" | wc -l )
183if [ "${3}" ]; then
184local installedsize="${3}"
185else
186local installedsize=$( du -hkc "${1}/Root" | tail -n1 | awk {'print $1'} )
187fi
188local header="<?xml version=\"1.0\"?>\n<pkg-info format-version=\"2\" "
189
190#[ "${3}" == "relocatable" ] && header+="relocatable=\"true\" "
191
192header+="identifier=\"${identifier}\" "
193header+="version=\"${version}\" "
194
195[ "${2}" != "relocatable" ] && header+="install-location=\"${2}\" "
196
197header+="auth=\"root\">\n"
198header+="\t<payload installKBytes=\"${installedsize##* }\" numberOfFiles=\"${filecount##* }\"/>\n"
199rm -R -f "${1}/Temp"
200
201[ -d "${1}/Temp" ] || mkdir -m 777 "${1}/Temp"
202[ -d "${1}/Root" ] && mkbom "${1}/Root" "${1}/Temp/Bom"
203
204if [ -d "${1}/Scripts" ]; then
205header+="\t<scripts>\n"
206for script in $( find "${1}/Scripts" -type f \( -name 'pre*' -or -name 'post*' \) )
207do
208header+="\t\t<${script##*/} file=\"./${script##*/}\"/>\n"
209done
210header+="\t</scripts>\n"
211chown -R 0:0 "${1}/Scripts"
212pushd "${1}/Scripts" >/dev/null
213find . -print | cpio -o -z -H cpio > "../Temp/Scripts"
214popd >/dev/null
215fi
216
217header+="</pkg-info>"
218echo -e "${header}" > "${1}/Temp/PackageInfo"
219pushd "${1}/Root" >/dev/null
220find . -print | cpio -o -z -H cpio > "../Temp/Payload"
221popd >/dev/null
222pushd "${1}/Temp" >/dev/null
223
224xar -c -f "${1%/*}/${packagename// /}.pkg" --compression none .
225
226popd >/dev/null
227
228outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"${packagename// /}\"/>"
229
230if [ "${4}" ]; then
231local choiceoptions="${indent[$xmlindent]}${4}\n"
232fi
233choices[$((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"
234
235rm -R -f "${1}"
236fi
237}
238
239makedistribution ()
240{
241rm -f "${1%/*}/${packagename// /}"*.pkg
242
243find "${1}" -type f -name '*.pkg' -depth 1 | while read component
244do
245mkdir -p "${1}/${packagename}/${component##*/}"
246pushd "${1}/${packagename}/${component##*/}" >/dev/null
247xar -x -f "${1%}/${component##*/}"
248popd >/dev/null
249done
250
251ditto --noextattr --noqtn "${pkgroot}/Distribution" "${1}/${packagename}/Distribution"
252ditto --noextattr --noqtn "${pkgroot}/Resources" "${1}/${packagename}/Resources"
253
254find "${1}/${packagename}/Resources" -type d -name '.svn' -exec rm -R -f {} \; 2>/dev/null
255
256for (( i=0; i < ${#outline[*]} ; i++));
257do
258echo -e "${outline[$i]}" >> "${1}/${packagename}/Distribution"
259done
260
261for (( i=0; i < ${#choices[*]} ; i++));
262do
263echo -e "${choices[$i]}" >> "${1}/${packagename}/Distribution"
264done
265
266echo "</installer-gui-script>" >> "${1}/${packagename}/Distribution"
267
268perl -i -p -e "s/%CHAMELEONVERSION%/${version%%-*}/g" `find "${1}/${packagename}/Resources" -type f`
269perl -i -p -e "s/%CHAMELEONREVISION%/${revision}/g" `find "${1}/${packagename}/Resources" -type f`
270
271# Adding Developer and credits
272perl -i -p -e "s/%DEVELOP%/${develop}/g" `find "${1}/${packagename}/Resources" -type f`
273perl -i -p -e "s/%CREDITS%/${credits}/g" `find "${1}/${packagename}/Resources" -type f`
274#
275
276stage=${stage/RC/Release Candidate }
277stage=${stage/FINAL/2.0 Final}
278perl -i -p -e "s/%CHAMELEONSTAGE%/${stage}/g" `find "${1}/${packagename}/Resources" -type f`
279
280find "${1}/${packagename}" -name '.DS_Store' -delete
281pushd "${1}/${packagename}" >/dev/null
282xar -c -f "${1%/*}/$packagename.pkg" --compression none .
283popd >/dev/null
284
285# Here is the place for assign a Icon to the pkg
286ditto -xk "${pkgroot}/Icons/pkg.zip" "${pkgroot}/Icons/"
287DeRez -only icns "${pkgroot}/Icons/Icons/pkg.icns" > tempicns.rsrc
288Rez -append tempicns.rsrc -o "${1%/*}/$packagename.pkg"
289SetFile -a C "${1%/*}/$packagename.pkg"
290rm -f tempicns.rsrc
291rm -rf "${pkgroot}/Icons/Icons"
292# End
293
294}
295
296main "${1}" "${2}" "${3}" "${4}" "${5}"
297
298

Archive Download this file

Revision: 333