File: cipe-common.init

package info (click to toggle)
cipe 1.5.4free-9
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 908 kB
  • ctags: 730
  • sloc: ansic: 5,976; sh: 358; makefile: 315; asm: 200; perl: 45
file content (85 lines) | stat: -rw-r--r-- 1,817 bytes parent folder | download | duplicates (2)
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
#!/bin/sh
#
# cipe        Start/stop the CIPE daemon
#
#        Written by Tommi Virtanen <tv@debian.org>
#

PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
DAEMON="/usr/sbin/ciped"
NAME="ciped"
DESC="encrypted tunnel"

PEERDIR="/etc/cipe/peers"
test -x $DAEMON || exit 0
test -d $PEERDIR || exit 0

PEERS=$(find "$PEERDIR" -type f -maxdepth 1 '!' -name '*~' -exec basename '{}' ';')
if [ "x$PEERS" = "x" ]; then
    echo CIPE is not configured yet, stopping.
    exit 0
fi

set -e

stop_all () {
  for peer in $PEERS; do
    IPADDR=`awk '{ if($1=="ipaddr") print $2 }' "$PEERDIR/$peer"`
    PTPADDR=`awk '{ if($1=="ptpaddr") print $2 }' "$PEERDIR/$peer"`
    if test -n "$IPADDR" -a -n "$PTPADDR"; then
      INTERFACE=`ifconfig | grep -A1 '^cip' | fgrep -B1 'inet addr:'$IPADDR | fgrep -B1 'P-t-P:'$PTPADDR | sed -e 's/ .*//' -eq`
      if test -n "$INTERFACE"; then
        echo -n "$peer "
        ifconfig "$INTERFACE" down
      fi
    fi
  done
}

start_all () {
  for peer in $PEERS; do
    echo -n "$peer "
    start-stop-daemon --start --quiet --exec $DAEMON -- -o "$PEERDIR/$peer"
  done
}

case "$1" in
  start)
    echo -n "Starting $DESC: "
    start_all
    echo "$NAME."
    ;;
  maybe-start)
    if [ "$2" = "$(uname -r)" ]; then
      echo -n "Starting $DESC: "
      start_all
      echo "$NAME."
    fi
    ;;
  stop)
    echo -n "Stopping $DESC: "
    stop_all
    echo "$NAME."
    ;;
  maybe-stop)
    if [ "$2" = "$(uname -r)" ]; then
      echo -n "Stopping $DESC: "
      stop_all
      echo "$NAME."
    fi
    ;;
  restart|force-reload)
    echo -n "Restarting $DESC: "
    stop_all
    sleep 1
    start_all
    echo "$NAME."
    ;;
  *)
    N=/etc/init.d/cipe
    echo "Usage: $N {start|stop|restart|force-reload|maybe-stop kvers}" >&2
    exit 1
    ;;
esac

exit 0