#!/bin/sh

set -e

case $1 in
    configure)
        # Add the "tunnel" user
        if ! getent passwd tunnel > /dev/null; then
            adduser --system --quiet \
                    --home /var/lib/tunnel --no-create-home \
                    --shell /bin/bash --group --gecos "Tunnel" tunnel
        fi
        if test "`id -u tunnel`" -eq 0; then
            echo "The tunnel administrative user must not be root." >&2
            false
        fi

        # Configure the permissions of the required directories
        chown -R tunnel /etc/tunnel
        chown -R tunnel /var/lib/tunnel

        chmod 0775 /etc/tunnel
	chmod 0755 /var/lib/tunnel
	touch /var/lib/tunnel/thosts
	chmod 666 /var/lib/tunnel/thosts
	chmod 644 /var/lib/tunnel/.ssh/tunnel_rsa
	;;

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

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

#DEBHELPER#
