Magellan Linux

Annotation of /trunk/hwinfo/emulate-hwsetup.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2677 - (hide annotations) (download) (as text)
Fri Jul 24 10:47:30 2015 UTC (8 years, 10 months ago) by niro
File MIME type: application/x-sh
File size: 6993 byte(s)
-detect the primary gfxcard only
1 niro 1197 #!/bin/bash
2    
3     export LC_ALL=C
4    
5 niro 1320 HWSETUP_DIR=/etc/conf.d/hwsetup
6 niro 1197 HWINFO="/usr/sbin/hwinfo"
7    
8 niro 1213 UNSUPPORTED_GFXCARD_DRIVERS=""
9     UNSUPPORTED_NETCARD_DRIVERS=""
10     if [ -f ${HWSETUP_DIR}/unsupported-gfxcard-drivers ]
11     then
12     UNSUPPORTED_GFXCARD_DRIVERS="$(< ${HWSETUP_DIR}/unsupported-gfxcard-drivers)"
13     fi
14     if [ -f ${HWSETUP_DIR}/unsupported-netcard-drivers ]
15     then
16     UNSUPPORTED_NETCARD_DRIVERS="$(< ${HWSETUP_DIR}/unsupported-netcard-drivers)"
17     fi
18    
19 niro 1197 clearconfig()
20     {
21     local file="$1"
22     : > ${HWSETUP_DIR}/${file}
23     }
24    
25     addconfig()
26     {
27     local file="$1"
28     local data="$2"
29    
30     echo "${data}" >> ${HWSETUP_DIR}/${file}
31     }
32    
33 niro 1213 # check_unsupported_netcard_drivers UNSUPPORTED_ARRAY DRIVER
34     check_unsupported_drivers()
35     {
36     local unsupported="$1"
37     local driver="$2"
38     local i
39    
40     # filter unsupported devices
41     for i in ${unsupported}
42     do
43     [[ ${i} = ${driver} ]] && return 1
44     done
45     return 0
46     }
47    
48 niro 2677 get_gfxcard_sysfsid_from_specific_hwid()
49     {
50     local SEARCH_ID="$1"
51     local hwid
52     local sysfsid
53     local counter
54    
55     declare -i counter=0
56    
57     echo "${GFXCARD_INFO}" | while read line
58     do
59     # get hwinfo device id, its always the first line
60     if [[ ${counter} = 0 ]]
61     then
62     # hwids begins all with ^ID:, sub informations have an empty space
63     hwid=$(echo "${line}" | grep '^[0-9].*' | sed 's:\(^[0-9]*\)\:\ .*:\1:')
64     fi
65    
66     # search for device id
67     if [[ ${SEARCH_ID} = ${hwid} ]]
68     then
69     case "${line}" in
70     *'SysFS ID:'*)
71     # subst the id
72     sysfsid="${line#*:}"
73     # trim spaces
74     sysfsid="${sysfsid// }"
75     echo "${sysfsid}"
76     ;;
77     esac
78     fi
79    
80     # next hardware item
81     if [[ -z ${line} ]]
82     then
83     counter=0
84     else
85     ((counter++))
86     fi
87     done
88     }
89    
90     get_primary_display_hwid()
91     {
92     local hwid
93     hwid="$(echo "${GFXCARD_INFO}" | grep 'Primary display adapter:' | sed 's:.*\:\ \#\([0-9]*\):\1:')"
94     echo "${hwid}"
95     }
96    
97    
98 niro 1225 # disable probeonly, load all modules by default
99     probeonly=0
100    
101     # check getops
102     for i in $*
103     do
104     case $1 in
105     # ignoring -p,-v,-a,-s
106     -p|-v|-a|-s) shift;;
107     # only support dry-run
108     -n) shift; probeonly=1 ;;
109     esac
110     shift
111     done
112    
113 niro 1200 echo -n "Autoconfiguring devices... " 1>&2
114    
115 niro 1197 GFXCARD_INFO="$(${HWINFO} --gfxcard)"
116 niro 2677 # check for a primary device and rerun hwinfo for this device only
117     primary_display_hwid="$(get_primary_display_hwid)"
118     if [[ -n ${primary_display_hwid} ]]
119     then
120     GFXCARD_INFO="$(${HWINFO} --gfxcard --only $(get_gfxcard_sysfsid_from_specific_hwid ${primary_display_hwid}))"
121     fi
122 niro 1197 NETCARD_INFO="$(${HWINFO} --netcard)"
123     MOUSE_INFO="$(${HWINFO} --mouse)"
124    
125     # eval arrays with all modules and descriptions
126     #
127     # graphic
128     eval $(echo GFXCARD_MODULE=\($(echo "${GFXCARD_INFO}" | grep 'XFree86.*Module:' | sed 's:.*\:\ \(.*\)$:\"\1\":')\))
129     eval $(echo GFXCARD_DESC=\($(echo "${GFXCARD_INFO}" | grep 'Model:' | sed 's:.*\:\ \"\(.*\)\"$:\"\1\":')\))
130     # the xserver is always xorg, no array needed
131     GFXCARD_XSERVER="Xorg"
132     #
133     # network
134     eval $(echo NETCARD_MODULE=\($(echo "${NETCARD_INFO}" | grep 'Driver Modules:' | sed 's:.*\:\ \"\(.*\)\"$:\"\1\":')\))
135     eval $(echo NETCARD_DESC=\($(echo "${NETCARD_INFO}" | grep 'Model:' | sed 's:.*\:\ \"\(.*\)\"$:\"\1\":')\))
136 niro 1200 # fallback (only needed for systems without netlink)
137     eval $(echo NETCARD_MODULE_FB=\($(echo "${NETCARD_INFO}" | grep 'Driver Activation Cmd:' | sed 's:.*\:\ \"modprobe\ \(.*\)\"$:\"\1\":')\))
138 niro 1197 #
139     # mouse
140     eval $(echo MOUSE_MODULE=\($(echo "${MOUSE_INFO}" | grep 'Driver Modules:' | sed 's:.*\:\ \"\(.*\)\"$:\"\1\":')\))
141     eval $(echo MOUSE_DESC=\($(echo "${MOUSE_INFO}" | grep 'Model:' | sed 's:.*\:\ \"\(.*\)\"$:\"\1\":')\))
142     eval $(echo MOUSE_DEVICE=\($(echo "${MOUSE_INFO}" | grep 'Device File:' | sed 's:.*\:\ \(.*\)[$\ ].*:\"\1\":')\))
143     eval $(echo MOUSE_GPM_PROTO=\($(echo "${MOUSE_INFO}" | grep 'GPM.*Protocol:' | sed 's:.*\:\ \(.*\)$:\"\1\":')\))
144     eval $(echo MOUSE_X11_PROTO=\($(echo "${MOUSE_INFO}" | grep 'XFree86.*Protocol:' | sed 's:.*\:\ \(.*\)$:\"\1\":')\))
145    
146     # get the number of devices for each class
147     GFXCARD_COUNT=$(echo "${GFXCARD_INFO}" | grep -c "[0-9a-zA-Z]\: .*\:\ .*")
148     NETCARD_COUNT=$(echo "${NETCARD_INFO}" | grep -c "[0-9a-zA-Z]\: .*\:\ .*")
149     MOUSE_COUNT=$(echo "${MOUSE_INFO}" | grep -c "[0-9a-zA-Z]\: .*\:\ .*")
150    
151    
152     # clear all config files
153     clearconfig xserver
154     clearconfig netcard
155     clearconfig knoppix
156     clearconfig mouse
157    
158     for ((i=0; i<GFXCARD_COUNT; i++))
159     do
160 niro 1198 # fallback to vesa
161     if [[ -z ${GFXCARD_MODULE[${i}]} ]]
162     then
163     GFXCARD_MODULE[${i}]="vesa"
164     fi
165 niro 1213
166     # exclude unsupported drivers
167     check_unsupported_drivers "${UNSUPPORTED_GFXCARD_DRIVERS}" "${NETCARD_MODULE[${i}]}" || continue
168    
169 niro 1197 addconfig xserver "XSERVER=\"${GFXCARD_XSERVER}\""
170     addconfig xserver "XMODULE=\"${GFXCARD_MODULE[${i}]}\""
171     addconfig xserver "XDESC=\"${GFXCARD_DESC[${i}]}\""
172    
173     # add them to knoppix too
174     addconfig knoppix "XSERVER=\"${GFXCARD_XSERVER}\""
175     addconfig knoppix "XMODULE=\"${GFXCARD_MODULE[${i}]}\""
176     addconfig knoppix "XDESC=\"${GFXCARD_DESC[${i}]}\""
177 niro 1227
178     # load some needed modules for xorg-servers without udev or hal support, which the driver would normally autoload
179     case "${GFXCARD_MODULE[${i}]}" in
180     intel|i810) modprobe -q intel-agp ;;
181     nv) modprobe -q nvidia-agp ;;
182     sis) modprobe -q sis-agp ;;
183     ati|radeon|r128|mach64) modprobe -q ati-agp ;;
184 niro 1545 via|openchrome|unichrome) modprobe -q via-agp ;;
185 niro 1227 esac
186 niro 1197 done
187    
188     for ((i=0; i<NETCARD_COUNT; i++))
189     do
190 niro 1200 # use fallback
191     if [[ -z ${NETCARD_MODULE[${i}]} ]]
192     then
193     NETCARD_MODULE[${i}]="${NETCARD_MODULE_FB[${i}]}"
194     fi
195 niro 1213
196 niro 2675 # exclude this driver if its still empty, the provided kernel does not support this hardware
197     if [[ -z ${NETCARD_MODULE[${i}]} ]]
198     then
199     continue
200     fi
201    
202 niro 1213 # exclude unsupported drivers
203     check_unsupported_drivers "${UNSUPPORTED_NETCARD_DRIVERS}" "${NETCARD_MODULE[${i}]}" || continue
204    
205 niro 1197 addconfig netcard "FULLNAME=\"${NETCARD_DESC[${i}]}\""
206     addconfig netcard "DRIVER=\"${NETCARD_MODULE[${i}]}\""
207    
208     # add them to knoppix too
209     addconfig knoppix "NETCARD_FULLNAME=\"${NETCARD_DESC[${i}]}\""
210     addconfig knoppix "NETCARD_DRIVER=\"${NETCARD_MODULE[${i}]}\""
211 niro 1225
212     # load the netcard modules
213     if [[ ${probeonly} = 0 ]]
214     then
215     modprobe -q "${NETCARD_MODULE[${i}]}"
216     fi
217 niro 1197 done
218    
219     for ((i=0; i<MOUSE_COUNT; i++))
220     do
221     # fix mouseproto to be hwsetup compatible (it just guesses the proto :/ )
222     case "${MOUSE_GPM_PROTO[${i}]}" in
223     exps2) MOUSE_GPM_PROTO[${i}]="ps2" ;;
224 niro 1198 "") MOUSE_GPM_PROTO[${i}]="ps2" ;;
225 niro 1197 esac
226     case "${MOUSE_X11_PROTO[${i}]}" in
227     explorerps/2) MOUSE_X11_PROTO[${i}]="IMPS/2" ;;
228     ps/2) MOUSE_X11_PROTO[${i}]="PS/2" ;;
229 niro 1198 "") MOUSE_X11_PROTO[${i}]="PS/2" ;;
230 niro 1197 esac
231    
232     addconfig mouse "MOUSETYPE=\"${MOUSE_GPM_PROTO[${i}]}\""
233     addconfig mouse "XMOUSETYPE=\"${MOUSE_X11_PROTO[${i}]}\""
234     addconfig mouse "FULLNAME=\"${MOUSE_DESC[${i}]}\""
235     addconfig mouse "DEVICE=\"${MOUSE_DEVICE[${i}]}\""
236     addconfig mouse "DRIVER=\"${MOUSE_MODULE[${i}]}\""
237    
238     # add them to knoppix too
239     addconfig knoppix "MOUSE_MOUSETYPE=\"${MOUSE_GPM_PROTO[${i}]}\""
240     addconfig knoppix "MOUSE_XMOUSETYPE=\"${MOUSE_X11_PROTO[${i}]}\""
241     addconfig knoppix "MOUSE_FULLNAME=\"${MOUSE_DESC[${i}]}\""
242     addconfig knoppix "MOUSE_DEVICE=\"${MOUSE_DEVICE[${i}]}\""
243     addconfig knoppix "MOUSE_DRIVER=\"${MOUSE_MODULE[${i}]}\""
244     done
245 niro 1200
246     echo "Done." 1>&2