slitaz-tools annotate tinyutils/tazhw @ rev 763

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