aboutsummaryrefslogtreecommitdiffstats
path: root/lsb-bootscripts/lib/network-services/ipv4-static
blob: 2a635feb8cecddf948428e2a0526843ac409c953 (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
#!/bin/sh
########################################################################
# Begin /lib/network-services/ipv4-static
#
# Description : IPV4 Static Boot Script
#
# Authors     : Nathan Coulson - nathan@linuxfromscratch.org
#		Kevin P. Fleming - kpfleming@linuxfromscratch.org
#
# Version     : 00.00
#
# Notes       :
#
########################################################################

. /lib/lsb/init-functions
. ${IFCONFIG}

if [ -z "${IP}" ]; then
	log_failure_msg "IP variable missing from ${IFCONFIG}, cannot continue."
	exit 1
fi

if [ -z "${PREFIX}" -a -z "${PEER}" ]; then
	log_warning_msg "PREFIX variable missing from ${IFCONFIG}, assuming 24."
	PREFIX=24
	args="${args} ${IP}/${PREFIX}"
elif [ -n "${PREFIX}" -a -n "${PEER}" ]; then
	log_failure_msg "PREFIX and PEER both specified in ${IFCONFIG}, cannot continue."
	exit 1
elif [ -n "${PREFIX}" ]; then
	args="${args} ${IP}/${PREFIX}"
elif [ -n "${PEER}" ]; then
	args="${args} ${IP} peer ${PEER}"
fi

if [ -n "${BROADCAST}" ]; then
	args="${args} broadcast ${BROADCAST}"
fi

if [ -n "${SOURCE}" ]; then
	args="${args} src ${SOURCE}"
fi

case "${2}" in
	up)
		MESSAGE="Adding IPv4 address ${IP} to the ${1} interface..."
		ip addr add ${args} dev ${1}
		evaluate_retval
	
		if [ -n "${GATEWAY}" ]; then
			if ip route | grep -q default; then
				log_warning_msg "Gateway already setup; skipping." ${WARNING}
			else
				MESSAGE="Setting up default gateway..."
				ip route add default via ${GATEWAY} dev ${1}
				evaluate_retval
			 fi
		fi
	;;
	
	down)
		if [ -n "${GATEWAY}" ];	then
			MESSAGE="Removing default gateway..."
			ip route del default
			evaluate_retval
		fi
	
		MESSAGE="Removing IPv4 address ${IP} from the ${1} interface..."
		ip addr del ${args} dev ${1}
		evaluate_retval
	;;
	
	*)
		echo "Usage: ${0} [interface] {up|down}"
		exit 1
	;;
esac

# End /lib/network-services/ipv4-static