#!/bin/sh
source "$RUNES_INTERFACE_DIR/RUNES/functions.sh"
[ -f "$RUNES_CONFIG_PATH" ] && source "$RUNES_CONFIG_PATH"
interface=$RUNES_INTERFACE_DIR/$RUNES_RUNE_NAME

eval $(runes_cmdline param_ DHCPd)
# 



eval $(runes_interface ipv4_ LOCAL IPv4Network getNetworkInterfacesList)
# ipv4_Interfaces

eval $(runes_interface tftp_ LOCAL TFTPBoot getNetworkInterfacesList)
# tftp_PXEBootFilePath

# 最初の1つを使う
netdev=$(echo $ipv4_Interfaces | cut -d ' ' -f 1)

if [ -z "$netdev" ];then
	gprintf_failure "No network interface was found."
	exit 1
fi


eval $(runes_interface netdev_ LOCAL IPv4Network getInterfaceInfo $netdev)
# netdev_IPAddress=
# netdev_NetworkAddress=
# netdev_BcastAddress=

vip=$(echo $netdev_IPAddress | cut -d '.' -f 1,2,3).222
prio=$(echo $netdev_IPAddress | cut -d '.' -f 4)


rm -rf $interface
mkdir $interface


./bin/vrrpd -i $netdev -n -v 43 -p $prio $vip
./bin/busybox httpd -p 8080 -h $interface


echo "
<html>
<head>
<title>VIVER VRRP Demo</title>
</head>

<body>
<p>alive</p>
<p>$netdev_IPAddress</p>
</body>

</html>
" > $interface/index.html

