]>
Commit | Line | Data |
---|---|---|
d1e90efc MT |
1 | #!/bin/sh |
2 | ######################################################################## | |
3 | # Begin | |
4 | # | |
5 | # Description : ANY Device Script | |
6 | # | |
7 | # Authors : Nathan Coulson - nathan@linuxfromscratch.org | |
8 | # Kevin P. Fleming - kpfleming@linuxfromscratch.org | |
9 | # Michael Tremer - mitch@ipfire.org | |
10 | # Maniacikarus - maniacikarus@ipfire.org | |
11 | # | |
12 | # Version : 01.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 | ||
64ff033d | 22 | if [ "$(basename $0)" == "green" ]; then |
d1e90efc MT |
23 | DEVICE="${GREEN_DEV}" |
24 | ADDRESS="${GREEN_ADDRESS}" | |
25 | BROADCAST="${GREEN_BROADCAST}" | |
26 | NETADDRESS="${GREEN_NETADDRESS}" | |
27 | NETMASK="${GREEN_NETMASK}" | |
28 | DEVICE="${GREEN_DEV}" | |
9bdf5e71 | 29 | MTU="${GREEN_MTU}" |
64ff033d | 30 | elif [ "$(basename $0)" == "blue" ]; then |
d1e90efc MT |
31 | DEVICE="${BLUE_DEV}" |
32 | ADDRESS="${BLUE_ADDRESS}" | |
33 | BROADCAST="${BLUE_BROADCAST}" | |
34 | NETADDRESS="${BLUE_NETADDRESS}" | |
35 | NETMASK="${BLUE_NETMASK}" | |
36 | DEVICE="${BLUE_DEV}" | |
e43c3206 | 37 | MTU="${BLUE_MTU}" |
64ff033d | 38 | elif [ "$(basename $0)" == "orange" ]; then |
d1e90efc MT |
39 | DEVICE="${ORANGE_DEV}" |
40 | ADDRESS="${ORANGE_ADDRESS}" | |
41 | BROADCAST="${ORANGE_BROADCAST}" | |
42 | NETADDRESS="${ORANGE_NETADDRESS}" | |
43 | NETMASK="${ORANGE_NETMASK}" | |
44 | DEVICE="${ORANGE_DEV}" | |
9bdf5e71 | 45 | MTU="${ORANGE_MTU}" |
d1e90efc MT |
46 | fi |
47 | ||
48 | if [ -z "${BROADCAST}" ]; then | |
49 | boot_mesg "BROADCAST variable missing from input, cannot continue." ${FAILURE} | |
50 | echo_failure | |
51 | exit 1 | |
52 | fi | |
53 | ||
54 | if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then | |
55 | PREFIX=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-` | |
56 | args="${args} ${ADDRESS}/${PREFIX} broadcast ${BROADCAST}" | |
57 | else | |
58 | boot_mesg "ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE} | |
59 | echo_failure | |
60 | exit 1 | |
61 | fi | |
62 | ||
64ff033d | 63 | case "${1}" in |
d1e90efc MT |
64 | |
65 | start) | |
66 | boot_mesg "Bringing up the ${DEVICE} interface..." | |
67 | boot_mesg_flush | |
68 | ||
69 | # Check if an interface is there... | |
70 | if ip link show ${DEVICE} > /dev/null 2>&1; then | |
71 | link_status=`ip link show ${DEVICE} 2> /dev/null` | |
72 | if [ -n "${link_status}" ]; then | |
73 | if ! echo "${link_status}" | grep -q UP; then | |
74 | ip link set ${DEVICE} up | |
75 | fi | |
76 | fi | |
77 | else | |
78 | boot_mesg "Interface ${DEVICE} doesn't exist." ${FAILURE} | |
79 | echo_failure | |
80 | exit 1 | |
81 | fi | |
6c33dc5c | 82 | |
9bdf5e71 MT |
83 | # Set the MTU |
84 | if [ -n "${MTU}" ]; then | |
85 | if ! ip link set dev "${DEVICE}" mtu "${MTU}" &>/dev/null; then | |
86 | boot_mesg "Could not set MTU of ${MTU} to ${DEVICE}..." | |
87 | echo_warning | |
88 | fi | |
89 | fi | |
90 | ||
1e4656cd AF |
91 | # Create & Enable vnstat data collection |
92 | /usr/bin/vnstat -u -i ${DEVICE} -r --enable --force > /dev/null 2>&1 | |
d1e90efc | 93 | |
fa4762fb AF |
94 | if [ ! "${ADDRESS}" == "1.1.1.1" ]; then |
95 | boot_mesg "Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..." | |
96 | ip addr add ${args} dev ${DEVICE} | |
97 | evaluate_retval | |
98 | fi | |
d1e90efc MT |
99 | ;; |
100 | ||
101 | stop) | |
fa4762fb AF |
102 | if [ ! "${ADDRESS}" == "1.1.1.1" ]; then |
103 | boot_mesg "Removing IPv4 addresses from the ${DEVICE} interface..." | |
104 | ip addr flush dev ${DEVICE} | |
105 | evaluate_retval | |
106 | fi | |
6c33dc5c | 107 | |
1e4656cd AF |
108 | # Disable vnstat collection |
109 | /usr/bin/vnstat -u -i ${DEVICE} -r --disable > /dev/null 2>&1 | |
6c33dc5c | 110 | exit 0; |
d1e90efc | 111 | ;; |
d1e90efc | 112 | esac |
d1e90efc | 113 | # End |