#!/bin/bash
#
# cfs-setup - set up NFS for use with CFS on Red Hat Linux
#
# Author: Jerry Sweet <cfs-tools@akamail.com>
#
# $Id: cfs-setup,v 1.1 2002/06/29 17:48:30 jsweet Rel $
#

umask 022

#
#  Create the /mnt/crypt directory:
#

test -d /mnt/crypt || mkdir -pm 755 /mnt/crypt


#
#  Create the "null" directory in a handy place.  My convention
#  is /<hostname>/null.  Yes, mode 000 is deliberate.
#

hostname=`hostname | perl -pe 's/\..*$//'`
test -d /$hostname/null || mkdir -pm 000 /$hostname/null


#
#  Add the "null" directory to your /etc/exports file and export it.
#  (Note: we keep the original as /etc/exports.cfs-bak.)
#

test -f /etc/exports.cfs-bak || cp -p /etc/exports /etc/exports.cfs-bak

egrep /$hostname/null /etc/exports || \
	( echo "/$hostname/null	localhost" >> /etc/exports && \
	  /usr/sbin/exportfs localhost:/$hostname/null )

/usr/sbin/exportfs -va

#
#  Add the /mnt/crypt directory to your /etc/fstab file.
#  (Note: we keep the original as /etc/fstab.cfs-bak.)
#

test -f /etc/fstab.cfs-bak || cp -p /etc/fstab /etc/fstab.cfs-bak

egrep /mnt/crypt /etc/fstab || \
	( echo "localhost:/$hostname/null /mnt/crypt nfs \
		nfsvers=2,rw,port=3049,intr,addr=127.0.0.1,noauto 0 0" \
	    >> /etc/fstab )
