Magellan Linux

Annotation of /trunk/opengl-update/dri-update.in

Parent Directory Parent Directory | Revision Log Revision Log


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