#!/bin/sh
#
# serial 1.1 1999/05/25 05:39:40 (David Hinds)
#
# Initialize or shutdown a PCMCIA parallel device
#
# The first argument should be either 'start' or 'stop'.  The second
# argument is the base name for the device.
#
# The script passes an extended device address to 'parallel.opts' in the
# ADDRESS variable, to retrieve device-specific configuration options.
# The address format is "scheme,socket,instance" where "scheme" is the
# PCMCIA configuration scheme, "socket" is the socket number, and
# "instance" is used to number multiple ports on a single card.  
#

if [ -r ./shared ] ; then . ./shared ; else . /etc/pcmcia/shared ; fi

# Get device attributes
get_info $DEVICE

# Load site-specific settings
ADDRESS="$SCHEME,$SOCKET,$INSTANCE"
. $0.opts

LP="lp$MINOR"

case "$ACTION" in

'start')
    if [ ! -c /dev/$LP ] ; then
	mknod /dev/$LP c $MAJOR $MINOR
    fi
    if [ "$LINK" ] ; then
	mv -f $LINK $LINK.O 2>/dev/null
	ln -s /dev/$DIALOUT $LINK
    fi
    if [ "$LP_OPTS" ] ; then
	tunelp /dev/$LP $LP_OPTS
    fi
    ;;

'check')
    fuser -s /dev/$LP /dev/$LP $LINK && exit 1
    ;;

'cksum')
    chk_simple "$3,$SOCKET,$INSTANCE" || exit 1
    ;;
    
'stop')
    fuser -s -k /dev/$LP $LINK
    rm -f $LINK ; mv -f $LINK.O $LINK 2>/dev/null
    ;;

'suspend')
    fuser -s -k -STOP /dev/$LP
    ;;

'resume')
    if [ "$LP_OPTS" ] ; then
	tunelp /dev/$LP $LP_OPTS
    fi
    fuser -s -k -CONT /dev/$LP $LINK
    ;;

*)
    usage
    ;;

esac

exit 0
