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