slitaz-tools annotate tinyutils/tazhw @ rev 434

fix typo /proc/bus/usb/devices
author Rohit Joshi <jozee@slitaz.org>
date Tue Feb 23 16:22:49 2010 +0000 (2010-02-23)
parents f8bb0d243acf
children f3b7d1f4c8ba
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
paul@317 6 # option --get-firmware to force installation. GUI uses GTKdialog, and is
paul@317 7 # called by args such as all box functions.
pankso@299 8 #
pankso@299 9 # (c) 2009 SliTaz GNU/Linux - GNU gpl v3
pankso@299 10 #
pankso@299 11
pankso@299 12 usage()
pankso@299 13 {
pankso@299 14 echo -e "\nSliTaz Hardware configuration\n
pankso@299 15 \033[1mUsage: \033[0m `basename $0` [command] [--option]
pankso@299 16 \033[1mCommands: \033[0m\n
pankso@299 17 usage Print this short usage.
pankso@299 18 box Start in graphical mode.
pankso@299 19 init Used at boot time to configure devices.
pankso@299 20 detect-pci Detect all PCI devices.
pankso@299 21 detect-usb Detect all USB devices.
pankso@299 22 detected-modules List all detected Kernel modules.
pankso@299 23
pankso@299 24 \033[1mOptions: \033[0m\n
pankso@299 25 --get-firmware Get and install non-free firmware (PCI and USB).\n"
pankso@299 26 }
pankso@299 27
pankso@299 28 # Check if user is root to install, or remove packages.
pankso@299 29 check_root()
pankso@299 30 {
pankso@299 31 if test $(id -u) != 0 ; then
pankso@299 32 echo -e "\nYou must be root to run `basename $0` with this option."
pankso@299 33 echo -e "Please use 'su' and root password to become super-user.\n"
pankso@299 34 exit 0
pankso@299 35 fi
pankso@299 36 }
pankso@299 37 box_check_root()
pankso@299 38 {
pankso@299 39 if test $(id -u) != 0 ; then
pankso@299 40 exec subox tazhw box
pankso@299 41 exit 0
pankso@299 42 fi
pankso@299 43 }
pankso@299 44
pankso@299 45 check_firmware()
pankso@299 46 {
pankso@299 47 if [ -x /usr/bin/get-$mod-firmware ]; then
pankso@299 48 if [ ! -d /var/lib/tazpkg/installed/$mod-firmware ]; then
pankso@299 49 # We need and active connection to install firmware and we
pankso@299 50 # only install firmware if specified from cmdline.
pankso@299 51 if ifconfig | grep -q "inet addr"; then
pankso@299 52 # Ensure module is not loaded and get files.
pankso@299 53 if [ "$firmware" == "get" ]; then
pankso@299 54 rmmod $mod 2>/dev/null
pankso@299 55 get-$mod-firmware
pankso@299 56 else
pankso@299 57 echo "* Use --get-firmware option to install missing files."
pankso@299 58 fi
pankso@299 59 else
pankso@299 60 echo "* No active connection to get and install firmware."
pankso@299 61 fi
pankso@299 62 else
pankso@299 63 echo "> Firmware in use: $mod-firmware"
pankso@299 64 fi
pankso@299 65 fi
pankso@299 66 }
pankso@299 67
pankso@299 68 load_module()
pankso@299 69 {
pankso@299 70 if ! lsmod | grep -q "^$mod"; then
pankso@306 71 # lsmod and some modules use underscore, other use dash.
pankso@306 72 # The real modprobe can handle both but not busybox version
pankso@306 73 modprobe $mod 2>/dev/null && \
pankso@306 74 echo "* Loaded module: $mod" || \
pankso@306 75 echo "! Missing module: $mod"
pankso@299 76 else
pankso@306 77 echo "> Module in use: $mod"
pankso@299 78 fi
pankso@299 79 # Add module to rcS.conf and avoid duplication.
pankso@299 80 . /etc/rcS.conf
pankso@299 81 if ! echo "$LOAD_MODULES" | grep -q "$mod"; then
pankso@299 82 sed -i s/"LOAD_MODULES=\"$LOAD_MODULES\""/"LOAD_MODULES=\"$LOAD_MODULES $mod\""/ \
pankso@299 83 /etc/rcS.conf
pankso@299 84 fi
pankso@299 85 }
pankso@299 86
pankso@299 87 # Detect PCI devices and load kernel module only at first boot,
pankso@299 88 # in LiveCD mode or with the command 'detect-pci'.
pankso@299 89 detect_pci_devices()
pankso@299 90 {
pankso@299 91 if [ ! -s /var/lib/detected-modules ]; then
pankso@299 92 . /etc/rcS.conf
pankso@299 93 # We need module_name to match output of lsmod.
pankso@299 94 list=`lspci -k | grep "modules" | cut -d ":" -f 2 | sed s/-/_/g`
pankso@299 95 echo "$list" > /var/lib/detected-modules
pankso@299 96 for mod in $list
pankso@299 97 do
pankso@299 98 check_firmware
pankso@299 99 load_module
pankso@299 100 done
pankso@299 101 # yenta_socket = laptop
pankso@299 102 if `lsmod | grep -q "yenta_socket"`; then
pascal@329 103 grep -qs batt /etc/lxpanel/default/panels/panel ||
pankso@299 104 sed -i 's/= cpu/= batt\n}\n\nPlugin {\n type = cpu/' \
pankso@299 105 /etc/lxpanel/default/panels/panel 2> /dev/null
pankso@299 106 fi
pankso@299 107 fi
pankso@299 108 }
pankso@299 109
pankso@299 110 # Detect all USB devices.
pankso@299 111 detect_usb_devices()
pankso@299 112 {
jozee@434 113 if [ -f /proc/bus/usb/devices -a ! -s /var/lib/detected-usb-modules ]; then
pankso@299 114 rm -f /var/lib/detected-usb-modules
pankso@299 115 cat /proc/bus/usb/devices | grep "Vendor" | while read line ; do
pankso@299 116 ID=`echo "$line" | awk '{ print $2,$3 }' | sed 's/ / /' | \
pankso@299 117 sed 's/Vendor=/0x/' | sed 's/ProdID=/0x/'`
jozee@413 118 if grep -q "$ID" /lib/modules/`uname -r`/modules.usbmap; then
jozee@413 119 mod=`grep "$ID" /lib/modules/$(uname -r)/modules.usbmap | \
jozee@412 120 awk '{ print $1 }'`
pankso@299 121 prod=`grep -A 2 "$line" /proc/bus/usb/devices | grep Product | \
pankso@299 122 cut -d "=" -f 2`
pankso@299 123 echo "$prod"
pankso@299 124 check_firmware
pankso@299 125 load_module
pankso@299 126 echo " $mod" >> /var/lib/detected-usb-modules
pankso@299 127 fi
pankso@299 128 done
pankso@299 129 fi
pankso@299 130 }
pankso@299 131
pankso@299 132 display_line()
pankso@299 133 {
pankso@299 134 echo "================================================================================"
pankso@299 135 }
pankso@299 136
pankso@299 137 # Box functions and dialog
pankso@299 138
pankso@299 139 box_list()
pankso@299 140 {
pankso@299 141 for mod in `cat /var/lib/detected-modules /var/lib/detected-usb-modules 2>/dev/null`
pankso@299 142 do
pankso@299 143 desc=`modinfo $mod | grep ^description | cut -d ":" -f 2`
pankso@299 144 [ -z "$desc" ] && desc="N/A"
pankso@299 145 echo "$mod | $desc"
pankso@299 146 done
pankso@299 147 }
pankso@299 148
pankso@299 149 box_detect_devices()
pankso@299 150 {
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
pankso@299 167 box()
pankso@299 168 {
pankso@299 169 export BIN=$0
pankso@299 170 export MAIN_DIALOG='
pankso@299 171 <window title="Tazhw Box" icon-name="computer">
pankso@299 172 <vbox>
pankso@299 173
pankso@299 174 <text width-chars="54" use-markup="true">
pankso@299 175 <label>"
pankso@299 176 <b>Hardware auto-detection and configuration tool</b>
pankso@299 177 "</label>
pankso@299 178 </text>
pankso@299 179 <tree>
pankso@299 180 <width>520</width><height>180</height>
pankso@299 181 <variable>MODULE</variable>
pankso@299 182 <label>Kernel Module|Description</label>
pankso@299 183 <input>$BIN box_list</input>
pankso@299 184 <action>refresh:MODULE</action>
pankso@299 185 </tree>
pankso@299 186 <hbox>
pankso@299 187 <checkbox>
pankso@299 188 <label>Auto install non-free Firmware</label>
pankso@299 189 <variable>INSTALL_FIRMARE</variable>
jozee@431 190 <default>true</default>
pankso@299 191 </checkbox>
pankso@299 192 <button>
pankso@299 193 <label>Detect PCI/USB devices</label>
pankso@299 194 <input file icon="forward"></input>
pankso@299 195 <action>$BIN box_detect_devices</action>
pankso@299 196 <action>refresh:MODULE</action>
pankso@299 197 </button>
pankso@299 198 <button>
pankso@299 199 <label>Exit</label>
pankso@299 200 <input file icon="exit"></input>
pankso@299 201 <action type="exit">Exit</action>
pankso@299 202 </button>
pankso@299 203 </hbox>
pankso@299 204 </vbox>
pankso@299 205 </window>'
pankso@299 206 gtkdialog --center --program=MAIN_DIALOG >/dev/null
pankso@299 207 }
pankso@299 208
pankso@299 209 # Get firmware used by check_firmware()
pankso@299 210 if [ "$2" == "--get-firmware" ]; then
pankso@299 211 firmware='get'
pankso@299 212 fi
pankso@299 213
pankso@299 214 # What to do.
pankso@299 215 case "$1" in
pankso@299 216 init)
pankso@299 217 check_root
pankso@299 218 echo "Detecting PCI devices Kernel modules..."
pankso@299 219 detect_pci_devices
pankso@299 220 echo "Detecting USB devices Kernel modules..."
pankso@326 221 detect_usb_devices ;;
pankso@299 222 detect-pci)
pankso@299 223 check_root
pankso@299 224 echo -e "\nDetected PCI devices Kernel modules" && display_line
pankso@299 225 rm -f /var/lib/detected-modules
pankso@299 226 detect_pci_devices
pankso@299 227 display_line && echo "" ;;
pankso@299 228 detect-usb)
pankso@299 229 check_root
pankso@299 230 echo -e "\nDetected USB devices Kernel modules" && display_line
pankso@299 231 rm -f /var/lib/detected-usb-modules
pankso@299 232 detect_usb_devices
pankso@299 233 display_line && echo "" ;;
pankso@299 234 box*)
pankso@299 235 box_check_root
pankso@299 236 $1 ;;
pankso@299 237 detected-modules)
pankso@299 238 echo -e "\nDetected PCI and USB modules" && display_line
pankso@299 239 cat /var/lib/detected-modules
pankso@304 240 cat /var/lib/detected-usb-modules 2>/dev/null
pankso@299 241 display_line && echo "" ;;
pankso@299 242 *)
pankso@299 243 usage ;;
pankso@299 244 esac
pankso@299 245
pankso@299 246 exit 0