summaryrefslogtreecommitdiff
path: root/roles/ws/minet/files/minet
blob: 6d6181e4bfe5413b71495c0c4f4118b4886083c7 (plain) (blame)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/sh
#
# This is the main script of the Minimalistic Network Manager
# Author: Christian Pointner <equinox@chaos-at-home.org>
#

NAME="Minimalistic Network Manager"
CURRENT_FILE="/var/run/minet.current"
SUSPENDED_FILE="$CURRENT_FILE.suspended"
SCRIPT_ROOT="/usr/local/lib/minet"

if [ -n "$1" ] && [ "$1" != "status" ] && [ "$USER" != "root" ]; then
		echo "$NAME: only root can do that!"
		exit 1
fi

. $SCRIPT_ROOT/minet_helpers.sh

case "$1" in
	start)
		if [ -z "$2" ]; then
			echo "$NAME: initializing..."
			if [ -f $CURRENT_FILE ]; then
				rm $CURRENT_FILE
			fi
			if [ -f $SUSPENDED_FILE ]; then
				rm $SUSPENDED_FILE
			fi
		else
			if [ -f $SUSPENDED_FILE ]; then
				echo -n "$NAME: "
				echo -n `cat $SUSPENDED_FILE`
				echo " is suspended"
				exit 0
			fi
			if [ -x $SCRIPT_ROOT/$2 ]; then
				if [ -f $CURRENT_FILE ]; then
					$SCRIPT_ROOT/`cat $CURRENT_FILE` stop
				fi
				$SCRIPT_ROOT/$2 start
				echo $2 > $CURRENT_FILE
			else
				echo "Unknown Connection"
				exit 2
			fi
			exit 0
		fi
		;;
	stop)
		echo "$NAME: stopping..."
		if [ -f $CURRENT_FILE ]; then
			$SCRIPT_ROOT/`cat $CURRENT_FILE` stop
			rm $CURRENT_FILE
		fi
		;;
	restart)
		echo "$NAME: restarting..."
		if [ -f $CURRENT_FILE ]; then
			$SCRIPT_ROOT/`cat $CURRENT_FILE` stop
			sleep 1
			$SCRIPT_ROOT/`cat $CURRENT_FILE` start
		fi
		;;
	suspend)
		echo -n "$NAME: "
		if [ ! -f $CURRENT_FILE ]; then
			echo "no active connection to suspend"
			exit 0
		else
		echo -n "suspending connection: "
			echo `cat $CURRENT_FILE`
			ln $CURRENT_FILE $SUSPENDED_FILE
			$SCRIPT_ROOT/`cat $CURRENT_FILE` stop
			rm $CURRENT_FILE
		fi
		;;
	resume)
		echo -n "$NAME: "
		if [ ! -f $SUSPENDED_FILE ]; then
			echo "no suspended connection to resume"
			exit 0
		else
		echo -n "resuming connection: "
			echo `cat $SUSPENDED_FILE`
			ln $SUSPENDED_FILE $CURRENT_FILE
			$SCRIPT_ROOT/`cat $CURRENT_FILE` start
			rm $SUSPENDED_FILE
		fi
		;;
	status)
		echo -n "$NAME status: "
		if [ ! -f $CURRENT_FILE ]; then
			if [ -f $SUSPENDED_FILE ]; then
				echo -n `cat $SUSPENDED_FILE`
				echo " is suspended"
				exit 0
			else
				echo "not connected"
				exit 0
			fi
		else
			echo -n "connected with "
			echo `cat $CURRENT_FILE`
		fi
		;;
	*)
		echo "Usage: $0 (start [connection name]|stop|suspend|resume|status)"
		;;
esac

exit 0