1 | #!/bin/bash␊ |
2 | ␊ |
3 | # $1 Path to store built package␊ |
4 | ␊ |
5 | packagesidentity="org.chameleon"␊ |
6 | ␊ |
7 | packagename="Chameleon"␊ |
8 | ␊ |
9 | pkgroot="${0%/*}"␊ |
10 | ␊ |
11 | # blackosx to use /usr/local as a place for temporary files␊ |
12 | # taken from http://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard#cite_note-27␊ |
13 | chamTemp="usr/local/chamTemp"␊ |
14 | ␊ |
15 | COL_BLACK="\x1b[30;01m"␊ |
16 | COL_RED="\x1b[31;01m"␊ |
17 | COL_GREEN="\x1b[32;01m"␊ |
18 | COL_YELLOW="\x1b[33;01m"␊ |
19 | COL_MAGENTA="\x1b[35;01m"␊ |
20 | COL_CYAN="\x1b[36;01m"␊ |
21 | COL_WHITE="\x1b[37;01m"␊ |
22 | COL_BLUE="\x1b[34;01m"␊ |
23 | COL_RESET="\x1b[39;49;00m"␊ |
24 | ␊ |
25 | #version=$( grep I386BOOT_CHAMELEONVERSION vers.h | awk '{ print $3 }' | tr -d '\"' )␊ |
26 | version=$( cat version )␊ |
27 | stage=${version##*-}␊ |
28 | revision=$( grep I386BOOT_CHAMELEONREVISION vers.h | awk '{ print $3 }' | tr -d '\"' )␊ |
29 | builddate=$( grep I386BOOT_BUILDDATE vers.h | awk '{ print $3,$4 }' | tr -d '\"' )␊ |
30 | timestamp=$( date -j -f "%Y-%m-%d %H:%M:%S" "${builddate}" "+%s" )␊ |
31 | ␊ |
32 | # =================␊ |
33 | ␊ |
34 | develop=$(awk "NR==6{print;exit}" ${pkgroot}/../CREDITS)␊ |
35 | credits=$(awk "NR==10{print;exit}" ${pkgroot}/../CREDITS)␊ |
36 | pkgdev=$(awk "NR==14{print;exit}" ${pkgroot}/../CREDITS)␊ |
37 | # =================␊ |
38 | ␊ |
39 | distributioncount=0␊ |
40 | xmlindent=0␊ |
41 | ␊ |
42 | indent[0]="\t"␊ |
43 | indent[1]="\t\t"␊ |
44 | indent[2]="\t\t\t"␊ |
45 | indent[3]="\t\t\t\t"␊ |
46 | ␊ |
47 | main ()␊ |
48 | {␊ |
49 | ␊ |
50 | # clean up the destination path␊ |
51 | ␊ |
52 | rm -R -f "${1}"␊ |
53 | echo ""␉␊ |
54 | echo -e $COL_CYAN"␉----------------------------------"$COL_RESET␊ |
55 | echo -e $COL_CYAN"␉Building $packagename Install Package"$COL_RESET␊ |
56 | echo -e $COL_CYAN"␉----------------------------------"$COL_RESET␊ |
57 | echo ""␊ |
58 | ␊ |
59 | outline[$((outlinecount++))]="${indent[$xmlindent]}<choices-outline>"␊ |
60 | ␊ |
61 | # build core package␊ |
62 | ␉echo "================= Core ================="␊ |
63 | ␉((xmlindent++))␊ |
64 | ␉packagesidentity="org.chameleon.core"␊ |
65 | ␉mkdir -p ${1}/Core/Root/usr/local/bin␊ |
66 | ␉mkdir -p ${1}/Core/Root/usr/standalone/i386␊ |
67 | ␉ditto --noextattr --noqtn ${1%/*}/i386/boot ${1}/Core/Root/usr/standalone/i386␊ |
68 | ␉ditto --noextattr --noqtn ${1%/*}/i386/boot0 ${1}/Core/Root/usr/standalone/i386␊ |
69 | ␉ditto --noextattr --noqtn ${1%/*}/i386/boot0md ${1}/Core/Root/usr/standalone/i386␊ |
70 | ␉ditto --noextattr --noqtn ${1%/*}/i386/boot1f32 ${1}/Core/Root/usr/standalone/i386␊ |
71 | ␉ditto --noextattr --noqtn ${1%/*}/i386/boot1h ${1}/Core/Root/usr/standalone/i386␊ |
72 | ␉ditto --noextattr --noqtn ${1%/*}/i386/boot1he ${1}/Core/Root/usr/standalone/i386␊ |
73 | ␉ditto --noextattr --noqtn ${1%/*}/i386/boot1hp ${1}/Core/Root/usr/standalone/i386␊ |
74 | ␉ditto --noextattr --noqtn ${1%/*}/i386/cdboot ${1}/Core/Root/usr/standalone/i386␊ |
75 | ␉ditto --noextattr --noqtn ${1%/*}/i386/chain0 ${1}/Core/Root/usr/standalone/i386␊ |
76 | ␉ditto --noextattr --noqtn ${1%/*}/i386/fdisk440 ${1}/Core/Root/usr/local/bin␊ |
77 | ␉ditto --noextattr --noqtn ${1%/*}/i386/bdmesg ${1}/Core/Root/usr/local/bin␊ |
78 | ␉local coresize=$( du -hkc "${1}/Core/Root" | tail -n1 | awk {'print $1'} )␊ |
79 | ␉echo "␉[BUILD] i386 "␊ |
80 | ␉buildpackage "${1}/Core" "/" "0" "start_visible=\"false\" start_selected=\"true\"" >/dev/null 2>&1␊ |
81 | ␊ |
82 | # build Chameleon package␊ |
83 | ␉echo "================= Chameleon ================="␊ |
84 | ␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"Chameleon\">"␊ |
85 | ␉choices[$((choicescount++))]="<choice\n\tid=\"Chameleon\"\n\ttitle=\"Chameleon_title\"\n\tdescription=\"Chameleon_description\"\n>\n</choice>\n"␊ |
86 | ␊ |
87 | ␉# build standard package ␊ |
88 | ␉␉mkdir -p ${1}/Standard/Root␊ |
89 | ␉␉mkdir -p ${1}/Standard/Scripts/Resources␊ |
90 | ␉␉cp -f ${pkgroot}/Scripts/Main/Standard/* ${1}/Standard/Scripts␊ |
91 | cp -f ${pkgroot}/Scripts/Sub/* ${1}/Standard/Scripts␊ |
92 | ␉␉ditto --arch i386 `which SetFile` ${1}/Standard/Scripts/Resources/SetFile␊ |
93 | ␉␉ditto --noextattr --noqtn ${1%/*/*}/revision ${1}/Standard/Scripts/Resources/revision␊ |
94 | ␉␉ditto --noextattr --noqtn ${1%/*/*}/version ${1}/Standard/Scripts/Resources/version␊ |
95 | ␉␉echo "␉[BUILD] Standard "␊ |
96 | buildpackage "${1}/Standard" "/" "${coresize}" "start_enabled=\"true\" start_selected=\"upgrade_allowed()\" selected=\"exclusive(choices['EFI']) && exclusive(choices['noboot'])\"" >/dev/null 2>&1␊ |
97 | # hh="selected=\"exclusive(choices['EFI']) && exclusive(choices['noboot'])\""␊ |
98 | # buildpackage "${1}/Standard" "/" "${coresize}" "start_enabled=\"true\" start_selected=\"upgrade_allowed()\" ${hh}" >/dev/null 2>&1␊ |
99 | ␉# End build standard package ␊ |
100 | ␊ |
101 | ␉# build efi package ␊ |
102 | ␉␉mkdir -p ${1}/EFI/Root␊ |
103 | ␉␉mkdir -p ${1}/EFI/Scripts/Resources␊ |
104 | ␉␉cp -f ${pkgroot}/Scripts/Main/EFI/* ${1}/EFI/Scripts␊ |
105 | cp -f ${pkgroot}/Scripts/Sub/* ${1}/EFI/Scripts␊ |
106 | ␉␉ditto --arch i386 `which SetFile` ${1}/EFI/Scripts/Resources/SetFile␊ |
107 | ␉␉ditto --noextattr --noqtn ${1%/*/*}/revision ${1}/EFI/Scripts/Resources/revision␊ |
108 | ␉␉ditto --noextattr --noqtn ${1%/*/*}/version ${1}/EFI/Scripts/Resources/version␊ |
109 | ␉␉echo "␉[BUILD] EFI "␊ |
110 | ␉␉buildpackage "${1}/EFI" "/" "${coresize}" "start_visible=\"systemHasGPT()\" start_selected=\"false\" selected=\"exclusive(choices['Standard']) && exclusive(choices['noboot'])\"" >/dev/null 2>&1␊ |
111 | ␉# End build efi package␊ |
112 | ␊ |
113 | ␉# build reset choice package ␊ |
114 | ␉␉mkdir -p ${1}/noboot/Root␊ |
115 | ␉␉echo "␉[BUILD] Reset choice "␊ |
116 | ␉␉buildpackage "${1}/noboot" "/$chamTemp" "" "start_visible=\"true\" start_selected=\"false\" selected=\"exclusive(choices['Standard']) && exclusive(choices['EFI'])\"" >/dev/null 2>&1␊ |
117 | ␉# End build reset choice package ␊ |
118 | ␊ |
119 | ␉# build Modules package␊ |
120 | echo "================= Modules ================="␊ |
121 | ###############################␊ |
122 | # Supported Modules #␊ |
123 | ###############################␊ |
124 | # klibc.dylib #␊ |
125 | # Resolution.dylib #␊ |
126 | # uClibcxx.dylib #␊ |
127 | # Keylayout.dylib #␊ |
128 | ###############################␊ |
129 | if [ "$(ls -A "${1%/*}/i386/modules")" ]; then␊ |
130 | {␊ |
131 | outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"Module\">"␊ |
132 | choices[$((choicescount++))]="<choice\n\tid=\"Module\"\n\ttitle=\"Module_title\"\n\tdescription=\"Module_description\"\n>\n</choice>\n"␊ |
133 | ((xmlindent++))␊ |
134 | packagesidentity="org.chameleon.modules"␊ |
135 | # -␊ |
136 | if [ -e ${1%/*}/i386/modules/klibc.dylib ]; then␊ |
137 | {␊ |
138 | mkdir -p ${1}/klibc/Root␊ |
139 | ditto --noextattr --noqtn ${1%/*}/i386/modules/klibc.dylib ${1}/klibc/Root␊ |
140 | echo "␉[BUILD] klibc "␊ |
141 | buildpackage "${1}/klibc" "/$chamTemp/Extra/modules" "" "start_selected=\"true\"" >/dev/null 2>&1␊ |
142 | }␊ |
143 | fi␊ |
144 | # -␊ |
145 | if [ -e ${1%/*}/i386/modules/Resolution.dylib ]; then␊ |
146 | {␊ |
147 | mkdir -p ${1}/AutoReso/Root␊ |
148 | ditto --noextattr --noqtn ${1%/*}/i386/modules/Resolution.dylib ${1}/AutoReso/Root␊ |
149 | echo "␉[BUILD] Resolution "␊ |
150 | buildpackage "${1}/AutoReso" "/$chamTemp/Extra/modules" "" "start_selected=\"false\"" >/dev/null 2>&1␊ |
151 | }␊ |
152 | fi␊ |
153 | # -␊ |
154 | if [ -e ${1%/*}/i386/modules/uClibcxx.dylib ]; then␊ |
155 | {␊ |
156 | mkdir -p ${1}/uClibc/Root␊ |
157 | ditto --noextattr --noqtn ${1%/*}/i386/modules/uClibcxx.dylib ${1}/uClibc/Root␊ |
158 | ditto --noextattr --noqtn ${1%/*}/i386/modules/klibc.dylib ${1}/uClibc/Root␊ |
159 | echo "␉[BUILD] uClibc++ "␊ |
160 | buildpackage "${1}/uClibc" "/$chamTemp/Extra/modules" "" "start_selected=\"true\"" >/dev/null 2>&1␊ |
161 | }␊ |
162 | fi␊ |
163 | # -␊ |
164 | if [ -e ${1%/*}/i386/modules/Keylayout.dylib ]; then␊ |
165 | {␊ |
166 | mkdir -p ${1}/Keylayout/Root␊ |
167 | ditto --noextattr --noqtn ${1%/*}/i386/modules/Keylayout.dylib ${1}/Keylayout/Root␊ |
168 | echo "␉[BUILD] Keylayout "␊ |
169 | buildpackage "${1}/Keylayout" "/$chamTemp/Extra/modules" "" "start_selected=\"true\"" >/dev/null 2>&1␊ |
170 | }␊ |
171 | fi␊ |
172 | ␊ |
173 | ((xmlindent--))␊ |
174 | outline[$((outlinecount++))]="${indent[$xmlindent]}\t</line>"␊ |
175 | }␊ |
176 | else␊ |
177 | {␊ |
178 | echo " -= no modules to include =-"␊ |
179 | }␊ |
180 | fi␊ |
181 | ␉# End build Modules packages␊ |
182 | ((xmlindent--))␊ |
183 | outline[$((outlinecount++))]="${indent[$xmlindent]}\t</line>"␊ |
184 | # End build Chameleon package␊ |
185 | ␊ |
186 | # build Extras package␊ |
187 | ␉# build options packages␊ |
188 | ␊ |
189 | ␉␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"Options\">"␊ |
190 | ␉␉choices[$((choicescount++))]="<choice\n\tid=\"Options\"\n\ttitle=\"Options_title\"\n\tdescription=\"Options_description\"\n>\n</choice>\n"␊ |
191 | ␉␉((xmlindent++))␊ |
192 | ␊ |
193 | ␉␉# ------------------------------------------------------␊ |
194 | ␉␉# parse BootOptions folder to find files of boot options.␊ |
195 | ␉␉# ------------------------------------------------------␊ |
196 | ␉␉bootOptionsFolder="${pkgroot}/BootOptions"␊ |
197 | ␉␉bootOptionFiles=($( find "${bootOptionsFolder}" -depth 1 -not -name '.svn' ))␊ |
198 | ␊ |
199 | ␉␉for (( i = 0 ; i < ${#bootOptionFiles[@]} ; i++ ))␊ |
200 | ␉␉do␊ |
201 | ␊ |
202 | ␉␉␉# Take filename and Strip .txt from end and path from front␊ |
203 | ␉␉␉builtOptionsFolderName=$( echo ${bootOptionFiles[$i]%.txt} )␊ |
204 | ␉␉␉builtOptionsFolderName=$( echo ${builtOptionsFolderName##*/} )␊ |
205 | ␉␉␉echo "================= $builtOptionsFolderName ================="␊ |
206 | ␊ |
207 | ␉␉␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"${builtOptionsFolderName}\">"␊ |
208 | ␉␉␉choices[$((choicescount++))]="<choice\n\tid=\"${builtOptionsFolderName}\"\n\ttitle=\"${builtOptionsFolderName}_title\"\n\tdescription=\"${builtOptionsFolderName}_description\"\n>\n</choice>\n"␊ |
209 | ␉␉␉((xmlindent++))␊ |
210 | ␉␉␉packagesidentity="org.chameleon.options.$builtOptionsFolderName"␊ |
211 | ␊ |
212 | ␉␉␉# ------------------------------------------------------␊ |
213 | ␉␉␉# Read boot option file. for example, Resolutions.txt.␊ |
214 | ␉␉␉# Each line in the file is a boot option to add.␊ |
215 | ␉␉␉# Structure of boot option in file is name:key=value␊ |
216 | ␉␉␉# ------------------------------------------------------␊ |
217 | ␉␉␉while read textLine␊ |
218 | ␉␉␉do␊ |
219 | ␉␉␉␉# split line - taking all before ':' as option name␊ |
220 | ␉␉␉␉# and all after ':' as key/value␊ |
221 | ␉␉␉␉optionName=${textLine%:*}␊ |
222 | ␉␉␉␉keyValue=${textLine##*:}␊ |
223 | ␊ |
224 | ␉␉␉␉# create folders required for each boot option␊ |
225 | ␉␉␉␉mkdir -p "${1}/$optionName/Root/"␊ |
226 | ␊ |
227 | ␉␉␉␉# create dummy file with name of key/value␊ |
228 | ␉␉␉␉echo "" > "${1}/$optionName/Root/${keyValue}"␊ |
229 | ␊ |
230 | ␉␉␉␉echo "␉[BUILD] ${optionName} "␊ |
231 | ␊ |
232 | ␉␉␉␉# ------------------------------------------------------␊ |
233 | ␉␉␉␉# Before calling buildpackage, see if any bootOptionFiles␊ |
234 | # have requested being set to exclusive.␊ |
235 | ␉␉␉␉# Manually set for now to 'Resolutions'.␊ |
236 | # It can eventually be non-specifc by adding a dedicated␊ |
237 | # field at the top of each bootOptionFiles to indicate␊ |
238 | # if the set should be exclusive or not.␊ |
239 | # ------------------------------------------------------␊ |
240 | # Note: This currently fails to achieve the desired effect?␊ |
241 | # I'll improve the code etc. once (if) I can get it working!␊ |
242 | ␉␉␉␉# ------------------------------------------------------␊ |
243 | ␉␉␉␉if [ $builtOptionsFolderName = "Resolution" ]; then␊ |
244 | ␉␉␉␉␉# build a list of all resolutions but exclude current resolution.␊ |
245 | ␉␉␉␉␉arrayCount=0␊ |
246 | ␉␉␉␉␉while read textLineTemp␊ |
247 | ␉␉␉␉␉do␊ |
248 | ␉␉␉␉␉␉optionNameTemp=${textLineTemp%:*}␊ |
249 | ␉␉␉␉␉␉if [ $optionNameTemp != $optionName ]; then␊ |
250 | ␉␉␉␉␉␉␉resolutionArray[arrayCount]=$optionNameTemp␊ |
251 | ␉␉␉␉␉␉␉((arrayCount++))␊ |
252 | ␉␉␉␉␉␉fi␊ |
253 | ␉␉␉␉␉done < ${bootOptionFiles[$i]}␊ |
254 | ␊ |
255 | ␉␉␉␉␉# Build exclusive string␊ |
256 | ␉␉␉␉␉stringStart="selected=\""␊ |
257 | stringBefore="exclusive(choices['"␊ |
258 | ␉␉␉␉␉stringAfter="']) && "␊ |
259 | ␉␉␉␉␉stringEnd="'])\""␊ |
260 | x=${stringStart}${stringBefore}␊ |
261 | ␊ |
262 | totalItems="${#resolutionArray[@]}"␊ |
263 | lastItem=$((totalItems-1))␊ |
264 | ␊ |
265 | ␉␉␉␉␉for (( r = 0 ; r < ${#resolutionArray[@]} ; r++ ))␊ |
266 | ␉␉␉␉␉do␊ |
267 | x="${x}${resolutionArray[r]}"␊ |
268 | # Only add these to end of string up to the one before the last item␊ |
269 | if [ $r -lt $lastItem ]; then␊ |
270 | x="${x}${stringAfter}${stringBefore}"␊ |
271 | fi␊ |
272 | ␉␉␉␉␉done␊ |
273 | x="${x}${stringEnd}"␊ |
274 | buildpackage "${1}/${optionName}" "/$chamTemp/options" "" "start_selected=\"false\"" ${x} >/dev/null 2>&1␊ |
275 | ␉␉␉␉else␊ |
276 | ␉␉␉␉␉buildpackage "${1}/${optionName}" "/$chamTemp/options" "" "start_selected=\"false\"" >/dev/null 2>&1␊ |
277 | ␉␉␉␉fi␊ |
278 | ␊ |
279 | ␉␉␉done < ${bootOptionFiles[$i]}␊ |
280 | ␊ |
281 | ␉␉␉((xmlindent--))␊ |
282 | ␉␉␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t</line>"␊ |
283 | ␉␉done␊ |
284 | ␊ |
285 | ␉␉# build KeyLayout options packages␊ |
286 | ␉␉␉echo "================= Keymaps Options ================="␊ |
287 | ␉␉␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"KeyLayout\">"␊ |
288 | ␉␉␉choices[$((choicescount++))]="<choice\n\tid=\"KeyLayout\"\n\ttitle=\"KeyLayout_title\"\n\tdescription=\"KeyLayout_description\"\n>\n</choice>\n"␊ |
289 | ␉␉␉((xmlindent++))␊ |
290 | ␉␉␉packagesidentity="org.chameleon.options.keylayout"␊ |
291 | ␉␉␉keymaps=($( find "${1%/sym/*}/Keymaps" -type f -depth 1 -name '*.lyt' | sed 's|.*/||;s|\.lyt||' ))␊ |
292 | ␉␉␉for (( i = 0 ; i < ${#keymaps[@]} ; i++ ))␊ |
293 | ␉␉␉do␊ |
294 | ␉␉␉␉mkdir -p "${1}/${keymaps[$i]##*/}/Root/"␊ |
295 | ␉␉␉␉echo "dummy file" >"${1}/${keymaps[$i]##*/}/Root/KeyLayout=${keymaps[$i]##*/}"␊ |
296 | ␉␉␉␉echo "␉[BUILD] ${keymaps[$i]##*/} "␊ |
297 | ␉␉␉␉buildpackage "${1}/${keymaps[$i]##*/}" "/$chamTemp/options" "" "start_selected=\"false\"" >/dev/null 2>&1␊ |
298 | ␉␉␉done␊ |
299 | ␉␉␉((xmlindent--))␊ |
300 | ␉␉␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t</line>"␊ |
301 | ␊ |
302 | ␉␉# End build KeyLayout options packages␊ |
303 | ␊ |
304 | ␉␉((xmlindent--))␊ |
305 | ␉␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t</line>"␊ |
306 | ␊ |
307 | ␉# End build options packages␊ |
308 | ␊ |
309 | ␉# build theme packages␊ |
310 | ␉␉echo "================= Themes ================="␊ |
311 | ␉␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"Themes\">"␊ |
312 | ␉␉choices[$((choicescount++))]="<choice\n\tid=\"Themes\"\n\ttitle=\"Themes_title\"\n\tdescription=\"Themes_description\"\n>\n</choice>\n"␊ |
313 | ␉␉((xmlindent++))␊ |
314 | ␊ |
315 | ␉␉# Using themes section from Azi's/package branch.␊ |
316 | ␉␉packagesidentity="org.chameleon.themes"␊ |
317 | ␉␉artwork="${1%/sym/package}/artwork/themes"␊ |
318 | ␉␉themes=($( find "${artwork}" -type d -depth 1 -not -name '.svn' ))␊ |
319 | ␉␉for (( i = 0 ; i < ${#themes[@]} ; i++ )) ␊ |
320 | ␉␉do␊ |
321 | ␉␉␉theme=$( echo ${themes[$i]##*/} | awk 'BEGIN{OFS=FS=""}{$1=toupper($1);print}' )␊ |
322 | ␉␉␉mkdir -p "${1}/${theme}/Root/"␊ |
323 | ␉␉␉rsync -r --exclude=.svn "${themes[$i]}/" "${1}/${theme}/Root/${theme}"␊ |
324 | ␉␉␉echo "␉[BUILD] ${theme}"␊ |
325 | ␉␉␉buildpackage "${1}/${theme}" "/$chamTemp/Extra/Themes" "" "start_selected=\"false\"" >/dev/null 2>&1␊ |
326 | ␉␉done␊ |
327 | ␊ |
328 | ␉␉((xmlindent--))␊ |
329 | ␉␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t</line>"␊ |
330 | ␉# End build theme packages␊ |
331 | # End build Extras package␊ |
332 | ␊ |
333 | # build post install package␊ |
334 | ␉echo "================= Post ================="␊ |
335 | ␉mkdir -p ${1}/Post/Root␊ |
336 | ␉mkdir -p ${1}/Post/Scripts␊ |
337 | ␉cp -f ${pkgroot}/Scripts/Main/Post/* ${1}/Post/Scripts␊ |
338 | ␉echo "␉[BUILD] Post "␊ |
339 | ␉buildpackage "${1}/Post" "/" "" "start_visible=\"false\" start_selected=\"true\"" >/dev/null 2>&1␊ |
340 | ␉outline[$((outlinecount++))]="${indent[$xmlindent]}</choices-outline>"␊ |
341 | ␊ |
342 | # build meta package␊ |
343 | ␊ |
344 | ␉makedistribution "${1}" "${2}" "${3}" "${4}" "${5}"␊ |
345 | ␊ |
346 | # clean up ␊ |
347 | ␊ |
348 | ␉#rm -R -f "${1}"␊ |
349 | ␊ |
350 | }␊ |
351 | ␊ |
352 | fixperms ()␊ |
353 | {␊ |
354 | ␉# $1 path␊ |
355 | ␉find "${1}" -type f -exec chmod 644 {} \;␊ |
356 | ␉find "${1}" -type d -exec chmod 755 {} \;␊ |
357 | ␉chown -R 0:0 "${1}"␊ |
358 | }␊ |
359 | ␊ |
360 | buildpackage ()␊ |
361 | {␊ |
362 | # $1 Path to package to build containing Root and or Scripts␊ |
363 | # $2 Install Location␊ |
364 | # $3 Size␊ |
365 | # $4 Options␊ |
366 | ␊ |
367 | if [ -d "${1}/Root" ] && [ "${1}/Scripts" ]; then␊ |
368 | ␊ |
369 | ␉local packagename="${1##*/}"␊ |
370 | ␉local identifier=$( echo ${packagesidentity}.${packagename//_/.} | tr [:upper:] [:lower:] )␊ |
371 | ␉find "${1}" -name '.DS_Store' -delete␊ |
372 | ␉local filecount=$( find "${1}/Root" | wc -l )␊ |
373 | ␉if [ "${3}" ]; then␊ |
374 | ␉␉local installedsize="${3}"␊ |
375 | ␉else␊ |
376 | ␉␉local installedsize=$( du -hkc "${1}/Root" | tail -n1 | awk {'print $1'} )␊ |
377 | ␉fi␊ |
378 | ␉local header="<?xml version=\"1.0\"?>\n<pkg-info format-version=\"2\" "␊ |
379 | ␊ |
380 | ␉#[ "${3}" == "relocatable" ] && header+="relocatable=\"true\" "␉␉␊ |
381 | ␊ |
382 | ␉header+="identifier=\"${identifier}\" "␊ |
383 | ␉header+="version=\"${version}\" "␊ |
384 | ␊ |
385 | ␉[ "${2}" != "relocatable" ] && header+="install-location=\"${2}\" "␊ |
386 | ␊ |
387 | ␉header+="auth=\"root\">\n"␊ |
388 | ␉header+="\t<payload installKBytes=\"${installedsize##* }\" numberOfFiles=\"${filecount##* }\"/>\n"␊ |
389 | ␉#rm -R -f "${1}/Temp"␊ |
390 | ␊ |
391 | ␉[ -d "${1}/Temp" ] || mkdir -m 777 "${1}/Temp"␊ |
392 | ␉[ -d "${1}/Root" ] && mkbom "${1}/Root" "${1}/Temp/Bom"␊ |
393 | ␊ |
394 | ␉if [ -d "${1}/Scripts" ]; then ␊ |
395 | ␉␉header+="\t<scripts>\n"␊ |
396 | ␉␉for script in $( find "${1}/Scripts" -type f \( -name 'pre*' -or -name 'post*' \) )␊ |
397 | ␉␉do␊ |
398 | ␉␉␉header+="\t\t<${script##*/} file=\"./${script##*/}\"/>\n"␊ |
399 | ␉␉done␊ |
400 | ␉␉header+="\t</scripts>\n"␊ |
401 | ␉␉chown -R 0:0 "${1}/Scripts"␊ |
402 | ␉␉pushd "${1}/Scripts" >/dev/null␊ |
403 | ␉␉find . -print | cpio -o -z -H cpio > "../Temp/Scripts"␊ |
404 | ␉␉popd >/dev/null␊ |
405 | ␉fi␊ |
406 | ␊ |
407 | ␉header+="</pkg-info>"␊ |
408 | ␉echo -e "${header}" >> ~/Desktop/header␊ |
409 | ␉echo -e "${header}" > "${1}/Temp/PackageInfo"␊ |
410 | ␉pushd "${1}/Root" >/dev/null␊ |
411 | ␉find . -print | cpio -o -z -H cpio > "../Temp/Payload"␊ |
412 | ␉popd >/dev/null␊ |
413 | ␉pushd "${1}/Temp" >/dev/null␊ |
414 | ␊ |
415 | ␉xar -c -f "${1%/*}/${packagename// /}.pkg" --compression none .␊ |
416 | ␊ |
417 | ␉popd >/dev/null␊ |
418 | ␊ |
419 | ␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"${packagename// /}\"/>"␊ |
420 | ␊ |
421 | ␉if [ "${4}" ]; then␊ |
422 | ␉␉local choiceoptions="${indent[$xmlindent]}${4}\n"␉␊ |
423 | ␉fi␊ |
424 | ␉choices[$((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"␊ |
425 | ␊ |
426 | ␉#rm -R -f "${1}"␊ |
427 | fi␊ |
428 | }␊ |
429 | ␊ |
430 | makedistribution ()␊ |
431 | {␊ |
432 | ␉rm -f "${1%/*}/${packagename// /}"*.pkg␊ |
433 | ␊ |
434 | ␉find "${1}" -type f -name '*.pkg' -depth 1 | while read component␊ |
435 | ␉do␊ |
436 | ␉␉mkdir -p "${1}/${packagename}/${component##*/}"␊ |
437 | ␉␉pushd "${1}/${packagename}/${component##*/}" >/dev/null␊ |
438 | ␉␉xar -x -f "${1%}/${component##*/}"␊ |
439 | ␉␉popd >/dev/null␊ |
440 | ␉done␊ |
441 | ␊ |
442 | ␉ditto --noextattr --noqtn "${pkgroot}/Distribution" "${1}/${packagename}/Distribution"␊ |
443 | ␉ditto --noextattr --noqtn "${pkgroot}/Resources" "${1}/${packagename}/Resources"␊ |
444 | ␊ |
445 | ␉find "${1}/${packagename}/Resources" -type d -name '.svn' -exec rm -R -f {} \; 2>/dev/null␊ |
446 | ␊ |
447 | ␉for (( i=0; i < ${#outline[*]} ; i++));␊ |
448 | ␉␉do␊ |
449 | ␉␉␉echo -e "${outline[$i]}" >> "${1}/${packagename}/Distribution"␊ |
450 | ␉␉done␊ |
451 | ␊ |
452 | ␉for (( i=0; i < ${#choices[*]} ; i++));␊ |
453 | ␉␉do␊ |
454 | ␉␉␉echo -e "${choices[$i]}" >> "${1}/${packagename}/Distribution"␊ |
455 | ␉␉done␊ |
456 | ␊ |
457 | ␉echo "</installer-gui-script>" >> "${1}/${packagename}/Distribution"␊ |
458 | ␊ |
459 | ␉perl -i -p -e "s/%CHAMELEONVERSION%/${version%%-*}/g" `find "${1}/${packagename}/Resources" -type f`␊ |
460 | ␉perl -i -p -e "s/%CHAMELEONREVISION%/${revision}/g" `find "${1}/${packagename}/Resources" -type f`␊ |
461 | ␊ |
462 | # Adding Developer and credits␊ |
463 | ␉perl -i -p -e "s/%DEVELOP%/${develop}/g" `find "${1}/${packagename}/Resources" -type f`␊ |
464 | ␉perl -i -p -e "s/%CREDITS%/${credits}/g" `find "${1}/${packagename}/Resources" -type f`␊ |
465 | ␉perl -i -p -e "s/%PKGDEV%/${pkgdev}/g" `find "${1}/${packagename}/Resources" -type f`␊ |
466 | ␊ |
467 | ␉stage=${stage/RC/Release Candidate }␊ |
468 | ␉stage=${stage/FINAL/2.0 Final}␊ |
469 | ␉perl -i -p -e "s/%CHAMELEONSTAGE%/${stage}/g" `find "${1}/${packagename}/Resources" -type f`␊ |
470 | ␊ |
471 | ␉find "${1}/${packagename}" -name '.DS_Store' -delete␊ |
472 | ␉pushd "${1}/${packagename}" >/dev/null␊ |
473 | ␉xar -c -f "${1%/*}/${packagename// /}-${version}-r${revision}.pkg" --compression none .␊ |
474 | ␉popd >/dev/null␊ |
475 | ␊ |
476 | # Here is the place for assign a Icon to the pkg␊ |
477 | # command use to generate the file:␊ |
478 | # ditto -c -k --sequesterRsrc --keepParent Icon.icns Icon.zip␊ |
479 | # ----␊ |
480 | # ditto -xk "${pkgroot}/Icons/pkg.zip" "${pkgroot}/Icons/"␊ |
481 | # DeRez -only icns "${pkgroot}/Icons/Icons/pkg.icns" > tempicns.rsrc␊ |
482 | # Rez -append tempicns.rsrc -o "${1%/*}/$packagename-${version}-r$revision.pkg"␊ |
483 | # SetFile -a C "${1%/*}/$packagename-${version}-r$revision.pkg"␊ |
484 | # rm -f tempicns.rsrc␊ |
485 | # rm -rf "${pkgroot}/Icons/Icons"␊ |
486 | # End␊ |
487 | ␊ |
488 | ␉md5=$( md5 "${1%/*}/${packagename// /}-${version}-r${revision}.pkg" | awk {'print $4'} )␊ |
489 | ␉echo "MD5 (${packagename// /}-${version}-r${revision}.pkg) = ${md5}" > "${1%/*}/${packagename// /}-${version}-r${revision}.pkg.md5"␊ |
490 | ␉echo ""␉␊ |
491 | ␊ |
492 | ␉echo -e $COL_GREEN"␉--------------------------"$COL_RESET␊ |
493 | ␉echo -e $COL_GREEN"␉Building process complete!"$COL_RESET␊ |
494 | ␉echo -e $COL_GREEN"␉--------------------------"$COL_RESET␊ |
495 | ␉echo ""␉␊ |
496 | ␉echo -e $COL_GREEN"␉Build info."␊ |
497 | ␉echo -e $COL_GREEN"␉==========="␊ |
498 | ␉echo -e $COL_BLUE"␉Package name:␉"$COL_RESET"$packagename-${version}-r$revision.pkg"␊ |
499 | ␉echo -e $COL_BLUE"␉MD5:␉␉"$COL_RESET"$md5"␊ |
500 | ␉echo -e $COL_BLUE"␉Version:␉"$COL_RESET"$version"␊ |
501 | ␉echo -e $COL_BLUE"␉Stage:␉␉"$COL_RESET"$stage"␊ |
502 | ␉echo -e $COL_BLUE"␉Date/Time:␉"$COL_RESET"$builddate"␊ |
503 | ␉echo ""␊ |
504 | ␊ |
505 | }␊ |
506 | ␊ |
507 | main "${1}" "${2}" "${3}" "${4}" "${5}"␊ |
508 | ␊ |
509 | |