slitaz-tools view tinyutils/tazhw @ rev 939

tazbox: fix subox icon when ~/.local/share/applications is absent; fix working with freegeoip; write full list of icons used; all other files: 2015 and insert blank lines.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Apr 17 07:35:02 2015 +0300 (2015-04-17)
parents b0d5fdb1e5f3
children 6ca520c64f35
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: $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 : $mod'
69 unset mod
70 else
71 _ "* Loaded module : $mod"
72 fi
73 else
74 if zcat /proc/config.gz | fgrep -i $mod | fgrep -q '=y'; then
75 _ '* Builtin module : $mod'
76 unset mod
77 else
78 _ '! Missing module : $mod'
79 fi
80 fi
81 else
82 _ '> Module in use : $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 # Detect PCI devices and load kernel module only at first boot,
94 # in LiveCD mode or with the command 'detect-pci'.
96 detect_pci_devices() {
97 if [ ! -s /var/lib/detected-modules ]; then
98 . /etc/rcS.conf
99 # We need module_name to match output of lsmod.
100 list=$(lspci -k | grep "driver" | cut -d ":" -f 2 | sed s/-/_/g)
101 echo "$list" > /var/lib/detected-modules
102 for mod in $(cat /var/lib/detected-modules | uniq)
103 do
104 check_firmware
105 load_module
106 done
107 fi
108 }
111 # Detect all USB devices.
113 detect_usb_devices() {
114 if [ -e /sys/bus/usb/devices/usb/usb1 ]; then
115 for product in /sys/bus/usb/devices/*/product
116 do
117 path=$(dirname $product)
118 product=$(cat $product)
119 config=$(cat $path/configuration)
120 debug "$path"
121 . $path/[0-9]*/uevent
122 [ ! "$DRIVER" ] && DRIVER="(none)"
123 echo "$product $config $(indent 40 $DRIVER)"
124 unset DRIVER
125 done
126 fi
127 }
130 # Get firmware used by check_firmware()
132 if [ "$2" == "--get-firmware" ]; then
133 firmware='get'
134 fi
137 # What to do.
139 case "$1" in
140 -i|init)
141 check_root
142 _ 'Detecting PCI devices Kernel modules...'
143 detect_pci_devices
144 _ 'Detecting USB devices Kernel modules...'
145 detect_usb_devices ;;
146 -dp|detect-pci)
147 check_root
148 newline; _ 'Detected PCI devices Kernel modules'; separator
149 rm -f /var/lib/detected-modules
150 detect_pci_devices
151 separator; newline ;;
152 -du|detect-usb)
153 check_root
154 newline; _ 'Detected USB devices Kernel modules'; separator
155 rm -f /var/lib/detected-usb-modules
156 detect_usb_devices
157 separator; newline ;;
158 -s|setup)
159 SETUP_OPTIONS=$(echo "$@" | sed 's/setup//')
160 check_root
161 hwsetup $SETUP_OPTIONS ;;
162 -dm|detected-modules)
163 newline; _ 'Detected PCI and USB modules'; separator
164 cat /var/lib/detected-modules
165 cat /var/lib/detected-usb-modules 2>/dev/null
166 separator; newline ;;
167 *)
168 usage ;;
169 esac
171 exit 0