#!/bin/sh

FSTAB_CONFIG="/etc/fstab"

write_home()
{
    mountpoint -q /home && umount /home >&2
    sed -r '\,^[[:space:]]*[^[:space:]]+[[:space:]]+/home[[:space:]], d' -i "$FSTAB_CONFIG"
    printf '%s /home nfs rw 0 0\n' "$1" >>"$FSTAB_CONFIG"
    service portmap start >/dev/null
    modprobe nfs
    mount /home >&2
}

. /usr/share/alterator/build/backend3.sh

on_message()
{
	case "$in_action" in
		write)
		    case "$in_type" in
			nfs)
			    [ -n "$in_location" ] && write_home "$in_location"
			    echo '()'
			    ;;
			*)
			    printf '(error "%s")' "Unknown storage type"
			    ;;
		    esac
			;;
		*)
			echo '#f'
			;;
	esac
}

message_loop
