slitaz-tools view tinyutils/tazhw @ rev 516

tazx: incorrect tux; slitaz installer creates 1008 user
author Rohit Joshi <jozee@slitaz.org>
date Wed Nov 10 20:26:12 2010 -0500 (2010-11-10)
parents 7d7b2a312362
children 49323f31a7a5
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 Adapters
5 # need non-free firmware not installed by default. Users must use the
6 # option --get-firmware to force installation. GUI uses GTKdialog, and is
7 # called by args such as all box functions.
8 #
9 # (c) 2009 SliTaz GNU/Linux - GNU gpl v3
10 #
11 # Authors : Christophe Lincoln <pankso@slitaz.org>
12 # Rohit Joshi <jozee@slitaz.org>
13 #
15 usage()
16 {
17 echo -e "\nSliTaz Hardware configuration\n
18 \033[1mUsage: \033[0m `basename $0` [command] [--option]
19 \033[1mCommands: \033[0m\n
20 usage Print this short usage.
21 box Start in graphical mode.
22 init Used at boot time to configure devices.
23 setup Setup hardware devices.
24 detect-pci Detect all PCI devices.
25 detect-usb Detect all USB devices.
26 detected-modules List all detected Kernel modules.
28 \033[1mOptions: \033[0m\n
29 --get-firmware Get and install non-free firmware (PCI and USB).\n"
30 }
32 # Check if user is root to install, or remove packages.
33 check_root()
34 {
35 if test $(id -u) != 0 ; then
36 echo -e "\nYou must be root to run `basename $0` with this option."
37 echo -e "Please use 'su' and root password to become super-user.\n"
38 exit 0
39 fi
40 }
41 box_check_root()
42 {
43 if test $(id -u) != 0 ; then
44 exec subox tazhw box
45 exit 0
46 fi
47 }
49 check_firmware()
50 {
51 if [ -x /usr/bin/get-$mod-firmware ]; then
52 if [ ! -d /var/lib/tazpkg/installed/$mod-firmware ]; then
53 # We need and active connection to install firmware and we
54 # only install firmware if specified from cmdline.
55 if ifconfig | grep -q "inet addr"; then
56 # Ensure module is not loaded and get files.
57 if [ "$firmware" == "get" ]; then
58 rmmod $mod 2>/dev/null
59 get-$mod-firmware
60 else
61 echo "* Use --get-firmware option to install missing files."
62 fi
63 else
64 echo "* No active connection to get and install firmware."
65 fi
66 else
67 echo "> Firmware in use: $mod-firmware"
68 fi
69 fi
70 }
72 load_module()
73 {
74 if ! lsmod | grep -q "^$mod"; then
75 # lsmod and some modules use underscore, other use dash.
76 # The real modprobe can handle both but not busybox version
77 modprobe $mod 2>/dev/null && \
78 echo "* Loaded module: $mod" || \
79 echo "! Missing module: $mod"
80 else
81 echo "> Module in use: $mod"
82 fi
83 # Add module to rcS.conf and avoid duplication.
84 . /etc/rcS.conf
85 if ! echo "$LOAD_MODULES" | grep -q "$mod"; then
86 sed -i s/"LOAD_MODULES=\"$LOAD_MODULES\""/"LOAD_MODULES=\"$LOAD_MODULES $mod\""/ \
87 /etc/rcS.conf
88 fi
89 }
91 # Detect PCI devices and load kernel module only at first boot,
92 # in LiveCD mode or with the command 'detect-pci'.
93 detect_pci_devices()
94 {
95 if [ ! -s /var/lib/detected-modules ]; then
96 . /etc/rcS.conf
97 # We need module_name to match output of lsmod.
98 list=`lspci -k | grep "modules" | cut -d ":" -f 2 | sed s/-/_/g`
99 echo "$list" > /var/lib/detected-modules
100 for mod in $list
101 do
102 check_firmware
103 load_module
104 done
105 # yenta_socket = laptop
106 if `lsmod | grep -q "yenta_socket"`; then
107 grep -qs batt /etc/lxpanel/default/panels/panel ||
108 sed -i 's/= cpu/= batt\n}\n\nPlugin {\n type = cpu/' \
109 /etc/lxpanel/default/panels/panel 2> /dev/null
110 fi
111 fi
112 }
114 # Detect all USB devices.
115 detect_usb_devices()
116 {
117 if [ -f /proc/bus/usb/devices -a ! -s /var/lib/detected-usb-modules ]; then
118 rm -f /var/lib/detected-usb-modules
119 cat /proc/bus/usb/devices | grep "Vendor" | while read line ; do
120 ID=`echo "$line" | awk '{ print $2,$3 }' | sed 's/ / /' | \
121 sed 's/Vendor=/0x/' | sed 's/ProdID=/0x/'`
122 if grep -q "$ID" /lib/modules/`uname -r`/modules.usbmap; then
123 mod=`grep "$ID" /lib/modules/$(uname -r)/modules.usbmap | \
124 awk '{ print $1 }'`
125 prod=`grep -A 2 "$line" /proc/bus/usb/devices | grep Product | \
126 cut -d "=" -f 2`
127 echo "$prod"
128 check_firmware
129 load_module
130 echo " $mod" >> /var/lib/detected-usb-modules
131 fi
132 done
133 fi
134 }
136 display_line()
137 {
138 echo "================================================================================"
139 }
141 # Box functions and dialog
143 box_list()
144 {
145 for mod in `cat /var/lib/detected-modules /var/lib/detected-usb-modules 2>/dev/null`
146 do
147 desc=`modinfo $mod | grep ^description | cut -d ":" -f 2`
148 [ -z "$desc" ] && desc="N/A"
149 echo "$mod | $desc"
150 done
151 }
153 box_detect_devices()
154 {
155 if [ $INSTALL_FIRMARE != true ]; then
156 xterm -T "Detect devices" \
157 -geometry 80x24 \
158 -e "$0 detect-pci; $0 detect-usb; \
159 echo -e \"----\nPress ENTER to close...\"; \
160 read i; exit 0"
161 else
162 xterm -T "Detect and get firmware" \
163 -geometry 80x24 \
164 -e "$0 detect-pci --get-firmware; \
165 $0 detect-usb --get-firmware; \
166 echo -e \"----\nPress ENTER to close...\"; \
167 read i; exit 0"
168 fi
169 }
171 box_setup_devices()
172 {
173 SETUP_OPTIONS=""
174 if [ $INSTALL_NON_FREE == true ]; then
175 SETUP_OPTIONS="$SETUP_OPTIONS --non-free"
176 fi
177 if [ $AUTO_INSTALL_SUGGESTED == true ]; then
178 SETUP_OPTIONS="$SETUP_OPTIONS --suggested"
179 elif [ $CONFIRM_INSTALL_SUGGESTED == true ]; then
180 SETUP_OPTIONS="$SETUP_OPTIONS --confirm"
181 fi
182 xterm -geometry 80x24 -T "$DEVICE Setup" \
183 -e "$0 setup $DEVICE $SETUP_OPTIONS; \
184 echo -e \"----\nPress ENTER to close...\"; \
185 read i; exit 0"
186 }
188 box()
189 {
190 export BIN=$0
191 export MAIN_DIALOG='
192 <window title="Tazhw box" icon-name="computer">
193 <vbox>
194 <text width-chars="54" use-markup="true">
195 <label>"
196 <b>Hardware auto-detection and configuration tool</b>
197 "</label>
198 </text>
199 <frame Loaded Kernel Modules>
200 <vbox>
201 <tree>
202 <width>470</width><height>180</height>
203 <variable>MODULE</variable>
204 <label>Module|Description</label>
205 <input>$BIN box_list</input>
206 <action>refresh:MODULE</action>
207 </tree>
208 <hbox>
209 <checkbox>
210 <label>Auto install non-free Firmware </label>
211 <variable>INSTALL_FIRMARE</variable>
212 <default>true</default>
213 </checkbox>
214 <button>
215 <label>Discover PCI/USB devices</label>
216 <input file icon="folder-saved-search"></input>
217 <action>$BIN box_detect_devices</action>
218 <action>refresh:MODULE</action>
219 </button>
220 </hbox>
221 </vbox>
222 </frame>
223 <frame Hardware Setup>
224 <hbox>
225 <button>
226 <label>Printer</label>
227 <input file icon="printer"></input>
228 <action>export DEVICE="printer";$BIN box_setup_devices</action>
229 </button>
230 <button>
231 <label>Scanner</label>
232 <input file icon="x-office-document"></input>
233 <action>export DEVICE="scanner";$BIN box_setup_devices</action>
234 </button>
235 <button>
236 <label>3G-Modem</label>
237 <input file icon="network-transmit-receive"></input>
238 <action>export DEVICE="3g-modem";$BIN box_setup_devices</action>
239 </button>
240 <button>
241 <label>Nvidia</label>
242 <input file icon="video-display"></input>
243 <action>export DEVICE="nvidia";$BIN box_setup_devices</action>
244 </button>
245 <button>
246 <label>ATI Radeon</label>
247 <input file icon="video-display"></input>
248 <action>export DEVICE="ati";$BIN box_setup_devices</action>
249 </button>
251 </hbox>
252 <hbox>
253 <button>
254 <label>Webcam </label>
255 <input file icon="camera-video"></input>
256 <action>export DEVICE="webcam";$BIN box_setup_devices</action>
257 </button>
259 <button>
260 <label>Digital Camera </label>
261 <input file icon="camera-photo"></input>
262 <action>export DEVICE="camera";$BIN box_setup_devices</action>
263 </button>
264 <button>
265 <label>Bluetooth </label>
266 <input file icon="preferences-desktop-multimedia"></input>
267 <action>export DEVICE="bluetooth";$BIN box_setup_devices</action>
268 </button>
270 <button>
271 <label>Firewall </label>
272 <input file icon="gtk-network"></input>
273 <action>export DEVICE="firewall";$BIN box_setup_devices</action>
274 </button>
276 </hbox>
277 <hbox>
278 <checkbox>
279 <label>Install non-free packages </label>
280 <variable>INSTALL_NON_FREE</variable>
281 <default>true</default>
282 </checkbox>
283 <checkbox>
284 <label>Auto-install all optional packages </label>
285 <variable>AUTO_INSTALL_SUGGESTED</variable>
286 <default>false</default>
287 </checkbox>
289 </hbox>
290 <hbox>
291 <checkbox>
292 <label>Choose optional packages to install</label>
293 <variable>CONFIRM_INSTALL_SUGGESTED</variable>
294 <default>false</default>
295 </checkbox>
296 </hbox>
298 </frame>
299 <hbox>
300 <button>
301 <label>Exit</label>
302 <input file icon="exit"></input>
303 <action type="exit">Exit</action>
304 </button>
305 </hbox>
307 </vbox>
308 </window>'
310 gtkdialog --center --program=MAIN_DIALOG >/dev/null
311 }
313 # Get firmware used by check_firmware()
314 if [ "$2" == "--get-firmware" ]; then
315 firmware='get'
316 fi
318 # What to do.
319 case "$1" in
320 init)
321 check_root
322 echo "Detecting PCI devices Kernel modules..."
323 detect_pci_devices
324 echo "Detecting USB devices Kernel modules..."
325 detect_usb_devices ;;
326 detect-pci)
327 check_root
328 echo -e "\nDetected PCI devices Kernel modules" && display_line
329 rm -f /var/lib/detected-modules
330 detect_pci_devices
331 display_line && echo "" ;;
332 detect-usb)
333 check_root
334 echo -e "\nDetected USB devices Kernel modules" && display_line
335 rm -f /var/lib/detected-usb-modules
336 detect_usb_devices
337 display_line && echo "" ;;
338 setup)
339 SETUP_OPTIONS=`echo "$@" | sed 's/setup//' `
340 hwsetup $SETUP_OPTIONS ;;
341 box*)
342 box_check_root
343 $1 ;;
344 detected-modules)
345 echo -e "\nDetected PCI and USB modules" && display_line
346 cat /var/lib/detected-modules
347 cat /var/lib/detected-usb-modules 2>/dev/null
348 display_line && echo "" ;;
349 *)
350 usage ;;
351 esac
353 exit 0