#!/usr/bin/env bash

# usage:
# "restart-dnsmasq" (restart now if needed)
# or
# "restart-dnsmasq -d" (wait for restart to be needed, restart, repeat)

while :
do
  if [ -e /etc/dnsmasq.d/restart.txt ] && rm /etc/dnsmasq.d/restart.txt
  then
    echo restarting
    /etc/init.d/dnsmasq restart
  fi
  if [ "-d" = "$1" ]
  then
    sleep 2
  else
    exit
  fi
done