Annotation of /trunk/hwinfo/emulate-hwsetup.sh
Parent Directory | Revision Log
Revision 1545 -
(hide annotations)
(download)
(as text)
Fri Nov 4 11:06:57 2011 UTC (13 years ago) by niro
File MIME type: application/x-sh
File size: 5642 byte(s)
Fri Nov 4 11:06:57 2011 UTC (13 years ago) by niro
File MIME type: application/x-sh
File size: 5642 byte(s)
-support unichrome
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 | 1225 | # disable probeonly, load all modules by default |
49 | probeonly=0 | ||
50 | |||
51 | # check getops | ||
52 | for i in $* | ||
53 | do | ||
54 | case $1 in | ||
55 | # ignoring -p,-v,-a,-s | ||
56 | -p|-v|-a|-s) shift;; | ||
57 | # only support dry-run | ||
58 | -n) shift; probeonly=1 ;; | ||
59 | esac | ||
60 | shift | ||
61 | done | ||
62 | |||
63 | niro | 1200 | echo -n "Autoconfiguring devices... " 1>&2 |
64 | |||
65 | niro | 1197 | GFXCARD_INFO="$(${HWINFO} --gfxcard)" |
66 | NETCARD_INFO="$(${HWINFO} --netcard)" | ||
67 | MOUSE_INFO="$(${HWINFO} --mouse)" | ||
68 | |||
69 | # eval arrays with all modules and descriptions | ||
70 | # | ||
71 | # graphic | ||
72 | eval $(echo GFXCARD_MODULE=\($(echo "${GFXCARD_INFO}" | grep 'XFree86.*Module:' | sed 's:.*\:\ \(.*\)$:\"\1\":')\)) | ||
73 | eval $(echo GFXCARD_DESC=\($(echo "${GFXCARD_INFO}" | grep 'Model:' | sed 's:.*\:\ \"\(.*\)\"$:\"\1\":')\)) | ||
74 | # the xserver is always xorg, no array needed | ||
75 | GFXCARD_XSERVER="Xorg" | ||
76 | # | ||
77 | # network | ||
78 | eval $(echo NETCARD_MODULE=\($(echo "${NETCARD_INFO}" | grep 'Driver Modules:' | sed 's:.*\:\ \"\(.*\)\"$:\"\1\":')\)) | ||
79 | eval $(echo NETCARD_DESC=\($(echo "${NETCARD_INFO}" | grep 'Model:' | sed 's:.*\:\ \"\(.*\)\"$:\"\1\":')\)) | ||
80 | niro | 1200 | # fallback (only needed for systems without netlink) |
81 | eval $(echo NETCARD_MODULE_FB=\($(echo "${NETCARD_INFO}" | grep 'Driver Activation Cmd:' | sed 's:.*\:\ \"modprobe\ \(.*\)\"$:\"\1\":')\)) | ||
82 | niro | 1197 | # |
83 | # mouse | ||
84 | eval $(echo MOUSE_MODULE=\($(echo "${MOUSE_INFO}" | grep 'Driver Modules:' | sed 's:.*\:\ \"\(.*\)\"$:\"\1\":')\)) | ||
85 | eval $(echo MOUSE_DESC=\($(echo "${MOUSE_INFO}" | grep 'Model:' | sed 's:.*\:\ \"\(.*\)\"$:\"\1\":')\)) | ||
86 | eval $(echo MOUSE_DEVICE=\($(echo "${MOUSE_INFO}" | grep 'Device File:' | sed 's:.*\:\ \(.*\)[$\ ].*:\"\1\":')\)) | ||
87 | eval $(echo MOUSE_GPM_PROTO=\($(echo "${MOUSE_INFO}" | grep 'GPM.*Protocol:' | sed 's:.*\:\ \(.*\)$:\"\1\":')\)) | ||
88 | eval $(echo MOUSE_X11_PROTO=\($(echo "${MOUSE_INFO}" | grep 'XFree86.*Protocol:' | sed 's:.*\:\ \(.*\)$:\"\1\":')\)) | ||
89 | |||
90 | # get the number of devices for each class | ||
91 | GFXCARD_COUNT=$(echo "${GFXCARD_INFO}" | grep -c "[0-9a-zA-Z]\: .*\:\ .*") | ||
92 | NETCARD_COUNT=$(echo "${NETCARD_INFO}" | grep -c "[0-9a-zA-Z]\: .*\:\ .*") | ||
93 | MOUSE_COUNT=$(echo "${MOUSE_INFO}" | grep -c "[0-9a-zA-Z]\: .*\:\ .*") | ||
94 | |||
95 | |||
96 | # clear all config files | ||
97 | clearconfig xserver | ||
98 | clearconfig netcard | ||
99 | clearconfig knoppix | ||
100 | clearconfig mouse | ||
101 | |||
102 | for ((i=0; i<GFXCARD_COUNT; i++)) | ||
103 | do | ||
104 | niro | 1198 | # fallback to vesa |
105 | if [[ -z ${GFXCARD_MODULE[${i}]} ]] | ||
106 | then | ||
107 | GFXCARD_MODULE[${i}]="vesa" | ||
108 | fi | ||
109 | niro | 1213 | |
110 | # exclude unsupported drivers | ||
111 | check_unsupported_drivers "${UNSUPPORTED_GFXCARD_DRIVERS}" "${NETCARD_MODULE[${i}]}" || continue | ||
112 | |||
113 | niro | 1197 | addconfig xserver "XSERVER=\"${GFXCARD_XSERVER}\"" |
114 | addconfig xserver "XMODULE=\"${GFXCARD_MODULE[${i}]}\"" | ||
115 | addconfig xserver "XDESC=\"${GFXCARD_DESC[${i}]}\"" | ||
116 | |||
117 | # add them to knoppix too | ||
118 | addconfig knoppix "XSERVER=\"${GFXCARD_XSERVER}\"" | ||
119 | addconfig knoppix "XMODULE=\"${GFXCARD_MODULE[${i}]}\"" | ||
120 | addconfig knoppix "XDESC=\"${GFXCARD_DESC[${i}]}\"" | ||
121 | niro | 1227 | |
122 | # load some needed modules for xorg-servers without udev or hal support, which the driver would normally autoload | ||
123 | case "${GFXCARD_MODULE[${i}]}" in | ||
124 | intel|i810) modprobe -q intel-agp ;; | ||
125 | nv) modprobe -q nvidia-agp ;; | ||
126 | sis) modprobe -q sis-agp ;; | ||
127 | ati|radeon|r128|mach64) modprobe -q ati-agp ;; | ||
128 | niro | 1545 | via|openchrome|unichrome) modprobe -q via-agp ;; |
129 | niro | 1227 | esac |
130 | niro | 1197 | done |
131 | |||
132 | for ((i=0; i<NETCARD_COUNT; i++)) | ||
133 | do | ||
134 | niro | 1200 | # use fallback |
135 | if [[ -z ${NETCARD_MODULE[${i}]} ]] | ||
136 | then | ||
137 | NETCARD_MODULE[${i}]="${NETCARD_MODULE_FB[${i}]}" | ||
138 | fi | ||
139 | niro | 1213 | |
140 | # exclude unsupported drivers | ||
141 | check_unsupported_drivers "${UNSUPPORTED_NETCARD_DRIVERS}" "${NETCARD_MODULE[${i}]}" || continue | ||
142 | |||
143 | niro | 1197 | addconfig netcard "FULLNAME=\"${NETCARD_DESC[${i}]}\"" |
144 | addconfig netcard "DRIVER=\"${NETCARD_MODULE[${i}]}\"" | ||
145 | |||
146 | # add them to knoppix too | ||
147 | addconfig knoppix "NETCARD_FULLNAME=\"${NETCARD_DESC[${i}]}\"" | ||
148 | addconfig knoppix "NETCARD_DRIVER=\"${NETCARD_MODULE[${i}]}\"" | ||
149 | niro | 1225 | |
150 | # load the netcard modules | ||
151 | if [[ ${probeonly} = 0 ]] | ||
152 | then | ||
153 | modprobe -q "${NETCARD_MODULE[${i}]}" | ||
154 | fi | ||
155 | niro | 1197 | done |
156 | |||
157 | for ((i=0; i<MOUSE_COUNT; i++)) | ||
158 | do | ||
159 | # fix mouseproto to be hwsetup compatible (it just guesses the proto :/ ) | ||
160 | case "${MOUSE_GPM_PROTO[${i}]}" in | ||
161 | exps2) MOUSE_GPM_PROTO[${i}]="ps2" ;; | ||
162 | niro | 1198 | "") MOUSE_GPM_PROTO[${i}]="ps2" ;; |
163 | niro | 1197 | esac |
164 | case "${MOUSE_X11_PROTO[${i}]}" in | ||
165 | explorerps/2) MOUSE_X11_PROTO[${i}]="IMPS/2" ;; | ||
166 | ps/2) MOUSE_X11_PROTO[${i}]="PS/2" ;; | ||
167 | niro | 1198 | "") MOUSE_X11_PROTO[${i}]="PS/2" ;; |
168 | niro | 1197 | esac |
169 | |||
170 | addconfig mouse "MOUSETYPE=\"${MOUSE_GPM_PROTO[${i}]}\"" | ||
171 | addconfig mouse "XMOUSETYPE=\"${MOUSE_X11_PROTO[${i}]}\"" | ||
172 | addconfig mouse "FULLNAME=\"${MOUSE_DESC[${i}]}\"" | ||
173 | addconfig mouse "DEVICE=\"${MOUSE_DEVICE[${i}]}\"" | ||
174 | addconfig mouse "DRIVER=\"${MOUSE_MODULE[${i}]}\"" | ||
175 | |||
176 | # add them to knoppix too | ||
177 | addconfig knoppix "MOUSE_MOUSETYPE=\"${MOUSE_GPM_PROTO[${i}]}\"" | ||
178 | addconfig knoppix "MOUSE_XMOUSETYPE=\"${MOUSE_X11_PROTO[${i}]}\"" | ||
179 | addconfig knoppix "MOUSE_FULLNAME=\"${MOUSE_DESC[${i}]}\"" | ||
180 | addconfig knoppix "MOUSE_DEVICE=\"${MOUSE_DEVICE[${i}]}\"" | ||
181 | addconfig knoppix "MOUSE_DRIVER=\"${MOUSE_MODULE[${i}]}\"" | ||
182 | done | ||
183 | niro | 1200 | |
184 | echo "Done." 1>&2 |