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 | declare -a pkgrefs␊ |
43 | ␊ |
44 | # Package identifiers␊ |
45 | modules_packages_identity="org.chameleon.modules"␊ |
46 | ␊ |
47 | getPackageRefId () {␊ |
48 | echo ${1//_/.}.${2//_/.} | tr [:upper:] [:lower:]␊ |
49 | }␊ |
50 | ␊ |
51 | addChoice () {␊ |
52 | # $1 Choice Id␊ |
53 | # $2 Choice Options␊ |
54 | # $3..$n Package reference id (optional)␊ |
55 | local choiceId="${1}"␊ |
56 | local choiceOptions="${2}"␊ |
57 | local choiceNode="\t<choice\n\t\tid=\"${choiceId}\"\n\t\ttitle=\"${choiceId}_title\"\n\t\tdescription=\"${choiceId}_description\""␊ |
58 | [[ -n "${choiceOptions}" ]] && choiceNode="${choiceNode}\n\t\t${choiceOptions}"␊ |
59 | choiceNode="${choiceNode}>"␊ |
60 | if [[ $# -ge 3 ]];then␊ |
61 | for pkgRefId in ${@:3};do␊ |
62 | choiceNode="${choiceNode}\n\t\t<pkg-ref id=\"${pkgRefId}\"/>"␊ |
63 | done␊ |
64 | fi␊ |
65 | choiceNode="${choiceNode}\n\t</choice>\n"␊ |
66 | ␊ |
67 | outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"${choiceId}\"/>"␊ |
68 | choices[$((choicescount++))]="$choiceNode"␊ |
69 | }␊ |
70 | ␊ |
71 | exclusive_one_choice () {␊ |
72 | # $1 Current choice (ie: test1)␊ |
73 | # $2..$n Others choice(s) (ie: "test2" "test3"). Current can or can't be in the others choices␊ |
74 | local myChoice="${1}"␊ |
75 | local result;␊ |
76 | local separator=' || ';␊ |
77 | for choice in ${@:2};do␊ |
78 | if [[ "$choice" != "$myChoice" ]];then␊ |
79 | result="${result}choices['$choice'].selected${separator}";␊ |
80 | fi␊ |
81 | done␊ |
82 | echo "!(${result%$separator})"␊ |
83 | }␊ |
84 | ␊ |
85 | exclusive_zero_or_one_choice () {␊ |
86 | # $1 Current choice (ie: test1)␊ |
87 | # $2..$n Others choice(s) (ie: "test2" "test3"). Current can or can't be in the others choices␊ |
88 | local myChoice="${1}"␊ |
89 | local result;␊ |
90 | echo "(my.choice.selected && $(exclusive_one_choice ${@}))"␊ |
91 | }␊ |
92 | ␊ |
93 | main ()␊ |
94 | {␊ |
95 | ␊ |
96 | # clean up the destination path␊ |
97 | ␊ |
98 | rm -R -f "${1}"␊ |
99 | echo ""␊ |
100 | echo -e $COL_CYAN" ----------------------------------"$COL_RESET␊ |
101 | echo -e $COL_CYAN" Building $packagename Install Package"$COL_RESET␊ |
102 | echo -e $COL_CYAN" ----------------------------------"$COL_RESET␊ |
103 | echo ""␊ |
104 | ␊ |
105 | outline[$((outlinecount++))]="${indent[$xmlindent]}<choices-outline>"␊ |
106 | ␊ |
107 | # build pre install package␊ |
108 | echo "================= Preinstall ================="␊ |
109 | ((xmlindent++))␊ |
110 | packagesidentity="org.chameleon"␊ |
111 | choiceId="Pre"␊ |
112 | mkdir -p ${1}/${choiceId}/Root␊ |
113 | mkdir -p ${1}/${choiceId}/Scripts␊ |
114 | ditto --noextattr --noqtn ${1%/*/*}/revision ${1}/${choiceId}/Scripts/Resources/revision␊ |
115 | ditto --noextattr --noqtn ${1%/*/*}/version ${1}/${choiceId}/Scripts/Resources/version␊ |
116 | cp -f ${pkgroot}/Scripts/Main/preinstall ${1}/${choiceId}/Scripts␊ |
117 | cp -f ${pkgroot}/Scripts/Sub/InstallLog.sh ${1}/${choiceId}/Scripts␊ |
118 | echo -e "\t[BUILD] ${choiceId} "␊ |
119 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
120 | buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/"␊ |
121 | addChoice "${choiceId}" "start_visible=\"false\" start_selected=\"true\"" "$packageRefId"␊ |
122 | # End build pre install package␊ |
123 | ␊ |
124 | # build core package␊ |
125 | echo "================= Core ================="␊ |
126 | packagesidentity="org.chameleon"␊ |
127 | choiceId="Core"␊ |
128 | mkdir -p ${1}/${choiceId}/Root/usr/local/bin␊ |
129 | mkdir -p ${1}/${choiceId}/Root/usr/standalone/i386␊ |
130 | ditto --noextattr --noqtn ${1%/*}/i386/boot ${1}/${choiceId}/Root/usr/standalone/i386␊ |
131 | ditto --noextattr --noqtn ${1%/*}/i386/boot0 ${1}/${choiceId}/Root/usr/standalone/i386␊ |
132 | ditto --noextattr --noqtn ${1%/*}/i386/boot0md ${1}/${choiceId}/Root/usr/standalone/i386␊ |
133 | ditto --noextattr --noqtn ${1%/*}/i386/boot1f32 ${1}/${choiceId}/Root/usr/standalone/i386␊ |
134 | ditto --noextattr --noqtn ${1%/*}/i386/boot1h ${1}/${choiceId}/Root/usr/standalone/i386␊ |
135 | ditto --noextattr --noqtn ${1%/*}/i386/boot1he ${1}/${choiceId}/Root/usr/standalone/i386␊ |
136 | ditto --noextattr --noqtn ${1%/*}/i386/boot1hp ${1}/${choiceId}/Root/usr/standalone/i386␊ |
137 | ditto --noextattr --noqtn ${1%/*}/i386/cdboot ${1}/${choiceId}/Root/usr/standalone/i386␊ |
138 | ditto --noextattr --noqtn ${1%/*}/i386/chain0 ${1}/${choiceId}/Root/usr/standalone/i386␊ |
139 | ditto --noextattr --noqtn ${1%/*}/i386/fdisk440 ${1}/${choiceId}/Root/usr/local/bin␊ |
140 | ditto --noextattr --noqtn ${1%/*}/i386/bdmesg ${1}/${choiceId}/Root/usr/local/bin␊ |
141 | echo -e "\t[BUILD] ${choiceId} "␊ |
142 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
143 | buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/"␊ |
144 | addChoice "${choiceId}" "start_visible=\"false\" start_selected=\"true\"" "$packageRefId"␊ |
145 | # End build core package␊ |
146 | ␊ |
147 | # build install type␊ |
148 | echo "================= Chameleon ================="␊ |
149 | outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"InstallType\">"␊ |
150 | choices[$((choicescount++))]="\t<choice\n\t\tid=\"InstallType\"\n\t\ttitle=\"InstallType_title\"\n\t\tdescription=\"InstallType_description\">\n\t</choice>\n"␊ |
151 | ((xmlindent++))␊ |
152 | packagesidentity="org.chameleon.type"␊ |
153 | allChoices="New Upgrade"␊ |
154 | ␊ |
155 | # build new install package␊ |
156 | choiceId="New"␊ |
157 | mkdir -p ${1}/${choiceId}/Root␊ |
158 | echo "" > "${1}/${choiceId}/Root/install_type_new"␊ |
159 | echo -e "\t[BUILD] ${choiceId} "␊ |
160 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
161 | buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp"␊ |
162 | exclusiveChoice=$(exclusive_one_choice "$choiceId" "$allChoices")␊ |
163 | addChoice "${choiceId}" "start_selected=\"!choices['Upgrade'].selected\" selected=\"${exclusiveChoice}\"" "$packageRefId"␊ |
164 | # End build new install package␊ |
165 | ␊ |
166 | # build upgrade package␊ |
167 | choiceId="Upgrade"␊ |
168 | mkdir -p ${1}/${choiceId}/Root␊ |
169 | echo "" > "${1}/${choiceId}/Root/install_type_upgrade"␊ |
170 | echo -e "\t[BUILD] ${choiceId} "␊ |
171 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
172 | buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp"␊ |
173 | exclusiveChoice=$(exclusive_one_choice "$choiceId" "$allChoices")␊ |
174 | addChoice "${choiceId}" "start_selected=\"chameleon_boot_plist_exists()\" selected=\"${exclusiveChoice}\"" "$packageRefId"␊ |
175 | # End build upgrade package␊ |
176 | ␊ |
177 | ((xmlindent--))␊ |
178 | outline[$((outlinecount++))]="${indent[$xmlindent]}</line>"␊ |
179 | # End build install type␊ |
180 | ␊ |
181 | # build Chameleon package␊ |
182 | echo "================= Chameleon ================="␊ |
183 | outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"Chameleon\">"␊ |
184 | choices[$((choicescount++))]="\t<choice\n\t\tid=\"Chameleon\"\n\t\ttitle=\"Chameleon_title\"\n\t\tdescription=\"Chameleon_description\">\n\t</choice>\n"␊ |
185 | ((xmlindent++))␊ |
186 | ␊ |
187 | allChoices="Standard EFI noboot"␊ |
188 | ␊ |
189 | # build standard package␊ |
190 | choiceId="Standard"␊ |
191 | mkdir -p ${1}/${choiceId}/Root␊ |
192 | mkdir -p ${1}/${choiceId}/Scripts/Resources␊ |
193 | cp -f ${pkgroot}/Scripts/Main/${choiceId}postinstall ${1}/${choiceId}/Scripts/postinstall␊ |
194 | cp -f ${pkgroot}/Scripts/Sub/* ${1}/${choiceId}/Scripts␊ |
195 | ditto --arch i386 `which SetFile` ${1}/${choiceId}/Scripts/Resources/SetFile␊ |
196 | echo -e "\t[BUILD] ${choiceId} "␊ |
197 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
198 | buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/"␊ |
199 | exclusiveChoice=$(exclusive_one_choice "$choiceId" "$allChoices")␊ |
200 | addChoice "${choiceId}" "start_selected=\"true\" selected=\"${exclusiveChoice}\"" "$packageRefId"␊ |
201 | # End build standard package␊ |
202 | ␊ |
203 | # build efi package␊ |
204 | choiceId="EFI"␊ |
205 | mkdir -p ${1}/${choiceId}/Root␊ |
206 | mkdir -p ${1}/${choiceId}/Scripts/Resources␊ |
207 | cp -f ${pkgroot}/Scripts/Main/ESPpostinstall ${1}/${choiceId}/Scripts/postinstall␊ |
208 | cp -f ${pkgroot}/Scripts/Sub/* ${1}/${choiceId}/Scripts␊ |
209 | ditto --arch i386 `which SetFile` ${1}/${choiceId}/Scripts/Resources/SetFile␊ |
210 | echo -e "\t[BUILD] ${choiceId} "␊ |
211 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
212 | buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/"␊ |
213 | exclusiveChoice=$(exclusive_one_choice "$choiceId" "$allChoices")␊ |
214 | addChoice "${choiceId}" "start_visible=\"systemHasGPT()\" start_selected=\"false\" selected=\"${exclusiveChoice}\"" "$packageRefId"␊ |
215 | # End build efi package␊ |
216 | ␊ |
217 | # build no bootloader choice package␊ |
218 | choiceId="noboot"␊ |
219 | mkdir -p ${1}/${choiceId}/Root␊ |
220 | echo -e "\t[BUILD] ${choiceId} "␊ |
221 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
222 | buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/"␊ |
223 | exclusiveChoice=$(exclusive_one_choice "$choiceId" "$allChoices")␊ |
224 | addChoice "${choiceId}" "start_selected=\"false\" selected=\"${exclusiveChoice}\"" "$packageRefId"␊ |
225 | # End build no bootloader choice package␊ |
226 | ␊ |
227 | ((xmlindent--))␊ |
228 | outline[$((outlinecount++))]="${indent[$xmlindent]}</line>"␊ |
229 | # End build Chameleon package␊ |
230 | ␊ |
231 | # build Modules package␊ |
232 | echo "================= Modules ================="␊ |
233 | ###############################␊ |
234 | # Supported Modules #␊ |
235 | ###############################␊ |
236 | # klibc.dylib #␊ |
237 | # Resolution.dylib #␊ |
238 | # uClibcxx.dylib #␊ |
239 | # Keylayout.dylib #␊ |
240 | ###############################␊ |
241 | if [ "$(ls -A "${1%/*}/i386/modules")" ]; then␊ |
242 | {␊ |
243 | outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"Module\">"␊ |
244 | choices[$((choicescount++))]="\t<choice\n\t\tid=\"Module\"\n\t\ttitle=\"Module_title\"\n\t\tdescription=\"Module_description\">\n\t</choice>\n"␊ |
245 | ((xmlindent++))␊ |
246 | ␊ |
247 | # -␊ |
248 | if [ -e ${1%/*}/i386/modules/klibc.dylib ]; then␊ |
249 | {␊ |
250 | # Start build klibc package module␊ |
251 | choiceId="klibc"␊ |
252 | mkdir -p ${1}/${choiceId}/Root␊ |
253 | ditto --noextattr --noqtn ${1%/*}/i386/modules/${choiceId}.dylib ${1}/${choiceId}/Root␊ |
254 | echo -e "\t[BUILD] ${choiceId} "␊ |
255 | packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")␊ |
256 | buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp/Extra/modules"␊ |
257 | addChoice "${choiceId}" "start_selected=\"false\"" "$packageRefId"␊ |
258 | # End build klibc package module␊ |
259 | }␊ |
260 | fi␊ |
261 | ␊ |
262 | # -␊ |
263 | if [ -e ${1%/*}/i386/modules/Resolution.dylib ]; then␊ |
264 | {␊ |
265 | # Start build Resolution package module␊ |
266 | choiceId="AutoReso"␊ |
267 | mkdir -p ${1}/${choiceId}/Root␊ |
268 | ditto --noextattr --noqtn ${1%/*}/i386/modules/Resolution.dylib ${1}/${choiceId}/Root␊ |
269 | echo -e "\t[BUILD] ${choiceId} "␊ |
270 | packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")␊ |
271 | buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp/Extra/modules"␊ |
272 | addChoice "${choiceId}" "start_selected=\"false\"" "$packageRefId"␊ |
273 | # End build Resolution package module␊ |
274 | }␊ |
275 | fi␊ |
276 | ␊ |
277 | # -␊ |
278 | if [ -e ${1%/*}/i386/modules/uClibcxx.dylib ]; then␊ |
279 | {␊ |
280 | # Start build uClibc package module␊ |
281 | choiceId="uClibc"␊ |
282 | mkdir -p ${1}/${choiceId}/Root␊ |
283 | ditto --noextattr --noqtn ${1%/*}/i386/modules/uClibcxx.dylib ${1}/${choiceId}/Root␊ |
284 | echo -e "\t[BUILD] ${choiceId} "␊ |
285 | packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")␊ |
286 | buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp/Extra/modules"␊ |
287 | # Add the klibc package because the uClibc module is dependent of klibc module␊ |
288 | addChoice "${choiceId}" "start_selected=\"false\"" \␊ |
289 | "$packageRefId" $(getPackageRefId "${modules_packages_identity}" "klibc")␊ |
290 | # End build uClibc package module␊ |
291 | }␊ |
292 | fi␊ |
293 | ␊ |
294 | # -␊ |
295 | # Warning Keylayout module need additional files␊ |
296 | if [ -e ${1%/*}/i386/modules/Keylayout.dylib ]; then␊ |
297 | {␊ |
298 | # Start build Keylayout package module␊ |
299 | choiceId="Keylayout"␊ |
300 | mkdir -p ${1}/${choiceId}/Root/Extra/{modules,Keymaps}␊ |
301 | mkdir -p ${1}/${choiceId}/Root/usr/local/bin␊ |
302 | layout_src_dir="${1%/sym/*}/i386/modules/Keylayout/layouts/layouts-src"␊ |
303 | if [ -d "$layout_src_dir" ];then␊ |
304 | # Create a tar.gz from layout sources␊ |
305 | (cd "$layout_src_dir"; \␊ |
306 | tar czf "${1}/Keylayout/Root/Extra/Keymaps/layouts-src.tar.gz" README *.slt)␊ |
307 | fi␊ |
308 | # Adding module␊ |
309 | ditto --noextattr --noqtn ${1%/*}/i386/modules/${choiceId}.dylib ${1}/${choiceId}/Root/Extra/modules␊ |
310 | # Adding Keymaps␊ |
311 | ditto --noextattr --noqtn ${1%/sym/*}/Keymaps ${1}/${choiceId}/Root/Extra/Keymaps␊ |
312 | # Adding tools␊ |
313 | ditto --noextattr --noqtn ${1%/*}/i386/cham-mklayout ${1}/${choiceId}/Root/usr/local/bin␊ |
314 | echo -e "\t[BUILD] ${choiceId} "␊ |
315 | packageRefId=$(getPackageRefId "${modules_packages_identity}" "${choiceId}")␊ |
316 | buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp"␊ |
317 | ␊ |
318 | # Don't add a choice for Keylayout module␊ |
319 | # addChoice "${choiceId}" "start_selected=\"false\"" "$packageRefId"␊ |
320 | # End build Keylayout package module␊ |
321 | }␊ |
322 | fi␊ |
323 | ␊ |
324 | ((xmlindent--))␊ |
325 | outline[$((outlinecount++))]="${indent[$xmlindent]}</line>"␊ |
326 | }␊ |
327 | else␊ |
328 | {␊ |
329 | echo " -= no modules to include =-"␊ |
330 | }␊ |
331 | fi␊ |
332 | # End build Modules packages␊ |
333 | ␊ |
334 | # build Options packages␊ |
335 | ␊ |
336 | outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"Options\">"␊ |
337 | choices[$((choicescount++))]="\t<choice\n\t\tid=\"Options\"\n\t\ttitle=\"Options_title\"\n\t\tdescription=\"Options_description\">\n\t</choice>\n"␊ |
338 | ((xmlindent++))␊ |
339 | ␊ |
340 | ␊ |
341 | # ------------------------------------------------------␊ |
342 | # parse OptionalSettings folder to find files of boot options.␊ |
343 | # ------------------------------------------------------␊ |
344 | OptionalSettingsFolder="${pkgroot}/OptionalSettings"␊ |
345 | OptionalSettingsFiles=($( find "${OptionalSettingsFolder}" -depth 1 ! -name '.svn' ! -name '.DS_Store' ))␊ |
346 | ␊ |
347 | for (( i = 0 ; i < ${#OptionalSettingsFiles[@]} ; i++ ))␊ |
348 | do␊ |
349 | ␊ |
350 | ␉␉# Take filename and Strip .txt from end and path from front␊ |
351 | ␉␉builtOptionsList=$( echo ${OptionalSettingsFiles[$i]%.txt} )␊ |
352 | ␉␉builtOptionsList=$( echo ${builtOptionsList##*/} )␊ |
353 | ␉␉echo "================= $builtOptionsList ================="␊ |
354 | ␉␉outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"${builtOptionsList}\">"␊ |
355 | ␉␉choices[$((choicescount++))]="\t<choice\n\t\tid=\"${builtOptionsList}\"\n\t\ttitle=\"${builtOptionsList}_title\"\n\t\tdescription=\"${builtOptionsList}_description\">\n\t</choice>\n"␊ |
356 | ␉␉((xmlindent++))␊ |
357 | ␉␉packagesidentity="org.chameleon.options.$builtOptionsList"␊ |
358 | ␊ |
359 | ␉␉# ------------------------------------------------------␊ |
360 | ␉␉# Read boot option file into an array.␊ |
361 | ␉␉# ------------------------------------------------------␊ |
362 | ␉␉availableOptions=() # array to hold the list of boot options, per 'section'.␊ |
363 | ␉␉exclusiveFlag=0 # used to indicate list has exclusive options␊ |
364 | ␉␉count=0 # used as index for stepping through array.␊ |
365 | ␉␉while read textLine; do␊ |
366 | ␉␉␉# ignore lines in the file beginning with a # and Exclusive=False␊ |
367 | ␉␉␉if [[ ${textLine} != \#* ]] && [[ ${textLine} != "Exclusive=False" ]];then␊ |
368 | ␉␉␉␉# check for 'Exclusive=True' option in file␊ |
369 | ␉␉␉␉if [[ ${textLine} == "Exclusive=True" ]];then␊ |
370 | ␉␉␉␉␉exclusiveFlag=1␊ |
371 | ␉␉␉␉else␊ |
372 | ␉␉␉␉␉availableOptions[${#availableOptions[@]}]=$textLine␊ |
373 | ␉␉␉␉fi␊ |
374 | ␉␉␉fi␊ |
375 | ␉␉done < ${OptionalSettingsFiles[$i]}␊ |
376 | ␊ |
377 | ␉␉# ------------------------------------------------------␊ |
378 | ␉␉# Loop through options in array and process each in turn␊ |
379 | ␉␉# ------------------------------------------------------␊ |
380 | ␉␉allChoices="${availableOptions[@]//:*/}"␊ |
381 | ␉␉for (( c = 0 ; c < ${#availableOptions[@]} ; c++ )); do␊ |
382 | ␉␉␉textLine=${availableOptions[c]}␊ |
383 | ␉␉␉# split line - taking all before ':' as option name␊ |
384 | ␉␉␉# and all after ':' as key/value␊ |
385 | ␉␉␉optionName=${textLine%:*}␊ |
386 | ␉␉␉keyValue=${textLine##*:}␊ |
387 | ␊ |
388 | ␉␉␉# create folders required for each boot option␊ |
389 | ␉␉␉mkdir -p "${1}/$optionName/Root/"␊ |
390 | ␊ |
391 | ␉␉␉# create dummy file with name of key/value␊ |
392 | ␉␉␉echo "" > "${1}/$optionName/Root/${keyValue}"␊ |
393 | ␊ |
394 | ␉␉␉echo -e "\t[BUILD] ${optionName} "␊ |
395 | ␉␉␉packageRefId=$(getPackageRefId "${packagesidentity}" "${optionName}")␊ |
396 | ␉␉␉buildpackage "$packageRefId" "${optionName}" "${1}/${optionName}" "/$chamTemp/options"␊ |
397 | ␉␉␉exclusiveSelect=""␊ |
398 | ␉␉␉if [[ ${exclusiveFlag} -eq 1 ]];then␊ |
399 | ␉␉␉␉exclusiveSelect="selected=\"$(exclusive_zero_or_one_choice "$optionName" "$allChoices")\""␊ |
400 | ␉␉␉fi␊ |
401 | ␉␉␉addChoice "${optionName}" "start_selected=\"false\" ${exclusiveSelect}" "$packageRefId"␊ |
402 | ␉␉done␊ |
403 | ␊ |
404 | ␉␉((xmlindent--))␊ |
405 | ␉␉outline[$((outlinecount++))]="${indent[$xmlindent]}</line>"␊ |
406 | ␉done␊ |
407 | ␊ |
408 | ␉# build KeyLayout options packages␊ |
409 | ␉echo "================= Keymaps Options ================="␊ |
410 | ␉outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"KeyLayout\">"␊ |
411 | ␉choices[$((choicescount++))]="\t<choice\n\t\tid=\"KeyLayout\"\n\t\ttitle=\"KeyLayout_title\"\n\t\tdescription=\"KeyLayout_description\">\n\t</choice>\n"␊ |
412 | ␉((xmlindent++))␊ |
413 | ␉packagesidentity="org.chameleon.options.keylayout"␊ |
414 | ␉keylayoutPackageRefId=$(getPackageRefId "${modules_packages_identity}" "Keylayout")␊ |
415 | ␊ |
416 | ␉# ------------------------------------------------------␊ |
417 | ␉# Available Keylayout boot options are discovered by␊ |
418 | ␉# reading contents of /Keymaps folder after compilation␊ |
419 | ␉# ------------------------------------------------------␊ |
420 | ␉availableOptions=($( find "${1%/sym/*}/Keymaps" -type f -depth 1 -name '*.lyt' | sed 's|.*/||;s|\.lyt||' ))␊ |
421 | ␉allChoices="${availableOptions[@]}"␊ |
422 | ␉# Adjust array contents to match expected format␊ |
423 | ␉# for boot options which is: name:key=value␊ |
424 | ␉for (( i = 0 ; i < ${#availableOptions[@]} ; i++ )); do␊ |
425 | ␉␉# availableOptions[i]=${availableOptions[i]}":KeyLayout="${availableOptions[i]}␊ |
426 | ␉␉# Start build of a keymap package module␊ |
427 | ␉␉choiceId="${availableOptions[i]}"␊ |
428 | ␉␉mkdir -p ${1}/${choiceId}/Root␊ |
429 | ␊ |
430 | ␉␉# create dummy file with name of key/value␊ |
431 | ␉␉echo "" > "${1}/${choiceId}/Root/KeyLayout=${availableOptions[i]}"␊ |
432 | ␊ |
433 | ␉␉echo -e "\t[BUILD] ${choiceId} "␊ |
434 | ␉␉packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
435 | ␉␉buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/$chamTemp/options"␊ |
436 | ␉␉exclusiveChoice=$(exclusive_zero_or_one_choice "$choiceId" "$allChoices")␊ |
437 | ␉␉# Add the Keylayout package because the Keylayout module is needed␊ |
438 | ␉␉addChoice "${choiceId}" "start_selected=\"false\" selected=\"${exclusiveChoice}\"" \␊ |
439 | ␉␉ "$packageRefId" "$keylayoutPackageRefId"␊ |
440 | ␉␉# End build uClibc package module␊ |
441 | ␉done␊ |
442 | ␊ |
443 | ␉((xmlindent--))␊ |
444 | ␉outline[$((outlinecount++))]="${indent[$xmlindent]}</line>"␊ |
445 | ␊ |
446 | ␉# End build KeyLayout options packages␊ |
447 | ␊ |
448 | ␉((xmlindent--))␊ |
449 | ␉outline[$((outlinecount++))]="${indent[$xmlindent]}</line>"␊ |
450 | # End build options packages␊ |
451 | ␊ |
452 | # build theme packages␊ |
453 | ␉echo "================= Themes ================="␊ |
454 | ␉outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"Themes\">"␊ |
455 | ␉choices[$((choicescount++))]="\t<choice\n\t\tid=\"Themes\"\n\t\ttitle=\"Themes_title\"\n\t\tdescription=\"Themes_description\">\n\t</choice>\n"␊ |
456 | ␉((xmlindent++))␊ |
457 | ␊ |
458 | ␉# Using themes section from Azi's/package branch.␊ |
459 | ␉packagesidentity="org.chameleon.themes"␊ |
460 | ␉artwork="${1%/sym/package}/artwork/themes"␊ |
461 | ␉themes=($( find "${artwork}" -type d -depth 1 -not -name '.svn' ))␊ |
462 | ␉for (( i = 0 ; i < ${#themes[@]} ; i++ )); do␊ |
463 | ␉␉theme=$( echo ${themes[$i]##*/} | awk 'BEGIN{OFS=FS=""}{$1=toupper($1);print}' )␊ |
464 | ␉␉mkdir -p "${1}/${theme}/Root/"␊ |
465 | ␉␉rsync -r --exclude=.svn "${themes[$i]}/" "${1}/${theme}/Root/${theme}"␊ |
466 | ␉␉echo -e "\t[BUILD] ${theme}"␊ |
467 | ␉␉packageRefId=$(getPackageRefId "${packagesidentity}" "${theme}")␊ |
468 | ␉␉buildpackage "$packageRefId" "${theme}" "${1}/${theme}" "/$chamTemp/Extra/Themes"␊ |
469 | ␉␉addChoice "${theme}" "start_selected=\"false\"" "$packageRefId"␊ |
470 | ␉done␊ |
471 | ␊ |
472 | ␉((xmlindent--))␊ |
473 | ␉outline[$((outlinecount++))]="${indent[$xmlindent]}</line>"␊ |
474 | # End build theme packages# End build Extras package␊ |
475 | ␊ |
476 | # build post install package␊ |
477 | echo "================= Post ================="␊ |
478 | packagesidentity="org.chameleon"␊ |
479 | choiceId="Post"␊ |
480 | mkdir -p ${1}/${choiceId}/Root␊ |
481 | mkdir -p ${1}/${choiceId}/Scripts␊ |
482 | cp -f ${pkgroot}/Scripts/Main/postinstall ${1}/${choiceId}/Scripts␊ |
483 | cp -f ${pkgroot}/Scripts/Sub/InstallLog.sh ${1}/${choiceId}/Scripts␊ |
484 | cp -f ${pkgroot}/Scripts/Sub/UnMountEFIvolumes.sh ${1}/${choiceId}/Scripts␊ |
485 | ditto --noextattr --noqtn ${1%/*/*}/revision ${1}/${choiceId}/Scripts/Resources/revision␊ |
486 | ditto --noextattr --noqtn ${1%/*/*}/version ${1}/${choiceId}/Scripts/Resources/version␊ |
487 | echo -e "\t[BUILD] ${choiceId} "␊ |
488 | packageRefId=$(getPackageRefId "${packagesidentity}" "${choiceId}")␊ |
489 | buildpackage "$packageRefId" "${choiceId}" "${1}/${choiceId}" "/"␊ |
490 | addChoice "${choiceId}" "start_visible=\"false\" start_selected=\"true\"" "$packageRefId"␊ |
491 | # End build post install package␊ |
492 | ␊ |
493 | ␉((xmlindent--))␊ |
494 | ␉outline[$((outlinecount++))]="${indent[$xmlindent]}</choices-outline>"␊ |
495 | ␊ |
496 | # build meta package␊ |
497 | ␊ |
498 | makedistribution "${1}" "${2}" "${3}" "${4}" #"${5}"␊ |
499 | ␊ |
500 | # clean up␊ |
501 | ␉# rm -R -f "${1}"␊ |
502 | ␊ |
503 | }␊ |
504 | ␊ |
505 | buildpackage ()␊ |
506 | {␊ |
507 | ␉# $1 Package Reference Id (ie: org.chameleon.themes.default)␊ |
508 | ␉# $2 Package Name (ie: Default)␊ |
509 | ␉# $3 Path to package to build containing Root and/or Scripts␊ |
510 | ␉# $4 Target install location␊ |
511 | ␉# $5 Size (optional)␊ |
512 | ␉if [[ -d "${3}/Root" ]]; then␊ |
513 | ␉␉local packageRefId="$1"␊ |
514 | ␉␉local packageName="$2"␊ |
515 | ␉␉local packagePath="$3"␊ |
516 | ␉␉local targetPath="$4"␊ |
517 | ␉␉local packageSize="$5"␊ |
518 | ␊ |
519 | ␉␉find "${packagePath}" -name '.DS_Store' -delete␊ |
520 | ␉␉local filecount=$( find "${packagePath}/Root" | wc -l )␊ |
521 | ␉␉if [ "${packageSize}" ]; then␊ |
522 | ␉␉␉local installedsize="${packageSize}"␊ |
523 | ␉␉else␊ |
524 | ␉␉␉local installedsize=$( du -hkc "${packagePath}/Root" | tail -n1 | awk {'print $1'} )␊ |
525 | ␉␉fi␊ |
526 | ␉␉local header="<?xml version=\"1.0\"?>\n<pkg-info format-version=\"2\" "␊ |
527 | ␊ |
528 | ␉␉#[ "${3}" == "relocatable" ] && header+="relocatable=\"true\" "␊ |
529 | ␊ |
530 | ␉␉header+="identifier=\"${packageRefId}\" "␊ |
531 | ␉␉header+="version=\"${version}\" "␊ |
532 | ␊ |
533 | ␉␉[ "${targetPath}" != "relocatable" ] && header+="install-location=\"${targetPath}\" "␊ |
534 | ␊ |
535 | ␉␉header+="auth=\"root\">\n"␊ |
536 | ␉␉header+="\t<payload installKBytes=\"${installedsize##* }\" numberOfFiles=\"${filecount##* }\"/>\n"␊ |
537 | ␉␉rm -R -f "${packagePath}/Temp"␊ |
538 | ␊ |
539 | ␉␉[ -d "${packagePath}/Temp" ] || mkdir -m 777 "${packagePath}/Temp"␊ |
540 | ␉␉[ -d "${packagePath}/Root" ] && mkbom "${packagePath}/Root" "${packagePath}/Temp/Bom"␊ |
541 | ␊ |
542 | ␉␉if [ -d "${packagePath}/Scripts" ]; then␊ |
543 | ␉␉␉header+="\t<scripts>\n"␊ |
544 | ␉␉␉for script in $( find "${packagePath}/Scripts" -type f \( -name 'pre*' -or -name 'post*' \) ); do␊ |
545 | ␉␉␉␉header+="\t\t<${script##*/} file=\"./${script##*/}\"/>\n"␊ |
546 | ␉␉␉done␊ |
547 | ␉␉␉header+="\t</scripts>\n"␊ |
548 | ␉␉␉# Create the Script archive file (cpio format)␊ |
549 | ␉␉␉(cd "${packagePath}/Scripts" && find . -print | cpio -o -z -R 0:0 --format cpio > "${packagePath}/Temp/Scripts") 2>&1 | \␊ |
550 | ␉␉␉ grep -vE '^[0-9]+\s+blocks?$' # to remove cpio stderr messages␊ |
551 | fi␊ |
552 | ␊ |
553 | ␉␉header+="</pkg-info>"␊ |
554 | ␉␉echo -e "${header}" > "${packagePath}/Temp/PackageInfo"␊ |
555 | ␊ |
556 | ␉␉# Create the Payload file (cpio format)␊ |
557 | ␉␉(cd "${packagePath}/Root" && find . -print | cpio -o -z -R 0:0 --format cpio > "${packagePath}/Temp/Payload") 2>&1 | \␊ |
558 | ␉ grep -vE '^[0-9]+\s+blocks?$' # to remove cpio stderr messages␊ |
559 | ␊ |
560 | ␉␉# Create the package␊ |
561 | ␉␉(cd "${packagePath}/Temp" && xar -c -f "${packagePath}/../${packageName}.pkg" --compression none .)␊ |
562 | ␊ |
563 | ␉␉# Add the package to the list of build packages␊ |
564 | ␉␉pkgrefs[${#pkgrefs[*]}]="\t<pkg-ref id=\"${packageRefId}\" installKBytes='${installedsize}' version='${version}.0.0.${timestamp}'>#${packageName}.pkg</pkg-ref>"␊ |
565 | ␊ |
566 | ␉␉rm -rf "${packagePath}"␊ |
567 | ␉fi␊ |
568 | }␊ |
569 | ␊ |
570 | makedistribution ()␊ |
571 | {␊ |
572 | distributionDestDir="${1%/*}"␊ |
573 | distributionFilename="${packagename// /}-${version}-r${revision}.pkg"␊ |
574 | distributionFilePath="${distributionDestDir}/${distributionFilename}"␊ |
575 | ␊ |
576 | rm -f "${distributionDestDir}/${packagename// /}"*.pkg␊ |
577 | ␊ |
578 | mkdir -p "${1}/${packagename}"␊ |
579 | ␊ |
580 | find "${1}" -type f -name '*.pkg' -depth 1 | while read component␊ |
581 | ␉do␊ |
582 | pkg="${component##*/}" # ie: EFI.pkg␊ |
583 | pkgdir="${1}/${packagename}/${pkg}"␊ |
584 | # expand individual packages␊ |
585 | pkgutil --expand "${1%}/${pkg}" "$pkgdir"␊ |
586 | rm -f "${1%}/${pkg}"␊ |
587 | done␊ |
588 | ␊ |
589 | # Create the Distribution file␊ |
590 | ditto --noextattr --noqtn "${pkgroot}/Distribution" "${1}/${packagename}/Distribution"␊ |
591 | ␊ |
592 | for (( i=0; i < ${#outline[*]} ; i++)); do␊ |
593 | ␉␉echo -e "${outline[$i]}" >> "${1}/${packagename}/Distribution"␊ |
594 | ␉done␊ |
595 | ␊ |
596 | for (( i=0; i < ${#choices[*]} ; i++)); do␊ |
597 | ␉␉echo -e "${choices[$i]}" >> "${1}/${packagename}/Distribution"␊ |
598 | ␉done␊ |
599 | ␊ |
600 | for (( i=0; i < ${#pkgrefs[*]} ; i++)); do␊ |
601 | echo -e "${pkgrefs[$i]}" >> "${1}/${packagename}/Distribution"␊ |
602 | done␊ |
603 | ␊ |
604 | echo -e "\n</installer-gui-script>" >> "${1}/${packagename}/Distribution"␊ |
605 | ␊ |
606 | # Create the Resources directory␊ |
607 | ditto --noextattr --noqtn "${pkgroot}/Resources" "${1}/${packagename}/Resources"␊ |
608 | ␊ |
609 | # CleanUp the directory␊ |
610 | find "${1}/${packagename}" -type d -name '.svn' -exec rm -rf {} \; 2>/dev/null␊ |
611 | find "${1}/${packagename}" -name '.DS_Store' -delete␊ |
612 | ␊ |
613 | # Add Chameleon Version and Revision␊ |
614 | perl -i -p -e "s/%CHAMELEONVERSION%/${version%%-*}/g" $( find "${1}/${packagename}/Resources" -type f )␊ |
615 | perl -i -p -e "s/%CHAMELEONREVISION%/${revision}/g" $( find "${1}/${packagename}/Resources" -type f )␊ |
616 | ␊ |
617 | # Add Chameleon Stage␊ |
618 | stage=${stage/RC/Release Candidate }␊ |
619 | stage=${stage/FINAL/2.0 Final}␊ |
620 | perl -i -p -e "s/%CHAMELEONSTAGE%/${stage}/g" $( find "${1}/${packagename}/Resources" -type f )␊ |
621 | ␊ |
622 | # Adding Developer and credits␊ |
623 | perl -i -p -e "s/%DEVELOP%/${develop}/g" $( find "${1}/${packagename}/Resources" -type f )␊ |
624 | perl -i -p -e "s/%CREDITS%/${credits}/g" $( find "${1}/${packagename}/Resources" -type f )␊ |
625 | perl -i -p -e "s/%PKGDEV%/${pkgdev}/g" $( find "${1}/${packagename}/Resources" -type f )␊ |
626 | ␊ |
627 | # Create the final package␊ |
628 | pkgutil --flatten "${1}/${packagename}" "${distributionFilePath}"␊ |
629 | ␊ |
630 | # Here is the place for assign a Icon to the pkg␊ |
631 | ditto -xk "${pkgroot}/Icons/pkg.zip" "${1}/Icons/"␊ |
632 | DeRez -only icns "${1}/Icons/Icons/pkg.icns" > "${1}/Icons/tempicns.rsrc"␊ |
633 | Rez -append "${1}/Icons/tempicns.rsrc" -o "${distributionFilePath}"␊ |
634 | SetFile -a C "${distributionFilePath}"␊ |
635 | rm -rf "${1}/Icons"␊ |
636 | ␊ |
637 | # End␊ |
638 | ␊ |
639 | md5=$( md5 "${distributionFilePath}" | awk {'print $4'} )␊ |
640 | echo "MD5 (${distributionFilePath}) = ${md5}" > "${distributionFilePath}.md5"␊ |
641 | echo ""␊ |
642 | ␊ |
643 | echo -e $COL_GREEN" --------------------------"$COL_RESET␊ |
644 | echo -e $COL_GREEN" Building process complete!"$COL_RESET␊ |
645 | echo -e $COL_GREEN" --------------------------"$COL_RESET␊ |
646 | echo ""␊ |
647 | echo -e $COL_GREEN" Build info."␊ |
648 | echo -e $COL_GREEN" ==========="␊ |
649 | echo -e $COL_BLUE" Package name: "$COL_RESET"${distributionFilename}"␊ |
650 | echo -e $COL_BLUE" MD5: "$COL_RESET"$md5"␊ |
651 | echo -e $COL_BLUE" Version: "$COL_RESET"$version"␊ |
652 | echo -e $COL_BLUE" Stage: "$COL_RESET"$stage"␊ |
653 | echo -e $COL_BLUE" Date/Time: "$COL_RESET"$builddate"␊ |
654 | echo ""␊ |
655 | ␊ |
656 | }␊ |
657 | ␊ |
658 | main "${1}" "${2}" "${3}" "${4}" #"${5}"␊ |
659 | |