#!/bin/sh
###############################################################################
##
## Export all file systems.
##
##  2007-01-16  Andreas Vogel (omega)
##
###############################################################################

exportDirs="/ /app /tmpfs /cloopfs /lib/modules /opt /img/www /img/bin /raid/data /raid/sys"

cmd=$1
srcfile=${2:-/etc/exports}
tmpfile=/tmp/tmp.exports

case "$cmd" in
    add)
        if [ ! -w "$srcfile" ] ; then
            echo "$0: ERROR: cannot open file '$srcfile' for writing!"
            exit 1
	fi
        for dir in $exportDirs ; do
            echo "Adding dir to $srcfile: $dir"
            grep -v -e "^\"$dir\"" -e "^$dir" $srcfile > $tmpfile
            echo "$dir *(rw,no_root_squash,sync)" >> $tmpfile
            cp $tmpfile $srcfile
            chown root.root $srcfile
            chmod 644 $srcfile
            rm -f $tmpfile
        done
        ;;

    del)
        if [ ! -w "$srcfile" ] ; then
            echo "$0: ERROR: cannot open file '$srcfile' for writing!"
            exit 1
	fi
        for dir in $exportDirs ; do
            echo "Removing dir from $srcfile: $dir"
            grep -v -e "^\"$dir\"" -e "^$dir" $srcfile > $tmpfile
            cp $tmpfile $srcfile
            chown root.root $srcfile
            chmod 644 $srcfile
            rm -f $tmpfile
        done
        ;;

    *)
        echo "Usage: $0 {add|del} [exportfile]"
        exit 1
        ;;
esac

exit 0
