#!/bin/bash export LC_ALL=C HWSETUP_DIR=/etc/conf.d/hwsetup HWINFO="/usr/sbin/hwinfo" UNSUPPORTED_GFXCARD_DRIVERS="" UNSUPPORTED_NETCARD_DRIVERS="" if [ -f ${HWSETUP_DIR}/unsupported-gfxcard-drivers ] then UNSUPPORTED_GFXCARD_DRIVERS="$(< ${HWSETUP_DIR}/unsupported-gfxcard-drivers)" fi if [ -f ${HWSETUP_DIR}/unsupported-netcard-drivers ] then UNSUPPORTED_NETCARD_DRIVERS="$(< ${HWSETUP_DIR}/unsupported-netcard-drivers)" fi clearconfig() { local file="$1" : > ${HWSETUP_DIR}/${file} } addconfig() { local file="$1" local data="$2" echo "${data}" >> ${HWSETUP_DIR}/${file} } # check_unsupported_netcard_drivers UNSUPPORTED_ARRAY DRIVER check_unsupported_drivers() { local unsupported="$1" local driver="$2" local i # filter unsupported devices for i in ${unsupported} do [[ ${i} = ${driver} ]] && return 1 done return 0 } get_gfxcard_sysfsid_from_specific_hwid() { local SEARCH_ID="$1" local hwid local sysfsid local counter declare -i counter=0 echo "${GFXCARD_INFO}" | while read line do # get hwinfo device id, its always the first line if [[ ${counter} = 0 ]] then # hwids begins all with ^ID:, sub informations have an empty space hwid=$(echo "${line}" | grep '^[0-9].*' | sed 's:\(^[0-9]*\)\:\ .*:\1:') fi # search for device id if [[ ${SEARCH_ID} = ${hwid} ]] then case "${line}" in *'SysFS ID:'*) # subst the id sysfsid="${line#*:}" # trim spaces sysfsid="${sysfsid// }" echo "${sysfsid}" ;; esac fi # next hardware item if [[ -z ${line} ]] then counter=0 else ((counter++)) fi done } get_primary_display_hwid() { local hwid hwid="$(echo "${GFXCARD_INFO}" | grep 'Primary display adapter:' | sed 's:.*\:\ \#\([0-9]*\):\1:')" echo "${hwid}" } # disable probeonly, load all modules by default probeonly=0 # check getops for i in $* do case $1 in # ignoring -p,-v,-a,-s -p|-v|-a|-s) shift;; # only support dry-run -n) shift; probeonly=1 ;; esac shift done echo -n "Autoconfiguring devices... " 1>&2 GFXCARD_INFO="$(${HWINFO} --gfxcard)" # check for a primary device and rerun hwinfo for this device only primary_display_hwid="$(get_primary_display_hwid)" if [[ -n ${primary_display_hwid} ]] then GFXCARD_INFO="$(${HWINFO} --gfxcard --only $(get_gfxcard_sysfsid_from_specific_hwid ${primary_display_hwid}))" fi NETCARD_INFO="$(${HWINFO} --netcard)" MOUSE_INFO="$(${HWINFO} --mouse)" # eval arrays with all modules and descriptions # # graphic eval $(echo GFXCARD_MODULE=\($(echo "${GFXCARD_INFO}" | grep 'XFree86.*Module:' | sed 's:.*\:\ \(.*\)$:\"\1\":')\)) eval $(echo GFXCARD_DESC=\($(echo "${GFXCARD_INFO}" | grep 'Model:' | sed 's:.*\:\ \"\(.*\)\"$:\"\1\":')\)) # the xserver is always xorg, no array needed GFXCARD_XSERVER="Xorg" # # network eval $(echo NETCARD_MODULE=\($(echo "${NETCARD_INFO}" | grep 'Driver Modules:' | sed 's:.*\:\ \"\(.*\)\"$:\"\1\":')\)) eval $(echo NETCARD_DESC=\($(echo "${NETCARD_INFO}" | grep 'Model:' | sed 's:.*\:\ \"\(.*\)\"$:\"\1\":')\)) # fallback (only needed for systems without netlink) eval $(echo NETCARD_MODULE_FB=\($(echo "${NETCARD_INFO}" | grep 'Driver Activation Cmd:' | sed 's:.*\:\ \"modprobe\ \(.*\)\"$:\"\1\":')\)) # # mouse eval $(echo MOUSE_MODULE=\($(echo "${MOUSE_INFO}" | grep 'Driver Modules:' | sed 's:.*\:\ \"\(.*\)\"$:\"\1\":')\)) eval $(echo MOUSE_DESC=\($(echo "${MOUSE_INFO}" | grep 'Model:' | sed 's:.*\:\ \"\(.*\)\"$:\"\1\":')\)) eval $(echo MOUSE_DEVICE=\($(echo "${MOUSE_INFO}" | grep 'Device File:' | sed 's:.*\:\ \(.*\)[$\ ].*:\"\1\":')\)) eval $(echo MOUSE_GPM_PROTO=\($(echo "${MOUSE_INFO}" | grep 'GPM.*Protocol:' | sed 's:.*\:\ \(.*\)$:\"\1\":')\)) eval $(echo MOUSE_X11_PROTO=\($(echo "${MOUSE_INFO}" | grep 'XFree86.*Protocol:' | sed 's:.*\:\ \(.*\)$:\"\1\":')\)) # get the number of devices for each class GFXCARD_COUNT=$(echo "${GFXCARD_INFO}" | grep -c "[0-9a-zA-Z]\: .*\:\ .*") NETCARD_COUNT=$(echo "${NETCARD_INFO}" | grep -c "[0-9a-zA-Z]\: .*\:\ .*") MOUSE_COUNT=$(echo "${MOUSE_INFO}" | grep -c "[0-9a-zA-Z]\: .*\:\ .*") # clear all config files clearconfig xserver clearconfig netcard clearconfig knoppix clearconfig mouse for ((i=0; i&2