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 for 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#cd "${3}/.Chameleon/"
75Dirlist=$(find . -type f | grep "@")
76for bootOptionFile in $Dirlist ; do
77echo $bootOptionFile
78rm $bootOptionFile
79done
80
81echo "-----------------------------------------------"
82echo ""
83
84else
85echo "No boot options in the temporary directory."
86fi
87fi
88}
89
90
91searchfilereplaceline ()
92{
93
94mv "${1}" "${1}.orig"
95
96prefunctionifs="${IFS}"
97
98unset fileinput
99unset fileoutput
100unset find
101unset replace
102unset deletelines
103unset deletelinesskip
104unset insertlinesskip
105
106fileinput="${1}.orig"
107fileoutput="${1}"
108find="${2}"
109replace="${3}"
110deletelines="${4%,*}"
111insertlinesskip="${5}"
112
113matchlinefound="0"
114
115if [ "${#4}" = "${4#*,}" ]; then
116 deletelinesskip="0"
117else
118deletelinesskip="${4#*,}"
119fi
120
121IFS="\n"
122while read line
123do
124{
125if [ ! "${line}" = "${line/${find}/}" ]; then
126{
127# Trim the longest match from the end for <*
128xmlelementindent="${line%%<*}"
129
130# Trim the longest match from the start for *<
131xmlelementtemp="${line#*<}"
132# Add back in stripped <
133xmlelement="<${xmlelementtemp}"
134
135# Trim the shortest match from the start for <
136xmltagtemp="${xmlelement#<}"
137# Trim the longest match from the end for >*
138xmltag="${xmltagtemp%%>*}"
139
140# Trim the shortest match from the start for *>
141xmltexttemp="${xmlelement#*>}"
142# Trim the longest match from the end for <*
143xmltext="${xmltexttemp%%<*}"
144
145if [ "${replace}" ]; then
146echo "DEBUG: Replace=${replace}"
147{
148echo "${xmlelementindent}<${xmltag}>${replace}</${xmltag}>" >>"${fileoutput}"
149}
150else
151{
152echo "${line}" >>"${fileoutput}"
153}
154fi
155matchlinefound="1"
156
157}
158else
159{
160
161if [ "${insertlinesskip}" ] && [ "${matchlinefound}" -gt 0 ] && [ "${matchlinefound}" -le "${insertlinesskip}" ]; then
162{
163if [ "${matchlinefound}" = "${insertlinesskip}" ]; then
164{
165arraysize=0
166while [ ${arraysize} -lt ${#array[@]} ];
167do
168#echo "DEBUG: ${xmlelementindent}${array[${arraysize}]}"
169echo "${xmlelementindent}${array[${arraysize}]}" >>"${fileoutput}"
170 let arraysize="${arraysize}+1"
171done
172}
173fi
174}
175fi
176
177if [ "${deletelines}" ] && [ "${matchlinefound}" -gt 0 ] && [ "${matchlinefound}" -lt $((${deletelines}+${deletelinesskip})) ] && [ "${matchlinefound}" -ge ${deletelinesskip} ]; then
178echo "DEBUG: Delete=${matchlinefound}"
179{
180:
181}
182else
183{
184echo "${line}" >>"${fileoutput}"
185}
186fi
187
188if [ "${matchlinefound}" -gt 0 ]; then
189let matchlinefound="${matchlinefound}+1"
190fi
191
192}
193fi
194}
195done < "${fileinput}"
196
197IFS=${prefunctionifs}
198
199rm -f "${fileinput}"
200}
201
202
203echo "==============================================="
204echo "Enter Build Boot Options script"
205echo "*******************************"
206
207# get the passed destination drive?
208
209if [ "$#" -eq 1 ]; then
210destinationDrive="$1"
211echo "DEBUG: passed argument for destinationDrive = $destinationDrive"
212fi
213
214# Build Boot Options
215main "${1}" "${2}" "${3}" "${4}"
216
217exit 0
218

Archive Download this file

Revision: 247