]>
Commit | Line | Data |
---|---|---|
9c16cd92 MT |
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 | # Michael Tremer - mitch@ipfire.org | |
10 | # | |
11 | # Version : 00.00 | |
12 | # | |
13 | # Notes : | |
14 | # | |
15 | ######################################################################## | |
16 | ||
17 | . /etc/sysconfig/rc | |
18 | . ${rc_functions} | |
19 | eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) | |
20 | ||
21 | if [ -z "${BROADCAST}" ]; then | |
22 | boot_mesg "BROADCAST variable missing from input, cannot continue." ${FAILURE} | |
23 | echo_failure | |
24 | exit 1 | |
25 | fi | |
26 | ||
27 | if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then | |
28 | PREFIX=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-` | |
29 | args="${args} ${ADDRESS}/${PREFIX} broadcast ${BROADCAST}" | |
30 | else | |
31 | boot_mesg "ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE} | |
32 | echo_failure | |
33 | exit 1 | |
34 | fi | |
35 | ||
36 | case "${2}" in | |
37 | up) | |
38 | boot_mesg "Adding IPv4 address ${ADDRESS} to the ${1} interface..." | |
39 | ip addr add ${args} dev ${1} | |
40 | evaluate_retval | |
41 | ||
42 | if [ -n "${GATEWAY}" ]; then | |
43 | if ip route | grep -q default; then | |
44 | boot_mesg "Gateway already setup; skipping." ${WARNING} | |
45 | echo_warning | |
46 | else | |
47 | boot_mesg "Setting up default gateway..." | |
48 | ip route add default via ${GATEWAY} dev ${1} | |
49 | evaluate_retval | |
50 | fi | |
51 | fi | |
52 | ;; | |
53 | ||
54 | down) | |
55 | if [ -n "${GATEWAY}" ]; then | |
56 | boot_mesg "Removing default gateway..." | |
57 | ip route del default | |
58 | evaluate_retval | |
59 | fi | |
60 | ||
61 | boot_mesg "Removing IPv4 address ${ADDRESS} from the ${1} interface..." | |
62 | ip addr del ${args} dev ${1} | |
63 | evaluate_retval | |
64 | ;; | |
65 | ||
66 | *) | |
67 | echo "Usage: ${0} [interface] {up|down}" | |
68 | exit 1 | |
69 | ;; | |
70 | esac | |
71 | ||
72 | # End $network_devices/services/ipv4-static |