Contents of /trunk/opengl-update/dri-update.in
Parent Directory | Revision Log
Revision 1326 -
(show annotations)
(download)
(as text)
Mon May 30 18:26:53 2011 UTC (13 years, 3 months ago) by niro
Original Path: trunk/opengl-update/dri-update.sh
File MIME type: application/x-sh
File size: 5363 byte(s)
Mon May 30 18:26:53 2011 UTC (13 years, 3 months ago) by niro
Original Path: trunk/opengl-update/dri-update.sh
File MIME type: application/x-sh
File size: 5363 byte(s)
-added dri-update for dynamic dri implementations
1 | #!/bin/bash |
2 | # Copyright 2011 Magellan-Linux |
3 | # Distributed under the terms of the GNU General Public License v2 |
4 | # $Id$ |
5 | # Author: Niels Rogalla <niro@magellan-linux.de> |
6 | # based on opengl-update from Gentoo-Linux |
7 | # |
8 | |
9 | source /etc/init.d/functions |
10 | |
11 | hasq() |
12 | { |
13 | local x |
14 | |
15 | local me=${1} |
16 | shift |
17 | |
18 | for x in $@ |
19 | do |
20 | [[ ${x} = ${me} ]] && return 0 |
21 | done |
22 | |
23 | return 1 |
24 | } |
25 | |
26 | check_user() |
27 | { |
28 | if [[ $(id -u) -ne 0 ]] |
29 | then |
30 | echo "${0}: Must be run as root." |
31 | exit 1 |
32 | fi |
33 | } |
34 | |
35 | get_current_implem() |
36 | { |
37 | local implem |
38 | |
39 | if [[ -f ${ENV_D} ]] |
40 | then |
41 | source ${ENV_D} |
42 | if [[ -n ${DRI_PROFILE} ]] |
43 | then |
44 | implem="${DRI_PROFILE}" |
45 | elif [[ -n ${LDPATH} ]] |
46 | then |
47 | implem="${LDPATH%%:*}" |
48 | implem="${implem##*mesa/}" |
49 | implem="${implem%/lib*}" |
50 | fi |
51 | unset LDPATH |
52 | unset DRI_PROFILE |
53 | fi |
54 | |
55 | echo ${implem} |
56 | } |
57 | |
58 | get_implementations() |
59 | { |
60 | local implems |
61 | |
62 | for dir in ${PREFIX}/lib{,32,64}/mesa/* |
63 | do |
64 | if [[ -d ${dir} ]] && |
65 | ! hasq ${dir##*/} ${implems} |
66 | then |
67 | implems=${implems:+${implems} }${dir##*/} |
68 | fi |
69 | done |
70 | |
71 | echo ${implems} |
72 | } |
73 | |
74 | print_version() |
75 | { |
76 | echo "dri-update ${VERSION}" |
77 | } |
78 | |
79 | print_usage() |
80 | { |
81 | # Get grammar right in message |
82 | local IS_ARE IMPLEM_PLURAL |
83 | |
84 | if [[ $(echo ${AVAIL_IMPLEMS} | wc -w) -eq 1 ]] |
85 | then |
86 | IS_ARE="is" |
87 | IMPLEM_PLURAL="" |
88 | else |
89 | IS_ARE="are" |
90 | IMPLEM_PLURAL="s" |
91 | fi |
92 | |
93 | print_version |
94 | |
95 | cat << FOO |
96 | Usage: ${0##*/} [<options>] <DRI implementation> |
97 | Set the dri implementation. |
98 | Valid options: |
99 | --help|-h|-?: Prints this help. |
100 | --version: Shows the version of this utility. |
101 | --use-old: If an implementation is already set, use that one. |
102 | --prefix=<val>: Set the source prefix (default: /usr) |
103 | --dst-prefix=<val>: Set the destination prefix (default: /usr) |
104 | |
105 | Usage: ${0##*/} --get-implementation |
106 | Print the current implementaion |
107 | |
108 | This utility switches between DRI implementations. There ${IS_ARE} |
109 | $(echo ${AVAIL_IMPLEMS} | wc -w) available implementation${IMPLEM_PLURAL}: ${AVAIL_IMPLEMS} |
110 | |
111 | Examples: |
112 | ${0##*/} classic |
113 | This will setup things to use the classic DRI drivers. |
114 | |
115 | ${0##*/} gallium |
116 | This will setup things to use the gallium DRI drivers. |
117 | |
118 | FOO |
119 | exit 1 |
120 | } |
121 | |
122 | parse_options() |
123 | { |
124 | local opt |
125 | |
126 | while [[ ${#} -gt 0 ]] |
127 | do |
128 | opt=${1} |
129 | shift |
130 | case ${opt} in |
131 | --use-old) |
132 | if [[ -n ${ACTION} ]] |
133 | then |
134 | ACTION="error" |
135 | echo "Invalid usage." |
136 | else |
137 | if [[ -n "${CURRENT_DRI_IMPLEM}" ]] && |
138 | hasq ${CURRENT_DRI_IMPLEM} ${AVAIL_IMPLEMS} |
139 | then |
140 | ACTION="old-implementation" |
141 | fi |
142 | fi |
143 | ;; |
144 | |
145 | --get-implementation) |
146 | if [[ -n ${ACTION} ]] |
147 | then |
148 | ACTION="error" |
149 | echo "Invalid usage." |
150 | else |
151 | ACTION="get-implementation" |
152 | fi |
153 | ;; |
154 | |
155 | --prefix=*) |
156 | PREFIX=${opt#*=} |
157 | AVAIL_IMPLEMS=$(get_implementations) |
158 | ;; |
159 | |
160 | --dst-prefix=*) DST_PREFIX=${opt#*=} ;; |
161 | |
162 | --help|-h|-?) ACTION="usage" ;; |
163 | |
164 | --version) ACTION="version" ;; |
165 | |
166 | *) |
167 | if hasq ${opt} ${AVAIL_IMPLEMS} |
168 | then |
169 | if [[ ${ACTION} != old-implementation ]] |
170 | then |
171 | if [[ -n ${ACTION} ]] |
172 | then |
173 | ACTION="error" |
174 | echo "Invalid usage." |
175 | else |
176 | ACTION="set-implementation" |
177 | NEW_DRI_IMPLEM="${opt}" |
178 | fi |
179 | fi |
180 | else |
181 | echo "Unrecognized option: ${opt}" |
182 | ACTION="error" |
183 | fi |
184 | ;; |
185 | esac |
186 | done |
187 | } |
188 | |
189 | set_new_implementation() |
190 | { |
191 | local DRI_IMPLEM=${1} |
192 | local DRI_LOCAL |
193 | |
194 | check_user |
195 | |
196 | # Set a sane umask... bug #83115 |
197 | umask 022 |
198 | |
199 | if ! hasq ${DRI_IMPLEM} ${AVAIL_IMPLEMS} |
200 | then |
201 | echo "Invalid profile selected." |
202 | exit 1 |
203 | fi |
204 | |
205 | echo "Switching to ${DRI_IMPLEM} DRI drivers" |
206 | |
207 | rm -f ${ENV_D} &> /dev/null |
208 | |
209 | LIBDIRS="lib32 lib lib64" |
210 | for LIBDIR in ${LIBDIRS} |
211 | do |
212 | # Special case handling of lib32 because it can be a symlink to |
213 | # emul libs |
214 | if [[ ${LIBDIR} = lib32 ]] |
215 | then |
216 | [[ -d ${PREFIX}/${LIBDIR}/mesa ]] || continue |
217 | else |
218 | [[ -d ${PREFIX}/${LIBDIR}/mesa ]] && |
219 | [[ ! -h ${PREFIX}/${LIBDIR} ]] || continue |
220 | fi |
221 | |
222 | # Fallback on classic if we don't have this implementation for this LIBDIR. |
223 | if [[ ! -d ${PREFIX}/${LIBDIR}/mesa/${DRI_IMPLEM} ]] |
224 | then |
225 | DRI_LOCAL="classic" |
226 | else |
227 | DRI_LOCAL="${DRI_IMPLEM}" |
228 | fi |
229 | |
230 | mkdir -p ${DST_PREFIX}/${LIBDIR}/dri |
231 | pushd ${DST_PREFIX}/${LIBDIR}/dri &> /dev/null |
232 | # First remove old symlinks |
233 | for file in *_dri.so |
234 | do |
235 | [[ -h ${file} ]] && rm -f ${file} |
236 | done |
237 | |
238 | for file in ${PREFIX}/${LIBDIR}/mesa/${DRI_LOCAL}/*_dri.so |
239 | do |
240 | [[ -f ${file} ]] || continue |
241 | [[ -f ${file##*/} ]] && rm -f ${file##*/} |
242 | |
243 | ln -s ${file} |
244 | done |
245 | popd &> /dev/null |
246 | done |
247 | |
248 | echo "DRI_PROFILE=\"${DRI_IMPLEM}\"" >> ${ENV_D} |
249 | |
250 | env-rebuild |
251 | |
252 | return 0 |
253 | } |
254 | |
255 | ## START PROGRAM ## |
256 | |
257 | ENV_D="/etc/env.d/03dri" |
258 | NEW_DRI_IMPLEM="" |
259 | ACTION="" |
260 | PREFIX="/usr" |
261 | DST_PREFIX="/usr" |
262 | AVAIL_IMPLEMS=$(get_implementations) |
263 | CURRENT_DRI_IMPLEM=$(get_current_implem) |
264 | VERSION="@@VERSION@@" |
265 | |
266 | parse_options ${@} |
267 | |
268 | case ${ACTION} in |
269 | get-implementation) |
270 | if [[ -n ${CURRENT_DRI_IMPLEM} ]] |
271 | then |
272 | echo ${CURRENT_DRI_IMPLEM} |
273 | exit 0 |
274 | else |
275 | exit 2 |
276 | fi |
277 | ;; |
278 | |
279 | old-implementation) |
280 | set_new_implementation ${CURRENT_DRI_IMPLEM} |
281 | exit $? |
282 | ;; |
283 | |
284 | set-implementation) |
285 | if [[ -n ${NEW_DRI_IMPLEM} ]] |
286 | then |
287 | set_new_implementation ${NEW_DRI_IMPLEM} |
288 | exit $? |
289 | else |
290 | print_usage |
291 | exit 1 |
292 | fi |
293 | ;; |
294 | |
295 | version) |
296 | print_version |
297 | exit 0 |
298 | ;; |
299 | |
300 | usage) |
301 | print_usage |
302 | exit 0 |
303 | ;; |
304 | |
305 | error) |
306 | print_usage |
307 | exit 1 |
308 | ;; |
309 | |
310 | *) |
311 | print_usage |
312 | exit 1 |
313 | ;; |
314 | esac |