summaryrefslogtreecommitdiff
path: root/network/miniupnpd/rc.miniupnpd.new
blob: cb88938345890b3fd1ec367b9b83feba2362cc73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash

PRG="MiniUPnPd"
ARGS="-f /etc/miniupnpd/miniupnpd.conf"
IPV6=@IPV6@

cleanup() {
  /etc/miniupnpd/iptables_removeall.sh &> /dev/null
  [ "$IPV6" = "yes" ] && /etc/miniupnpd/ip6tables_removeall.sh &> /dev/null
}

start() {
  echo -n "Starting $PRG..."
  /etc/miniupnpd/iptables_init.sh &> /dev/null
  [ "$IPV6" = "yes" ] && /etc/miniupnpd/ip6tables_init.sh &> /dev/null
  if /usr/sbin/miniupnpd $ARGS; then
    echo "Done."
  else
    EXIT=$?
    cleanup
    exit $EXIT
  fi
}

stop() {
  echo -n "Stopping $PRG..."
  killall miniupnpd &> /dev/null
  cleanup
  echo "Done."
}

ensure_running() {
  if pidof miniupnpd &> /dev/null; then
    RUN=1
  else
    echo "$PRG is not running."
    exit 1
  fi
}

case "$1" in
  "start")
    if pidof miniupnpd &> /dev/null; then
      echo "$PRG already running."
      exit 0
    fi
    start
    ;;
  "stop")
    ensure_running
    stop
    ;;
  "restart")
    if pidof miniupnpd &> /dev/null; then
      stop
    else
      echo -n "$PRG is not running. Cleaning..."
      cleanup
      echo "Done."
    fi
    start
    ;;
  "flush")
    ensure_running
    echo -n "Flushing $PRG iptables rules..."
    /etc/miniupnpd/iptables_flush.sh
    [ "$IPV6" = "yes" ] && /etc/miniupnpd/ip6tables_flush.sh
    echo "Done."
    ;;
  "display")
    ensure_running
    /etc/miniupnpd/iptables_display.sh
    [ "$IPV6" = "yes" ] && /etc/miniupnpd/ip6tables_display.sh
    ;;
  "status")
    ensure_running
    echo "$PRG is running."
    ;;
  "cleanup")
    if pidof miniupnpd &> /dev/null; then
      echo "$PRG is running. Refusing to cleanup."
      exit 1
    fi
    echo -n "Cleaning..."
    cleanup
    echo "Done."
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|flush|display|cleanup|status}"
    exit 1
    ;;
esac