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/Standardpostinstall ${1}/Standard/Scripts/postinstall␊ |
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/ESPpostinstall ${1}/EFI/Scripts/postinstall␊ |
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# End build Extras package␊ |
300 | ␊ |
301 | # build post install package␊ |
302 | ␉echo "================= Post ================="␊ |
303 | ␉packagesidentity="org.chameleon"␊ |
304 | ␉mkdir -p ${1}/Post/Root␊ |
305 | ␉mkdir -p ${1}/Post/Scripts␊ |
306 | ␉cp -f ${pkgroot}/Scripts/Main/postinstall ${1}/Post/Scripts␊ |
307 | ␉cp -f ${pkgroot}/Scripts/Sub/InstallLog.sh ${1}/Post/Scripts␊ |
308 | ␉cp -f ${pkgroot}/Scripts/Sub/UnMountEFIvolumes.sh ${1}/Post/Scripts␊ |
309 | ␉ditto --noextattr --noqtn ${1%/*/*}/revision ${1}/Post/Scripts/Resources/revision␊ |
310 | ␉ditto --noextattr --noqtn ${1%/*/*}/version ${1}/Post/Scripts/Resources/version␊ |
311 | ␉echo "␉[BUILD] Post "␊ |
312 | ␉buildpackage "${1}/Post" "/" "" "start_visible=\"false\" start_selected=\"true\"" >/dev/null 2>&1␊ |
313 | # End build post install package␊ |
314 | ␊ |
315 | ((xmlindent--))␊ |
316 | outline[$((outlinecount++))]="${indent[$xmlindent]}</choices-outline>"␊ |
317 | ␊ |
318 | # build meta package␊ |
319 | ␊ |
320 | ␉makedistribution "${1}" "${2}" "${3}" "${4}" #"${5}"␊ |
321 | ␊ |
322 | # clean up ␊ |
323 | ␊ |
324 | ␉#rm -R -f "${1}"␊ |
325 | ␊ |
326 | }␊ |
327 | ␊ |
328 | fixperms ()␊ |
329 | {␊ |
330 | ␉# $1 path␊ |
331 | ␉find "${1}" -type f -exec chmod 644 {} \;␊ |
332 | ␉find "${1}" -type d -exec chmod 755 {} \;␊ |
333 | ␉chown -R 0:0 "${1}"␊ |
334 | }␊ |
335 | ␊ |
336 | buildoptionalsettings()␊ |
337 | {␊ |
338 | ␉# $1 Path to package to build containing Root and or Scripts␊ |
339 | ␉# $2 = exclusiveFlag␊ |
340 | ␉# S3 = exclusiveName ␊ |
341 | ␉␊ |
342 | ␉# ------------------------------------------------------␊ |
343 | ␉# if exclusiveFlag=1 then re-build array␊ |
344 | ␉# adding extra boot option at beginning to give␊ |
345 | |
346 | ␉# ------------------------------------------------------␊ |
347 | ␉if [ ${2} = "1" ]; then␊ |
348 | ␉␉tempArray=("${availableOptions[@]}")␊ |
349 | ␉␉availableOptions=()␊ |
350 | ␉␉availableOptions[0]="ChooseNone-"$3":DONT=ADD"␊ |
351 | ␉␉position=0␊ |
352 | ␉␉totalItems="${#tempArray[@]}"␉␊ |
353 | ␉␉for (( position = 0 ; position < $totalItems ; position++ ))␊ |
354 | ␉␉do␊ |
355 | ␉␉␉availableOptions[$position+1]=${tempArray[${position}]}␊ |
356 | ␉␉done␊ |
357 | ␉fi␊ |
358 | ␉␊ |
359 | ␉# ------------------------------------------------------␊ |
360 | ␉# Loop through options in array and process each in turn␊ |
361 | ␉# ------------------------------------------------------␊ |
362 | ␉for (( c = 0 ; c < ${#availableOptions[@]} ; c++ ))␊ |
363 | ␉do␊ |
364 | ␉␉textLine=${availableOptions[c]}␊ |
365 | ␉␉# split line - taking all before ':' as option name␊ |
366 | ␉␉# and all after ':' as key/value␊ |
367 | ␉␉optionName=${textLine%:*}␊ |
368 | ␉␉keyValue=${textLine##*:}␊ |
369 | ␊ |
370 | ␉␉# create folders required for each boot option␊ |
371 | ␉␉mkdir -p "${1}/$optionName/Root/"␊ |
372 | ␊ |
373 | ␉␉# create dummy file with name of key/value␊ |
374 | ␉␉echo "" > "${1}/$optionName/Root/${keyValue}"␊ |
375 | ␊ |
376 | ␉␉echo "␉[BUILD] ${optionName} "␊ |
377 | ␊ |
378 | ␉␉# ------------------------------------------------------␊ |
379 | ␉␉# Before calling buildpackage, add exclusive options␊ |
380 | ␉␉# to buildpackage call if requested.␊ |
381 | ␉␉# ------------------------------------------------------␊ |
382 | ␉␉if [ $2 = "1" ]; then␊ |
383 | ␊ |
384 | ␉␉␉# Prepare individual string parts␊ |
385 | ␉␉␉stringStart="selected=\""␊ |
386 | ␉␉␉stringBefore="exclusive(choices['"␊ |
387 | ␉␉␉stringAfter="']) && "␊ |
388 | ␉␉␉stringEnd="'])\""␊ |
389 | ␉␉␉x=${stringStart}${stringBefore}␊ |
390 | ␊ |
391 | ␉␉␉# build string for sending to buildpackage␊ |
392 | ␉␉␉totalItems="${#availableOptions[@]}"␊ |
393 | ␉␉␉lastItem=$((totalItems-1))␊ |
394 | ␊ |
395 | ␉␉␉for (( r = 0 ; r < ${totalItems} ; r++ ))␊ |
396 | ␉␉␉do␊ |
397 | ␉␉␉␉textLineTemp=${availableOptions[r]}␊ |
398 | ␉␉␉␉optionNameTemp=${textLineTemp%:*}␊ |
399 | ␉␉␉␉if [ "${optionNameTemp}" != "${optionName}" ]; then␊ |
400 | ␉␉␉␉␉ x="${x}${optionNameTemp}"␊ |
401 | ␉␉␉␉␉ # Only add these to end of string up to the one before the last item␊ |
402 | ␉␉␉␉␉if [ $r -lt $lastItem ]; then␊ |
403 | ␉␉␉␉␉␉x="${x}${stringAfter}${stringBefore}"␊ |
404 | ␉␉␉␉␉fi␊ |
405 | ␉␉␉␉fi␊ |
406 | ␉␉␉done␊ |
407 | ␉␉␉x="${x}${stringEnd}"␊ |
408 | ␊ |
409 | ␉␉␉# First exclusive option is the 'no choice' option, so let's make that selected by default.␊ |
410 | ␉␉␉if [ $c = 0 ]; then␊ |
411 | ␉␉␉␉initialChoice="true"␊ |
412 | ␉␉␉else␊ |
413 | ␉␉␉␉initialChoice="false"␊ |
414 | ␉␉␉fi␊ |
415 | ␊ |
416 | ␉␉␉buildpackage "${1}/${optionName}" "/$chamTemp/options" "" "start_selected=\"${initialChoice}\" ${x}" >/dev/null 2>&1␊ |
417 | ␉␉else␊ |
418 | ␉␉␉buildpackage "${1}/${optionName}" "/$chamTemp/options" "" "start_selected=\"false\"" >/dev/null 2>&1␊ |
419 | ␉␉fi␊ |
420 | ␉done␊ |
421 | }␊ |
422 | ␊ |
423 | buildpackage ()␊ |
424 | {␊ |
425 | # $1 Path to package to build containing Root and or Scripts␊ |
426 | # $2 Install Location␊ |
427 | # $3 Size␊ |
428 | # $4 Options␊ |
429 | ␊ |
430 | if [ -d "${1}/Root" ] && [ "${1}/Scripts" ]; then␊ |
431 | ␊ |
432 | ␉local packagename="${1##*/}"␊ |
433 | ␉local identifier=$( echo ${packagesidentity}.${packagename//_/.} | tr [:upper:] [:lower:] )␊ |
434 | ␉find "${1}" -name '.DS_Store' -delete␊ |
435 | ␉local filecount=$( find "${1}/Root" | wc -l )␊ |
436 | ␉if [ "${3}" ]; then␊ |
437 | ␉␉local installedsize="${3}"␊ |
438 | ␉else␊ |
439 | ␉␉local installedsize=$( du -hkc "${1}/Root" | tail -n1 | awk {'print $1'} )␊ |
440 | ␉fi␊ |
441 | ␉local header="<?xml version=\"1.0\"?>\n<pkg-info format-version=\"2\" "␊ |
442 | ␊ |
443 | ␉#[ "${3}" == "relocatable" ] && header+="relocatable=\"true\" "␉␉␊ |
444 | ␊ |
445 | ␉header+="identifier=\"${identifier}\" "␊ |
446 | ␉header+="version=\"${version}\" "␊ |
447 | ␊ |
448 | ␉[ "${2}" != "relocatable" ] && header+="install-location=\"${2}\" "␊ |
449 | ␊ |
450 | ␉header+="auth=\"root\">\n"␊ |
451 | ␉header+="\t<payload installKBytes=\"${installedsize##* }\" numberOfFiles=\"${filecount##* }\"/>\n"␊ |
452 | ␉#rm -R -f "${1}/Temp"␊ |
453 | ␊ |
454 | ␉[ -d "${1}/Temp" ] || mkdir -m 777 "${1}/Temp"␊ |
455 | ␉[ -d "${1}/Root" ] && mkbom "${1}/Root" "${1}/Temp/Bom"␊ |
456 | ␊ |
457 | ␉if [ -d "${1}/Scripts" ]; then ␊ |
458 | ␉␉header+="\t<scripts>\n"␊ |
459 | ␉␉for script in $( find "${1}/Scripts" -type f \( -name 'pre*' -or -name 'post*' \) )␊ |
460 | ␉␉do␊ |
461 | ␉␉␉header+="\t\t<${script##*/} file=\"./${script##*/}\"/>\n"␊ |
462 | ␉␉done␊ |
463 | ␉␉header+="\t</scripts>\n"␊ |
464 | ␉␉chown -R 0:0 "${1}/Scripts"␊ |
465 | ␉␉pushd "${1}/Scripts" >/dev/null␊ |
466 | ␉␉find . -print | cpio -o -z -H cpio > "../Temp/Scripts"␊ |
467 | ␉␉popd >/dev/null␊ |
468 | ␉fi␊ |
469 | ␊ |
470 | ␉header+="</pkg-info>"␊ |
471 | ␉echo -e "${header}" > "${1}/Temp/PackageInfo"␊ |
472 | ␉pushd "${1}/Root" >/dev/null␊ |
473 | ␉find . -print | cpio -o -z -H cpio > "../Temp/Payload"␊ |
474 | ␉popd >/dev/null␊ |
475 | ␉pushd "${1}/Temp" >/dev/null␊ |
476 | ␊ |
477 | ␉xar -c -f "${1%/*}/${packagename// /}.pkg" --compression none .␊ |
478 | ␊ |
479 | ␉popd >/dev/null␊ |
480 | ␊ |
481 | ␉outline[$((outlinecount++))]="${indent[$xmlindent]}<line choice=\"${packagename// /}\"/>"␊ |
482 | ␊ |
483 | ␉if [ "${4}" ]; then␊ |
484 | ␉␉local choiceoptions="\t\t${4}"␊ |
485 | ␉fi␊ |
486 | ␉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"␉␊ |
487 | ␉#rm -R -f "${1}"␊ |
488 | fi␊ |
489 | }␊ |
490 | ␊ |
491 | makedistribution ()␊ |
492 | {␊ |
493 | ␉rm -f "${1%/*}/${packagename// /}"*.pkg␊ |
494 | ␊ |
495 | ␉find "${1}" -type f -name '*.pkg' -depth 1 | while read component␊ |
496 | ␉do␊ |
497 | ␉␉mkdir -p "${1}/${packagename}/${component##*/}"␊ |
498 | ␉␉pushd "${1}/${packagename}/${component##*/}" >/dev/null␊ |
499 | ␉␉xar -x -f "${1%}/${component##*/}"␊ |
500 | ␉␉popd >/dev/null␊ |
501 | ␉done␊ |
502 | ␊ |
503 | ␉ditto --noextattr --noqtn "${pkgroot}/Distribution" "${1}/${packagename}/Distribution"␊ |
504 | ␉ditto --noextattr --noqtn "${pkgroot}/Resources" "${1}/${packagename}/Resources"␊ |
505 | ␊ |
506 | ␉find "${1}/${packagename}/Resources" -type d -name '.svn' -exec rm -R -f {} \; 2>/dev/null␊ |
507 | ␊ |
508 | ␉for (( i=0; i < ${#outline[*]} ; i++));␊ |
509 | ␉␉do␊ |
510 | ␉␉␉echo -e "${outline[$i]}" >> "${1}/${packagename}/Distribution"␊ |
511 | ␉␉done␊ |
512 | ␊ |
513 | ␉for (( i=0; i < ${#choices[*]} ; i++));␊ |
514 | ␉␉do␊ |
515 | ␉␉␉echo -e "${choices[$i]}" >> "${1}/${packagename}/Distribution"␊ |
516 | ␉␉done␊ |
517 | ␊ |
518 | ␉echo "</installer-gui-script>" >> "${1}/${packagename}/Distribution"␊ |
519 | ␊ |
520 | ␉perl -i -p -e "s/%CHAMELEONVERSION%/${version%%-*}/g" `find "${1}/${packagename}/Resources" -type f`␊ |
521 | ␉perl -i -p -e "s/%CHAMELEONREVISION%/${revision}/g" `find "${1}/${packagename}/Resources" -type f`␊ |
522 | ␊ |
523 | # Adding Developer and credits␊ |
524 | ␉perl -i -p -e "s/%DEVELOP%/${develop}/g" `find "${1}/${packagename}/Resources" -type f`␊ |
525 | ␉perl -i -p -e "s/%CREDITS%/${credits}/g" `find "${1}/${packagename}/Resources" -type f`␊ |
526 | ␉perl -i -p -e "s/%PKGDEV%/${pkgdev}/g" `find "${1}/${packagename}/Resources" -type f`␊ |
527 | ␊ |
528 | ␉stage=${stage/RC/Release Candidate }␊ |
529 | ␉stage=${stage/FINAL/2.0 Final}␊ |
530 | ␉perl -i -p -e "s/%CHAMELEONSTAGE%/${stage}/g" `find "${1}/${packagename}/Resources" -type f`␊ |
531 | ␊ |
532 | ␉find "${1}/${packagename}" -name '.DS_Store' -delete␊ |
533 | ␉pushd "${1}/${packagename}" >/dev/null␊ |
534 | ␉xar -c -f "${1%/*}/${packagename// /}-${version}-r${revision}.pkg" --compression none .␊ |
535 | ␉popd >/dev/null␊ |
536 | ␊ |
537 | # Here is the place for assign a Icon to the pkg␊ |
538 | # command use to generate the file:␊ |
539 | # ditto -c -k --sequesterRsrc --keepParent Icon.icns Icon.zip␊ |
540 | # ----␊ |
541 | ditto -xk "${pkgroot}/Icons/pkg.zip" "${pkgroot}/Icons/"␊ |
542 | DeRez -only icns "${pkgroot}/Icons/Icons/pkg.icns" > tempicns.rsrc␊ |
543 | Rez -append tempicns.rsrc -o "${1%/*}/$packagename-${version}-r$revision.pkg"␊ |
544 | SetFile -a C "${1%/*}/$packagename-${version}-r$revision.pkg"␊ |
545 | rm -f tempicns.rsrc␊ |
546 | rm -rf "${pkgroot}/Icons/Icons"␊ |
547 | # End␊ |
548 | ␊ |
549 | ␉md5=$( md5 "${1%/*}/${packagename// /}-${version}-r${revision}.pkg" | awk {'print $4'} )␊ |
550 | ␉echo "MD5 (${packagename// /}-${version}-r${revision}.pkg) = ${md5}" > "${1%/*}/${packagename// /}-${version}-r${revision}.pkg.md5"␊ |
551 | ␉echo ""␉␊ |
552 | ␊ |
553 | ␉echo -e $COL_GREEN"␉--------------------------"$COL_RESET␊ |
554 | ␉echo -e $COL_GREEN"␉Building process complete!"$COL_RESET␊ |
555 | ␉echo -e $COL_GREEN"␉--------------------------"$COL_RESET␊ |
556 | ␉echo ""␉␊ |
557 | ␉echo -e $COL_GREEN"␉Build info."␊ |
558 | ␉echo -e $COL_GREEN"␉==========="␊ |
559 | ␉echo -e $COL_BLUE"␉Package name:␉"$COL_RESET"$packagename-${version}-r$revision.pkg"␊ |
560 | ␉echo -e $COL_BLUE"␉MD5:␉␉"$COL_RESET"$md5"␊ |
561 | ␉echo -e $COL_BLUE"␉Version:␉"$COL_RESET"$version"␊ |
562 | ␉echo -e $COL_BLUE"␉Stage:␉␉"$COL_RESET"$stage"␊ |
563 | ␉echo -e $COL_BLUE"␉Date/Time:␉"$COL_RESET"$builddate"␊ |
564 | ␉echo ""␊ |
565 | ␊ |
566 | }␊ |
567 | ␊ |
568 | main "${1}" "${2}" "${3}" "${4}" #"${5}"␊ |
569 | ␊ |
570 | |