[f874424] | 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 "${BROADCAST}" ]; then
|
---|
| 40 | args="${args} broadcast ${BROADCAST}"
|
---|
| 41 | fi
|
---|
| 42 |
|
---|
| 43 | case "${2}" in
|
---|
| 44 | up)
|
---|
| 45 | if [ "$(ip addr show ${1} | grep ${IP})" == "" ]; then
|
---|
| 46 | log_info_msg2 "\n" # Terminate the previous message
|
---|
| 47 | log_info_msg "Adding IPv4 address ${IP} to the ${1} interface..."
|
---|
| 48 | ip addr add ${args} dev ${1}
|
---|
| 49 | evaluate_retval
|
---|
| 50 |
|
---|
| 51 | if [ -n "${GATEWAY}" ]; then
|
---|
| 52 | if ip route | grep -q default; then
|
---|
| 53 | log_warning_msg "\nGateway already setup; skipping."
|
---|
| 54 | else
|
---|
| 55 | log_info_msg "Setting up default gateway..."
|
---|
| 56 | ip route add default via ${GATEWAY} dev ${1}
|
---|
| 57 | evaluate_retval
|
---|
| 58 | fi
|
---|
| 59 | fi
|
---|
| 60 | else
|
---|
| 61 | msg="Cannot add IPv4 address ${IP} to ${1}. Already present."
|
---|
| 62 | log_warning_msg "$msg"
|
---|
| 63 | fi
|
---|
| 64 | ;;
|
---|
| 65 |
|
---|
| 66 | down)
|
---|
| 67 | if [ "$(ip addr show ${1} | grep ${IP})" != "" ]; then
|
---|
| 68 | log_info_msg "Removing IPv4 address ${IP} from the ${1} interface..."
|
---|
| 69 | ip addr del ${args} dev ${1}
|
---|
| 70 | evaluate_retval
|
---|
| 71 | fi
|
---|
| 72 |
|
---|
| 73 | if [ -n "${GATEWAY}" ]; then
|
---|
| 74 | # Only remove the gateway if ther are no remaining ipv4 addresses
|
---|
| 75 | if [ "$(ip addr show ${1} | grep 'inet ')" != "" ]; then
|
---|
| 76 | log_info_msg "Removing default gateway..."
|
---|
| 77 | ip route del default
|
---|
| 78 | evaluate_retval
|
---|
| 79 | fi
|
---|
| 80 | fi
|
---|
| 81 | ;;
|
---|
| 82 |
|
---|
| 83 | *)
|
---|
| 84 | echo "Usage: ${0} [interface] {up|down}"
|
---|
| 85 | exit 1
|
---|
| 86 | ;;
|
---|
| 87 | esac
|
---|
| 88 |
|
---|
| 89 | # End /lib/services/ipv4-static
|
---|