Chameleon

Chameleon Svn Source Tree

Root/trunk/package/Scripts/Options/GraphicsEnabler/postinstall.sh

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

Archive Download this file

Revision: 1012