We should use lower case for normal variables.
[openresolv] / dnsmasq.in
index bac90e1f721f51e491cdadc75ea6a6a43e26b718..21450f30886b2a0d59b35b3d88aab0ed7ee8e76b 100644 (file)
 eval "$(${RESOLVCONF:-resolvconf} -v)"
 
 PREFIX=@PREFIX@
-DNSMASQPID="${dnsmasq_pid:-/var/run/dnsmasq.pid}"
+dnsmasqpid="${dnsmasq_pid:-/var/run/dnsmasq.pid}"
 
-NEWCONF="# Generated by resolvconf\n"
-NEWRESOLV="${NEWCONF}"
+newconf="# Generated by resolvconf\n"
+newresolv="${newconf}"
 
-# Using DBUS means that we never have to restart the daemon
+# Using dbus means that we never have to restart the daemon
 # This is important as it means we should not drop DNS queries
-# whilst changing DNS options around. However, DBUS support is optional
+# whilst changing DNS options around. However, dbus support is optional
 # so we need to validate a few things first.
 # Check for DBus support in the binary
 
-DBUS=no
-DBUSPID="${dbus_pid:-/var/run/dbus/dbus.pid}"
-[ -s "${DBUSPID}" ] || DBUSPID=/var/run/dbus.pid
-[ -s "${DBUSPID}" ] || DBUSPID=/var/run/dbus/pid
-if [ -s "${DBUSPID}" -a -s ${DNSMASQPID} ]; then
+dbus=false
+dbuspid="${dbus_pid:-/var/run/dbus/dbus.pid}"
+[ -s "${dbuspid}" ] || dbuspid=/var/run/dbus.pid
+[ -s "${dbuspid}" ] || dbuspid=/var/run/dbus/pid
+if [ -s "${dbuspid}" -a -s ${dnsmasqpid} ]; then
        if dnsmasq --version 2>/dev/null | \
                grep -q "^Compile time options.*[[:space:]]DBus[[:space:]]"
        then
                # Sanity - check that dnsmasq and dbus are running
-               if kill -0 $(cat "${DBUSPID}") 2>/dev/null && \
-                       kill -0 $(cat ${DNSMASQPID}) 2>/dev/null
+               if kill -0 $(cat "${dbuspid}") 2>/dev/null && \
+                       kill -0 $(cat ${dnsmasqpid}) 2>/dev/null
                then
-                       DBUS=yes
-                       NEWCONF="${NEWCONF}\n# Domain specific servers will"
-                       NEWCONF="${NEWCONF} be sent over dbus\nenable-dbus\n"
+                       dbus=true
+                       newconf="${newconf}\n# Domain specific servers will"
+                       newconf="${newconf} be sent over dbus\nenable-dbus\n"
                fi
        fi
 fi
 
-for N in ${NAMESERVERS}; do
-       case "\n${NEWRESOLV}\n" in
-       *"\nnameserver ${N}\n");;
-       *) NEWRESOLV="${NEWRESOLV}nameserver ${N}\n";;
+for n in ${NAMESERVERS}; do
+       case "\n${newresolv}\n" in
+       *"\nnameserver ${n}\n");;
+       *) newresolv="${newresolv}nameserver ${n}\n";;
        esac
 done
 
-DBUSDEST=
-for D in ${DOMAINS}; do
-       DN="${D%%:*}"
-       NS="${D#*:}"
-       while [ -n "${NS}" ]; do
-               if [ "${DBUS}" = "yes" ]; then
+dbusdest=
+for d in ${DOMAINS}; do
+       dn="${d%%:*}"
+       ns="${d#*:}"
+       while [ -n "${ns}" ]; do
+               if ${dbus}; then
                        SIFS=${IFS-y} OIFS=$IFS
                        IFS=.
-                       set -- ${NS%%,*}
-                       NUM="0x$(printf "%02x" $1 $2 $3 $4)"
+                       set -- ${ns%%,*}
+                       num="0x$(printf "%02x" $1 $2 $3 $4)"
                        if [ "${SIFS}" = "y" ]; then
                                unset IFS
                        else
                                IFS=$OIFS
                        fi
-                       DBUSDEST="${DBUSDEST} uint32:$(printf "%u" ${NUM})"
-                       DBUSDEST="${DBUSDEST} string:${DN}"
+                       dbusdest="${dbusdest} uint32:$(printf "%u" ${num})"
+                       dbusdest="${dbusdest} string:${dn}"
                else
-                       NEWCONF="${NEWCONF}server=/${DN}/${NS%%,*}\n"
+                       newconf="${newconf}server=/${db}/${ns%%,*}\n"
                fi
-               [ "${NS}" = "${NS#*,}" ] && break
-               NS="${NS#*,}"
+               [ "${ns}" = "${ns#*,}" ] && break
+               ns="${ns#*,}"
        done
 done
 
-RELOAD="no"
+changed=false
 if [ -f "${dnsmasq_conf}" ]; then
-       if [ "$(cat "${dnsmasq_conf}")" != "$(printf "${NEWCONF}")" ]; then
-               RELOAD="yes"
-               printf "${NEWCONF}" > "${dnsmasq_conf}"
+       if [ "$(cat "${dnsmasq_conf}")" != "$(printf "${newconf}")" ]; then
+               changes=true
+               printf "${newconf}" > "${dnsmasq_conf}"
        fi
 else
-       RELOAD="yes"
-       printf "${NEWCONF}" > "${dnsmasq_conf}"
+       changed=true
+       printf "${newconf}" > "${dnsmasq_conf}"
 fi
 if [ -f "${dnsmasq_resolv}" ]; then
-       if [ "$(cat "${dnsmasq_resolv}")" != "$(printf "${NEWRESOLV}")" ]; then
-               RELOAD="yes"
-               printf "${NEWRESOLV}" > "${dnsmasq_resolv}"
+       if [ "$(cat "${dnsmasq_resolv}")" != "$(printf "${newresolv}")" ]; then
+               changed=true
+               printf "${newresolv}" > "${dnsmasq_resolv}"
        fi
 else
-       # dnsmasq polls this file so no need to set RELOAD="yes"
-       printf "${NEWRESOLV}" > "${dnsmasq_resolv}"
+       # dnsmasq polls this file so no need to set changed=true
+       printf "${newresolv}" > "${dnsmasq_resolv}"
 fi
 
-[ "${RELOAD}" = "yes" ] && resolvconf -s dnsmasq restart
-if [ "${DBUS}" = "yes" ]; then
-       [ "${RELOAD}" != "yes" ] && kill -HUP $(cat ${DNSMASQPID})
+${changed} && resolvconf -s dnsmasq restart
+if ${dbus}; then
+       ${restart} || kill -HUP $(cat ${dnsmasqpid})
        # Send even if empty so old servers are cleared
        dbus-send --system --dest=uk.org.thekelleys.dnsmasq \
                /uk/org/thekelleys/dnsmasq uk.org.thekelleys.SetServers \
-               ${DBUSDEST}
+               ${dbusdest}
 fi