Root/
| |
---|---|
Source at commit 1081 created 13 years 1 month ago. By azimutz, Sync these two with trunk (r1078). | |
1 | #!/bin/bash␊ |
2 | ␊ |
3 | # set com.apple.Boot.plist options␊ |
4 | ␊ |
5 | overide="EthernetBuiltIn"␊ |
6 | string="y"␊ |
7 | ␊ |
8 | main ()␊ |
9 | {␊ |
10 | ␊ |
11 | ␉bootplist="${3}/.Chameleon/Extra/com.apple.Boot.plist"␊ |
12 | ␉systemplist="/Library/Preferences/SystemConfiguration/com.apple.Boot.plist"␊ |
13 | ␊ |
14 | ␉bootoptionshdextra[1]="<key>${overide}</key>"␊ |
15 | ␉bootoptionshdextra[2]="<string>${string}</string>"␊ |
16 | ␊ |
17 | ␉[ ! -d "${bootplist%/*}" ] && mkdir -p "${bootplist%/*}"␊ |
18 | ␉␊ |
19 | ␉if [ ! -f "${bootplist}" ]; then␊ |
20 | ␉␉if [ -f "${systemplist}" ]; then␊ |
21 | ␉␉␉cp -f "${systemplist}" "${bootplist}"␊ |
22 | ␉␉fi␊ |
23 | ␉fi␊ |
24 | ␉␊ |
25 | ␉xmlvalue=$( getxmlvalue ${overide} "${bootplist}" | tr "[:upper:]" "[:lower:]" )␊ |
26 | ␉␊ |
27 | ␉case "${xmlvalue:0:1}" in␊ |
28 | ␉␉␉␉␊ |
29 | ␉␉y)␉echo "${overide}=y already set in ${bootplist} skipping."␊ |
30 | ␉␉␉;;␊ |
31 | ␊ |
32 | ␉␉n)␉echo "${overide}=n is set in ${bootplist} leaving."␊ |
33 | ␉␉␉;;␊ |
34 | ␉␊ |
35 | ␉ ␉*)␉echo "Adding ${overide}=y to ${bootplist}"␊ |
36 | ␉ ␉␉array=("${bootoptionshdextra[@]}")␊ |
37 | ␉␉␉searchfilereplaceline "${bootplist}" "<key>Kernel Flags</key>" "" "" "2"␊ |
38 | ␉␉␉;;␊ |
39 | ␉esac␊ |
40 | ␊ |
41 | ␉chown "${USER}:20" "${bootplist}"␊ |
42 | }␊ |
43 | ␊ |
44 | getxmlvalue ()␊ |
45 | {␊ |
46 | # 1 xml key␊ |
47 | # 2 xml file␊ |
48 | if [ -f "${2}" ]; then␊ |
49 | ␉local value␊ |
50 | ␉while read value; do␊ |
51 | ␉if [ ! "${value}" = "${value/<key>${1}</key>/}" ]; then␊ |
52 | ␉␉read value␊ |
53 | ␉␉value="${value#*<}" ; value="<${value}" ; value="${value#*>}" ; value="${value# *}" ; value="${value%%<*}"␊ |
54 | ␉␉echo "$value"␊ |
55 | ␉␉break␊ |
56 | ␉fi␊ |
57 | ␉done < "${2}"␊ |
58 | fi␊ |
59 | }␊ |
60 | ␊ |
61 | searchfilereplaceline ()␊ |
62 | {␊ |
63 | ␊ |
64 | mv "${1}" "${1}.orig"␊ |
65 | ␊ |
66 | prefunctionifs="${IFS}"␊ |
67 | ␊ |
68 | unset fileinput␊ |
69 | unset fileoutput␊ |
70 | unset find␊ |
71 | unset replace␊ |
72 | unset deletelines␊ |
73 | unset deletelinesskip␊ |
74 | unset insertlinesskip␊ |
75 | ␊ |
76 | fileinput="${1}.orig"␊ |
77 | fileoutput="${1}"␊ |
78 | find="${2}"␊ |
79 | replace="${3}"␊ |
80 | deletelines="${4%,*}"␊ |
81 | insertlinesskip="${5}"␊ |
82 | ␊ |
83 | matchlinefound="0"␊ |
84 | ␊ |
85 | if [ "${#4}" = "${4#*,}" ]; then␊ |
86 | deletelinesskip="0"␊ |
87 | ␉else␊ |
88 | ␉deletelinesskip="${4#*,}"␊ |
89 | fi␊ |
90 | ␊ |
91 | IFS="\n"␊ |
92 | while read line␊ |
93 | do␊ |
94 | ␉{␊ |
95 | ␉if [ ! "${line}" = "${line/${find}/}" ]; then␊ |
96 | ␉␉{␊ |
97 | ␉␉# Trim the longest match from the end for <*␊ |
98 | ␉␉xmlelementindent="${line%%<*}"␊ |
99 | ␊ |
100 | ␉␉# Trim the longest match from the start for *<␊ |
101 | ␉␉xmlelementtemp="${line#*<}"␊ |
102 | ␉␉# Add back in stripped <␊ |
103 | ␉␉xmlelement="<${xmlelementtemp}"␊ |
104 | ␊ |
105 | ␉␉# Trim the shortest match from the start for <␊ |
106 | ␉␉xmltagtemp="${xmlelement#<}"␊ |
107 | ␉␉# Trim the longest match from the end for >*␊ |
108 | ␉␉xmltag="${xmltagtemp%%>*}"␊ |
109 | ␊ |
110 | ␉␉# Trim the shortest match from the start for *>␊ |
111 | ␉␉xmltexttemp="${xmlelement#*>}"␊ |
112 | ␉␉# Trim the longest match from the end for <*␊ |
113 | ␉␉xmltext="${xmltexttemp%%<*}"␊ |
114 | ␊ |
115 | ␉␉if [ "${replace}" ]; then␊ |
116 | ␉␉␉{␊ |
117 | ␉␉␉␉echo "${xmlelementindent}<${xmltag}>${replace}</${xmltag}>" >>"${fileoutput}"␊ |
118 | ␉␉␉}␊ |
119 | ␉␉␉else␊ |
120 | ␉␉␉{␊ |
121 | ␉␉␉␉echo "${line}" >>"${fileoutput}"␊ |
122 | ␉␉␉}␊ |
123 | ␉␉fi␊ |
124 | ␉␉matchlinefound="1"␊ |
125 | ␊ |
126 | ␉␉}␊ |
127 | ␉␉else␊ |
128 | ␉␉{␊ |
129 | ␊ |
130 | ␉␉if [ "${insertlinesskip}" ] && [ "${matchlinefound}" -gt 0 ] && [ "${matchlinefound}" -le "${insertlinesskip}" ]; then␊ |
131 | ␉␉␉{␊ |
132 | ␉␉␉if [ "${matchlinefound}" = "${insertlinesskip}" ]; then␊ |
133 | ␉␉␉␉{␊ |
134 | ␉␉␉␉arraysize=0␊ |
135 | ␉␉␉␉while [ ${arraysize} -lt ${#array[@]} ];␊ |
136 | ␉␉␉␉do␊ |
137 | ␉␉␉␉␉echo "${xmlelementindent}${array[${arraysize}]}" >>"${fileoutput}"␊ |
138 | ␉␉␉␉ let arraysize="${arraysize}+1"␊ |
139 | ␉␉␉␉done␊ |
140 | ␉␉␉␉}␊ |
141 | ␉␉␉fi␊ |
142 | ␉␉␉}␊ |
143 | ␉␉fi␊ |
144 | ␊ |
145 | ␉␉if [ "${deletelines}" ] && [ "${matchlinefound}" -gt 0 ] && [ "${matchlinefound}" -lt $((${deletelines}+${deletelinesskip})) ] && [ "${matchlinefound}" -ge ${deletelinesskip} ]; then␊ |
146 | ␉␉␉{␊ |
147 | ␉␉␉:␊ |
148 | ␉␉␉}␊ |
149 | ␉␉␉else␊ |
150 | ␉␉␉{␊ |
151 | ␉␉␉echo "${line}" >>"${fileoutput}"␊ |
152 | ␉␉␉}␊ |
153 | ␉␉fi␊ |
154 | ␊ |
155 | ␉␉if [ "${matchlinefound}" -gt 0 ]; then␊ |
156 | ␉␉␉let matchlinefound="${matchlinefound}+1"␊ |
157 | ␉␉fi␊ |
158 | ␊ |
159 | ␉␉}␊ |
160 | ␉fi␊ |
161 | ␉}␊ |
162 | done < "${fileinput}"␊ |
163 | ␊ |
164 | IFS=${prefunctionifs}␊ |
165 | ␊ |
166 | rm -f "${fileinput}"␊ |
167 | }␊ |
168 | ␊ |
169 | main "${1}" "${2}" "${3}" "${4}"␊ |
170 |