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