#!/bin/bash
#
# Add lines to /etc/fstab if needed
# Automount mail and Opt from a main NFS server
#######################################################
#
#<------ functions ------>

##### Creat a dir for the nfs mount
nfsDir (){
if ! [ -e /mnt/opt-linux ] ; then
	mkdir /mnt/opt-linux 2>/dev/null
fi
}

### Add mail mount to /etc/fstab
changeFstabMail () {
FSTAB=/etc/fstab
if grep -q "hard" $FSTAB  ; then
touch /etc/fstmp
TEMP=/etc/fstmp
/bin/cp -pf --backup=numbered $FSTAB $FSTAB  #Creat a backup of the existing fstab
cat>> $TEMP << END
server:/storage/mail/dir /var/mail            nfs 	rw,intr,soft,actimeo=0 0 0  #<---- Change the server:/storage/mail/dir to the location of your mail
END
/bin/mv -f $TEMP $FSTAB
fi
umount -fl /var/mail
mount -a
}

### Add Opt mount to /etc/fstab
changeFstabOpt () {
FSTAB=/etc/fstab
if grep -q "hard" $FSTAB  ; then
touch /etc/fstmp
TEMP=/etc/fstmp
/bin/cp -pf --backup=numbered $FSTAB $FSTAB  #Creat a backup of the existing fstab
cat>> $TEMP << END
server:/storage/opt-linux 	/mnt/opt-linux      nfs     	ro,intr,soft,bg        0 0   #<---- Change the server:/storage/opt-linux to the location of your opt
END
/bin/mv -f $TEMP $FSTAB
fi
umount -fl /mnt/opt-linux
mount -a
}

#<------ Main -------->
nfsDir
changeFstabMail
changeFstabOpt

