2013-11-07 04:25:34 +00:00
|
|
|
#!/bin/bash
|
2014-09-04 04:56:29 +00:00
|
|
|
|
|
|
|
if [ ${DIB_DEBUG_TRACE:-1} -gt 0 ]; then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
set -eu
|
2014-03-29 03:28:22 +00:00
|
|
|
set -o pipefail
|
2013-03-05 17:34:19 +00:00
|
|
|
|
|
|
|
SCRIPTDIR=$(dirname $0)
|
|
|
|
|
2019-11-28 12:20:16 +00:00
|
|
|
if [ -e "/etc/redhat-release" ]; then
|
2020-08-11 14:57:40 +00:00
|
|
|
# NOTE(TheJulia): While the internal client which every networkmanager user
|
|
|
|
# should have is internal, dhclient has better behavior which includes
|
|
|
|
# shutting down the port between retries which is critical for recovery
|
|
|
|
# from LACP port blocking situations. As such, we'll force it to dhclient.
|
|
|
|
# For more information, see https://storyboard.openstack.org/#!/story/2008001
|
|
|
|
DIB_DHCP_CLIENT=${DIB_DHCP_CLIENT:-dhclient}
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Sets appropriate NetworkManager configuration, if the folder is present.
|
|
|
|
if [ -x "/etc/NetworkManager" ]; then
|
|
|
|
install -D -g root -o root -m 0644 ${SCRIPTDIR}/NetworkManager-conf.d-00-main.conf /etc/NetworkManager/conf.d/00-main.conf
|
|
|
|
sed -i "s/DIB_DHCP_CLIENT/${DIB_DHCP_CLIENT:-internal}/g" /etc/NetworkManager/conf.d/00-main.conf
|
|
|
|
sed -i "s/DIB_DHCP_TIMEOUT/${DIB_DHCP_TIMEOUT:-30}/g" /etc/NetworkManager/conf.d/00-main.conf
|
2022-01-23 22:09:11 +00:00
|
|
|
if [ "${DIB_DHCP_NETWORK_MANAGER_AUTO:-false}" == true ]; then
|
|
|
|
# Use NetworkManager for auto configuration, it will behave just as
|
|
|
|
# good as dhcp-all-interfaces.sh in most cases.
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -e "/etc/redhat-release" ]; then
|
|
|
|
# TODO(hjensas): Once ndisc6 package is available in EPEL8 drop this,
|
|
|
|
# and add the package back in pkg-map.
|
|
|
|
# See: https://bugzilla.redhat.com/show_bug.cgi?id=1779134
|
|
|
|
if type dnf &>/dev/null; then
|
|
|
|
dnf -v -y install ndisc6 || true
|
|
|
|
else
|
|
|
|
yum -v -y install ndisc6 || true
|
|
|
|
fi
|
2019-11-28 12:20:16 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2016-03-31 00:48:19 +00:00
|
|
|
# this script is not needed on Gentoo.
|
|
|
|
if [ "$DISTRO_NAME" != "gentoo" ]; then
|
|
|
|
install -D -g root -o root -m 0755 ${SCRIPTDIR}/dhcp-all-interfaces.sh /usr/local/sbin/dhcp-all-interfaces.sh
|
2017-12-24 12:57:56 +00:00
|
|
|
sed -i "s/DIB_DHCP_TIMEOUT/${DIB_DHCP_TIMEOUT:-30}/" /usr/local/sbin/dhcp-all-interfaces.sh
|
2016-03-31 00:48:19 +00:00
|
|
|
fi
|
2014-01-09 20:32:52 +00:00
|
|
|
|
2018-04-05 13:12:09 +00:00
|
|
|
if [ -f /etc/dhcp/dhclient.conf ] ; then
|
|
|
|
# Set the dhclient timeout configurations to match DIB_DHCP_TIMEOUT,
|
|
|
|
if grep -o "^timeout " /etc/dhcp/dhclient.conf ; then
|
2018-07-06 04:30:28 +00:00
|
|
|
sed -i -e "s/^timeout .*/# \"timeout\" Value set by dhcp-all-interfaces\ntimeout ${DIB_DHCP_TIMEOUT:-30};/" /etc/dhcp/dhclient.conf
|
2018-04-05 13:12:09 +00:00
|
|
|
else
|
2018-07-06 04:30:28 +00:00
|
|
|
echo -e "# \"timeout\" Value set by dhcp-all-interfaces\ntimeout ${DIB_DHCP_TIMEOUT:-30};" >> /etc/dhcp/dhclient.conf
|
2018-04-05 13:12:09 +00:00
|
|
|
fi
|
2019-10-30 11:27:30 +00:00
|
|
|
if grep -o "^retry " /etc/dhcp/dhclient.conf ; then
|
|
|
|
sed -i -e '/^retry/s/^/# \"retry\" Value commented by dhcp-all-interfaces\n# /g' /etc/dhcp/dhclient.conf
|
|
|
|
fi
|
2018-04-05 13:12:09 +00:00
|
|
|
fi
|
|
|
|
|
2014-01-09 20:32:52 +00:00
|
|
|
if [ "$DIB_INIT_SYSTEM" == "upstart" ]; then
|
2016-11-02 11:01:15 +00:00
|
|
|
if [ -e "/etc/redhat-release" ] ; then
|
2017-05-31 04:16:17 +00:00
|
|
|
# the init system is upstart but networking is using sysv compatibility (i.e. Centos/RHEL 6)
|
2016-11-02 11:01:15 +00:00
|
|
|
install -D -g root -o root -m 0755 ${SCRIPTDIR}/dhcp-all-interfaces.init /etc/init.d/dhcp-all-interfaces
|
|
|
|
chkconfig dhcp-all-interfaces on
|
|
|
|
else
|
|
|
|
install -D -g root -o root -m 0755 ${SCRIPTDIR}/dhcp-all-interfaces.conf /etc/init/dhcp-all-interfaces.conf
|
|
|
|
fi
|
2014-01-09 20:32:52 +00:00
|
|
|
elif [ "$DIB_INIT_SYSTEM" == "systemd" ]; then
|
2016-12-12 16:55:03 +00:00
|
|
|
install -D -g root -o root -m 0644 ${SCRIPTDIR}/dhcp-interface@.service /usr/lib/systemd/system/dhcp-interface@.service
|
2014-03-21 19:12:37 +00:00
|
|
|
install -D -g root -o root -m 0644 ${SCRIPTDIR}/dhcp-all-interfaces-udev.rules /etc/udev/rules.d/99-dhcp-all-interfaces.rules
|
2019-10-30 11:27:30 +00:00
|
|
|
sed -i "s/TimeoutStartSec=DIB_DHCP_TIMEOUT/TimeoutStartSec=$(( ${DIB_DHCP_TIMEOUT:-30} * 2 ))s/" /usr/lib/systemd/system/dhcp-interface@.service
|
2014-04-09 11:58:36 +00:00
|
|
|
elif [ "$DIB_INIT_SYSTEM" == "sysv" ]; then
|
|
|
|
install -D -g root -o root -m 0755 ${SCRIPTDIR}/dhcp-all-interfaces.init /etc/init.d/dhcp-all-interfaces
|
|
|
|
update-rc.d dhcp-all-interfaces defaults
|
2016-03-31 00:48:19 +00:00
|
|
|
elif [ "$DISTRO_NAME" == "gentoo" ]; then
|
|
|
|
# let ipv6 use normal slaac
|
|
|
|
sed -i 's/slaac/#slaac/g' /etc/dhcpcd.conf
|
|
|
|
# don't let dhcpcd set domain name or hostname
|
|
|
|
sed -i 's/domain_name\,\ domain_search\,\ host_name/domain_search/g' /etc/dhcpcd.conf
|
|
|
|
rc-update add dhcpcd default
|
2013-10-14 22:54:37 +00:00
|
|
|
fi
|