Chameleon Applications

Chameleon Applications Svn Source Tree

Root/branches/blackosx/trunk/PackageBuilder/Main_Package_Elements/Scripts/BuildBootOptions.sh

  • Property svn:executable set to *
1#!/bin/bash
2
3main ()
4{
5tempDir="${destainationDrive}/.Chameleon/"
6echo "DEBUG: tempDir is ${tempDir}"
7
8
9if [ ! -d "${tempDir}" ]; then
10echo "the temporary directory does not exist so no boot options have been selected"
11else
12# check for see if there are any boot options in the temporary directory
13
14cd "${tempDir}"
15Dirlist=$(find . -type d | grep "@")
16
17if [ "${Dirlist}" ]; then
18
19echo "==============================================="
20echo "set com.apple.Boot.plist variables"
21echo "**********************************"
22
23#bootplist="${destainationDrive}/.Chameleon/Extra/com.apple.Boot.plist"
24bootplist="${tempDir}/Extra/com.apple.Boot.plist"
25echo "DEBUG: bootplist = ${bootplist}"
26
27systemplist="/Library/Preferences/SystemConfiguration/com.apple.Boot.plist"
28echo "DEBUG: systemplist= ${systemplist}"
29
30echo "if no directory exists named ${bootplist%/*} then mkdir ${bootplist%/*}"
31[ ! -d "${bootplist%/*}" ] && mkdir -p "${bootplist%/*}"
32
33if [ ! -f "${bootplist}" ]; then
34echo "${bootplist} doesn't exist"
35if [ -f "${systemplist}" ]; then
36echo "${systemplist} doesn't exist"
37echo "copy ${systemplist} to ${bootplist}"
38cp "${systemplist}" "${bootplist}"
39fi
40fi
41echo "-----------------------------------------------"
42echo ""
43
44
45echo "==============================================="
46echo "Build Extra/com.apple.Boot.plist"
47echo "********************************"
48
49for directory in $Dirlist ; do
50overide=$(echo $directory | sed 's/_/ /g' | tr -d "./@" |cut -d '+' -f1)
51string=$(echo $directory | tr -d "./@" |cut -d'+' -f2)
52
53bootoptionshdextra[1]="<key>${overide}</key>"
54bootoptionshdextra[2]="<string>${string}</string>"
55#echo "DEBUG: bootoptionshdextra 1 = ${bootoptionshdextra[1]}"
56#echo "DEBUG: bootoptionshdextra 2= ${bootoptionshdextra[2]}"
57
58xmlvalue=$( getxmlvalue ${overide} "${bootplist}" | tr "[:upper:]" "[:lower:]" )
59
60case "${xmlvalue:0:1}" in
61
62y)echo "${overide}=y already set in ${bootplist} skipping."
63echo ""
64;;
65
66n)echo "${overide}=n is set in ${bootplist} leaving."
67echo ""
68;;
69
70 *)echo "Adding ${overide}=${string} to ${bootplist}"
71 array=("${bootoptionshdextra[@]}")
72searchfilereplaceline "${bootplist}" "<key>Kernel Flags</key>" "" "" "2"
73echo ""
74;;
75esac
76
77#echo "set owner privileges for ${bootplist}"
78chown "${USER}:20" "${bootplist}"
79done
80
81echo "-----------------------------------------------"
82echo ""
83
84
85echo "==============================================="
86echo "Remove Boot Options Folders"
87echo "***************************"
88
89#Note - Can this be somehow included above and delete the directory after reading it?
90
91#cd "${3}/.Chameleon/"
92Dirlist=$(find . -type d | grep "@")
93for directory in $Dirlist ; do
94echo $directory
95rm -rf $directory
96done
97
98echo "-----------------------------------------------"
99echo ""
100
101else
102echo "No boot options in the temporary directory."
103fi
104
105fi
106
107
108
109
110}
111
112getxmlvalue ()
113{
114# 1 xml key
115# 2 xml file
116if [ -f "${2}" ]; then
117local value
118while read value; do
119if [ ! "${value}" = "${value/<key>${1}</key>/}" ]; then
120read value
121value="${value#*<}" ; value="<${value}" ; value="${value#*>}" ; value="${value# *}" ; value="${value%%<*}"
122echo "$value"
123break
124fi
125done < "${2}"
126fi
127}
128
129searchfilereplaceline ()
130{
131
132mv "${1}" "${1}.orig"
133
134prefunctionifs="${IFS}"
135
136unset fileinput
137unset fileoutput
138unset find
139unset replace
140unset deletelines
141unset deletelinesskip
142unset insertlinesskip
143
144fileinput="${1}.orig"
145fileoutput="${1}"
146find="${2}"
147replace="${3}"
148deletelines="${4%,*}"
149insertlinesskip="${5}"
150
151matchlinefound="0"
152
153if [ "${#4}" = "${4#*,}" ]; then
154 deletelinesskip="0"
155else
156deletelinesskip="${4#*,}"
157fi
158
159IFS="\n"
160while read line
161do
162{
163if [ ! "${line}" = "${line/${find}/}" ]; then
164{
165# Trim the longest match from the end for <*
166xmlelementindent="${line%%<*}"
167
168# Trim the longest match from the start for *<
169xmlelementtemp="${line#*<}"
170# Add back in stripped <
171xmlelement="<${xmlelementtemp}"
172
173# Trim the shortest match from the start for <
174xmltagtemp="${xmlelement#<}"
175# Trim the longest match from the end for >*
176xmltag="${xmltagtemp%%>*}"
177
178# Trim the shortest match from the start for *>
179xmltexttemp="${xmlelement#*>}"
180# Trim the longest match from the end for <*
181xmltext="${xmltexttemp%%<*}"
182
183if [ "${replace}" ]; then
184{
185echo "${xmlelementindent}<${xmltag}>${replace}</${xmltag}>" >>"${fileoutput}"
186}
187else
188{
189echo "${line}" >>"${fileoutput}"
190}
191fi
192matchlinefound="1"
193
194}
195else
196{
197
198if [ "${insertlinesskip}" ] && [ "${matchlinefound}" -gt 0 ] && [ "${matchlinefound}" -le "${insertlinesskip}" ]; then
199{
200if [ "${matchlinefound}" = "${insertlinesskip}" ]; then
201{
202arraysize=0
203while [ ${arraysize} -lt ${#array[@]} ];
204do
205echo "${xmlelementindent}${array[${arraysize}]}" >>"${fileoutput}"
206 let arraysize="${arraysize}+1"
207done
208}
209fi
210}
211fi
212
213if [ "${deletelines}" ] && [ "${matchlinefound}" -gt 0 ] && [ "${matchlinefound}" -lt $((${deletelines}+${deletelinesskip})) ] && [ "${matchlinefound}" -ge ${deletelinesskip} ]; then
214{
215:
216}
217else
218{
219echo "${line}" >>"${fileoutput}"
220}
221fi
222
223if [ "${matchlinefound}" -gt 0 ]; then
224let matchlinefound="${matchlinefound}+1"
225fi
226
227}
228fi
229}
230done < "${fileinput}"
231
232IFS=${prefunctionifs}
233
234rm -f "${fileinput}"
235}
236
237
238echo "==============================================="
239echo "Enter Build Boot Options script"
240echo "*******************************"
241
242# get the passed destination drive?
243
244if [ "$#" -eq 1 ]; then
245destainationDrive="$1"
246echo "DEBUG: passed argument for destainationDrive = $destainationDrive"
247fi
248
249# Build Boot Options
250main "${1}" "${2}" "${3}" "${4}"
251
252exit 0
253

Archive Download this file

Revision: 221