2010-05-17 00:35:22 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Script to install Shoreline Firewall Init
|
|
|
|
#
|
|
|
|
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
|
|
|
|
#
|
|
|
|
# (c) 2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010 - Tom Eastep (teastep@shorewall.net)
|
2010-05-23 23:10:50 +02:00
|
|
|
# (c) 2010 - Roberto C. Sanchez (roberto@connexer.com)
|
2010-05-17 00:35:22 +02:00
|
|
|
#
|
|
|
|
# Shorewall documentation is available at http://shorewall.net
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of Version 2 of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# 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, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
|
2010-07-25 17:11:49 +02:00
|
|
|
VERSION=4.4.12-Beta2
|
2010-05-17 00:35:22 +02:00
|
|
|
|
|
|
|
usage() # $1 = exit status
|
|
|
|
{
|
|
|
|
ME=$(basename $0)
|
|
|
|
echo "usage: $ME"
|
|
|
|
echo " $ME -v"
|
|
|
|
echo " $ME -h"
|
|
|
|
exit $1
|
|
|
|
}
|
|
|
|
|
|
|
|
split() {
|
|
|
|
local ifs
|
|
|
|
ifs=$IFS
|
|
|
|
IFS=:
|
|
|
|
set -- $1
|
|
|
|
echo $*
|
|
|
|
IFS=$ifs
|
|
|
|
}
|
|
|
|
|
|
|
|
qt()
|
|
|
|
{
|
|
|
|
"$@" >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
|
|
|
mywhich() {
|
|
|
|
local dir
|
|
|
|
|
|
|
|
for dir in $(split $PATH); do
|
|
|
|
if [ -x $dir/$1 ]; then
|
|
|
|
echo $dir/$1
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
|
|
|
|
run_install()
|
|
|
|
{
|
2010-05-24 00:34:42 +02:00
|
|
|
if ! install $*; then
|
2010-05-17 00:35:22 +02:00
|
|
|
echo
|
|
|
|
echo "ERROR: Failed to install $*" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
cant_autostart()
|
|
|
|
{
|
|
|
|
echo
|
|
|
|
echo "WARNING: Unable to configure shorewall init to start automatically at boot" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
delete_file() # $1 = file to delete
|
|
|
|
{
|
|
|
|
rm -f $1
|
|
|
|
}
|
|
|
|
|
|
|
|
install_file() # $1 = source $2 = target $3 = mode
|
|
|
|
{
|
2010-05-29 19:50:39 +02:00
|
|
|
run_install $T $OWNERSHIP -m $3 $1 ${2}
|
2010-05-17 00:35:22 +02:00
|
|
|
}
|
|
|
|
|
2010-06-01 15:42:11 +02:00
|
|
|
[ -n "$DESTDIR" ] || DESTDIR="$PREFIX"
|
|
|
|
|
2010-05-17 00:35:22 +02:00
|
|
|
#
|
|
|
|
# Parse the run line
|
|
|
|
#
|
|
|
|
# DEST is the SysVInit script directory
|
|
|
|
# INIT is the name of the script in the $DEST directory
|
|
|
|
# ARGS is "yes" if we've already parsed an argument
|
|
|
|
#
|
|
|
|
ARGS=""
|
|
|
|
|
|
|
|
if [ -z "$DEST" ] ; then
|
|
|
|
DEST="/etc/init.d"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$INIT" ] ; then
|
|
|
|
INIT="shorewall-init"
|
|
|
|
fi
|
|
|
|
|
|
|
|
while [ $# -gt 0 ] ; do
|
|
|
|
case "$1" in
|
|
|
|
-h|help|?)
|
|
|
|
usage 0
|
|
|
|
;;
|
|
|
|
-v)
|
|
|
|
echo "Shorewall Init Installer Version $VERSION"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
ARGS="yes"
|
|
|
|
done
|
|
|
|
|
|
|
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
|
|
|
|
|
|
|
|
#
|
|
|
|
# Determine where to install the firewall script
|
|
|
|
#
|
|
|
|
|
|
|
|
case $(uname) in
|
2010-05-29 19:50:39 +02:00
|
|
|
Darwin)
|
|
|
|
[ -z "$OWNER" ] && OWNER=root
|
|
|
|
[ -z "$GROUP" ] && GROUP=wheel
|
|
|
|
T=
|
|
|
|
;;
|
2010-05-17 00:35:22 +02:00
|
|
|
*)
|
|
|
|
[ -z "$OWNER" ] && OWNER=root
|
|
|
|
[ -z "$GROUP" ] && GROUP=root
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
OWNERSHIP="-o $OWNER -g $GROUP"
|
|
|
|
|
2010-06-01 15:42:11 +02:00
|
|
|
if [ -n "$DESTDIR" ]; then
|
2010-05-17 00:35:22 +02:00
|
|
|
if [ `id -u` != 0 ] ; then
|
|
|
|
echo "Not setting file owner/group permissions, not running as root."
|
|
|
|
OWNERSHIP=""
|
|
|
|
fi
|
|
|
|
|
2010-06-01 15:42:11 +02:00
|
|
|
install -d $OWNERSHIP -m 755 ${DESTDIR}${DEST}
|
2010-05-23 23:26:29 +02:00
|
|
|
elif [ -f /etc/debian_version ]; then
|
2010-05-17 00:35:22 +02:00
|
|
|
DEBIAN=yes
|
2010-05-18 01:47:51 +02:00
|
|
|
elif [ -f /etc/SuSE-release ]; then
|
|
|
|
SUSE=Yes
|
2010-05-17 00:35:22 +02:00
|
|
|
elif [ -f /etc/slackware-version ] ; then
|
2010-05-19 00:30:53 +02:00
|
|
|
echo "Shorewall-init is currently not supported on Slackware" >&2
|
|
|
|
exit 1
|
|
|
|
# DEST="/etc/rc.d"
|
|
|
|
# INIT="rc.firewall"
|
2010-05-17 00:35:22 +02:00
|
|
|
elif [ -f /etc/arch-release ] ; then
|
2010-05-19 00:30:53 +02:00
|
|
|
echo "Shorewall-init is currently not supported on Arch Linux" >&2
|
|
|
|
exit 1
|
|
|
|
# DEST="/etc/rc.d"
|
|
|
|
# INIT="shorewall-init"
|
|
|
|
# ARCHLINUX=yes
|
|
|
|
elif [ -d /etc/sysconfig/network-scripts/ ]; then
|
2010-05-18 19:27:12 +02:00
|
|
|
#
|
2010-05-19 00:30:53 +02:00
|
|
|
# Assume RedHat-based
|
2010-05-18 19:27:12 +02:00
|
|
|
#
|
|
|
|
REDHAT=Yes
|
2010-05-19 00:30:53 +02:00
|
|
|
else
|
|
|
|
echo "Unknown distribution: Shorewall-init support is not available" >&2
|
|
|
|
exit 1
|
2010-05-17 00:35:22 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# Change to the directory containing this script
|
|
|
|
#
|
|
|
|
cd "$(dirname $0)"
|
|
|
|
|
|
|
|
echo "Installing Shorewall Init Version $VERSION"
|
|
|
|
|
|
|
|
#
|
|
|
|
# Check for /usr/share/shorewall-init/version
|
|
|
|
#
|
2010-06-01 15:42:11 +02:00
|
|
|
if [ -f ${DESTDIR}/usr/share/shorewall-init/version ]; then
|
2010-05-17 00:35:22 +02:00
|
|
|
first_install=""
|
|
|
|
else
|
|
|
|
first_install="Yes"
|
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# Install the Init Script
|
|
|
|
#
|
|
|
|
if [ -n "$DEBIAN" ]; then
|
2010-06-01 15:42:11 +02:00
|
|
|
install_file init.debian.sh ${DESTDIR}/etc/init.d/shorewall-init 0544
|
2010-05-19 00:30:53 +02:00
|
|
|
#elif [ -n "$ARCHLINUX" ]; then
|
2010-06-01 15:42:11 +02:00
|
|
|
# install_file init.archlinux.sh ${DESTDIR}${DEST}/$INIT 0544
|
2010-05-17 00:35:22 +02:00
|
|
|
else
|
2010-06-01 15:42:11 +02:00
|
|
|
install_file init.sh ${DESTDIR}${DEST}/$INIT 0544
|
2010-05-17 00:35:22 +02:00
|
|
|
fi
|
|
|
|
|
2010-06-01 15:42:11 +02:00
|
|
|
echo "Shorewall Init script installed in ${DESTDIR}${DEST}/$INIT"
|
2010-05-17 00:35:22 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# Create /usr/share/shorewall-init if needed
|
|
|
|
#
|
2010-06-01 15:42:11 +02:00
|
|
|
mkdir -p ${DESTDIR}/usr/share/shorewall-init
|
|
|
|
chmod 755 ${DESTDIR}/usr/share/shorewall-init
|
2010-05-17 00:35:22 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# Create the version file
|
|
|
|
#
|
2010-06-01 15:42:11 +02:00
|
|
|
echo "$VERSION" > ${DESTDIR}/usr/share/shorewall-init/version
|
|
|
|
chmod 644 ${DESTDIR}/usr/share/shorewall-init/version
|
2010-05-17 00:35:22 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# Remove and create the symbolic link to the init script
|
|
|
|
#
|
2010-06-01 15:42:11 +02:00
|
|
|
if [ -z "$DESTDIR" ]; then
|
2010-05-17 00:35:22 +02:00
|
|
|
rm -f /usr/share/shorewall-init/init
|
|
|
|
ln -s ${DEST}/${INIT} /usr/share/shorewall-init/init
|
|
|
|
fi
|
|
|
|
|
2010-05-19 00:30:53 +02:00
|
|
|
if [ -n "$DEBIAN" ]; then
|
2010-06-01 15:42:11 +02:00
|
|
|
if [ -n "${DESTDIR}" ]; then
|
|
|
|
mkdir -p ${DESTDIR}/etc/network/if-up.d/
|
|
|
|
mkdir -p ${DESTDIR}/etc/network/if-post-down.d/
|
2010-05-24 00:34:42 +02:00
|
|
|
fi
|
|
|
|
|
2010-06-01 15:42:11 +02:00
|
|
|
if [ ! -f ${DESTDIR}/etc/default/shorewall-init ]; then
|
|
|
|
if [ -n "${DESTDIR}" ]; then
|
|
|
|
mkdir ${DESTDIR}/etc/default
|
2010-05-24 00:34:42 +02:00
|
|
|
fi
|
|
|
|
|
2010-06-01 15:42:11 +02:00
|
|
|
install_file sysconfig ${DESTDIR}/etc/default/shorewall-init 0644
|
2010-05-19 00:30:53 +02:00
|
|
|
fi
|
|
|
|
else
|
2010-06-01 15:42:11 +02:00
|
|
|
if [ -n "$DESTDIR" ]; then
|
|
|
|
mkdir -p ${DESTDIR}/etc/sysconfig
|
2010-05-24 00:34:42 +02:00
|
|
|
|
2010-05-27 15:49:49 +02:00
|
|
|
if [ -z "$RPM" ]; then
|
|
|
|
if [ -n "$SUSE" ]; then
|
2010-06-01 15:42:11 +02:00
|
|
|
mkdir -p ${DESTDIR}/etc/sysconfig/network/if-up.d
|
|
|
|
mkdir -p ${DESTDIR}/etc/sysconfig/network/if-down.d
|
2010-05-27 15:49:49 +02:00
|
|
|
else
|
2010-06-01 15:42:11 +02:00
|
|
|
mkdir -p ${DESTDIR}/etc/NetworkManager/dispatcher.d
|
2010-05-27 15:49:49 +02:00
|
|
|
fi
|
2010-05-24 00:34:42 +02:00
|
|
|
fi
|
2010-05-17 00:35:22 +02:00
|
|
|
fi
|
|
|
|
|
2010-06-01 15:42:11 +02:00
|
|
|
if [ -d ${DESTDIR}/etc/sysconfig -a ! -f ${DESTDIR}/etc/sysconfig/shorewall-init ]; then
|
|
|
|
install_file sysconfig ${DESTDIR}/etc/sysconfig/shorewall-init 0644
|
2010-05-17 00:35:22 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2010-05-23 21:53:56 +02:00
|
|
|
#
|
|
|
|
# Install the ifupdown script
|
|
|
|
#
|
2010-05-24 00:34:42 +02:00
|
|
|
|
2010-06-01 15:42:11 +02:00
|
|
|
mkdir -p ${DESTDIR}/usr/share/shorewall-init
|
2010-05-27 01:45:09 +02:00
|
|
|
|
2010-06-01 15:42:11 +02:00
|
|
|
install_file ifupdown.sh ${DESTDIR}/usr/share/shorewall-init/ifupdown 0544
|
2010-05-23 21:53:56 +02:00
|
|
|
|
2010-06-01 15:42:11 +02:00
|
|
|
if [ -d ${DESTDIR}/etc/NetworkManager ]; then
|
|
|
|
install_file ifupdown.sh ${DESTDIR}/etc/NetworkManager/dispatcher.d/01-shorewall 0544
|
2010-05-23 21:53:56 +02:00
|
|
|
fi
|
|
|
|
|
2010-05-23 23:44:35 +02:00
|
|
|
if [ -n "$DEBIAN" ]; then
|
2010-06-01 15:42:11 +02:00
|
|
|
install_file ifupdown.sh ${DESTDIR}/etc/network/if-up.d/shorewall 0544
|
|
|
|
install_file ifupdown.sh ${DESTDIR}/etc/network/if-post-down.d/shorewall 0544
|
2010-05-23 23:44:35 +02:00
|
|
|
elif [ -n "$SUSE" ]; then
|
2010-06-01 15:42:11 +02:00
|
|
|
install_file ifupdown.sh ${DESTDIR}/etc/sysconfig/network/if-up.d/shorewall 0544
|
|
|
|
install_file ifupdown.sh ${DESTDIR}/etc/sysconfig/network/if-down.d/shorewall 0544
|
2010-05-23 23:44:35 +02:00
|
|
|
elif [ -n "$REDHAT" ]; then
|
2010-06-01 15:42:11 +02:00
|
|
|
if [ -f ${DESTDIR}/sbin/ifup-local -o -f ${DESTDIR}/sbin/ifdown-local ]; then
|
2010-05-23 23:44:35 +02:00
|
|
|
echo "WARNING: /sbin/ifup-local and/or /sbin/ifdown-local already exist; up/down events will not be handled"
|
|
|
|
else
|
2010-06-01 15:42:11 +02:00
|
|
|
install_file ifupdown.sh ${DESTDIR}/sbin/ifup-local 0544
|
|
|
|
install_file ifupdown.sh ${DESTDIR}/sbin/ifdown-local 0544
|
2010-05-23 23:44:35 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2010-06-01 15:42:11 +02:00
|
|
|
if [ -z "$DESTDIR" ]; then
|
2010-05-17 00:35:22 +02:00
|
|
|
if [ -n "$first_install" ]; then
|
|
|
|
if [ -n "$DEBIAN" ]; then
|
2010-06-25 20:14:55 +02:00
|
|
|
if [ -x /sbin/insserv ]; then
|
|
|
|
insserv /etc/init.d/shorewall-init
|
|
|
|
else
|
|
|
|
ln -sf ../init.d/shorewall-init /etc/rcS.d/S38shorewall-init
|
|
|
|
fi
|
|
|
|
|
2010-05-17 00:35:22 +02:00
|
|
|
echo "Shorewall Init will start automatically at boot"
|
|
|
|
else
|
|
|
|
if [ -x /sbin/insserv -o -x /usr/sbin/insserv ]; then
|
|
|
|
if insserv /etc/init.d/shorewall-init ; then
|
|
|
|
echo "Shorewall Init will start automatically at boot"
|
|
|
|
else
|
|
|
|
cant_autostart
|
|
|
|
fi
|
|
|
|
elif [ -x /sbin/chkconfig -o -x /usr/sbin/chkconfig ]; then
|
|
|
|
if chkconfig --add shorewall-init ; then
|
|
|
|
echo "Shorewall Init will start automatically in run levels as follows:"
|
|
|
|
chkconfig --list shorewall-init
|
|
|
|
else
|
|
|
|
cant_autostart
|
|
|
|
fi
|
|
|
|
elif [ -x /sbin/rc-update ]; then
|
|
|
|
if rc-update add shorewall-init default; then
|
|
|
|
echo "Shorewall Init will start automatically at boot"
|
|
|
|
else
|
|
|
|
cant_autostart
|
|
|
|
fi
|
|
|
|
elif [ "$INIT" != rc.firewall ]; then #Slackware starts this automatically
|
|
|
|
cant_autostart
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
2010-05-23 23:10:50 +02:00
|
|
|
else
|
|
|
|
if [ -n "$first_install" ]; then
|
|
|
|
if [ -n "$DEBIAN" ]; then
|
2010-06-01 15:42:11 +02:00
|
|
|
if [ -n "${DESTDIR}" ]; then
|
|
|
|
mkdir -p ${DESTDIR}/etc/rcS.d
|
2010-05-24 00:34:42 +02:00
|
|
|
fi
|
|
|
|
|
2010-06-25 20:14:55 +02:00
|
|
|
ln -sf ../init.d/shorewall-init ${DESTDIR}/etc/rcS.d/S38shorewall-init
|
2010-05-23 23:10:50 +02:00
|
|
|
echo "Shorewall Init will start automatically at boot"
|
|
|
|
fi
|
|
|
|
fi
|
2010-05-17 00:35:22 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# Report Success
|
|
|
|
#
|
|
|
|
echo "shorewall Init Version $VERSION Installed"
|