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