#!/bin/sh
# BLURB gpl
# 
#                            Coda File System
#                               Release 6
# 
#           Copyright (c) 1987-2003 Carnegie Mellon University
#                   Additional copyrights listed below
# 
# This  code  is  distributed "AS IS" without warranty of any kind under
# the terms of the GNU General Public Licence Version 2, as shown in the
# file  LICENSE.  The  technical and financial  contributors to Coda are
# listed in the file CREDITS.
# 
#                         Additional copyrights
#                            none currently
# 
#*/

# frobnicate /etc/services
NEWSERVICES=/tmp/services.$$

case `uname -s` in
    CYGWIN* )
        for d in c d e f g h i j ; do 
	  if [ -f /cygdrive/$d/WINNT/system32/drivers/etc/SERVICES ] ; then
	    SERVICES=/cygdrive/$d/WINNT/system32/drivers/etc/SERVICES
	    break
	  fi
	  if [ -f /cygdrive/$d/WINDOWS/system32/drivers/etc/SERVICES ] ; then
	    SERVICES=/cygdrive/$d/WINDOWS/system32/drivers/etc/SERVICES
	    break
	  fi
	done
	if [ x$SERVICES = x ] ; then
	    echo "I can not find your Windows SERVICES file.  You will"
	    echo "need to add the coda ports to your SERVICES file by hand."
	    exit 1
	fi
    ;;

    *)
	SERVICES=/etc/services
    ;;
esac

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

if grep rpc2portmap $SERVICES >/dev/null ; then 
echo "$SERVICES already has new services registered! Good."
else 
cat <<EOF >> $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

echo "$SERVICES ready for Coda"
