#!/bin/bash

function enable_tftp()
{
    if ! CreoleRun "systemctl is-enabled tftpd-hpa &>/dev/null" dhcp;then
        echo "* Activation du service tftp local"
        CreoleRun "systemctl unmask tftpd-hpa" dhcp
        CreoleRun "systemctl enable tftpd-hpa" dhcp
    fi
    CreoleRun "systemctl restart tftpd-hpa" dhcp
}

function disable_tftp()
{
    if CreoleRun "systemctl is-enabled tftpd-hpa &>/dev/null" dhcp;then
        echo "* Désactivation du service tftp local"
        CreoleRun "systemctl stop tftpd-hpa" dhcp
        CreoleRun "systemctl disable tftpd-hpa" dhcp
    fi
}

adresse_ip_tftp="$(CreoleGet adresse_ip_tftp '')"
if [ -n "$adresse_ip_tftp" ];then
    if [ "$adresse_ip_tftp" = "$(CreoleGet adresse_ip_eth0)" ] ||
       [ "$adresse_ip_tftp" = "$(CreoleGet adresse_ip_fichier_link '')" ];then
        enable_tftp
    else
        disable_tftp
    fi
else
    disable_tftp
fi
exit 0
