#!/bin/sh 
# postinst script for gpsdrive
#
# see: dh_installdeb(1)

set -e

case "$1" in
    configure)

        . /usr/share/debconf/confmodule

        # Create mysql database
        echo "gpsdrive.postinst:  Create mysql database"
        db_get gpsdrive/initdb
	INIT_DB=$RET
	if [ "$INIT_DB" = "true" ] ; then

	    echo "/usr/bin/geoinfo.pl --create-db --fill-defaults"
	    /usr/bin/geoinfo.pl --create-db --fill-defaults

	    db_get gpsdrive/importosm
	    IMPORT_OSM=$RET
	    if [ "$IMPORT_OSM" = "true" ] ; then
		db_get gpsdrive/importosmarea
		IMPORT_OSM_AREA=$RET
		echo "/usr/bin/geoinfo.pl --osm --area=$IMPORT_OSM_AREA"
		/usr/bin/geoinfo.pl --osm --area=$IMPORT_OSM_AREA
	    fi 
	fi

	# More things we could add here:
	#   - Ask about downloading planet.osm once
	#   - Ask about a contab entry for regularly downloading planet.osm
	#   - ask for an optional area of planet.osm to import
	#   - Ask about installing current mapnik data: planet.sql, shapefiles
	#   - Ask about downloading maps arround your current gps position

    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac


# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
