Contents of /tags/openglupdate-2_2_9/opengl-update.sh
Parent Directory | Revision Log
Revision 633 -
(show annotations)
(download)
(as text)
Wed Nov 14 19:19:16 2007 UTC (16 years, 10 months ago) by niro
Original Path: trunk/opengl-update/opengl-update.sh
File MIME type: application/x-sh
File size: 9739 byte(s)
Wed Nov 14 19:19:16 2007 UTC (16 years, 10 months ago) by niro
Original Path: trunk/opengl-update/opengl-update.sh
File MIME type: application/x-sh
File size: 9739 byte(s)
-fixed usage: tell something about the --help and --version option
1 | #!/bin/bash |
2 | # Copyright 1999-2004 Gentoo Foundation |
3 | # Distributed under the terms of the GNU General Public License v2 |
4 | # $Header: /home/cvsd/magellan-cvs/magellan-src/opengl-update/opengl-update.sh,v 1.10 2007-11-14 19:19:16 niro Exp $ |
5 | # Author: Martin Schlemmer <azarah@gentoo.org> |
6 | # Further modifications by Donnie Berkholz <spyderous@gentoo.org> |
7 | # Further modifications based off submissions to bug #54984 <cyfred@gentoo.org> |
8 | # Further modifications by Jeremy Huddleston <eradicator@gentoo.org> |
9 | # |
10 | # hacked for use with magellan-linux |
11 | # <niro@magellan-linux.de> |
12 | # |
13 | |
14 | . /etc/init.d/functions |
15 | |
16 | hasq() |
17 | { |
18 | local x |
19 | |
20 | local me=${1} |
21 | shift |
22 | |
23 | for x in $@ |
24 | do |
25 | [[ ${x} = ${me} ]] && return 0 |
26 | done |
27 | |
28 | return 1 |
29 | } |
30 | |
31 | check_user() |
32 | { |
33 | if [[ $(id -u) -ne 0 ]] |
34 | then |
35 | echo "${0}: Must be run as root." |
36 | exit 1 |
37 | fi |
38 | } |
39 | |
40 | get_current_implem() |
41 | { |
42 | local implem |
43 | |
44 | if [[ -f ${ENV_D} ]] |
45 | then |
46 | source ${ENV_D} |
47 | if [[ -n ${OPENGL_PROFILE} ]] |
48 | then |
49 | implem="${OPENGL_PROFILE}" |
50 | elif [[ -n ${LDPATH} ]] |
51 | then |
52 | implem="${LDPATH%%:*}" |
53 | implem="${implem##*opengl/}" |
54 | implem="${implem%/lib*}" |
55 | fi |
56 | unset LDPATH |
57 | unset OPENGL_PROFILE |
58 | fi |
59 | |
60 | echo ${implem} |
61 | } |
62 | |
63 | get_implementations() |
64 | { |
65 | local implems |
66 | |
67 | for dir in ${PREFIX}/lib{,32,64}/opengl/* |
68 | do |
69 | if [[ -d ${dir} ]] && |
70 | [[ ${dir##*/} != global ]] && |
71 | ! hasq ${dir##*/} ${implems} |
72 | then |
73 | implems=${implems:+${implems} }${dir##*/} |
74 | fi |
75 | done |
76 | |
77 | echo ${implems} |
78 | } |
79 | |
80 | print_version() |
81 | { |
82 | echo "opengl-update ${VERSION}" |
83 | } |
84 | |
85 | print_usage() |
86 | { |
87 | # Get grammar right in message |
88 | local IS_ARE IMPLEM_PLURAL |
89 | |
90 | if [[ $(echo ${AVAIL_IMPLEMS} | wc -w) -eq 1 ]] |
91 | then |
92 | IS_ARE="is" |
93 | IMPLEM_PLURAL="" |
94 | else |
95 | IS_ARE="are" |
96 | IMPLEM_PLURAL="s" |
97 | fi |
98 | |
99 | print_version |
100 | |
101 | cat << FOO |
102 | Usage: ${0##*/} [<options>] <GL implementation> |
103 | Set the opengl implementation. |
104 | Valid options: |
105 | --help|-h|-?: Prints this help. |
106 | --version: Shows the version of this utility. |
107 | --use-old: If an implementation is already set, use that one. |
108 | --prefix=<val>: Set the source prefix (default: /usr) |
109 | --dst-prefix=<val>: Set the destination prefix (default: /usr) |
110 | --impl-headers: Use headers provided by this implementation to |
111 | override global ones provided by opengl-update. |
112 | |
113 | Usage: ${0##*/} --get-implementation |
114 | Print the current implementaion |
115 | |
116 | Notes: |
117 | --impl-headers was default in <opengl-update-2.2. |
118 | |
119 | This utility switches between OpenGL implementations. There ${IS_ARE} |
120 | $(echo ${AVAIL_IMPLEMS} | wc -w) available implementation${IMPLEM_PLURAL}: ${AVAIL_IMPLEMS} |
121 | |
122 | Examples: |
123 | ${0##*/} xorg |
124 | This will setup things to use libGL.so from X.org. |
125 | |
126 | ${0##*/} nvidia |
127 | This will setup things to use libGL.so from the nVidia drivers. |
128 | |
129 | FOO |
130 | exit 1 |
131 | } |
132 | |
133 | parse_options() |
134 | { |
135 | local opt |
136 | |
137 | while [[ ${#} -gt 0 ]] |
138 | do |
139 | opt=${1} |
140 | shift |
141 | case ${opt} in |
142 | --use-old) |
143 | if [[ -n ${ACTION} ]] |
144 | then |
145 | ACTION="error" |
146 | echo "Invalid usage." |
147 | else |
148 | if [[ -n "${CURRENT_GL_IMPLEM}" ]] && |
149 | hasq ${CURRENT_GL_IMPLEM} ${AVAIL_IMPLEMS} |
150 | then |
151 | ACTION="old-implementation" |
152 | fi |
153 | fi |
154 | ;; |
155 | |
156 | --get-implementation) |
157 | if [[ -n ${ACTION} ]] |
158 | then |
159 | ACTION="error" |
160 | echo "Invalid usage." |
161 | else |
162 | ACTION="get-implementation" |
163 | fi |
164 | ;; |
165 | |
166 | --prefix=*) |
167 | PREFIX=${opt#*=} |
168 | AVAIL_IMPLEMS=$(get_implementations) |
169 | ;; |
170 | |
171 | --dst-prefix=*) DST_PREFIX=${opt#*=} ;; |
172 | |
173 | --impl-headers) USE_PROFILE_HEADERS="yes" ;; |
174 | |
175 | --help|-h|-?) ACTION="usage" ;; |
176 | |
177 | --version) ACTION="version" ;; |
178 | |
179 | *) |
180 | if hasq ${opt} ${AVAIL_IMPLEMS} |
181 | then |
182 | if [[ ${ACTION} != old-implementation ]] |
183 | then |
184 | if [[ -n ${ACTION} ]] |
185 | then |
186 | ACTION="error" |
187 | echo "Invalid usage." |
188 | else |
189 | ACTION="set-implementation" |
190 | NEW_GL_IMPLEM="${opt}" |
191 | fi |
192 | fi |
193 | else |
194 | echo "Unrecognized option: ${opt}" |
195 | ACTION="error" |
196 | fi |
197 | ;; |
198 | esac |
199 | done |
200 | } |
201 | |
202 | set_new_implementation() |
203 | { |
204 | local GL_IMPLEM=${1} |
205 | local GL_LOCAL |
206 | |
207 | check_user |
208 | |
209 | # Set a sane umask... bug #83115 |
210 | umask 022 |
211 | |
212 | if ! hasq ${GL_IMPLEM} ${AVAIL_IMPLEMS} |
213 | then |
214 | echo "Invalid profile selected." |
215 | exit 1 |
216 | fi |
217 | |
218 | echo "Switching to ${GL_IMPLEM} OpenGL interface" |
219 | |
220 | rm -f ${ENV_D} &> /dev/null |
221 | |
222 | LIBDIRS="lib32 lib lib64" |
223 | for LIBDIR in ${LIBDIRS} |
224 | do |
225 | # Special case handling of lib32 because it can be a symlink to |
226 | # emul libs |
227 | if [[ ${LIBDIR} = lib32 ]] |
228 | then |
229 | [[ -d ${PREFIX}/${LIBDIR}/opengl ]] || continue |
230 | else |
231 | [[ -d ${PREFIX}/${LIBDIR}/opengl ]] && |
232 | [[ ! -h ${PREFIX}/${LIBDIR} ]] || continue |
233 | fi |
234 | |
235 | # Fallback on xorg if we don't have this implementation for this LIBDIR. |
236 | if [[ ! -d ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM} ]] |
237 | then |
238 | GL_LOCAL="xorg" |
239 | else |
240 | GL_LOCAL="${GL_IMPLEM}" |
241 | fi |
242 | |
243 | mkdir -p ${DST_PREFIX}/${LIBDIR} |
244 | pushd ${DST_PREFIX}/${LIBDIR} &> /dev/null |
245 | # First remove old symlinks |
246 | for file in libGL{,core}.{a,so,la} |
247 | do |
248 | [[ -h ${file} ]] && rm -f ${file} |
249 | done |
250 | |
251 | # Note that we don't do .so*, just .so on purpose. The |
252 | # loader knows to look in the profile dir, and the |
253 | # linked just needs the .so |
254 | for file in ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib/libGL{,core}.{so,a,la} |
255 | do |
256 | [[ -f ${file} ]] || continue |
257 | [[ -f ${file##*/} ]] && rm -f ${file##*/} |
258 | |
259 | # Fix libtool archives (#48297) |
260 | if [[ ${file%.la} != ${file} ]] |
261 | then |
262 | sed "s:${PREFIX}/[^/]*/opengl/[^/]*/lib:${DST_PREFIX}/${LIBDIR}:g" ${file} > ${file##*/} |
263 | else |
264 | ln -s ${file} |
265 | fi |
266 | done |
267 | popd &> /dev/null |
268 | |
269 | if [[ -e ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib/tls ]] |
270 | then |
271 | mkdir -p ${DST_PREFIX}/${LIBDIR}/tls |
272 | pushd ${DST_PREFIX}/${LIBDIR}/tls &> /dev/null |
273 | # First remove old symlinks |
274 | for file in libGL{,core}.{a,so,la} |
275 | do |
276 | [[ -h ${file} ]] && rm -f ${file} |
277 | done |
278 | |
279 | for file in ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib/tls/libGL{,core}.{so,a,la} |
280 | do |
281 | [[ -f ${file} ]] || continue |
282 | [[ -f ${file##*/} ]] && rm -f ${file##*/} |
283 | |
284 | # Fix libtool archives (#48297) |
285 | if [[ ${file%.la} != ${file} ]] |
286 | then |
287 | sed "s:${PREFIX}/[^/]*/opengl/[^/]*/lib:${DST_PREFIX}/${LIBDIR}:g" ${file} > ${file##*/} |
288 | else |
289 | ln -s ${file} |
290 | fi |
291 | done |
292 | popd &> /dev/null |
293 | fi |
294 | |
295 | local MODULEDIR |
296 | if [[ -e ${DST_PREFIX}/${LIBDIR}/xorg/modules ]] |
297 | then |
298 | MODULEDIR="xorg/modules" |
299 | else |
300 | MODULEDIR="modules" |
301 | fi |
302 | |
303 | if [[ -e ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/extensions ]] |
304 | then |
305 | mkdir -p ${DST_PREFIX}/${LIBDIR}/${MODULEDIR}/extensions |
306 | pushd ${DST_PREFIX}/${LIBDIR}/${MODULEDIR}/extensions &> /dev/null |
307 | # First remove old symlinks |
308 | for file in libglx.so libglx.a |
309 | do |
310 | [[ -h ${file} ]] && rm -f ${file} |
311 | done |
312 | |
313 | for file in ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/extensions/*.{so,a,la} |
314 | do |
315 | [[ -f ${file} ]] || continue |
316 | [[ -f ${file##*/} ]] && rm -f ${file##*/} |
317 | |
318 | # Fix libtool archives (#48297) |
319 | if [[ ${file%.la} != ${file} ]] |
320 | then |
321 | sed "s:${PREFIX}/[^/]*/opengl/[^/]*/lib:${DST_PREFIX}/${LIBDIR}:g" ${file} > ${file##*/} |
322 | else |
323 | ln -s ${file} |
324 | fi |
325 | done |
326 | popd &> /dev/null |
327 | fi |
328 | |
329 | # Setup the includes |
330 | mkdir -p ${DST_PREFIX}/include/GL |
331 | pushd ${DST_PREFIX}/include/GL &> /dev/null |
332 | for file in gl.h glx.h glxtokens.h glext.h glxext.h glxmd.h glxproto.h |
333 | do |
334 | # IMPORTANT |
335 | # It is preferable currently to use the standard glext.h file |
336 | # however if an OpenGL provider must use a self produced glext.h |
337 | # then it should be installed to ${GL_IMPLEM}/include and the user |
338 | # can add the --impl-headers option to select it. |
339 | |
340 | if [[ ${USE_PROFILE_HEADERS} = yes ]] |
341 | then |
342 | # Check the profile first. |
343 | if [[ -e ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${file} ]] |
344 | then |
345 | [[ -f "${file}" || ( -L "${file}" && ! -e "${file}" ) ]] && rm -f ${file} |
346 | ln -s ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${file} |
347 | fi |
348 | continue |
349 | fi |
350 | |
351 | if [[ -e ${PREFIX}/${LIBDIR}/opengl/global/include/${file} ]] |
352 | then |
353 | [[ -f "${file}" || ( -L "${file}" && ! -e "${file}" ) ]] && rm -f ${file} |
354 | ln -s ${PREFIX}/${LIBDIR}/opengl/global/include/${file} |
355 | elif [[ -e ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${file} ]] |
356 | then |
357 | [[ -f "${file}" || ( -L "${file}" && ! -e "${file}" ) ]] && rm -f ${file} |
358 | ln -s ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${file} |
359 | elif [[ -e ${PREFIX}/${LIBDIR}/opengl/xorg/include/${file} ]] |
360 | then |
361 | [[ -f "${file}" || ( -L "${file}" && ! -e "${file}" ) ]] && rm -f ${file} |
362 | ln -s ${PREFIX}/${LIBDIR}/opengl/xorg/include/${file} |
363 | fi |
364 | done |
365 | popd &> /dev/null |
366 | |
367 | # Setup the $LDPATH |
368 | ldpath="${ldpath:+${ldpath}:}${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib" |
369 | |
370 | done |
371 | |
372 | # put only one LDPATH per line! |
373 | local i |
374 | for i in $(echo ${ldpath} | sed "s:\::\ :g") |
375 | do |
376 | echo "LDPATH=\"${i}\"" >> ${ENV_D} |
377 | done |
378 | echo "OPENGL_PROFILE=\"${GL_IMPLEM}\"" >> ${ENV_D} |
379 | |
380 | env-rebuild |
381 | |
382 | return 0 |
383 | } |
384 | |
385 | ## START PROGRAM ## |
386 | |
387 | ENV_D="/etc/env.d/03opengl" |
388 | NEW_GL_IMPLEM="" |
389 | ACTION="" |
390 | PREFIX="/usr" |
391 | DST_PREFIX="/usr" |
392 | AVAIL_IMPLEMS=$(get_implementations) |
393 | CURRENT_GL_IMPLEM=$(get_current_implem) |
394 | USE_PROFILE_HEADERS="no" |
395 | VERSION="@@VERSION@@" |
396 | |
397 | parse_options ${@} |
398 | |
399 | case ${ACTION} in |
400 | get-implementation) |
401 | if [[ -n ${CURRENT_GL_IMPLEM} ]] |
402 | then |
403 | echo ${CURRENT_GL_IMPLEM} |
404 | exit 0 |
405 | else |
406 | exit 2 |
407 | fi |
408 | ;; |
409 | |
410 | old-implementation) |
411 | set_new_implementation ${CURRENT_GL_IMPLEM} |
412 | exit $? |
413 | ;; |
414 | |
415 | set-implementation) |
416 | if [[ -n ${NEW_GL_IMPLEM} ]] |
417 | then |
418 | set_new_implementation ${NEW_GL_IMPLEM} |
419 | exit $? |
420 | else |
421 | print_usage |
422 | exit 1 |
423 | fi |
424 | ;; |
425 | |
426 | version) |
427 | print_version |
428 | exit 0 |
429 | ;; |
430 | |
431 | usage) |
432 | print_usage |
433 | exit 0 |
434 | ;; |
435 | |
436 | error) |
437 | print_usage |
438 | exit 1 |
439 | ;; |
440 | |
441 | *) |
442 | print_usage |
443 | exit 1 |
444 | ;; |
445 | esac |