#!/bin/sh 
#
#
clear

if test "$UID" != "0" -a "$USER" != root -a -z "$ROOT" ; then
	echo ""
	echo "   Only superuser is allowed to start this script! Please become root before."
	echo ""
	exit 1
fi

echo "##################################################################################"
echo ""
echo "  This file installs the firewall startup script in '/etc/init.d' and"
echo "  creates the links in the runlevel-dirs (rc3.d and rc5.d)."
echo ""
echo "  Afterwards you just have to adapt the name of your iptables-script"
echo "  in /etc/init.d/firewall"
echo "  (Tested on SuSE 8.1, should work on 8.0 too)"
echo ""
echo "  Andreas Hochsteger <e9625392@student.tuwien.ac.at>"
echo "  based on the script of Olaf.Zenker@t-systems.de"
echo "##################################################################################"

sleep 2	 

# Backup old /etc/firewall directory:
if [ -d /etc/firewall ]; then
	mv /etc/firewall /etc/firewall.bak
fi
# Create directory:
mkdir /etc/firewall

# Backup old /etc/sysconfig/firewall file:
if [ -d /etc/sysconfig/firewall ]; then
	mv /etc/sysconfig/firewall /etc/sysconfig/firewall.bak
fi
# Install new sysconfig file:
cp firewall.sysconfig /etc/sysconfig/firewall
chmod 644 /etc/sysconfig/firewall

if [ -f firewall ]; then
	# Backup old /etc/init.d/firewall service:
	if [ -f /etc/init.d/firewall ]; then
		mv -f /etc/init.d/firewall /etc/init.d/firewall.bak;
	fi
	# Install new firewall service:
	cp firewall /etc/init.d/
	chmod 744 /etc/init.d/firewall
else
	echo ""
	echo " Firewall startscript not found, please put in same directory like this install script!"
	echo ""
	exit 1
fi

# Install rcfirewall symlink:
ln -sf /etc/init.d/firewall /usr/sbin/rcfirewall

# Delete old runlevel symlinks:
rm -f /etc/init.d/rc?.d/???firewall
# Install firewall service
insserv firewall

echo "   Startup script has been successfully installed."

exit 0
