[7125722] | 1 | #!/bin/sh
|
---|
| 2 | ########################################################################
|
---|
| 3 | # Begin $network_devices/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 | #
|
---|
| 10 | # Version : 00.00
|
---|
| 11 | #
|
---|
| 12 | # Notes :
|
---|
| 13 | #
|
---|
| 14 | ########################################################################
|
---|
| 15 |
|
---|
| 16 | . /etc/sysconfig/rc
|
---|
| 17 | . ${rc_functions}
|
---|
| 18 | . ${IFCONFIG}
|
---|
| 19 |
|
---|
| 20 | if [ -z "${IP}" ]; then
|
---|
| 21 | boot_mesg "IP variable missing from ${IFCONFIG}, cannot continue." ${FAILURE}
|
---|
| 22 | echo_failure
|
---|
| 23 | exit 1
|
---|
| 24 | fi
|
---|
| 25 |
|
---|
| 26 | if [ -z "${PREFIX}" -a -z "${PEER}" ]; then
|
---|
| 27 | boot_mesg -n "PREFIX variable missing from ${IFCONFIG}," ${WARNING}
|
---|
| 28 | boot_mesg " assuming 24."
|
---|
| 29 | echo_warning
|
---|
| 30 | PREFIX=24
|
---|
| 31 | args="${args} ${IP}/${PREFIX}"
|
---|
| 32 | elif [ -n "${PREFIX}" -a -n "${PEER}" ]; then
|
---|
| 33 | boot_mesg "PREFIX and PEER both specified in ${IFCONFIG}, cannot continue." ${FAILURE}
|
---|
| 34 | echo_failure
|
---|
| 35 | exit 1
|
---|
| 36 | elif [ -n "${PREFIX}" ]; then
|
---|
| 37 | args="${args} ${IP}/${PREFIX}"
|
---|
| 38 | elif [ -n "${PEER}" ]; then
|
---|
| 39 | args="${args} ${IP} peer ${PEER}"
|
---|
| 40 | fi
|
---|
| 41 |
|
---|
| 42 | if [ -n "${BROADCAST}" ]; then
|
---|
| 43 | args="${args} broadcast ${BROADCAST}"
|
---|
| 44 | fi
|
---|
| 45 |
|
---|
| 46 | if [ -n "${SOURCE}" ]; then
|
---|
| 47 | args="${args} src ${SOURCE}"
|
---|
| 48 | fi
|
---|
| 49 |
|
---|
| 50 | case "${2}" in
|
---|
| 51 | up)
|
---|
| 52 | boot_mesg "Adding IPv4 address ${IP} to the ${1} interface..."
|
---|
| 53 | if [ "${INTERFACE}" != "" ]; then
|
---|
| 54 | ip addr add ${args} dev ${1} label ${1}
|
---|
| 55 | else
|
---|
| 56 | ip addr add ${args} dev ${1}
|
---|
| 57 | fi
|
---|
| 58 | evaluate_retval
|
---|
| 59 |
|
---|
| 60 | if [ "${INTERFACE}" = "" ]; then
|
---|
| 61 | if [ -n "${GATEWAY}" ]; then
|
---|
| 62 | if ip route | grep -q default; then
|
---|
| 63 | boot_mesg "Gateway already setup; skipping." ${WARNING}
|
---|
| 64 | echo_warning
|
---|
| 65 | else
|
---|
| 66 | boot_mesg "Setting up default gateway..."
|
---|
| 67 | ip route add default via ${GATEWAY} dev ${1}
|
---|
| 68 | evaluate_retval
|
---|
| 69 | fi
|
---|
| 70 | fi
|
---|
| 71 | fi
|
---|
| 72 | ;;
|
---|
| 73 |
|
---|
| 74 | down)
|
---|
| 75 | if [ "${INTERFACE}" = "" ]; then
|
---|
| 76 | boot_mesg "Removing Settings From ${1} interface..."
|
---|
| 77 | ip address flush dev ${1}
|
---|
| 78 | evaluate_retval
|
---|
| 79 | fi
|
---|
| 80 | ;;
|
---|
| 81 |
|
---|
| 82 | *)
|
---|
| 83 | echo "Usage: ${0} [interface] {up|down}"
|
---|
| 84 | exit 1
|
---|
| 85 | ;;
|
---|
| 86 | esac
|
---|
| 87 |
|
---|
| 88 | # End $network_devices/services/ipv4-static
|
---|