Magellan Linux

Annotation of /tags/openglupdate-2_3_12/dri-update.in

Parent Directory Parent Directory | Revision Log Revision Log


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