#!/bin/sh export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/mod/sbin:/mod/bin:/mod/usr/sbin:/mod/usr/bin export LD_LIBRARY_PATH=/mod/lib DAEMON=dnsmasq . /etc/init.d/modlibrc # Do we have a UPnP server (igdd) or was ist stripped from the firmware? _igdd=$(basename $(which igdd) 2> /dev/null) # Does a multid option to start without UPnP device (-u) exist? _multid_upnp=$(/sbin/multid -? 2>&1 | grep upnp) # Set multid "no UPnP" option, if # a) it has the parameter at all AND # b) igdd binary does *not* exist [ "$_multid_upnp" ] && [ ! "$_igdd" ] && MULTIDPARAM="-u" start() { local lease modlib_addgroup nobody modlib_adduser nobody -s /bin/false -D -S -H -G nobody -g 'nobody' ( if [ -x "/tmp/flash/${DAEMON}_conf" ]; then /tmp/flash/${DAEMON}_conf else /mod/etc/default.$DAEMON/${DAEMON}_conf fi if [ -r "/tmp/flash/${DAEMON}.extra" ]; then cat /tmp/flash/${DAEMON}.extra fi ) > /mod/etc/$DAEMON.conf echo -n 'Starting dnsmasq...' if [ "$1" != "nomultid" ]; then multid -s > /dev/null 2>&1 fi OPTIONS="$DNSMASQ_OPTIONS" if [ "$DNSMASQ_DNS_PORT" ]; then OPTIONS="$OPTIONS -p \"$DNSMASQ_DNS_PORT\"" fi eval "$DAEMON $OPTIONS" exitval=$? if [ "$1" != "nomultid" ]; then multid $MULTIDPARAM > /dev/null 2>&1 # protect against dnsmasq crash [ -f /var/tmp/avm-resolv.conf -a ! -L /var/tmp/avm-resolv.conf ] && mv /var/tmp/avm-resolv.conf /var/tmp/resolv.conf ln -s resolv.conf /var/tmp/avm-resolv.conf fi 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 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 if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' exit $exitval fi } stop() { echo -n 'Stopping dnsmasq...' if [ "$1" != "nomultid" ]; then multid -s > /dev/null 2>&1 rm /var/tmp/avm-resolv.conf fi killall $DAEMON > /dev/null 2>&1 exitval=$? if [ "$1" != "nomultid" ]; then multid $MULTIDPARAM > /dev/null 2>&1 fi rm -f /mod/etc/$DAEMON.conf 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 if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' exit $exitval fi } case "$1" in ""|load) modreg cgi 'dnsmasq' 'Dnsmasq' if [ "$DNSMASQ_ENABLED" != "yes" ]; then echo "$DAEMON is disabled" 1>&2 exit 1; fi if [ -e "/var/run/dnsmasq.pid" ]; then echo "$DAEMON already started." else if [ -z "$(pidof multid)" ]; then start nomultid else start fi fi ;; unload) stop modunreg cgi 'dnsmasq' ;; start) start ;; stop) stop ;; restart) multid -s > /dev/null 2>&1 stop nomultid sleep 1 start nomultid multid $MULTIDPARAM > /dev/null 2>&1 ;; status) if [ -z "$(pidof "$DAEMON")" ]; then echo 'stopped' else echo 'running' fi ;; *) echo "Usage: $0 [load|unload|start|stop|restart|status]" 1>&2 exit 1 ;; esac exit 0