Fabrice Fontaine | 5823088 | 2016-07-21 14:05:57 +0200 | [diff] [blame^] | 1 | #!/bin/sh |
| 2 | |
| 3 | NAME=upnpd |
| 4 | PIDFILE=/var/run/$NAME.pid |
| 5 | DAEMON=/usr/sbin/$NAME |
| 6 | CFGFILE=/etc/default/$NAME |
| 7 | |
| 8 | LAN=eth0 |
| 9 | WAN=eth0 |
| 10 | |
| 11 | # For the UPnP library to function correctly, networking must be configured |
| 12 | # properly for multicasting as described in |
| 13 | # https://sourceforge.net/p/pupnp/code/ci/master/tree/README. |
| 14 | # Without this addition, device advertisements and control point searches will |
| 15 | # not function. |
| 16 | # However, the route has to be configured once for all UPnP applications |
| 17 | # (igd2-for-linux, ushare, ...) so do not manage UPnP route by default |
| 18 | MANAGE_UPNP_MULTICAST_ROUTE_ON_LAN=0 |
| 19 | |
| 20 | # Read configuration variable file if it is present |
| 21 | if [ -f $CFGFILE ]; then |
| 22 | . $CFGFILE |
| 23 | fi |
| 24 | |
| 25 | DAEMON_ARGS="-f $WAN $LAN" |
| 26 | |
| 27 | start() { |
| 28 | if [ $MANAGE_UPNP_MULTICAST_ROUTE_ON_LAN != 0 ]; then |
| 29 | printf "Add UPnP multicast route on $LAN\n" |
| 30 | route add -net 239.0.0.0 netmask 255.0.0.0 $LAN |
| 31 | fi |
| 32 | printf "Starting $NAME: " |
| 33 | start-stop-daemon -S -q -m -b -p $PIDFILE --exec $DAEMON -- $DAEMON_ARGS |
| 34 | [ $? = 0 ] && echo "OK" || echo "FAIL" |
| 35 | } |
| 36 | |
| 37 | stop() { |
| 38 | printf "Stopping $NAME: " |
| 39 | start-stop-daemon -K -q -p $PIDFILE |
| 40 | [ $? = 0 ] && echo "OK" || echo "FAIL" |
| 41 | if [ $MANAGE_UPNP_MULTICAST_ROUTE_ON_LAN != 0 ]; then |
| 42 | printf "Remove UPnP multicast route on $LAN\n" |
| 43 | route del -net 239.0.0.0 netmask 255.0.0.0 $LAN |
| 44 | fi |
| 45 | } |
| 46 | |
| 47 | restart() { |
| 48 | stop |
| 49 | start |
| 50 | } |
| 51 | |
| 52 | case "$1" in |
| 53 | start) |
| 54 | start |
| 55 | ;; |
| 56 | stop) |
| 57 | stop |
| 58 | ;; |
| 59 | restart|reload) |
| 60 | restart |
| 61 | ;; |
| 62 | *) |
| 63 | echo "Usage: $0 {start|stop|restart|reload}" |
| 64 | exit 1 |
| 65 | esac |
| 66 | |
| 67 | exit $? |