#!/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 startupscript in '/etc/init.d' and"
	 echo "	creates the links in the runlevel-dirs (rc3.d and rc5.d)"
	 echo ""
	 echo "	After that you just have to adapt the name of your iptables-script"
	 echo "	in /etc/init.d/firewall"
	 echo " (Tested on SuSE 7.1 and 7.2)"
	 echo ""								     
	 echo "	Olaf.Zenker@t-systems.de"
	 echo "##################################################################################"
  
  sleep 2	 

     if	[ ! -d /etc/firewall ]; then
     		mkdir /etc/firewall
		
     	else
		mv /etc/firewall /etc/firewall.bak
		mkdir /etc/firewall
     fi
     
     if [ -f firewall ]; then
	
	if [ -f /etc/init.d/firewall ]; then
		mv -f /etc/init.d/firewall /etc/init.d/firewall.bak
        	cp firewall /etc/init.d/
		chmod 744 /etc/init.d/firewall
	 
	 else
      		cp firewall /etc/init.d/
		chmod 744 /etc/init.d/firewall
	fi
     
     else
       	
	 echo ""
       	 echo " Firewall startscript not found, please put in same directory like this install script!"
       	 echo ""    
       
       exit 1
     
     fi
       		rm -f /etc/init.d/rc3.d/S??firewall
		ln -s /etc/init.d/firewall /etc/init.d/rc3.d/S04firewall
	 	
		rm -f /etc/init.d/rc3.d/K??firewall
		ln -s /etc/init.d/firewall /etc/init.d/rc3.d/K20firewall
	 		
		rm -f /etc/init.d/rc5.d/S??firewall
		ln -s /etc/init.d/firewall /etc/init.d/rc5.d/S04firewall
	 		
	        rm -f /etc/init.d/rc5.d/K??firewall
		ln -s /etc/init.d/firewall /etc/init.d/rc5.d/K20firewall
	 
     	 echo "   Startup script has been successfully installed."
 
 exit
