]>
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 | |
58b1108f | 10 | # Maniacikarus - Maniacikarus@ipfire.org |
9c16cd92 MT |
11 | # |
12 | # Version : 00.00 | |
13 | # | |
14 | # Notes : | |
15 | # | |
16 | ######################################################################## | |
17 | ||
18 | . /etc/sysconfig/rc | |
19 | . ${rc_functions} | |
20 | eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) | |
21 | ||
22 | if [ -z "${BROADCAST}" ]; then | |
23 | boot_mesg "BROADCAST variable missing from input, cannot continue." ${FAILURE} | |
24 | echo_failure | |
25 | exit 1 | |
26 | fi | |
27 | ||
28 | if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then | |
29 | PREFIX=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-` | |
30 | args="${args} ${ADDRESS}/${PREFIX} broadcast ${BROADCAST}" | |
31 | else | |
32 | boot_mesg "ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE} | |
33 | echo_failure | |
34 | exit 1 | |
35 | fi | |
36 | ||
37 | case "${2}" in | |
38 | up) | |
39 | boot_mesg "Adding IPv4 address ${ADDRESS} to the ${1} interface..." | |
40 | ip addr add ${args} dev ${1} | |
41 | evaluate_retval | |
42 | ||
43 | if [ -n "${GATEWAY}" ]; then | |
44 | if ip route | grep -q default; then | |
45 | boot_mesg "Gateway already setup; skipping." ${WARNING} | |
46 | echo_warning | |
58b1108f CS |
47 | elif [ "${CONFIG_TYPE}" == "0" ] || [ "${CONFIG_TYPE}" == "" ] && [ "${GATEWAY}" != "" ]; then |
48 | boot_mesg "Setting up default gateway for green only..." | |
49 | ip route add default via ${GATEWAY} dev ${1} | |
50 | evaluate_retval | |
51 | if [ "${DNS1}" != "" ];then | |
52 | boot_mesg "Registering DNS Server for green only..." | |
53 | echo "nameserver $DNS1" > /etc/resolv.conf | |
54 | fi | |
55 | if [ "${DNS2}" != "" ];then | |
56 | echo "nameserver $DNS2" >> /etc/resolv.conf | |
57 | fi | |
9c16cd92 MT |
58 | else |
59 | boot_mesg "Setting up default gateway..." | |
f3770039 | 60 | echo $DEFAULT_GATEWAY > /var/ipfire/red/remote-ipaddress |
9c16cd92 MT |
61 | ip route add default via ${GATEWAY} dev ${1} |
62 | evaluate_retval | |
f3770039 MT |
63 | boot_mesg "Registering DNS server..." |
64 | echo $DNS1 > /var/ipfire/red/dns1 | |
65 | echo $DNS2 > /var/ipfire/red/dns2 | |
e2627c00 | 66 | echo "nameserver 127.0.0.1" > /etc/resolv.conf |
f3770039 MT |
67 | echo $ADDRESS > /var/ipfire/red/local-ipaddress |
68 | evaluate_retval | |
69 | fi | |
9c16cd92 MT |
70 | fi |
71 | ;; | |
72 | ||
73 | down) | |
74 | if [ -n "${GATEWAY}" ]; then | |
75 | boot_mesg "Removing default gateway..." | |
76 | ip route del default | |
77 | evaluate_retval | |
78 | fi | |
79 | ||
80 | boot_mesg "Removing IPv4 address ${ADDRESS} from the ${1} interface..." | |
81 | ip addr del ${args} dev ${1} | |
82 | evaluate_retval | |
83 | ;; | |
84 | ||
85 | *) | |
86 | echo "Usage: ${0} [interface] {up|down}" | |
87 | exit 1 | |
88 | ;; | |
89 | esac | |
90 | ||
91 | # End $network_devices/services/ipv4-static |