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