simple script for updating HE IPv4 endpoint

This is a simple script for updating Hurricane Electric's IPv4 endpoint for 6in4 tunnels. Some of these barebones systems lack curl or a wget that supports SSL so HE_URL utilizes an insecure endpoint. Not perfect, but it works.

#!/bin/sh

IP=$(nvram get wan_ipaddr)
OLD_IP="n/a"
DEBUG=0
HE_PASS="YOUR_PASSWORD"
HE_USER="YOUR_USERNAME"
HE_TUNNEL_ID=YOUR_TUNNEL_ID
HE_URL="http://ipv4.tunnelbroker.net/ipv4_end.php"

log() {
  if [ $DEBUG -gt 0 ]; then
      echo "DEBUG: $@"
      logger -t he-updater -- "$@"
  fi
}

if [ -f /jffs/local/he-updater.cfg ]; then
  source /jffs/local/he-updater.cfg
fi

if [ "$1" == "FORCE" ]; then
  DEBUG=1
  log "forcing an update"
  OLD_IP="na"
fi

log "IP: "$IP", OLD_IP: "$OLD_IP

if [ $IP != $OLD_IP ]; then
  OUTPUT=$(wget -T 2 -O - "${HE_URL}?ipv4b=AUTO&pass=${HE_PASS}&user_id=${HE_USER}&tunnel_id=${HE_TUNNEL_ID}")
  log "${OUTPUT}"
  echo "OLD_IP=\"$IP\"" > /jffs/local/he-updater.cfg
fi