]>
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}" | |
64ff033d | 29 | elif [ "$(basename $0)" == "blue" ]; then |
d1e90efc MT |
30 | DEVICE="${BLUE_DEV}" |
31 | ADDRESS="${BLUE_ADDRESS}" | |
32 | BROADCAST="${BLUE_BROADCAST}" | |
33 | NETADDRESS="${BLUE_NETADDRESS}" | |
34 | NETMASK="${BLUE_NETMASK}" | |
35 | DEVICE="${BLUE_DEV}" | |
64ff033d | 36 | elif [ "$(basename $0)" == "orange" ]; then |
d1e90efc MT |
37 | DEVICE="${ORANGE_DEV}" |
38 | ADDRESS="${ORANGE_ADDRESS}" | |
39 | BROADCAST="${ORANGE_BROADCAST}" | |
40 | NETADDRESS="${ORANGE_NETADDRESS}" | |
41 | NETMASK="${ORANGE_NETMASK}" | |
42 | DEVICE="${ORANGE_DEV}" | |
43 | fi | |
44 | ||
45 | if [ -z "${BROADCAST}" ]; then | |
46 | boot_mesg "BROADCAST variable missing from input, cannot continue." ${FAILURE} | |
47 | echo_failure | |
48 | exit 1 | |
49 | fi | |
50 | ||
51 | if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then | |
52 | PREFIX=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-` | |
53 | args="${args} ${ADDRESS}/${PREFIX} broadcast ${BROADCAST}" | |
54 | else | |
55 | boot_mesg "ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE} | |
56 | echo_failure | |
57 | exit 1 | |
58 | fi | |
59 | ||
64ff033d | 60 | case "${1}" in |
d1e90efc MT |
61 | |
62 | start) | |
63 | boot_mesg "Bringing up the ${DEVICE} interface..." | |
64 | boot_mesg_flush | |
65 | ||
66 | # Check if an interface is there... | |
67 | if ip link show ${DEVICE} > /dev/null 2>&1; then | |
68 | link_status=`ip link show ${DEVICE} 2> /dev/null` | |
69 | if [ -n "${link_status}" ]; then | |
70 | if ! echo "${link_status}" | grep -q UP; then | |
71 | ip link set ${DEVICE} up | |
72 | fi | |
73 | fi | |
74 | else | |
75 | boot_mesg "Interface ${DEVICE} doesn't exist." ${FAILURE} | |
76 | echo_failure | |
77 | exit 1 | |
78 | fi | |
79 | ||
80 | boot_mesg "Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..." | |
81 | ip addr add ${args} dev ${DEVICE} | |
82 | evaluate_retval | |
83 | ;; | |
84 | ||
85 | stop) | |
f6504eb3 | 86 | boot_mesg "Removing IPv4 address ${ADDRESS} from the ${2} interface..." |
d1e90efc MT |
87 | ip addr del ${args} dev ${DEVICE} |
88 | evaluate_retval | |
89 | ;; | |
90 | ||
91 | esac | |
92 | ||
93 | # End |