slitaz-tools view tinyutils/tazhw @ rev 930

Finish previous tiny edit
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Nov 25 00:41:01 2014 +0200 (2014-11-25)
parents ddddaa342ba0
children 5d80f6fdbdb7
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 Yad and is
7 # called by args such as all box functions.
8 #
9 # (c) 2009-2014 SliTaz GNU/Linux - GNU GPL v3
10 #
11 # Authors: Christophe Lincoln <pankso@slitaz.org>
12 # Rohit Joshi <jozee@slitaz.org>
13 #
14 . /lib/libtaz.sh
15 export TEXTDOMAIN='slitaz-tools' # i18n text mode
17 usage() {
18 cat << EOT
20 $(_n 'SliTaz Hardware configuration')
22 $(boldify "$(_n 'Usage:')") $(basename $0) [$(_n 'command')] [--$(_n 'option')]
24 $(boldify "$(_n 'Commands:')")
25 usage $(_n 'Print this short usage.')
26 init $(_n 'Used at boot time to configure devices.')
27 setup $(_n 'Setup hardware devices.')
28 detect-pci $(_n 'Detect all PCI devices.')
29 detect-usb $(_n 'Detect all USB devices.')
30 detected-modules $(_n 'List all detected Kernel modules.')
32 $(boldify "$(_n 'Options:')")
33 --get-firmware $(_n 'Get and install non-free firmware (PCI and USB).')
35 EOT
36 }
38 check_firmware() {
39 if [ -x /usr/bin/get-$mod-firmware ]; then
40 if [ ! -d /var/lib/tazpkg/installed/$mod-firmware ]; then
41 # We need an active connection to install firmware and we
42 # only install firmware if specified from cmdline.
43 if ifconfig | grep -q "inet addr"; then
44 # Ensure module is not loaded and get files.
45 if [ "$firmware" == "get" ]; then
46 rmmod $mod 2>/dev/null
47 get-$mod-firmware
48 else
49 _ '* Use --get-firmware option to install missing files.'
50 fi
51 else
52 _ '* No active connection to get and install firmware.'
53 fi
54 else
55 _ '> Firmware in use: $mod-firmware'
56 fi
57 fi
58 }
60 load_module() {
61 if ! lsmod | grep -q "^$mod"; then
62 # Check if builtin, loaded or missing
63 if modprobe $mod 2>/dev/null; then
64 if zcat /proc/config.gz | fgrep -i $mod | fgrep -q '=y'; then
65 _ '* Builtin module : $mod'
66 unset mod
67 else
68 _ "* Loaded module : $mod"
69 fi
70 else
71 if zcat /proc/config.gz | fgrep -i $mod | fgrep -q '=y'; then
72 _ '* Builtin module : $mod'
73 unset mod
74 else
75 _ '! Missing module : $mod'
76 fi
77 fi
78 else
79 _ '> Module in use : $mod'
80 fi
81 # Add it to load automatically at next boot.
82 if ! echo "$LOAD_MODULES" | grep -q "$mod"; then
83 sed -i s/"LOAD_MODULES=\"$LOAD_MODULES\""/"LOAD_MODULES=\"$LOAD_MODULES $mod\""/ \
84 /etc/rcS.conf
85 fi
86 . /etc/rcS.conf
87 }
89 # Detect PCI devices and load kernel module only at first boot,
90 # in LiveCD mode or with the command 'detect-pci'.
91 detect_pci_devices() {
92 if [ ! -s /var/lib/detected-modules ]; then
93 . /etc/rcS.conf
94 # We need module_name to match output of lsmod.
95 list=$(lspci -k | grep "driver" | cut -d ":" -f 2 | sed s/-/_/g)
96 echo "$list" > /var/lib/detected-modules
97 for mod in $(cat /var/lib/detected-modules | uniq)
98 do
99 check_firmware
100 load_module
101 done
102 fi
103 }
105 # Detect all USB devices.
106 detect_usb_devices() {
107 if [ -e /sys/bus/usb/devices/usb/usb1 ]; then
108 for product in /sys/bus/usb/devices/*/product
109 do
110 path=$(dirname $product)
111 product=$(cat $product)
112 config=$(cat $path/configuration)
113 debug "$path"
114 . $path/[0-9]*/uevent
115 [ ! "$DRIVER" ] && DRIVER="(none)"
116 echo "$product $config $(indent 40 $DRIVER)"
117 unset DRIVER
118 done
119 fi
120 }
122 # Get firmware used by check_firmware()
123 if [ "$2" == "--get-firmware" ]; then
124 firmware='get'
125 fi
127 # What to do.
128 case "$1" in
129 -i|init)
130 check_root
131 _ 'Detecting PCI devices Kernel modules...'
132 detect_pci_devices
133 _ 'Detecting USB devices Kernel modules...'
134 detect_usb_devices ;;
135 -dp|detect-pci)
136 check_root
137 newline; _ 'Detected PCI devices Kernel modules'; separator
138 rm -f /var/lib/detected-modules
139 detect_pci_devices
140 separator; newline ;;
141 -du|detect-usb)
142 check_root
143 newline; _ 'Detected USB devices Kernel modules'; separator
144 rm -f /var/lib/detected-usb-modules
145 detect_usb_devices
146 separator; newline ;;
147 -s|setup)
148 SETUP_OPTIONS=$(echo "$@" | sed 's/setup//')
149 check_root
150 hwsetup $SETUP_OPTIONS ;;
151 -dm|detected-modules)
152 newline; _ 'Detected PCI and USB modules'; separator
153 cat /var/lib/detected-modules
154 cat /var/lib/detected-usb-modules 2>/dev/null
155 separator; newline ;;
156 *)
157 usage ;;
158 esac
160 exit 0