#!/bin/sh DAEMON=multid DAEMON_LONG_NAME="AVM multid" CONF_NAME=avm . /etc/init.d/modlibrc TMPFILE_IGD=/tmp/.multid.igd TMPFILE_NTP=/tmp/.multid.ntp # include environment required for multid restart [ -r /var/env.cache ] && . /var/env.cache start() { echo -n "Starting ${DAEMON_LONG_NAME} ... " if [ -e $TMPFILE_IGD ]; then DAEMON_CMD_IGD=$(cat $TMPFILE_IGD) else if [ ! -e /sbin/igdd -a ! -e /sbin/upnpd ]; then DAEMON_CMD_IGD="$(multid -? 2>&1 | grep "upnp" | grep -v "plugins" | sed 's/^[ \t]*//' | cut -c 1-3)" fi echo "$DAEMON_CMD_IGD" > $TMPFILE_IGD fi if [ -e $TMPFILE_NTP ]; then DAEMON_CMD_NTP=$(cat $TMPFILE_NTP) else if [ -e "/usr/sbin/ntpd" -o -e "/sbin/chronyd" ]; then DAEMON_CMD_NTP="$(multid -? 2>&1 | grep "NTP" | sed 's/^[ \t]*//' | cut -c 1-3 | sed 's/ //')" fi echo "$DAEMON_CMD_NTP" > $TMPFILE_NTP fi #save ipv6 for 'lan' (since fw 04.86) if [ -e /proc/sys/net/ipv6/conf/lan/disable_ipv6 ]; then local addresses_ipv6_lan="$(ip -6 addr show dev lan | sed -n 's/.*inet6 \(.*\)scope global.*/\1/p')" local disable_ipv6_lan="$(cat /proc/sys/net/ipv6/conf/lan/disable_ipv6)" fi rm -rf /var/tmp/avm-resolv.conf /var/tmp/resolv.conf 2>/dev/null $DAEMON $DAEMON_CMD_IGD $DAEMON_CMD_NTP exitval=$? sleep 1 [ -f /tmp/flash/mod/multid.start ] && . /tmp/flash/mod/multid.start #load ipv6 for 'lan' (since fw 04.86) if [ -n "$disable_ipv6_lan" ]; then if [ "$(cat /proc/sys/net/ipv6/conf/lan/disable_ipv6)" != "$disable_ipv6_lan" ]; then ifconfig lan down echo $disable_ipv6_lan > /proc/sys/net/ipv6/conf/lan/disable_ipv6 ifconfig lan up fi for address_ipv6_lan in $addresses_ipv6_lan; do ip -6 addr add $address_ipv6_lan dev lan 2>/dev/null done fi # overwrite upstream-dnsserver for avm-daemons like multid (dnsserver) or voipd if [ -n "$AVM_MULTID_DNS" ]; then echo > /var/tmp/avm-resolv.conf for dnsserver in $AVM_MULTID_DNS; do echo "nameserver $dnsserver" >>/var/tmp/avm-resolv.conf done cat /var/tmp/avm-resolv.conf > /var/tmp/resolv.conf fi # do we have another local dns-sever? multid doesn't create /var/tmp/avm-resolv.conf itself if port 53 is in use. # some (older?) boxes uses /var/tmp/resolv.conf for upstream-dnsserver. for resolv_file in /var/tmp/avm-resolv.conf /var/tmp/resolv.conf; do [ ! -e $resolv_file ] && echo "nameserver 127.0.0.1" > $resolv_file done if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' exit $exitval fi } stop() { $DAEMON -s } ntp_mode() { DAEMON_CMD_NTP_OLD="$(cat $TMPFILE_NTP 2>/dev/null)" [ "$1" == "ntp_disable" ] && DAEMON_CMD_NTP_NEW="$(multid -? 2>&1 | grep "NTP" | sed 's/^[ \t]*//' | cut -c 1-3 | sed 's/ //')" if [ "$DAEMON_CMD_NTP_OLD" != "$DAEMON_CMD_NTP_NEW" ]; then echo "$DAEMON_CMD_NTP_NEW" > $TMPFILE_NTP [ "$(modlib_status)" != "stopped" ] && modlib_restart fi } case $1 in ""|load) modreg daemon -p avm multid ;; unload) modunreg daemon avm multid ;; start) modlib_start ;; stop) modlib_stop ;; restart) modlib_restart ;; status) modlib_status ;; ntp_*) ntp_mode $1 ;; *) echo "Usage: $0 [start|stop|restart|status|ntp_enable|ntp_disable]" 1>&2 exit 1 ;; esac exit 0