#!/bin/bash

# isc dhcpd specific section
if [[ $DISTRO_NAME = "ubuntu" || $DISTRO_NAME = "debian" ]]; then

  echo '#!/bin/sh
if [ "$reason" = "BOUND" ]; then
    if `grep -q "#ListenAddress 0.0.0.0" /etc/ssh/sshd_config`; then
        /bin/sed -i "s/^#ListenAddress 0.0.0.0.*$/ListenAddress $new_ip_address/g" /etc/ssh/sshd_config
        if `/bin/ps -ef|/bin/grep -v grep|/bin/grep -q sshd`; then
            /usr/sbin/service ssh restart
        fi
    fi
fi' > /etc/dhcp/dhclient-enter-hooks.d/rebind-sshd
  chmod +x /etc/dhcp/dhclient-enter-hooks.d/rebind-sshd
fi
