#!/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
	    HTTP_PROXY=$RET
	fi
    fi
    db_get nvidia-cg-toolkit/delete
    if [ "$RET" = "true" ]; then
	DELETE="--delete-after"
    fi
    
    if [ "$INSTALL" = "true" ]; then
	http_proxy=$HTTP_PROXY /usr/bin/update-nvidia-cg-toolkit \
	    --install $DELETE $LOCALDIR || true
    fi
    ;;
esac

#DEBHELPER#
