#!/bin/sh
#
# serial 1.4 2000/06/06 21:02:09 (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')
    is_true $NO_CHECK && exit 0
    do_fuser -s /dev/$LP /dev/$LP $LINK && exit 1
    ;;

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

'suspend')
    do_fuser -k -STOP /dev/$LP > /dev/null
    ;;

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

*)
    usage
    ;;

esac

exit 0
