#!/bin/sh

# Change kmem to staff and mode to 0755 if you don't have a kmem group,
# or if you don't want normal users to be able to use these utilities.
MEM=kmem
MODE=02755

# These must all be in the same filesystem.
AUTHD=/etc/authd
TCPUID=/etc/tcpuid
TCPUNAME=/etc/tcpuname

AUTHUSER=/usr/lib/libauthuser.a
AUTHUSERH=/usr/include/authuser.h

# Man pages.
MAUTHUSER=/usr/man/man3/authuser.3
MAUTHD=/usr/man/man8/authd.8
MTCPUID=/usr/man/man8/tcpuid.8
MTCPUNAME=/usr/man/man8/tcpuname.8

# Name of port 113 in /etc/services.
PORTNAME=auth

echo "Each action will be printed before it is run. Press return to proceed."

echo "1. Install authd, tcpuid, and tcpuname."
echo "! install -c -g $MEM -m $MODE authd $AUTHD: " | tr -d '\012'
read line
install -c -g "$MEM" -m "$MODE" authd "$AUTHD"

echo "! rm -f $TCPUID; ln $AUTHD $TCPUID: " | tr -d '\012'
read line
rm -f "$TCPUID"; ln "$AUTHD" "$TCPUID"

echo "! rm -f $TCPUNAME; ln $AUTHD $TCPUNAME: " | tr -d '\012'
read line
rm -f "$TCPUNAME"; ln "$AUTHD" "$TCPUNAME"

echo "2. Install the authuser library."
echo "! install -c -m 0444 authuser.h $AUTHUSERH: " | tr -d '\012'
read line
install -c -m 0444 authuser.h "$AUTHUSERH"

echo "! ar rv $AUTHUSER authuser.o: " | tr -d '\012'
read line
ar rv "$AUTHUSER" authuser.o

echo "! ranlib $AUTHUSER: " | tr -d '\012'
read line
ranlib "$AUTHUSER"

echo "! chmod 644 $AUTHUSER: " | tr -d '\012'
read line
chmod 644 "$AUTHUSER"

echo "3. Make the man pages available."
echo "! install -c -m 0444 authuser.3 $MAUTHUSER: " | tr -d '\012'
read line
install -c -m 0444 authuser.3 "$MAUTHUSER"

echo "! install -c -m 0444 authd.8 $MAUTHD: " | tr -d '\012'
read line
install -c -m 0444 authd.8 "$MAUTHD"

echo "! install -c -m 0444 tcpuid.8 $MTCPUID: " | tr -d '\012'
read line
install -c -m 0444 tcpuid.8 "$MTCPUID"

echo "! install -c -m 0444 tcpuname.8 $MTCPUNAME: " | tr -d '\012'
read line
install -c -m 0444 tcpuname.8 "$MTCPUNAME"

echo "4. Make sure an auth port is in /etc/services."
echo "Let me glance at /etc/services for you..."
if grep '^'$PORTNAME'[ 	]*113/tcp' /etc/services >/dev/null 2>&1
then echo "Okay, you have it already. Let's continue."
else echo "Nope, it's not there."
     echo "Let me check that you don't have a different auth port..."
     if grep '^'$PORTNAME'[ 	][ 	]*' /etc/services >/dev/null 2>&1
     then echo "Aaack! $PORTNAME is already used in /etc/services. Exiting."
	  exit 1
     fi
     echo "! echo $PORTNAME'	113/tcp' >> /etc/services: " | tr -d '\012'
     read line
     echo "$PORTNAME"'		113/tcp' >> /etc/services
fi

echo "5. Enable auth in /etc/inetd.conf."
echo "Let me glance at /etc/inetd.conf for you..."
if grep '^'"$PORTNAME"'[ 	]' /etc/inetd.conf >/dev/null 2>&1
then echo "Okay, it's already there. That's it!"
     exit 0
fi
if grep 'telnet.*root' /etc/inetd.conf >/dev/null 2>&1
then echo "It's not there yet. Hmmm, looks like you have a Sun-style inetd."
     echo "! echo $PORTNAME' stream tcp nowait root '$AUTHD' authd' >> /etc/inetd.conf: " | tr -d '\012'
     read line
     echo "$PORTNAME"'	stream	tcp	nowait	root	'"$AUTHD"'	authd' >> /etc/inetd.conf
else echo "It's not there yet."
     echo "! echo $PORTNAME' stream tcp nowait '$AUTHD' authd' >> /etc/inetd.conf: " | tr -d '\012'
     read line
     echo "$PORTNAME"'	stream	tcp	nowait	'"$AUTHD"'	authd' >> /etc/inetd.conf
fi

echo "6. Let inetd know about the new service."
echo "On most machines you have to % kill -HUP nn"
echo "where nn is the number of the inetd process."
echo "Here's what ps acugx shows about inetd:"
ps acugx | sed -n -e 1p -e /inetd/p
echo "I'll leave this step to you. That's it!"

exit 0
