#!/bin/sh -e

##########################################################################
#   Title:
#       Optional, defaults to the name of the script sans extention
#
#   Section:
#       8
#
#   Synopsis:
#       
#   Description:
#       Amend /etc/fstab from an fstab fragment
#       
#   Arguments:
#       Filename of fstab fragment
#       
#   Returns:
#
#   Examples:
#
#   Files:
#
#   Environment:
#
#   See also:
#       
#   History:
#   Date        Name        Modification
#   2019-01-05  Jason Bacon Begin
#   2024-11-11  Jason Bacon Add man page template and usage
##########################################################################

usage()
{
    printf "Usage: $0 fstab-fragment\n"
    exit 1
}


##########################################################################
#   Main
##########################################################################

if [ $# != 1 ]; then
    usage
fi
fstab=$1

# Factor out from cluster-setup scripts
while read mount; do
    dir=`echo $mount | awk '{ print $2 }'`
    if awk '{ print $2 }' /etc/fstab | fgrep -qw $dir; then
	printf "$dir is already in fstab.\n"
    elif echo $mount | fgrep -q $(hostname -s); then
	printf "$mount is on this host, skipping...\n"
    else
	# FIXME: Make sure mount dir is empty
	
	printf "Adding $dir to fstab...\n"
	printf "$mount\n" >> /etc/fstab
	mkdir -p $dir
    fi
done < $fstab
