aboutsummaryrefslogtreecommitdiff
path: root/network/noip2/rc.noip2.new
blob: d0284b919237b3f10f5f33ff3f65ea0a72bfa011 (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
#!/bin/sh
#
# /etc/rc.d/rc.noip2
#
# start/stop/restart the no-ip.com Dynamic dns client daemon
#
# To make noip2 client start automatically at boot, make this
# file executable: chmod 755 /etc/rc.d/rc.noip2
# and add this lines to /etc/rc.d/rc.local
#
# if [ -x /etc/rc.d/rc.noip2 ]; then
#  . /etc/rc.d/rc.noip2 start
# fi
#
# Written by slack.dhabyx@gmail.com and tested on Slackware 12.1
#

NOIP_PATH='/usr/bin'
NOIPCONFIG='/etc/no-ip2.conf'

config_exist() {
	if [ ! -f $NOIPCONFIG ] ; then
		echo "Please create the configuration file"
		echo "$NOIP_PATH/noip2 -C -c $NOIPCONFIG"
		exit 0;
	fi
}

start() {
	config_exist
	if ! /sbin/route -n | grep "^0.0.0.0" 1> /dev/null ; then
		echo "Gateway not defined yet, please init the network services."
		exit 0;
	fi
	echo "Starting no-ip client daemon: "
	/usr/bin/noip2 -c $NOIPCONFIG
}

stop() {
	config_exist
	if $NOIP_PATH/noip2 -S -c $NOIPCONFIG 2>&1 | grep Process 1> /dev/null ; then
		echo "Stopping no-ip client daemon: ";
		for i in `$NOIP_PATH/noip2 -S -c $NOIPCONFIG 2>&1 | grep Process | awk '{print $2}' | tr -d ','`
		do
			$NOIP_PATH/noip2 -c $NOIPCONFIG -K $i
		done
	else
		echo "no-ip client daemon is not running" && exit 0
	fi
}

status() {
	config_exist
	if $NOIP_PATH/noip2 -S -c $NOIPCONFIG 2>&1 | grep Process 1>/dev/null ; then
		echo "no-ip client daemon is running"
	else
		echo "no-ip client daemon is not runnig"
	fi
}

restart() {
	stop
	start
}

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  status)
	status
	;;
  restart)
  	restart
	;;
  *)
	echo "Usage: $0 {start|stop|status|restart}"
	exit 1
esac