# This pluin overrides the default Debian plugin, see #904427 for details. It is
# needed to be able to provide the LTSP client root fs via NFS instead of NBD.
case "$MODE" in
    commandline)
        add_option "squashfs-image" "`eval_gettext "create squashfs image for use with NBD"`" "advanced" "false"
        add_option "no-squashfs-image" "`eval_gettext "skip squashfs image creation"`" "advanced" "false"
        add_option "default-nfs" "`eval_gettext "use NFS instead of NBD as default"`" "advanced" "false"
        ;;
    configure)
        if [ -n "$option_squashfs_image_value" ]; then
            # set an environment variable we can pick up later
            SQUASHFS_IMAGE="True"
        fi
        if [ -n "$option_no_squashfs_image_value" ]; then
            # set an environment variable we can pick up later
            SQUASHFS_IMAGE="False"
        fi
        if [ -n "$option_default_nfs_value" ]; then
            # set an environment variable we can pick up later
            DEFAULT_NFS="True"
        fi
        if [ -z "$SQUASHFS_IMAGE" ]; then
            SQUASHFS_IMAGE="True"
        fi
        ;;
    after-install)
        if [ "True" = "$DEFAULT_NFS" ]; then
            sed -i 's#NBD AOE NFS#NFS NBD AOE#' $ROOT/etc/ltsp/update-kernels.conf
        fi
        ;;
    finalization)
        if [ "True" = "$SQUASHFS_IMAGE" ]; then
            DEBIAN_OLD_FRONTEND=$DEBIAN_FRONTEND

            if [ -n "$CHROOT" ]; then
                UPDATE_IMAGE_OPTIONS="${CHROOT}"
            fi

            DEBIAN_FRONTEND=noninteractive
            export DEBIAN_FRONTEND

            /usr/sbin/ltsp-update-image --config-nbd ${UPDATE_IMAGE_OPTIONS}

            DEBIAN_FRONTEND=$DEBIAN_OLD_FRONTEND
            export DEBIAN_FRONTEND

        fi
        ;;
esac
