Hurricane Electric's Tunnelbroker endpoint address update script

This script is purely based on common tools and does not require Perl packages.
It is intended to work with all platforms, including lightweight, busybox based, routers (like OpenWrt or dd-wrt).

Usage

All parameters can be staticly set into the shell script, so edit it first.
	USERID="your_userid"
PASSWORD="your_password"
TUNNELID="your_tunnel_id"
# When empty, IPv4 value is fetched from whatismyip
# IPV4=""

Get first your userid and tunnelid from your tunnel web interface (the numeric value is shown in the configured tunnel detail url, tunnelid variable)
http://tunnelbroker.net/index.php

Command line (overrides static parameters) also available:
	updateipv4 [ipv4 [ tunnel_id [ userid password ] ] ]

Download

Download (version 0.50, NON-WORKING!) here: updateipv4-.sh.old
Download (version 0.51) here: updateipv4.sh (updated for the new userid parameter)
0.51 version does not handle return codes yet (TODO)

How to integrate

The best way is to create a script that will run standalone.
As DDwrt firmware (and openwrt ?) does not provide nohup command we need this kind of script:
(Please replace adresses with your own one as given on tunnelbroker's website, iproute2 section)
#!/bin/sh
trap 'echo 0' 1
while [ true ]
do
IPV4=`ifconfig vlan1 | grep "inet addr" | sed -e "s+inet addr:++" -e "s+Bcas.*++" -e "s+ *++"`

if [ "$IPV4" != "$OLDIP" ]
then
sh /jffs/updateipv4.sh $IPV4
insmod ipv6
ip tunnel del he-ipv6
ip tunnel add he-ipv6 mode sit remote 216.66.xx local $IPV4 ttl 255
ip link set he-ipv6 up
ip addr add 2001:470:xxxx::2/64 dev he-ipv6
ip addr add 2001:470:xxxx::3/64 dev br0
ip route add ::/0 dev he-ipv6
ip route del 2001:470:xxxx::/64 dev he-ipv6
ip route add 2001:470:xxxx::/64 dev br0
fi

OLDIP="$IPV4"
sleep 60

done
This script use static adresses (as radvd is broken on ddwrt). We just route packets through our network.
All network hosts should use the gateway on interface br0.