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