source: bootscripts/lfs/lib/services/ipv4-static@ 530d929

multilib-10.1 multilib-before-cross
Last change on this file since 530d929 was 530d929, checked in by Thomas Trepl <thomas@…>, 4 years ago

Merge changes from trunk

git-svn-id: http://svn.linuxfromscratch.org/LFS/branches/multilib@11611 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

  • Property mode set to 100755
File size: 2.2 KB
Line 
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
18if [ -z "${IP}" ]; then
19 log_failure_msg "\nIP variable missing from ${IFCONFIG}, cannot continue."
20 exit 1
21fi
22
23if [ -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
28elif [ -n "${PREFIX}" -a -n "${PEER}" ]; then
29 log_failure_msg "\nPREFIX and PEER both specified in ${IFCONFIG}, cannot continue."
30 exit 1
31
32elif [ -n "${PREFIX}" ]; then
33 args="${args} ${IP}/${PREFIX}"
34
35elif [ -n "${PEER}" ]; then
36 args="${args} ${IP} peer ${PEER}"
37fi
38
39if [ -n "${LABEL}" ]; then
40 args="${args} label ${LABEL}"
41fi
42
43if [ -n "${BROADCAST}" ]; then
44 args="${args} broadcast ${BROADCAST}"
45fi
46
47case "${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 ;;
79esac
80
81# End /lib/services/ipv4-static
Note: See TracBrowser for help on using the repository browser.