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