# Save TFP address, comming from DHCP, into UCI

date | logger
logger "Script 60tftp."

loga(){
    logger "60tftp: $1"
    echo "60tftp: $1"
}


if [ -z "$tftp150" ]; then
    loga "tftp150 environment variable is empty."
    exit 0
else
    loga "tftp150: $tftp150"
fi

ADDRESS=`uci get informacast.dhcp.address`

if [ "$tftp150" = "$ADDRESS" ]; then
    loga "TFTP address has not changed."
    exit 0
else
    loga "UCI TFTP Address: $ADDRESS"
fi

uci set informacast.dhcp.address="$tftp150"

if [ $? -eq 0 ]; then
    #No need to commit the changes
    #uci commit
    if [ $? -eq 0 ]; then
        exit 0;
    fi
fi

loga "Failed updating UCI TFTP address."
exit 1
