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="${destinationDrive}/.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 to see if there are any boot options in the temporary directory
13
14cd "${tempDir}"
15Dirlist=$(ls | grep "@")
16
17if [ "${Dirlist}" ]; then
18
19echo "==============================================="
20echo "set com.apple.Boot.plist variables"
21echo "**********************************"
22
23bootplist="${tempDir}Extra/com.apple.Boot.plist"
24echo "DEBUG: bootplist = ${bootplist}"
25
26systemplist="/Library/Preferences/SystemConfiguration/com.apple.Boot.plist"
27echo "DEBUG: systemplist= ${systemplist}"
28
29echo "if no directory exists named ${bootplist%/*} then mkdir ${bootplist%/*}"
30[ ! -d "${bootplist%/*}" ] && mkdir -p "${bootplist%/*}"
31
32if [ ! -f "${bootplist}" ]; then
33echo "${bootplist} doesn't exist"
34if [ -f "${systemplist}" ]; then
35echo "${systemplist} doesn't exist"
36echo "copy ${systemplist} to ${bootplist}"
37cp "${systemplist}" "${bootplist}"
38fi
39fi
40echo "-----------------------------------------------"
41echo ""
42
43
44echo "==============================================="
45echo "Build Extra/com.apple.Boot.plist"
46echo "********************************"
47
48for bootOptionFile in $Dirlist ; do
49overide=$(echo $bootOptionFile | sed 's/_/ /g' | tr -d "./@" |cut -d '+' -f1)
50string=$(echo $bootOptionFile | tr -d "./@" |cut -d'+' -f2)
51
52bootoptionshdextra[1]="<key>${overide}</key>"
53bootoptionshdextra[2]="<string>${string}</string>"
54#echo "DEBUG: bootoptionshdextra 1 = ${bootoptionshdextra[1]}"
55#echo "DEBUG: bootoptionshdextra 2= ${bootoptionshdextra[2]}"
56
57echo "Attempting to add ${overide}=${string} to ${bootplist}"
58 array=("${bootoptionshdextra[@]}")
59searchfilereplaceline "${bootplist}" "<key>Kernel Flags</key>" "" "" "2"
60echo ""
61
62#echo "set owner privileges for ${bootplist}"
63chown "${USER}:20" "${bootplist}"
64done
65
66echo "-----------------------------------------------"
67echo ""
68
69
70echo "==============================================="
71echo "Clean up and Remove Boot Option Null Files"
72echo "******************************************"
73
74# make sure we're in the right directory
75cd "${tempDir}"
76
77Dirlist=$(find . -type f | grep "@")
78for bootOptionFile in ${Dirlist} ; do
79echo "Removing temporary boot option file: ${bootOptionFile}"
80rm $bootOptionFile
81done
82
83echo "-----------------------------------------------"
84echo ""
85
86else
87echo "No boot options in the temporary directory."
88fi
89fi
90}
91
92
93searchfilereplaceline ()
94{
95
96mv "${1}" "${1}.orig"
97
98prefunctionifs="${IFS}"
99
100unset fileinput
101unset fileoutput
102unset find
103unset replace
104unset deletelines
105unset deletelinesskip
106unset insertlinesskip
107
108fileinput="${1}.orig"
109fileoutput="${1}"
110find="${2}"
111replace="${3}"
112deletelines="${4%,*}"
113insertlinesskip="${5}"
114
115matchlinefound="0"
116
117if [ "${#4}" = "${4#*,}" ]; then
118 deletelinesskip="0"
119else
120deletelinesskip="${4#*,}"
121fi
122
123IFS="\n"
124while read line
125do
126{
127if [ ! "${line}" = "${line/${find}/}" ]; then
128{
129# Trim the longest match from the end for <*
130xmlelementindent="${line%%<*}"
131
132# Trim the longest match from the start for *<
133xmlelementtemp="${line#*<}"
134# Add back in stripped <
135xmlelement="<${xmlelementtemp}"
136
137# Trim the shortest match from the start for <
138xmltagtemp="${xmlelement#<}"
139# Trim the longest match from the end for >*
140xmltag="${xmltagtemp%%>*}"
141
142# Trim the shortest match from the start for *>
143xmltexttemp="${xmlelement#*>}"
144# Trim the longest match from the end for <*
145xmltext="${xmltexttemp%%<*}"
146
147if [ "${replace}" ]; then
148echo "DEBUG: Replace=${replace}"
149{
150echo "${xmlelementindent}<${xmltag}>${replace}</${xmltag}>" >>"${fileoutput}"
151}
152else
153{
154echo "${line}" >>"${fileoutput}"
155}
156fi
157matchlinefound="1"
158
159}
160else
161{
162
163if [ "${insertlinesskip}" ] && [ "${matchlinefound}" -gt 0 ] && [ "${matchlinefound}" -le "${insertlinesskip}" ]; then
164{
165if [ "${matchlinefound}" = "${insertlinesskip}" ]; then
166{
167arraysize=0
168while [ ${arraysize} -lt ${#array[@]} ];
169do
170#echo "DEBUG: ${xmlelementindent}${array[${arraysize}]}"
171echo "${xmlelementindent}${array[${arraysize}]}" >>"${fileoutput}"
172 let arraysize="${arraysize}+1"
173done
174}
175fi
176}
177fi
178
179if [ "${deletelines}" ] && [ "${matchlinefound}" -gt 0 ] && [ "${matchlinefound}" -lt $((${deletelines}+${deletelinesskip})) ] && [ "${matchlinefound}" -ge ${deletelinesskip} ]; then
180echo "DEBUG: Delete=${matchlinefound}"
181{
182:
183}
184else
185{
186echo "${line}" >>"${fileoutput}"
187}
188fi
189
190if [ "${matchlinefound}" -gt 0 ]; then
191let matchlinefound="${matchlinefound}+1"
192fi
193
194}
195fi
196}
197done < "${fileinput}"
198
199IFS=${prefunctionifs}
200
201echo " rm -f ${fileinput}"
202rm -f "${fileinput}"
203}
204
205
206echo "==============================================="
207echo "Enter Build Boot Options script"
208echo "*******************************"
209
210# get the passed destination drive?
211
212if [ "$#" -eq 1 ]; then
213destinationDrive="$1"
214echo "DEBUG: passed argument for destinationDrive = $destinationDrive"
215fi
216
217# Build Boot Options
218main "${1}" "${2}" "${3}" "${4}"
219
220exit 0
221

Archive Download this file

Revision: 252