#!/bin/sh

case "$1" in
    start)
        /bin/echo "The tunnel service is starting"
        if [ -z "`/sbin/lsmod | /bin/grep \^tun`" ]; then
            /sbin/insmod tun
        fi
        if [ -e /opt/share/gw6c/gw6ckeys.pub ]; then
            mv -f /opt/share/gw6c/gw6ckeys.pub /tmp/local/root/
        fi
        /opt/bin/gw6c -f /opt/etc/gw6c.conf
        ;;

    stop)
        if [ -n "`/bin/pidof gw6c`" ]; then
            /usr/bin/killall gw6c 2>/dev/null
        fi
        if [ -n "`/bin/pidof radvd`" ]; then
            /usr/bin/killall radvd 2>/dev/null
        fi
        if [ -e /tmp/local/root/gw6ckeys.pub ]; then
            mv -f /tmp/local/root/gw6ckeys.pub /opt/share/gw6c/
        fi
        /bin/echo "The tunnel service is stopped"
        ;;

    restart)
        $0 stop
esac

exit 0
