slitaz-tools view tinyutils/tazhw @ rev 305

tazhw: fix loading of sound module
author Christophe Lincoln <pankso@slitaz.org>
date Fri Feb 27 00:03:55 2009 +0100 (2009-02-27)
parents dbce87a5fbdb
children a75a6a522130
line source
1 #!/bin/sh
2 #
3 # SliTaz Hardware configuration tool. Auto-detect and configure in a
4 # simple way all PCI, PCMCIA and USB devices. Some Wireless Adapaters
5 # need non-free firmware not installed by default, users must use the
6 # option --get-firmware to force installation. GUI use GTKdialog, is
7 # called by arg such as all box functions.
8 #
9 # (c) 2009 SliTaz GNU/Linux - GNU gpl v3
10 #
12 usage()
13 {
14 echo -e "\nSliTaz Hardware configuration\n
15 \033[1mUsage: \033[0m `basename $0` [command] [--option]
16 \033[1mCommands: \033[0m\n
17 usage Print this short usage.
18 box Start in graphical mode.
19 init Used at boot time to configure devices.
20 detect-pci Detect all PCI devices.
21 detect-usb Detect all USB devices.
22 detected-modules List all detected Kernel modules.
24 \033[1mOptions: \033[0m\n
25 --get-firmware Get and install non-free firmware (PCI and USB).\n"
26 }
28 # Check if user is root to install, or remove packages.
29 check_root()
30 {
31 if test $(id -u) != 0 ; then
32 echo -e "\nYou must be root to run `basename $0` with this option."
33 echo -e "Please use 'su' and root password to become super-user.\n"
34 exit 0
35 fi
36 }
37 box_check_root()
38 {
39 if test $(id -u) != 0 ; then
40 exec subox tazhw box
41 exit 0
42 fi
43 }
45 check_firmware()
46 {
47 if [ -x /usr/bin/get-$mod-firmware ]; then
48 if [ ! -d /var/lib/tazpkg/installed/$mod-firmware ]; then
49 # We need and active connection to install firmware and we
50 # only install firmware if specified from cmdline.
51 if ifconfig | grep -q "inet addr"; then
52 # Ensure module is not loaded and get files.
53 if [ "$firmware" == "get" ]; then
54 rmmod $mod 2>/dev/null
55 get-$mod-firmware
56 else
57 echo "* Use --get-firmware option to install missing files."
58 fi
59 else
60 echo "* No active connection to get and install firmware."
61 fi
62 else
63 echo "> Firmware in use: $mod-firmware"
64 fi
65 fi
66 }
68 load_module()
69 {
70 if ! lsmod | grep -q "^$mod"; then
71 # lsmod use ubderscore and modprobe list file with dash
72 mod=`echo $mod | sed s/_/-/g`
73 if [ -f "$(modprobe -l $mod)" ]; then
74 echo "* Loading Kernel module: $mod"
75 /sbin/modprobe $mod
76 else
77 echo "! Missing module: $mod"
78 fi
79 else
80 echo "> Found module: $mod"
81 fi
82 # Add module to rcS.conf and avoid duplication.
83 . /etc/rcS.conf
84 if ! echo "$LOAD_MODULES" | grep -q "$mod"; then
85 sed -i s/"LOAD_MODULES=\"$LOAD_MODULES\""/"LOAD_MODULES=\"$LOAD_MODULES $mod\""/ \
86 /etc/rcS.conf
87 fi
88 }
90 # Retry a Ethernet connection with DHCP after detection (used at boot).
91 # TODO: try a wireless connection but stop eth0 to avoid conflict.
92 start_network()
93 {
94 if ifconfig -a | grep -q "eth0"; then
95 if [ ! -f /var/run/udhcpc.eth0.pid ]; then
96 echo "Starting udhcpc client on: eth0... "
97 /sbin/udhcpc -b -i eth0 -p /var/run/udhcpc.eth0.pid
98 fi
99 fi
100 }
102 # Detect PCI devices and load kernel module only at first boot,
103 # in LiveCD mode or with the command 'detect-pci'.
104 detect_pci_devices()
105 {
106 if [ ! -s /var/lib/detected-modules ]; then
107 . /etc/rcS.conf
108 # We need module_name to match output of lsmod.
109 list=`lspci -k | grep "modules" | cut -d ":" -f 2 | sed s/-/_/g`
110 echo "$list" > /var/lib/detected-modules
111 for mod in $list
112 do
113 check_firmware
114 load_module
115 done
116 # yenta_socket = laptop
117 if `lsmod | grep -q "yenta_socket"`; then
118 for mod in ac battery
119 do
120 load_module
121 echo " $mod" >> /var/lib/detected-modules
122 done
123 sed -i 's/= cpu/= batt\n}\n\nPlugin {\n type = cpu/' \
124 /etc/lxpanel/default/panels/panel 2> /dev/null
125 fi
126 fi
127 }
129 # Detect all USB devices.
130 detect_usb_devices()
131 {
132 if [ ! -s /var/lib/detected-usb-modules ]; then
133 rm -f /var/lib/detected-usb-modules
134 cat /proc/bus/usb/devices | grep "Vendor" | while read line ; do
135 ID=`echo "$line" | awk '{ print $2,$3 }' | sed 's/ / /' | \
136 sed 's/Vendor=/0x/' | sed 's/ProdID=/0x/'`
137 if grep -q "$ID" /lib/modules/*-slitaz/modules.usbmap; then
138 mod=`grep "$ID" /lib/modules/*-slitaz/modules.usbmap | \
139 awk '{ print $1 }'`
140 prod=`grep -A 2 "$line" /proc/bus/usb/devices | grep Product | \
141 cut -d "=" -f 2`
142 echo "$prod"
143 check_firmware
144 load_module
145 echo " $mod" >> /var/lib/detected-usb-modules
146 fi
147 done
148 fi
149 }
151 display_line()
152 {
153 echo "================================================================================"
154 }
156 # Box functions and dialog
158 box_list()
159 {
160 for mod in `cat /var/lib/detected-modules /var/lib/detected-usb-modules 2>/dev/null`
161 do
162 desc=`modinfo $mod | grep ^description | cut -d ":" -f 2`
163 [ -z "$desc" ] && desc="N/A"
164 echo "$mod | $desc"
165 done
166 }
168 box_detect_devices()
169 {
170 if [ $INSTALL_FIRMARE != true ]; then
171 xterm -T "Detect devices" \
172 -geometry 80x24 \
173 -e "$0 detect-pci; $0 detect-usb; \
174 echo -e \"----\nPress ENTER to close...\"; \
175 read i; exit 0"
176 else
177 xterm -T "Detect and get firmware" \
178 -geometry 80x24 \
179 -e "$0 detect-pci --get-firmware; \
180 $0 detect-usb --get-firmware; \
181 echo -e \"----\nPress ENTER to close...\"; \
182 read i; exit 0"
183 fi
184 }
186 box()
187 {
188 export BIN=$0
189 export MAIN_DIALOG='
190 <window title="Tazhw Box" icon-name="computer">
191 <vbox>
193 <text width-chars="54" use-markup="true">
194 <label>"
195 <b>Hardware auto-detection and configuration tool</b>
196 "</label>
197 </text>
198 <tree>
199 <width>520</width><height>180</height>
200 <variable>MODULE</variable>
201 <label>Kernel Module|Description</label>
202 <input>$BIN box_list</input>
203 <action>refresh:MODULE</action>
204 </tree>
205 <hbox>
206 <checkbox>
207 <label>Auto install non-free Firmware</label>
208 <variable>INSTALL_FIRMARE</variable>
209 <default>false</default>
210 </checkbox>
211 <button>
212 <label>Detect PCI/USB devices</label>
213 <input file icon="forward"></input>
214 <action>$BIN box_detect_devices</action>
215 <action>refresh:MODULE</action>
216 </button>
217 <button>
218 <label>Exit</label>
219 <input file icon="exit"></input>
220 <action type="exit">Exit</action>
221 </button>
222 </hbox>
223 </vbox>
224 </window>'
225 gtkdialog --center --program=MAIN_DIALOG >/dev/null
226 }
228 # Get firmware used by check_firmware()
229 if [ "$2" == "--get-firmware" ]; then
230 firmware='get'
231 fi
233 # What to do.
234 case "$1" in
235 init)
236 check_root
237 echo "Detecting PCI devices Kernel modules..."
238 detect_pci_devices
239 echo "Detecting USB devices Kernel modules..."
240 detect_usb_devices
241 start_network ;;
242 detect-pci)
243 check_root
244 echo -e "\nDetected PCI devices Kernel modules" && display_line
245 rm -f /var/lib/detected-modules
246 detect_pci_devices
247 display_line && echo "" ;;
248 detect-usb)
249 check_root
250 echo -e "\nDetected USB devices Kernel modules" && display_line
251 rm -f /var/lib/detected-usb-modules
252 detect_usb_devices
253 display_line && echo "" ;;
254 box*)
255 box_check_root
256 $1 ;;
257 detected-modules)
258 echo -e "\nDetected PCI and USB modules" && display_line
259 cat /var/lib/detected-modules
260 cat /var/lib/detected-usb-modules 2>/dev/null
261 display_line && echo "" ;;
262 *)
263 usage ;;
264 esac
266 exit 0