#!/bin/sh

TFTPDATA=/tmp/dhcpc-tftp
echo -n "" > $TFTPDATA

case "$1" in
	deconfig)
		;;

	renew|bound)
		# client ip
		echo "dhcp_ip $ip" >> $TFTPDATA

		# boot_file (default option) if set, otherwise option 67 (vendor boot file)
		( [ -n "$boot_file" ] && echo "dhcp_bootfile $boot_file" || echo "dhcp_bootfile $bootfile" ) >> $TFTPDATA

		# root path
		echo "dhcp_rootpath $rootpath" >> $TFTPDATA

		# opt150 (serverip), is a hex-form of IP addresses; take the first one only, convert to dotted-decimal
		[ -n "$opt150" ] && serverip="$(( 0x${opt150:0:2} )).$(( 0x${opt150:2:2} )).$(( 0x${opt150:4:2} )).$(( 0x${opt150:6:2} ))"
		echo "dhcp_serverip $serverip" >> $TFTPDATA
		;;

	nak)
		;;
esac
