Chameleon

Chameleon Svn Source Tree

Root/tags/2.1/package/slimpkg.sh

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

Archive Download this file

Revision: 2403