#!/bin/sh
#
# Coda client installation script
# Made for Linux coda-client rpm distribution 
# Peter J. Braam, Dec 1996
# included suggestions from Elliot Lee, may 1997.
#
# Usage: venus-setup comma,separated,list,of,servers [cachesize in kb]
#
# the script will verify that the necessary directories and /etc/services
# are present.
#


CODAETC=/usr/coda/etc
CACHEDIR=/usr/coda/venus.cache
TMPDIR=/usr/coda/tmp
CACHESIZE=40000
# SERVERS=testserver.coda.cs.cmu.edu

CFSDEV=/dev/cfs0
case `uname -sr` in
	"NetBSD 1.2" )
		CFSMAJOR=46 ;;
	NetBSD\ 1.3 )
		CFSMAJOR=51 ;;
	NetBSD\ 1.3.* )
		CFSMAJOR=51 ;;
	NetBSD\ 1.3* )
		CFSMAJOR=60 ;;
	FreeBSD* )
		CFSMAJOR=93 ;;
	*)
		CFSMAJOR=67 ;;
esac

CFSMINOR=0
CODAROOT=/coda

if [ x$RPM_BUILD_ROOT = x ]; then
  RPM_BUILD_ROOT=/
fi

if [ $# != 2 ]; then
	echo "Usage: $0 comma,separated,list,of,servers cachesize-in-kb"
	exit 1
else
	SERVERS=$1
	CACHESIZE=$2
fi


VSTAB=/coda:$CFSDEV:$SERVERS:$CACHEDIR:$CACHESIZE:1

# set up the /coda root if it isn't there yet
if [ ! -d $CODAROOT ]; then mkdir -p $CODAROOT; fi
if [ ! -f $CODAROOT/NOT_REALLY_CODA ]; then 
 echo 'If you can see this file, venus is not running.' > \
	$RPM_BUILD_ROOT/coda/NOT_REALLY_CODA
fi

# set up a cache directory
if [ ! -d $CACHEDIR ]; then mkdir -p $CACHEDIR; chmod 700 $CACHEDIR; fi
if [ ! -d $TMPDIR ]; then mkdir -p $TMPDIR; chmod 700 $TMPDIR; fi

# next run will always initialize
touch $CACHEDIR/INIT

# set up the etc directory with the vstab
if [ ! -d $CODAETC ]; then mkdir -p $CODAETC; fi
echo $VSTAB > $CODAETC/vstab

# make the psdev
if [ ! -c $CFSDEV ]; then 
    mknod $CFSDEV c $CFSMAJOR $CFSMINOR 
    chmod 0600 $CFSDEV
fi

# frobnicate /etc/services
NEWSERVICES=/tmp/services.$$
if grep coda_filesrv /etc/services >/dev/null ; then 
echo Removing old Coda entries from /etc/services..
perl -n -e 'if ( ! /^coda/ ) { print ; }'  < /etc/services > $NEWSERVICES
mv $NEWSERVICES /etc/services
rm $NEWSERVICES
fi 

if grep rpc2portmap /etc/services >/dev/null ; then 
echo "/etc/services already has new services registered! Good."
else 
cat <<EOF >> /etc/services
# Iana allocated Coda filesystem port numbers
rpc2portmap     369/tcp    
rpc2portmap     369/udp    # Coda portmapper
codaauth2       370/tcp    
codaauth2       370/udp    # Coda authentication server

venus           2430/tcp   # codacon port
venus           2430/udp   # Venus callback/wbc interface 
venus-se        2431/tcp   # tcp side effects
venus-se        2431/udp   # udp sftp side effect
codasrv         2432/tcp   # not used
codasrv         2432/udp   # server port
codasrv-se      2433/tcp   # tcp side effects
codasrv-se      2433/udp   # udp sftp side effect
EOF
fi

# tell the kernel about the new module 
if [ X`uname` = XLinux ]; then 
   if ! grep coda /etc/conf.modules > /dev/null; then
	echo 'alias char-major-67 coda' >> /etc/conf.modules
   fi
   /sbin/depmod -a
fi


