slitaz-tools view tinyutils/tazhw @ rev 961

tazlocale: accept only existing locales, show locale description; translations: un-fuzzy already translated messages
author Aleksej Bobylev <al.bobylev@gmail.com>
date Wed Nov 25 23:50:30 2015 +0200 (2015-11-25)
parents 4475062064ee
children fa4c5571e046
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-2015 SliTaz GNU/Linux - GNU GPL v3
10 #
11 # Authors: Christophe Lincoln <pankso@slitaz.org>
12 # Rohit Joshi <jozee@slitaz.org>
13 #
15 . /lib/libtaz.sh
16 export TEXTDOMAIN='slitaz-tools' # i18n text mode
18 usage() {
19 cat << EOT
21 $(_n 'SliTaz Hardware configuration')
23 $(boldify "$(_n 'Usage:')") $(basename $0) [$(_n 'command')] [--$(_n 'option')]
25 $(boldify "$(_n 'Commands:')")
26 usage $(_n 'Print this short usage.')
27 init $(_n 'Used at boot time to configure devices.')
28 setup $(_n 'Setup hardware devices.')
29 detect-pci $(_n 'Detect all PCI devices.')
30 detect-usb $(_n 'Detect all USB devices.')
31 detected-modules $(_n 'List all detected Kernel modules.')
33 $(boldify "$(_n 'Options:')")
34 --get-firmware $(_n 'Get and install non-free firmware (PCI and USB).')
36 EOT
37 }
40 check_firmware() {
41 if [ -x /usr/bin/get-$mod-firmware ]; then
42 if [ ! -d /var/lib/tazpkg/installed/$mod-firmware ]; then
43 # We need an active connection to install firmware and we
44 # only install firmware if specified from cmdline.
45 if ifconfig | grep -q "inet addr"; then
46 # Ensure module is not loaded and get files.
47 if [ "$firmware" == "get" ]; then
48 rmmod $mod 2>/dev/null
49 get-$mod-firmware
50 else
51 _ '* Use --get-firmware option to install missing files.'
52 fi
53 else
54 _ '* No active connection to get and install firmware.'
55 fi
56 else
57 _ '> Firmware in use: %s' "$mod-firmware"
58 fi
59 fi
60 }
63 load_module() {
64 if ! lsmod | grep -q "^$mod"; then
65 # Check if builtin, loaded or missing
66 if modprobe $mod 2>/dev/null; then
67 if zcat /proc/config.gz | fgrep -i $mod | fgrep -q '=y'; then
68 _ '* Builtin module : %s' "$mod"
69 unset mod
70 else
71 _ '* Loaded module : %s' "$mod"
72 fi
73 else
74 if zcat /proc/config.gz | fgrep -i $mod | fgrep -q '=y'; then
75 _ '* Builtin module : %s' "$mod"
76 unset mod
77 else
78 _ '! Missing module : %s' "$mod"
79 fi
80 fi
81 else
82 _ '> Module in use : %s' "$mod"
83 fi
84 # Add it to load automatically at next boot.
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 . /etc/rcS.conf
90 }
93 module_name()
94 {
95 local mod mod2
96 while read mod; do
97 if [ -d /sys/module -a ! -d /sys/module/${mod//-/_} ]; then
98 mod2=$(ls -d /sys/module/*/drivers/*:$mod 2>/dev/null | \
99 sed 's|/sys/module/\(.*\)/drivers/.*|\1|')
100 [ "$mod2" ] && mod=$mod2
101 fi
102 echo ${mod//-/_}
103 done
104 }
107 # Detect PCI devices and load kernel module only at first boot,
108 # in LiveCD mode or with the command 'detect-pci'.
110 detect_pci_devices() {
111 if [ ! -s /var/lib/detected-modules ]; then
112 . /etc/rcS.conf
113 # We need module_name to match output of lsmod.
114 list=$(lspci -k | grep 'driver' | cut -d: -f2 | module_name)
115 echo "$list" > /var/lib/detected-modules
116 for mod in $(sort < /var/lib/detected-modules | uniq)
117 do
118 check_firmware
119 load_module
120 done
121 fi
122 }
125 # Detect all USB devices.
127 detect_usb_devices() {
128 if [ -e /sys/bus/usb/devices/usb/usb1 ]; then
129 for product in /sys/bus/usb/devices/*/product
130 do
131 path=$(dirname $product)
132 product=$(cat $product)
133 config=$(cat $path/configuration)
134 debug "$path"
135 . $path/[0-9]*/uevent
136 [ ! "$DRIVER" ] && DRIVER="(none)"
137 echo "$product $config $(indent 40 $DRIVER)"
138 unset DRIVER
139 done
140 fi
141 }
144 # Get firmware used by check_firmware()
146 if [ "$2" == "--get-firmware" ]; then
147 firmware='get'
148 fi
151 # What to do.
153 case "$1" in
154 -i|init)
155 check_root
156 _ 'Detecting PCI devices Kernel modules...'
157 detect_pci_devices
158 _ 'Detecting USB devices Kernel modules...'
159 detect_usb_devices ;;
160 -dp|detect-pci)
161 check_root
162 title 'Detected PCI devices Kernel modules'
163 rm -f /var/lib/detected-modules
164 detect_pci_devices
165 footer ;;
166 -du|detect-usb)
167 check_root
168 title 'Detected USB devices Kernel modules'
169 rm -f /var/lib/detected-usb-modules
170 detect_usb_devices
171 footer ;;
172 -s|setup)
173 SETUP_OPTIONS=$(echo "$@" | sed 's/setup//')
174 check_root
175 hwsetup $SETUP_OPTIONS ;;
176 -dm|detected-modules)
177 title 'Detected PCI and USB modules'
178 cat /var/lib/detected-modules
179 cat /var/lib/detected-usb-modules 2>/dev/null
180 footer ;;
181 *)
182 usage ;;
183 esac
185 exit 0