# Shares the server /home with NFS, for localapps or fat clients.
# Warning: it modifies the server, i.e. it installs nfs-kernel-server and
# it adds /home to /etc/exports.
case "$MODE" in
    commandline)
        add_option "nfs-home" "`eval_gettext "share the server /home with NFS, for localapps or fat clients"`" "advanced" "false"
        ;;

    configure)
        if [ -n "$option_nfs_home_value" ]; then
            NFS_HOME="True"
        elif [ -n "$FAT_CLIENT_DESKTOPS" ]; then
            NFS_HOME="True"
        fi
        if [ "$NFS_HOME" = "True" ]; then
            LATE_PACKAGES="$LATE_PACKAGES nfs-common"
        fi
        ;;

    finalization)
        test "$NFS_HOME" = "True" || return 0

        # If the admin wanted NFS, use it by default.
        mkdir -p "$ROOT/usr/share/ltsp/ltsp_config.d"
        echo 'export NFS_HOME="${NFS_HOME:-/home}"' >> "$ROOT/usr/share/ltsp/ltsp_config.d/020-fat-client-defaults"

        # the following are done on the server, not on the chroot
        if [ -z "$(dpkg-query -W -f '${Version}' nfs-kernel-server 2>/dev/null)" ]; then
            apt-get $APT_GET_OPTS install nfs-kernel-server
        fi
        if ! grep -q ^/home /etc/exports; then
            echo '/home	*(rw,sync,no_subtree_check)' >> /etc/exports
            exportfs -ra || true
        fi
    ;;
esac
