#!/bin/sh
##
## Adapted by Rick Moen in 2004 based on a long-ago co-worker's script 
## fragment.  This script may be freely copied, modified, or
## distributed, with attribution.  (I'd credit the core fragment, 
## too, if only I remembered who wrote it.)
## 
## Configures /dev/ttyS2 serial port for a US Robotics PCI modem.
##
## This startup Bourne shell script for Linux, written for a USR model 5610 PCI 
## non-winmodem, searches lines of "lspci" output until a line contains the 
## string "US Robotics", then parses from that line the IRQ and I/O port 
## assigned to that device by the PCI controller chip, then runs 
## "setserial" to initialise serial port /dev/ttyS2 (COM3, to MS-DOS people) 
## with those hardware settings.  With minimal work, the script should
## be adaptable to any other PCI non-winmodem.
## 
DEVICE=$(lspci | grep "US Robotics" | awk '{print $1}')
IRQ=$(lspci -v -s $DEVICE | head -n 3 | tail -n 1 | cut -d ' ' -f 5)
PORTS=$(lspci -v -s $DEVICE | head -n 4 | tail -n 1 | cut -d ' ' -f 4)

echo US Robotics modem is at IRQ $IRQ
echo ...and the base of the I/O port range is $PORTS

setserial /dev/ttyS2 port 0x$PORTS irq $IRQ autoconfig

