#!/bin/sh
#
# Neat idea from http://www.doit.org/udhcpc/
#

# Figure out where we are, then run vtund.
#
# If running in my intranet, connect directly to my server.
#
# If we're out in the big scary world somewhere, public access, then route
# vtund through the Internet to my server box.  If you want to do this,
# you'll need a static IP address somewhere and port 5000 open.
#
# Replace addresses and ESSIDs as needed.  If you're smart enough to
# figure out vtun, you're smart enough to figure this out.
start_vtun() {
    case `iwgetid --scheme` in
	"")		return ;;			# No WiFi at all
	"linuxwlan")	server=192.168.0.1 ;;		# Intranet
	*)		server=11.22.33.44 ;;		# World
    esac

    ps aux|grep vtund|grep -v grep || vtund  zaurus $server
}
stop_vtun() {
    killall vtund
}

#
# udhcpc calls us with one of four different possible arguments.  See if
# you can figure out what each means.
#
case "$1" in
    bound)		start_vtun ;;
    renew)		start_vtun ;;
    deconfig)		stop_vtun  ;;
    nak)		;;
    *)			logger -t "dhcp" "weird, dunno what '$1' is"
esac

exit 0
