#!/bin/sh
#
# etc/install-etc 1.19 2002/07/17 06:41:49 (David Hinds)
#
# This handles updating the PCMCIA startup and device configuration
# scripts.  I used to do this in the Makefile, but it is really much
# more of a shell scripty thing.

# Get configuration settings
. ../config.out

if [ $1 ] ; then PREFIX=$1 ; fi
PROBE=../cardmgr/pcic_probe
if [ "CONFIG_PCMCIA" = "y" ] ; then PK=-k ; else PK= ; fi
ETC=$PREFIX/etc/pcmcia

install_clients ()
{
    echo "-> Updating client scripts in $ETC"
    mkdir -p $ETC
    CONF=`echo *.conf`
    if [ "$CONF" != "*.conf" ] ; then
	cp *.conf $ETC
    fi
    for f in *.opts ; do
	[ -r $ETC/$f ] || cp $f $ETC/$f
	b=`basename $f .opts`
	cmp -s $b $ETC/$b && continue
	[ -r $ETC/$b ] && mv $ETC/$b $ETC/$b.O
	cp $b $ETC/$b
    done
    for f in shared ; do
	cmp -s $f $ETC/$f && continue
	[ -r $ETC/$f ] && mv $ETC/$f $ETC/$f.O
	cp $f $ETC/$f
    done
    # Tweak network.opts for Red Hat
    if [ -f /etc/redhat-release ] && \
	cmp -s network.opts $ETC/network.opts ; then
	echo "->   Configuring /etc/pcmcia/network.opts for Red Hat"
	cat network.rh >> $ETC/network.opts
    fi
    # Tweak network.opts for Debian
    if [ -f /etc/debian_version ] && \
	cmp -s network.opts $ETC/network.opts ; then
	echo "->   Configuring /etc/pcmcia/network.opts for Debian"
	cat network.deb >> $ETC/network.opts
    fi
}

install_hhl ()
{

	mkdir -p $PREFIX/etc/pcmcia
	CFG=$PREFIX/etc/pcmcia/pcmcia.conf
	SYSV=$PREFIX/etc/init.d/pcmcia

	if [ -f $CFG ] ; then . $CFG ; fi

	if [ "$PCMCIA" != "yes" ] ; then
	    echo "-> Creating PCMCIA options file $CFG"
	    echo PCMCIA=yes > $CFG
	    PCIC=$MODULE
	    if [ -x $PROBE ] ; then PCIC=`$PROBE -m $PK` ; fi
	    echo "PCIC=i82365" >> $CFG
	    echo "PCIC_OPTS=" >> $CFG
	    echo "CORE_OPTS=" >> $CFG
	    echo "CARDMGR_OPTS=" >> $CFG
	fi

	if ! cmp -s pcmcia $SYSV ; then
	   # Just clobber old startup script on RedHat-ish systems
  		if [ $RC_DIR = "/etc/rc.d" ] ; then
         	    rm -f $SYSV.N
  		elif [ -e $SYSV ] ; then
           	  SYSV=$SYSV.N
	  	fi
        fi
	echo "-> Installing PCMCIA startup script as $SYSV"
	mkdir -p $PREFIX$RC_DIR/init.d
	cp ./rc.pcmcia $SYSV
	chmod +x $SYSV
}

install_hhl
install_clients

# Directory to receive cardmgr's 'stab' socket status file
mkdir -p $PREFIX/var/lib/pcmcia
