#!/bin/sh

set -e

. /usr/share/debconf/confmodule

case "$1" in
    configure*)
    db_get nvidia-cg-toolkit/local
    if [ -d "$RET" ]; then
        LOCALDIR="--search-path $RET"
        INSTALL="true"
    fi
    if [ -z "$LOCALDIR" ]; then
    db_get nvidia-cg-toolkit/httpget
    if [ "$RET" = "true" ]; then
        INSTALL=$RET
        db_get nvidia-cg-toolkit/http_proxy
        if [ $RET ]; then
            HTTP_PROXY="--proxy $RET"
        fi
    fi
    fi
    db_get nvidia-cg-toolkit/delete
    if [ "$RET" = "true" ]; then
        DELETE="--delete-after"
    fi

    { if [ "$INSTALL" = "true" ]; then
          nvidia-cg-toolkit-installer \
          --install $DELETE $LOCALDIR $HTTP_PROXY
      fi
      if which install-docs >/dev/null 2>&1; then
          install-docs -i /usr/share/doc-base/nvidia-cg-toolkit
      fi
    } || true
    ;;
esac

#DEBHELPER#
