#!/bin/sh DAEMON=dnsmasq PID_FILE=/var/run/$DAEMON/$DAEMON.pid . /etc/init.d/modlibrc [ -r /etc/options.cfg ] && . /etc/options.cfg if [ "$FREETZ_AVMDAEMON_DISABLE_DNS" != "y" ]; then [ "$(/etc/init.d/rc.multid status)" != "running" -o "$DNSMASQ_MULTID_RESTART" != "yes" ] && nomultid=y else nomultid=y fi config() { modlib_config } startdaemon_pre() { [ "$nomultid" != "y" ] && /etc/init.d/rc.multid stop >/dev/null || true } start() { local OPTIONS="--pid-file=$PID_FILE $DNSMASQ_OPTIONS" [ "$DNSMASQ_DNS_PORT" ] && OPTIONS="$OPTIONS -p $DNSMASQ_DNS_PORT" modlib_startdaemon $DAEMON $OPTIONS } startdaemon_post() { [ "$nomultid" != "y" ] && /etc/init.d/rc.multid start >/dev/null if [ ! -L "/var/flash/multid.leases" -a "$DNSMASQ_DHCP" = "yes" ]; then rm -f /var/flash/multid.leases touch /var/tmp/multid.leases ln -s /var/tmp/multid.leases /var/flash/multid.leases fi # this could pose problems when a client comes too fast local lease for lease in /var/tmp/multid.leases /var/tmp/dnsmasq.leases; do if [ -f $lease ]; then chmod 0664 $lease chown root:nobody $lease fi done } stop_pre() { [ "$nomultid" != "y" ] && /etc/init.d/rc.multid stop >/dev/null } stop_post() { [ "$nomultid" != "y" ] && /etc/init.d/rc.multid start >/dev/null if [ -L "/var/flash/multid.leases" ]; then major=$(grep tffs /proc/devices) rm -f /var/flash/multid.leases mknod /var/flash/multid.leases c ${major%%tffs} $((0x70)) fi } case $1 in ""|load|multid) if [ "$1" == "multid" ]; then [ "$DNSMASQ_WRAPPER" != "yes" ] && exit else [ "$DNSMASQ_WRAPPER" == "yes" ] && exit fi mkdir -p "/tmp/flash/${DAEMON}" [ -r "/tmp/flash/${DAEMON}.extra" ] && mv "/tmp/flash/${DAEMON}.extra" "/tmp/flash/${DAEMON}/${DAEMON}.extra" modreg cgi 'dnsmasq' 'Dnsmasq' modreg daemon $DAEMON modreg file dnsmasq extra 'extra' 0 dnsmasq_extra modlib_add_user_and_group nobody mkdir -p ${PID_FILE%/*} chown nobody:nobody ${PID_FILE%/*} modlib_start $DNSMASQ_ENABLED ;; unload) modunreg file dnsmasq modunreg daemon $DAEMON modunreg cgi dnsmasq modlib_stop ;; start) modlib_start ;; stop) modlib_stop ;; restart) if [ "$FREETZ_AVMDAEMON_DISABLE_DNS" != "y" ]; then modlib_check_running && nomultid=y fi modlib_restart ;; reload) modlib_reload ;; status) modlib_status ;; *) echo "Usage: $0 [load|unload|start|stop|restart|reload|status]" 1>&2 exit 1 ;; esac exit 0