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