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