Files
bpfire/src/initscripts/networking/any
Jonatan Schlag 8ae238a588 Use bash as shebang in network initscripts
/bin/sh is a symlink to /bin/bash on ipfire systems. Using /bin/sh in
the scripts as shebang hurts in two ways:

1. We use features which do not work with sh as shell. This is not
   really a problem but if we rely on features of a real bash we can
   state this clearly.
2. The syntay highlighting in vim does not work without a correct
   shebang. As I want and need correct syntax highlighting I propose to
   change the shebang.

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2023-09-05 15:15:53 +00:00

103 lines
3.5 KiB
Bash

#!/bin/bash
###############################################################################
# #
# IPFire.org - A linux based firewall #
# Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
###############################################################################
. /etc/sysconfig/rc
. ${rc_functions}
eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
if [ "$(basename $0)" == "green" ]; then
DEVICE="${GREEN_DEV}"
ADDRESS="${GREEN_ADDRESS}"
NETADDRESS="${GREEN_NETADDRESS}"
NETMASK="${GREEN_NETMASK}"
DEVICE="${GREEN_DEV}"
MTU="${GREEN_MTU}"
elif [ "$(basename $0)" == "blue" ]; then
DEVICE="${BLUE_DEV}"
ADDRESS="${BLUE_ADDRESS}"
NETADDRESS="${BLUE_NETADDRESS}"
NETMASK="${BLUE_NETMASK}"
DEVICE="${BLUE_DEV}"
MTU="${BLUE_MTU}"
elif [ "$(basename $0)" == "orange" ]; then
DEVICE="${ORANGE_DEV}"
ADDRESS="${ORANGE_ADDRESS}"
NETADDRESS="${ORANGE_NETADDRESS}"
NETMASK="${ORANGE_NETMASK}"
DEVICE="${ORANGE_DEV}"
MTU="${ORANGE_MTU}"
fi
if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then
PREFIX=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-`
args="${args} ${ADDRESS}/${PREFIX}"
else
boot_mesg "ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE}
echo_failure
exit 1
fi
case "${1}" in
start)
boot_mesg "Bringing up the ${DEVICE} interface..."
boot_mesg_flush
# Check if an interface is there...
if ip link show ${DEVICE} > /dev/null 2>&1; then
link_status=`ip link show ${DEVICE} 2> /dev/null`
if [ -n "${link_status}" ]; then
if ! echo "${link_status}" | grep -q UP; then
ip link set ${DEVICE} up
fi
fi
else
boot_mesg "Interface ${DEVICE} doesn't exist." ${FAILURE}
echo_failure
exit 1
fi
# Set the MTU
if [ -n "${MTU}" ]; then
if ! ip link set dev "${DEVICE}" mtu "${MTU}" &>/dev/null; then
boot_mesg "Could not set MTU of ${MTU} to ${DEVICE}..."
echo_warning
fi
fi
if [ ! "${ADDRESS}" == "1.1.1.1" ]; then
boot_mesg "Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..."
ip addr add ${args} dev ${DEVICE}
evaluate_retval
fi
;;
stop)
if [ ! "${ADDRESS}" == "1.1.1.1" ]; then
boot_mesg "Removing IPv4 addresses from the ${DEVICE} interface..."
ip addr flush dev ${DEVICE}
evaluate_retval
fi
exit 0;
;;
esac