#! /bin/sh -e

# amdconfig - Interactive configuration script for the 4.4BSD automount daemon
# Copyright (C) 1996 by Dominik Kubla, <Dominik.Kubla@Uni-Mainz.DE>

umask 022
CONFIGDIR=/etc/amd

cat <<EOT

####################### AUTOMOUNTER CONFIGURATION ##############################

This script will lead you through a very simple AMD configuration.  If you want
to use the automounter in a more complex setup, you will have to read the AMD
Reference Manual (type "info amdref" to do this) and perform the necessary steps
manually.  The use of NIS and the fsinfo command is highly recommend.

EOT

echo -n "Configure the automounter now [Y/n] ? "
read ans; test -z "$ans" && ans="Y"
if [ $ans = "n" -o $ans = "N" ]
then
	cat <<EOT

You can configure AMD later by invoking

  amdconfig

EOT
	exit 0
fi

if [ -f $CONFIGDIR/config ]
then
	echo "Backing up old configuration ..."
	mv -f $CONFIGDIR/config $CONFIGDIR/config.old
	mv -f $CONFIGDIR/amd.master $CONFIGDIR/amd.master.old
fi

echo -n "-a /amd -r " >$CONFIGDIR/amd.master 

cat <<EOT

GENERIC CONFIGURATION
=====================

The automounter has the capability of logging either to a specified file
or use the syslog facility where available.
EOT

echo -n "Where should the log messages of AMD go [syslog] ? "
read ans; test -z "$ans" && ans="syslog"
echo "LOGFILE=$ans"			> $CONFIGDIR/config

cat <<EOT

At large sites the automounter tables (called 'maps') may be available through
the "Network Information Service", or NIS for short (formerly know as "Yellow
pages").  This is the recommended way of using the automounter on client
systems.

Note: If your system is using the SUN automounter instead of the 4.4BSD
      automounter, then your system administrator can use the scripts
      provided in /usr/doc/examples/amd to convert them to the AMD syntax
      and add them to the NIS maps on the server.
      SUN AUTOMOUNT MAPS WILL NOT WORK WITH THE AMD!

EOT

echo -n "Does your site propagate the AMD maps through NIS [y/N] ? "
read ans; test -z "$ans" && ans="N"
if [ $ans = "y" -o $ans = "Y" ]
then
	PREFIX=""
	echo -n "  What is the name of the master map [amd.master] ? "
	read ans; test -z "$ans" && ans="amd.master"
	echo NISMAP=$ans		>>$CONFIGDIR/config
	echo -n "  Does this map offer several entries [Y/n] ? "
	read ans; test -z "$ans" && ans="Y"
	if [ $ans = "y" -o $ans = "Y" ]
	then
		echo -n "   What is the key of the entry for this system [default] ? "
		read ans; test -z "$ans" && ans="default"
		echo NISKEY=$ans	>>$CONFIGDIR/config
	fi
	exit 0
fi

cat <<EOT

The original SUN automounter offered a special map called '-hosts',
which allowed the access to the exported files systems of all known hosts
through

  /n/<HOSTNAME>/<FILESYSTEM>

This can be emulated by AMD if desired (but the mountpoint will be named
/net instead /n).

EOT

echo -n "Emulate SUN's host map? [y/N] ?"
read ans

case "$ans" in
y*|Y*)	echo -n "/net $CONFIGDIR/amd.net " >>$CONFIGDIR/amd.master
	cp /usr/doc/examples/amd/a_net $CONFIGDIR/amd.net
        ;;
*)      ;;
esac

cat <<EOT

HOME FILE SYSTEMS
=================

The main purpose of the automounter is to perform NFS mounts on demand and
reverse them after a certain time of inactivity.  This is especially useful
for home directories:  People can have their home directories on their main
workstation, making the cluster more robust to server failures.
If you use the following syntax for the home directories of your users, then
you will not need to do any configuration, because the AMD provides a special
"passwd" map type for that case.  AMD will break the string

   /anydir/[dom1[/...]/]domN/login

to:

  rfs:=/anydir/domN
  rhost:=domN[[....].dom1]
  sublink:=login

At the moment this is the only AMD map for home directories supported by this
configuration tool.
EOT

echo -n "Access home directories with the automounter [y/N] ?"
read ans

case "$ans" in
y|Y)	echo -n "home /etc/passwd " >>$CONFIGDIR/amd.master
	;;
*)	;;
esac


cat <<EOT

RWHO SERVERS
============

If your site uses the RWHO service instead of more sophisticated cluster
services like GNU finger, you might want to export the RWHO database from
so-called RWHO servers

Note: If your site has systems with different endianess, you will need at
      least one server for each byte-order.

EOT

echo -n "Add map entry for the RWHO spool directory [y/N] ? "
read ans; test -z "$ans" && ans="N"
case "$ans" in
y|Y)
	echo "/var/spool/rwho $CONFIGDIR/amd.rwho " >>$CONFIGDIR/amd.master
	echo -n "What are the RWHO servers for big endian systems, eg m68k ? "
	read ans1
	echo -n "What are the RWHO servers for little endian systems, eg i386 ? "
	read ans2
	echo "Creating the 'rwho' map..."
	if [ -n "$ans1" -a -n "$ans2" ]
	then
		echo "/defaults               type:=nfs" >$CONFIGDIR/amd.rwho
                echo "var/spool/rwho          -byte==little;rfs:=/var/spool/rwho \\" >>$CONFIGDIR/amd.rwho
		echo -n "                          " >>$CONFIGDIR/amd.rwho
		for i in $ans2
		do
			echo -n "rhost:=$i " >>$CONFIGDIR/amd.rwho
		done
		echo "\\" >>$CONFIGDIR/amd.rwho
		echo "                         || -rfs:=/var/spool/rwho \\" >>$CONFIGDIR/amd.rwho
		for i in $ans2
		do
			echo -n "rhost:=$i " >>$CONFIGDIR/amd.rwho
		done
	else
		test -n "$ans1" && ans="$ans1"
		test -n "$ans2" && ans="$ans2"
		echo "/defaults               type:=nfs" >$CONFIGDIR/amd.rwho
		echo "var/spool/mail          rfs:=/var/spool/mail \\">>$CONFIGDIR/amd.rwho
		echo "                          " >>$CONFIGDIR/amd.rwho
		for i in $ans
		do
			echo -n "rhost:=$i " >>$CONFIGDIR/amd.rwho
		done
	fi
	;;
*)	;;
esac

cat <<EOT

This completes the AMD configuration.  You can always reconfigure AMD by
invoking '/usr/sbin/amdconfig'.

EOT
