2006-06-03 17:16:21 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2006-06-05 21:19:35 +02:00
|
|
|
# Script to install Shoreline Firewall Lite
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
2007-09-08 18:09:51 +02:00
|
|
|
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
2007-01-12 23:54:42 +01:00
|
|
|
# (c) 2000,2001,2002,2003,2004,2005,2006,2007 - Tom Eastep (teastep@shorewall.net)
|
2006-06-03 17:16:21 +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
|
2007-09-08 18:09:51 +02:00
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
|
|
|
|
2009-03-17 19:51:17 +01:00
|
|
|
VERSION=4.3.8
|
2006-06-03 17:16:21 +02:00
|
|
|
|
|
|
|
usage() # $1 = exit status
|
|
|
|
{
|
|
|
|
ME=$(basename $0)
|
|
|
|
echo "usage: $ME"
|
|
|
|
echo " $ME -v"
|
|
|
|
echo " $ME -h"
|
2006-08-09 18:18:32 +02:00
|
|
|
echo " $ME -n"
|
2006-06-03 17:16:21 +02:00
|
|
|
exit $1
|
|
|
|
}
|
|
|
|
|
|
|
|
split() {
|
2008-03-14 03:07:28 +01:00
|
|
|
local ifs
|
|
|
|
ifs=$IFS
|
2006-06-03 17:16:21 +02:00
|
|
|
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()
|
|
|
|
{
|
|
|
|
if ! install $*; then
|
|
|
|
echo
|
|
|
|
echo "ERROR: Failed to install $*" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
cant_autostart()
|
|
|
|
{
|
|
|
|
echo
|
|
|
|
echo "WARNING: Unable to configure shorewall to start automatically at boot" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
delete_file() # $1 = file to delete
|
|
|
|
{
|
|
|
|
rm -f $1
|
|
|
|
}
|
|
|
|
|
|
|
|
install_file() # $1 = source $2 = target $3 = mode
|
|
|
|
{
|
|
|
|
run_install $OWNERSHIP -m $3 $1 ${2}
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Parse the run line
|
|
|
|
#
|
|
|
|
# DEST is the SysVInit script directory
|
|
|
|
# INIT is the name of the script in the $DEST directory
|
|
|
|
# RUNLEVELS is the chkconfig parmeters for firewall
|
|
|
|
# ARGS is "yes" if we've already parsed an argument
|
|
|
|
#
|
|
|
|
ARGS=""
|
|
|
|
|
|
|
|
if [ -z "$DEST" ] ; then
|
|
|
|
DEST="/etc/init.d"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$INIT" ] ; then
|
2006-06-09 19:10:41 +02:00
|
|
|
INIT="shorewall-lite"
|
2006-06-03 17:16:21 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$RUNLEVELS" ] ; then
|
|
|
|
RUNLEVELS=""
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$OWNER" ] ; then
|
|
|
|
OWNER=root
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$GROUP" ] ; then
|
|
|
|
GROUP=root
|
|
|
|
fi
|
|
|
|
|
|
|
|
while [ $# -gt 0 ] ; do
|
|
|
|
case "$1" in
|
|
|
|
-h|help|?)
|
|
|
|
usage 0
|
|
|
|
;;
|
|
|
|
-v)
|
2006-06-09 18:59:14 +02:00
|
|
|
echo "Shorewall Lite Firewall Installer Version $VERSION"
|
2006-06-03 17:16:21 +02:00
|
|
|
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
|
|
|
|
#
|
|
|
|
DEBIAN=
|
|
|
|
|
|
|
|
OWNERSHIP="-o $OWNER -g $GROUP"
|
|
|
|
|
2006-11-12 17:00:38 +01:00
|
|
|
if [ -n "$PREFIX" ]; then
|
|
|
|
if [ `id -u` != 0 ] ; then
|
|
|
|
echo "Not setting file owner/group permissions, not running as root."
|
|
|
|
OWNERSHIP=""
|
|
|
|
fi
|
|
|
|
|
|
|
|
install -d $OWNERSHIP -m 755 ${PREFIX}/sbin
|
|
|
|
install -d $OWNERSHIP -m 755 ${PREFIX}${DEST}
|
2006-12-24 01:53:12 +01:00
|
|
|
elif [ -d /etc/apt -a -e /usr/bin/dpkg ]; then
|
|
|
|
DEBIAN=yes
|
|
|
|
elif [ -f /etc/slackware-version ] ; then
|
|
|
|
DEST="/etc/rc.d"
|
|
|
|
INIT="rc.firewall"
|
|
|
|
elif [ -f /etc/arch-release ] ; then
|
|
|
|
DEST="/etc/rc.d"
|
|
|
|
INIT="shorewall-lite"
|
|
|
|
ARCHLINUX=yes
|
2006-11-12 17:00:38 +01:00
|
|
|
fi
|
|
|
|
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
|
|
|
# Change to the directory containing this script
|
|
|
|
#
|
|
|
|
cd "$(dirname $0)"
|
|
|
|
|
2006-06-03 17:57:33 +02:00
|
|
|
echo "Installing Shorewall Lite Version $VERSION"
|
2006-06-03 17:16:21 +02:00
|
|
|
|
|
|
|
#
|
2006-06-09 18:59:14 +02:00
|
|
|
# Check for /etc/shorewall-lite
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
2006-06-16 16:59:41 +02:00
|
|
|
if [ -z "$PREFIX" -a -d /etc/shorewall-lite ]; then
|
2006-06-03 17:16:21 +02:00
|
|
|
first_install=""
|
2007-01-04 00:26:13 +01:00
|
|
|
[ -f /etc/shorewall-lite/shorewall.conf ] && \
|
|
|
|
mv -f /etc/shorewall-lite/shorewall.conf /etc/shorewall-lite/shorewall-lite.conf
|
2006-06-03 17:16:21 +02:00
|
|
|
else
|
|
|
|
first_install="Yes"
|
2006-06-09 18:59:14 +02:00
|
|
|
rm -rf ${PREFIX}/etc/shorewall-lite
|
|
|
|
rm -rf ${PREFIX}/usr/share/shorewall-lite
|
|
|
|
rm -rf ${PREFIX}/var/lib/shorewall-lite
|
2006-06-03 17:16:21 +02:00
|
|
|
fi
|
|
|
|
|
2006-09-07 22:48:40 +02:00
|
|
|
delete_file ${PREFIX}/usr/share/shorewall-lite/xmodules
|
|
|
|
|
2009-02-22 22:06:51 +01:00
|
|
|
install_file shorewall-lite ${PREFIX}/sbin/shorewall-lite 0544 ${PREFIX}/var/lib/shorewall-lite-${VERSION}.bkout
|
2006-06-12 19:48:20 +02:00
|
|
|
|
|
|
|
echo "Shorewall Lite control program installed in ${PREFIX}/sbin/shorewall-lite"
|
|
|
|
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
|
|
|
# Install the Firewall Script
|
|
|
|
#
|
|
|
|
if [ -n "$DEBIAN" ]; then
|
2009-02-22 22:06:51 +01:00
|
|
|
install_file init.debian.sh /etc/init.d/shorewall-lite 0544 ${PREFIX}/usr/share/shorewall-lite-${VERSION}.bkout
|
2006-06-03 17:16:21 +02:00
|
|
|
elif [ -n "$ARCHLINUX" ]; then
|
2009-02-22 22:06:51 +01:00
|
|
|
install_file init.archlinux.sh ${PREFIX}${DEST}/$INIT 0544 ${PREFIX}/usr/share/shorewall-lite-${VERSION}.bkout
|
2006-06-03 17:16:21 +02:00
|
|
|
|
|
|
|
else
|
2009-02-22 22:06:51 +01:00
|
|
|
install_file init.sh ${PREFIX}${DEST}/$INIT 0544 ${PREFIX}/usr/share/shorewall-lite-${VERSION}.bkout
|
2006-06-03 17:16:21 +02:00
|
|
|
fi
|
|
|
|
|
2006-06-09 18:59:14 +02:00
|
|
|
echo "Shorewall Lite script installed in ${PREFIX}${DEST}/$INIT"
|
2006-06-03 17:16:21 +02:00
|
|
|
|
|
|
|
#
|
2006-06-09 18:59:14 +02:00
|
|
|
# Create /etc/shorewall-lite, /usr/share/shorewall-lite and /var/lib/shorewall-lite if needed
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
2006-06-09 18:59:14 +02:00
|
|
|
mkdir -p ${PREFIX}/etc/shorewall-lite
|
|
|
|
mkdir -p ${PREFIX}/usr/share/shorewall-lite
|
|
|
|
mkdir -p ${PREFIX}/var/lib/shorewall-lite
|
2006-06-03 17:16:21 +02:00
|
|
|
|
2006-06-09 18:59:14 +02:00
|
|
|
chmod 755 ${PREFIX}/etc/shorewall-lite
|
|
|
|
chmod 755 ${PREFIX}/usr/share/shorewall-lite
|
2006-06-03 17:16:21 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# Install the config file
|
|
|
|
#
|
2007-01-04 00:26:13 +01:00
|
|
|
if [ ! -f ${PREFIX}/etc/shorewall-lite/shorewall-lite.conf ]; then
|
|
|
|
run_install $OWNERSHIP -m 0744 shorewall-lite.conf ${PREFIX}/etc/shorewall-lite/shorewall-lite.conf
|
|
|
|
echo "Config file installed as ${PREFIX}/etc/shorewall-lite/shorewall-lite.conf"
|
2006-06-03 17:16:21 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$ARCHLINUX" ] ; then
|
2006-06-09 18:59:14 +02:00
|
|
|
sed -e 's!LOGFILE=/var/log/messages!LOGFILE=/var/log/messages.log!' -i ${PREFIX}/etc/shorewall-lite/shorewall.conf
|
2006-06-03 17:16:21 +02:00
|
|
|
fi
|
|
|
|
|
2006-06-05 19:13:48 +02:00
|
|
|
#
|
|
|
|
# Install the Makefile
|
|
|
|
#
|
2006-06-09 18:59:14 +02:00
|
|
|
run_install $OWNERSHIP -m 0600 Makefile ${PREFIX}/etc/shorewall-lite/Makefile
|
|
|
|
echo "Makefile installed as ${PREFIX}/etc/shorewall-lite/Makefile"
|
|
|
|
|
2006-06-03 19:04:45 +02:00
|
|
|
#
|
|
|
|
# Install the default config path file
|
|
|
|
#
|
2006-06-09 18:59:14 +02:00
|
|
|
install_file configpath ${PREFIX}/usr/share/shorewall-lite/configpath 0644
|
|
|
|
echo "Default config path file installed as ${PREFIX}/usr/share/shorewall-lite/configpath"
|
2006-06-03 19:04:45 +02:00
|
|
|
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
2006-10-29 18:29:30 +01:00
|
|
|
# Install the libraries
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
2006-10-29 18:29:30 +01:00
|
|
|
for f in lib.* ; do
|
|
|
|
if [ -f $f ]; then
|
2006-10-29 18:32:45 +01:00
|
|
|
install_file $f ${PREFIX}/usr/share/shorewall-lite/$f 0644
|
2006-10-29 18:30:55 +01:00
|
|
|
echo "Library ${f#*.} file installed as ${PREFIX}/usr/share/shorewall-lite/$f"
|
2006-10-29 18:29:30 +01:00
|
|
|
fi
|
|
|
|
done
|
2006-09-05 16:29:47 +02:00
|
|
|
|
2006-09-03 22:01:18 +02:00
|
|
|
ln -sf lib.base ${PREFIX}/usr/share/shorewall-lite/functions
|
2006-06-03 17:16:21 +02:00
|
|
|
|
2006-09-03 18:23:15 +02:00
|
|
|
echo "Common functions linked through ${PREFIX}/usr/share/shorewall-lite/functions"
|
2006-06-03 17:16:21 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# Install Shorecap
|
|
|
|
#
|
|
|
|
|
2007-07-02 16:50:57 +02:00
|
|
|
install_file shorecap ${PREFIX}/usr/share/shorewall-lite/shorecap 0755
|
2006-06-03 17:16:21 +02:00
|
|
|
|
|
|
|
echo
|
2006-06-09 18:59:14 +02:00
|
|
|
echo "Capability file builder installed in ${PREFIX}/usr/share/shorewall-lite/shorecap"
|
2006-06-03 17:16:21 +02:00
|
|
|
|
2007-01-01 01:40:42 +01:00
|
|
|
#
|
|
|
|
# Install wait4ifup
|
|
|
|
#
|
|
|
|
|
2007-07-02 16:50:57 +02:00
|
|
|
install_file wait4ifup ${PREFIX}/usr/share/shorewall-lite/wait4ifup 0755
|
2007-01-01 01:40:42 +01:00
|
|
|
|
|
|
|
echo
|
|
|
|
echo "wait4ifup installed in ${PREFIX}/usr/share/shorewall-lite/wait4ifup"
|
|
|
|
|
2006-06-05 23:04:19 +02:00
|
|
|
#
|
2006-09-07 22:48:40 +02:00
|
|
|
# Install the Modules file
|
2006-06-05 23:04:19 +02:00
|
|
|
#
|
2006-07-21 18:37:00 +02:00
|
|
|
run_install $OWNERSHIP -m 0600 modules ${PREFIX}/usr/share/shorewall-lite/modules
|
|
|
|
echo "Modules file installed as ${PREFIX}/usr/share/shorewall-lite/modules"
|
2006-06-05 23:04:19 +02:00
|
|
|
|
2006-11-19 05:13:06 +01:00
|
|
|
#
|
|
|
|
# Install the Man Pages
|
|
|
|
#
|
|
|
|
|
|
|
|
cd manpages
|
|
|
|
|
|
|
|
for f in *.5; do
|
2007-07-11 17:06:44 +02:00
|
|
|
gzip -c $f > $f.gz
|
2007-07-02 16:50:57 +02:00
|
|
|
run_install -D -m 644 $f.gz ${PREFIX}/usr/share/man/man5/$f.gz
|
2006-11-19 05:13:06 +01:00
|
|
|
echo "Man page $f.gz installed to /usr/share/man/man5/$f.gz"
|
|
|
|
done
|
|
|
|
|
|
|
|
for f in *.8; do
|
2007-07-21 00:37:21 +02:00
|
|
|
gzip -c $f > $f.gz
|
2007-07-02 16:50:57 +02:00
|
|
|
run_install -D -m 644 $f.gz ${PREFIX}/usr/share/man/man8/$f.gz
|
2006-11-19 05:13:06 +01:00
|
|
|
echo "Man page $f.gz installed to /usr/share/man/man8/$f.gz"
|
|
|
|
done
|
|
|
|
|
|
|
|
cd ..
|
|
|
|
|
|
|
|
echo "Man Pages Installed"
|
|
|
|
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
|
|
|
# Create the version file
|
|
|
|
#
|
2006-06-09 18:59:14 +02:00
|
|
|
echo "$VERSION" > ${PREFIX}/usr/share/shorewall-lite/version
|
|
|
|
chmod 644 ${PREFIX}/usr/share/shorewall-lite/version
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
|
|
|
# Remove and create the symbolic link to the init script
|
|
|
|
#
|
|
|
|
|
|
|
|
if [ -z "$PREFIX" ]; then
|
2006-06-09 18:59:14 +02:00
|
|
|
rm -f /usr/share/shorewall-lite/init
|
|
|
|
ln -s ${DEST}/${INIT} /usr/share/shorewall-lite/init
|
2006-06-03 17:16:21 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$PREFIX" -a -n "$first_install" ]; then
|
|
|
|
if [ -n "$DEBIAN" ]; then
|
2006-06-09 18:59:14 +02:00
|
|
|
run_install $OWNERSHIP -m 0644 default.debian /etc/default/shorewall-lite
|
|
|
|
ln -s ../init.d/shorewall-lite /etc/rcS.d/S40shorewall-lite
|
|
|
|
echo "Shorewall Lite will start automatically at boot"
|
2006-06-03 17:16:21 +02:00
|
|
|
touch /var/log/shorewall-init.log
|
|
|
|
else
|
|
|
|
if [ -x /sbin/insserv -o -x /usr/sbin/insserv ]; then
|
2006-06-09 18:59:14 +02:00
|
|
|
if insserv /etc/init.d/shorewall-lite ; then
|
|
|
|
echo "Shorewall Lite will start automatically at boot"
|
2006-06-03 17:16:21 +02:00
|
|
|
else
|
|
|
|
cant_autostart
|
|
|
|
fi
|
|
|
|
elif [ -x /sbin/chkconfig -o -x /usr/sbin/chkconfig ]; then
|
2006-06-09 18:59:14 +02:00
|
|
|
if chkconfig --add shorewall-lite ; then
|
|
|
|
echo "Shorewall Lite will start automatically in run levels as follows:"
|
|
|
|
chkconfig --list shorewall-lite
|
2006-06-03 17:16:21 +02:00
|
|
|
else
|
|
|
|
cant_autostart
|
|
|
|
fi
|
|
|
|
elif [ -x /sbin/rc-update ]; then
|
2006-06-09 18:59:14 +02:00
|
|
|
if rc-update add shorewall-lite default; then
|
|
|
|
echo "Shorewall Lite will start automatically at boot"
|
2006-06-03 17:16:21 +02:00
|
|
|
else
|
|
|
|
cant_autostart
|
|
|
|
fi
|
|
|
|
elif [ "$INIT" != rc.firewall ]; then #Slackware starts this automatically
|
|
|
|
cant_autostart
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# Report Success
|
|
|
|
#
|
2006-06-09 18:59:14 +02:00
|
|
|
echo "shorewall Lite Version $VERSION Installed"
|