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
33if [ -f "${systemplist}" ]; then
34echo "Using Apple's com.apple.Boot.plist as base for /Extra/com.apple.Boot.plist"
35cp "${systemplist}" "${bootplist}"
36fi
37fi
38echo "-----------------------------------------------"
39echo ""
40
41
42echo "==============================================="
43echo "Build Extra/com.apple.Boot.plist"
44echo "********************************"
45
46mv "${bootplist}" "${bootplist}.orig"
47
48#prefunctionifs="${IFS}"
49
50fileinput="${bootplist}.orig"
51fileoutput="${bootplist}"
52find="<key>Kernel Flags</key>"
53replace=""
54deletelines=""
55insertlinesskip="2"
56
57matchlinefound="0"
58
59while read line
60do
61{
62if [ ! "${line}" = "${line/${find}/}" ]; then
63{
64# Trim the longest match from the end for <*
65xmlelementindent="${line%%<*}"
66
67# Trim the longest match from the start for *<
68xmlelementtemp="${line#*<}"
69# Add back in stripped <
70xmlelement="<${xmlelementtemp}"
71
72# Trim the shortest match from the start for <
73xmltagtemp="${xmlelement#<}"
74# Trim the longest match from the end for >*
75xmltag="${xmltagtemp%%>*}"
76
77# Trim the shortest match from the start for *>
78xmltexttemp="${xmlelement#*>}"
79# Trim the longest match from the end for <*
80xmltext="${xmltexttemp%%<*}"
81
82if [ "${replace}" ]; then
83echo "${xmlelementindent}<${xmltag}>${replace}</${xmltag}>" >>"${fileoutput}"
84else
85echo "${line}" >>"${fileoutput}"
86fi
87
88matchlinefound="1"
89
90}
91else
92{
93
94if [ "${insertlinesskip}" ] && [ "${matchlinefound}" -gt 0 ] && [ "${matchlinefound}" -le "${insertlinesskip}" ]; then
95if [ "${matchlinefound}" = "${insertlinesskip}" ]; then
96
97for bootOptionFile in $Dirlist ; do
98overide=$(echo $bootOptionFile | sed 's/_/ /g' | tr -d "./@" |cut -d '+' -f1)
99string=$(echo $bootOptionFile | tr -d "./@" |cut -d'+' -f2)
100
101bootoptionshdextra[1]="<key>${overide}</key>"
102bootoptionshdextra[2]="<string>${string}</string>"
103
104echo "Adding ${overide}=${string} to ${bootplist}"
105 array=("${bootoptionshdextra[@]}")
106arraysize=0
107
108#prefunctionifs="${IFS}"
109#IFS="\n"
110
111while [ ${arraysize} -lt ${#array[@]} ];
112do
113echo "${xmlelementindent}${array[${arraysize}]}" >>"${fileoutput}"
114 let arraysize="${arraysize}+1"
115done
116
117#IFS=${prefunctionifs}
118done
119
120#echo "set owner privileges for ${bootplist}"
121chown "${USER}:20" "${bootplist}"
122fi
123fi
124
125if [ "${deletelines}" ] && [ "${matchlinefound}" -gt 0 ] && [ "${matchlinefound}" -lt $((${deletelines}+${deletelinesskip})) ] && [ "${matchlinefound}" -ge ${deletelinesskip} ]; then
126:
127else
128echo "${line}" >>"${fileoutput}"
129fi
130
131if [ "${matchlinefound}" -gt 0 ]; then
132let matchlinefound="${matchlinefound}+1"
133fi
134
135}
136fi
137}
138done < "${fileinput}"
139
140#IFS=${prefunctionifs}
141rm -f "${fileinput}"
142
143echo ""
144
145echo "-----------------------------------------------"
146echo ""
147
148
149echo "==============================================="
150echo "Clean up and Remove Boot Option Null Files"
151echo "******************************************"
152
153# make sure we're in the right directory
154cd "${tempDir}"
155
156Dirlist=$(find . -type f | grep "@")
157for bootOptionFile in ${Dirlist} ; do
158echo "Removing temporary boot option file: ${bootOptionFile}"
159rm $bootOptionFile
160done
161
162echo "-----------------------------------------------"
163echo ""
164
165else
166echo "No boot options in the temporary directory."
167fi
168fi
169}
170
171
172
173echo "==============================================="
174echo "Enter Build Boot Options script"
175echo "*******************************"
176
177# get the passed destination drive?
178
179if [ "$#" -eq 1 ]; then
180destinationDrive="$1"
181echo "DEBUG: passed argument for destinationDrive = $destinationDrive"
182fi
183
184# Build Boot Options
185main "${1}" "${2}" "${3}" "${4}"
186
187exit 0
188

Archive Download this file

Revision: 257