1 | #!/bin/sh
|
---|
2 | ########################################################################
|
---|
3 | # Begin /lib/services/ipv4-static
|
---|
4 | #
|
---|
5 | # Description : IPV4 Static Boot Script
|
---|
6 | #
|
---|
7 | # Authors : Nathan Coulson - nathan@linuxfromscratch.org
|
---|
8 | # Kevin P. Fleming - kpfleming@linuxfromscratch.org
|
---|
9 | # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
|
---|
10 | #
|
---|
11 | # Version : LFS 7.0
|
---|
12 | #
|
---|
13 | ########################################################################
|
---|
14 |
|
---|
15 | . /lib/lsb/init-functions
|
---|
16 | . ${IFCONFIG}
|
---|
17 |
|
---|
18 | if [ -z "${IP}" ]; then
|
---|
19 | log_failure_msg "\nIP variable missing from ${IFCONFIG}, cannot continue."
|
---|
20 | exit 1
|
---|
21 | fi
|
---|
22 |
|
---|
23 | if [ -z "${PREFIX}" -a -z "${PEER}" ]; then
|
---|
24 | log_warning_msg "\nPREFIX variable missing from ${IFCONFIG}, assuming 24."
|
---|
25 | PREFIX=24
|
---|
26 | args="${args} ${IP}/${PREFIX}"
|
---|
27 |
|
---|
28 | elif [ -n "${PREFIX}" -a -n "${PEER}" ]; then
|
---|
29 | log_failure_msg "\nPREFIX and PEER both specified in ${IFCONFIG}, cannot continue."
|
---|
30 | exit 1
|
---|
31 |
|
---|
32 | elif [ -n "${PREFIX}" ]; then
|
---|
33 | args="${args} ${IP}/${PREFIX}"
|
---|
34 |
|
---|
35 | elif [ -n "${PEER}" ]; then
|
---|
36 | args="${args} ${IP} peer ${PEER}"
|
---|
37 | fi
|
---|
38 |
|
---|
39 | if [ -n "${LABEL}" ]; then
|
---|
40 | args="${args} label ${LABEL}"
|
---|
41 | fi
|
---|
42 |
|
---|
43 | if [ -n "${BROADCAST}" ]; then
|
---|
44 | args="${args} broadcast ${BROADCAST}"
|
---|
45 | fi
|
---|
46 |
|
---|
47 | case "${2}" in
|
---|
48 | up)
|
---|
49 | if [ "$(ip addr show ${1} 2>/dev/null | grep ${IP}/)" = "" ]; then
|
---|
50 | log_info_msg "Adding IPv4 address ${IP} to the ${1} interface..."
|
---|
51 | ip addr add ${args} dev ${1}
|
---|
52 | evaluate_retval
|
---|
53 | else
|
---|
54 | log_warning_msg "Cannot add IPv4 address ${IP} to ${1}. Already present."
|
---|
55 | fi
|
---|
56 | ;;
|
---|
57 |
|
---|
58 | down)
|
---|
59 | if [ "$(ip addr show ${1} 2>/dev/null | grep ${IP}/)" != "" ]; then
|
---|
60 | log_info_msg "Removing IPv4 address ${IP} from the ${1} interface..."
|
---|
61 | ip addr del ${args} dev ${1}
|
---|
62 | evaluate_retval
|
---|
63 | fi
|
---|
64 |
|
---|
65 | if [ -n "${GATEWAY}" ]; then
|
---|
66 | # Only remove the gateway if there are no remaining ipv4 addresses
|
---|
67 | if [ "$(ip addr show ${1} 2>/dev/null | grep 'inet ')" != "" ]; then
|
---|
68 | log_info_msg "Removing default gateway..."
|
---|
69 | ip route del default
|
---|
70 | evaluate_retval
|
---|
71 | fi
|
---|
72 | fi
|
---|
73 | ;;
|
---|
74 |
|
---|
75 | *)
|
---|
76 | echo "Usage: ${0} [interface] {up|down}"
|
---|
77 | exit 1
|
---|
78 | ;;
|
---|
79 | esac
|
---|
80 |
|
---|
81 | # End /lib/services/ipv4-static
|
---|