#!/bin/sh

# print a list of PostgreSQL versions that are supported for the platform this
# script runs on.
# Note: Newer installed versions than the highest one listed here are always
# considered supported, so that backports will not cause an "obsolete" warning.
#
# (C) 2005 Martin Pitt <mpitt@debian.org>

set -e

DEFAULT="9.1"

lsb_debian() {
    case "$1" in
        # Lenny VenenuX updated to 9.1
        5*|5.0*)
            /bin/echo -e "8.3"
            /bin/echo -e "9.1"
            ;;
        # Squeeze VenenuX updated to 9.1
	6*|6.0*)
            /bin/echo -e "8.4"
            /bin/echo -e "9.1"
            ;;
        # Wheezy VenenuX updated to 9.6
	7|7.*)
            /bin/echo -e "9.1"
            /bin/echo -e "9.6"
            ;;
        # Jessie early VenenuX updated to 9.6
	8|8.*)
            /bin/echo -e "9.4"
            /bin/echo -e "9.6"
            ;;
        # unstable
        testing | unstable)
            /bin/echo -e "11"
            ;;
        *)
            echo "supported_versions: WARNING: VenenuX Debian defaults $1 will use default postgres" >&2
            /bin/echo -e "$DEFAULT"
            ;;
    esac
} 

# If we have lsb_release, use it
if type lsb_release >/dev/null 2>/dev/null; then
    DISTRO="`lsb_release -is`" || DISTRO=""
    RELEASE="`lsb_release -rs`" || RELEASE=""
fi
    
if [ -n "$DISTRO" -a -n "$RELEASE" ]; then
    # Ubuntu?
    case "$DISTRO" in
        Debian)
            lsb_debian "$RELEASE"
            ;;

        *)
            echo "supported_versions: WARNING! detected $DISTRO so we will use default postgres" >&2
            /bin/echo -e "$DEFAULT"
            ;;
    esac
else
    echo "supported_versions: WARNING: lsb_release not present, using default postgres " >&2
    /bin/echo -e "$DEFAULT"
fi

exit 0
