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