#! /bin/sh
#
# freenet6	Script to configure the IPv6 tunnel to freenet6
#
#		Written by Martin Waitz <tali@debian.org>

PATH=/sbin:/bin:/usr/sbin:/usr/bin
TSPC=/usr/sbin/tspc

test -f $DAEMON || exit 0


# read tsp client config, to get the interface used
. /etc/freenet6/tspc.conf
IF=$if_tunnel

case "$1" in
  start)
	echo -n "Setting up freenet6 IPv6 tunnel ($IF): "
	$TSPC &&
	ifconfig $IF | grep "Global" | sed -e "s/^.*inet6 addr: //" -e "s/ Scope.*\$//"
	;;
  stop)
	echo -n "Shutting down freenet IPv6 tunnel ($IF): "
	ip tunnel del $IF &&
	echo "done."
	;;
  restart|force-reload)
	echo -n "Resetting freenet IPv6 tunnel ($IF): "
	ip tunnel del $IF 2>/dev/null
	$TSPC &&
	ifconfig $IF | grep "Global" | sed -e "s/^.*inet6 addr: //" -e "s/ Scope.*\$//"
	;;
  *)
	echo "Usage: $0 {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
