#!/bin/sh

period=3600
interface="eth0"
logfile="/var/log/ipaddr.knock"

# lifetimes
preferred=${period}
valid=`expr ${period} \* 2`

inotifywait -m -e close_write /home/html/tmp/ipaddr  | while true
do
	read FILE EVENT
	if [ "$FILE" == "/home/html/tmp/ipaddr" ]
	then
		# Create or update the new address.  Allows for the case where a duplicate
		# address is generated.
		#
		now=`date +%s`
		ipaddr=`cat /home/html/tmp/ipaddr`
		/sbin/ip -6 addr replace ${ipaddr}/64 dev ${interface} valid_lft ${valid} preferred_lft ${preferred}
		echo "${now} ${ipaddr}" >>${logfile}
	fi
done
