project-config/nodepool/elements/nodepool-base/post-install.d/20-iptables

69 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.
# dib-lint: disable=setu setpipefail
if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then
set -x
fi
set -e
if [[ "$DISTRO_NAME" =~ (debian|ubuntu) ]] ; then
if [[ "$DIB_RELEASE" == 'trusty' ]] ; then
service_name=iptables-persistent
else
service_name=netfilter-persistent
fi
elif [[ "$DISTRO_NAME" =~ (centos|rhel7|fedora) ]] ; then
service_name=iptables
elif [[ "$DISTRO_NAME" == 'opensuse' ]] ; then
service_name=SuSEfirewall2
elif [[ "$DISTRO_NAME" == 'gentoo' ]] ; then
# for use in loops in both openrc and systemd
service_name='iptables ip6tables'
else
echo "Unsupported operating system $DISTRO_NAME"
exit 1
fi
case "$DIB_INIT_SYSTEM" in
upstart)
# nothing to do
;;
systemd)
if [[ "$DISTRO_NAME" == 'gentoo' ]] ; then
for service in ${service_name}; do
systemctl enable "${service}-restore.service"
systemctl enable "${service}-store.service"
done
else
systemctl enable ${service_name}.service
fi
if [[ "$DISTRO_NAME" =~ (centos|rhel7|fedora) ]] ; then
systemctl enable ip6tables.service
fi
;;
openrc)
for service in ${service_name}; do
rc-update add "${service}" default
done
;;
*)
echo "Unsupported init system $DIB_INIT_SYSTEM"
exit 1
;;
esac