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