slitaz-tools annotate tinyutils/tazhw @ rev 828

tazhw: clean up and remove box (use gtkdialog)
author Christophe Lincoln <pankso@slitaz.org>
date Wed Jan 29 01:00:37 2014 +0100 (2014-01-29)
parents c79e656b37a5
children 6b444a8504e5
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 #
pascal@821 9 # (c) 2009-2014 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
al@813 39 box_check_root() {
pankso@299 40 if test $(id -u) != 0 ; then
pankso@299 41 exec subox tazhw box
pankso@299 42 exit 0
pankso@299 43 fi
pankso@299 44 }
pankso@299 45
al@813 46 check_firmware() {
pankso@299 47 if [ -x /usr/bin/get-$mod-firmware ]; then
pankso@299 48 if [ ! -d /var/lib/tazpkg/installed/$mod-firmware ]; then
paul@811 49 # We need an 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
al@813 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
al@813 57 _ '* Use --get-firmware option to install missing files.'
pankso@299 58 fi
pankso@299 59 else
al@813 60 _ '* No active connection to get and install firmware.'
pankso@299 61 fi
pankso@299 62 else
al@813 63 _ '> Firmware in use: $mod-firmware'
pankso@299 64 fi
pankso@299 65 fi
pankso@299 66 }
pankso@299 67
al@813 68 load_module() {
pankso@299 69 if ! lsmod | grep -q "^$mod"; then
gokhlayeh@705 70
paul@725 71 # lsmod and some modules use underscore, others use dash.
gokhlayeh@705 72 # The real modprobe can handle both but not busybox version
gokhlayeh@705 73 modprobe $mod 2>/dev/null && \
al@813 74 _ '* Loaded module: $mod' || \
al@813 75 _ '! Missing module: $mod'
gokhlayeh@705 76
gokhlayeh@705 77 # Add it to load automatically at next boot.
gokhlayeh@705 78 if ! echo "$LOAD_MODULES" | grep -q "$mod"; then
gokhlayeh@705 79 sed -i s/"LOAD_MODULES=\"$LOAD_MODULES\""/"LOAD_MODULES=\"$LOAD_MODULES $mod\""/ \
gokhlayeh@705 80 /etc/rcS.conf
gokhlayeh@705 81 fi
gokhlayeh@705 82 . /etc/rcS.conf
gokhlayeh@705 83
pankso@299 84 else
al@813 85 _ '> Module in use: $mod'
pankso@299 86 fi
pankso@299 87 }
pankso@299 88
pankso@299 89 # Detect PCI devices and load kernel module only at first boot,
pankso@299 90 # in LiveCD mode or with the command 'detect-pci'.
al@813 91 detect_pci_devices() {
pankso@299 92 if [ ! -s /var/lib/detected-modules ]; then
pankso@299 93 . /etc/rcS.conf
pankso@299 94 # We need module_name to match output of lsmod.
al@813 95 list=$(lspci -k | grep "modules" | cut -d ":" -f 2 | sed s/-/_/g)
pankso@299 96 echo "$list" > /var/lib/detected-modules
al@813 97 for mod in $list; do
pankso@299 98 check_firmware
pankso@299 99 load_module
pankso@299 100 done
pankso@299 101 fi
pankso@299 102 }
pankso@299 103
pankso@299 104 # Detect all USB devices.
al@813 105 detect_usb_devices() {
jozee@434 106 if [ -f /proc/bus/usb/devices -a ! -s /var/lib/detected-usb-modules ]; then
pankso@299 107 rm -f /var/lib/detected-usb-modules
pankso@299 108 cat /proc/bus/usb/devices | grep "Vendor" | while read line ; do
al@813 109 ID=$(echo "$line" | awk '{ print $2,$3 }' | sed 's/ / /' | \
al@813 110 sed 's/Vendor=/0x/' | sed 's/ProdID=/0x/')
al@813 111 if grep -q "$ID" /lib/modules/$(uname -r)/modules.usbmap; then
al@813 112 mod=$(grep "$ID" /lib/modules/$(uname -r)/modules.usbmap | \
al@813 113 awk '{ print $1 }')
al@813 114 prod=$(grep -A 2 "$line" /proc/bus/usb/devices | grep Product | \
al@813 115 cut -d"=" -f2)
pankso@299 116 echo "$prod"
pankso@299 117 check_firmware
pankso@299 118 load_module
pankso@299 119 echo " $mod" >> /var/lib/detected-usb-modules
pankso@299 120 fi
pankso@299 121 done
pankso@299 122 fi
pankso@299 123 }
pankso@299 124
pankso@299 125 # Box functions and dialog
pankso@299 126
al@813 127 box_list() {
al@813 128 for mod in $(cat /var/lib/detected-modules /var/lib/detected-usb-modules 2>/dev/null); do
al@813 129 desc=$(modinfo $mod | grep ^description | cut -d":" -f2)
pankso@299 130 [ -z "$desc" ] && desc="N/A"
pankso@299 131 echo "$mod | $desc"
pankso@299 132 done
pankso@299 133 }
pankso@299 134
al@813 135 box_detect_devices() {
pankso@299 136 if [ $INSTALL_FIRMARE != true ]; then
pankso@299 137 xterm -T "Detect devices" \
pankso@299 138 -geometry 80x24 \
pankso@299 139 -e "$0 detect-pci; $0 detect-usb; \
pankso@299 140 echo -e \"----\nPress ENTER to close...\"; \
pankso@299 141 read i; exit 0"
pankso@299 142 else
pankso@304 143 xterm -T "Detect and get firmware" \
pankso@299 144 -geometry 80x24 \
pankso@304 145 -e "$0 detect-pci --get-firmware; \
pankso@304 146 $0 detect-usb --get-firmware; \
pankso@304 147 echo -e \"----\nPress ENTER to close...\"; \
pankso@299 148 read i; exit 0"
pankso@299 149 fi
pankso@299 150 }
pankso@299 151
al@813 152 box_setup_devices() {
jozee@457 153 SETUP_OPTIONS=""
jozee@457 154 if [ $INSTALL_NON_FREE == true ]; then
al@813 155 SETUP_OPTIONS="$SETUP_OPTIONS --non-free"
jozee@457 156 fi
jozee@457 157 if [ $AUTO_INSTALL_SUGGESTED == true ]; then
al@813 158 SETUP_OPTIONS="$SETUP_OPTIONS --suggested"
jozee@457 159 elif [ $CONFIRM_INSTALL_SUGGESTED == true ]; then
al@813 160 SETUP_OPTIONS="$SETUP_OPTIONS --confirm"
al@813 161 fi
jozee@457 162 xterm -geometry 80x24 -T "$DEVICE Setup" \
jozee@457 163 -e "$0 setup $DEVICE $SETUP_OPTIONS; \
jozee@457 164 echo -e \"----\nPress ENTER to close...\"; \
al@813 165 read i; exit 0"
jozee@457 166 }
jozee@457 167
pankso@299 168 # Get firmware used by check_firmware()
pankso@299 169 if [ "$2" == "--get-firmware" ]; then
pankso@299 170 firmware='get'
pankso@299 171 fi
al@813 172
pankso@299 173 # What to do.
pankso@299 174 case "$1" in
pankso@299 175 init)
pankso@299 176 check_root
al@813 177 _ 'Detecting PCI devices Kernel modules...'
pankso@299 178 detect_pci_devices
al@813 179 _ 'Detecting USB devices Kernel modules...'
pankso@326 180 detect_usb_devices ;;
pankso@299 181 detect-pci)
pankso@299 182 check_root
al@813 183 newline; _ 'Detected PCI devices Kernel modules'; separator
pankso@299 184 rm -f /var/lib/detected-modules
pankso@299 185 detect_pci_devices
al@813 186 separator; newline ;;
pankso@299 187 detect-usb)
pankso@299 188 check_root
al@813 189 newline; _ 'Detected USB devices Kernel modules'; separator
pankso@299 190 rm -f /var/lib/detected-usb-modules
pankso@299 191 detect_usb_devices
al@813 192 separator; newline ;;
al@813 193 setup)
al@813 194 SETUP_OPTIONS=$(echo "$@" | sed 's/setup//')
pankso@828 195 check_root
jozee@457 196 hwsetup $SETUP_OPTIONS ;;
pankso@299 197 detected-modules)
al@813 198 newline; _ 'Detected PCI and USB modules'; separator
pankso@299 199 cat /var/lib/detected-modules
pankso@304 200 cat /var/lib/detected-usb-modules 2>/dev/null
al@813 201 separator; newline ;;
pankso@299 202 *)
pankso@299 203 usage ;;
pankso@299 204 esac
pankso@299 205
pankso@299 206 exit 0