#!/bin/sh
#
# %coypright%
#
# Please report bugs to: %maintainer%
#
# %license%
#
# Installer script for KMyFirewall %version%
# This is an automatic generated file DO NOT EDIT
#

readSetting() {
# echo "Reading config..."
    source ./install.config
}

install() {
	ans="y"
	echo "Do you want to install this firewall configuration"
 	echo "to be started wenehver you boot this computer? [Y/n]"
	read newans

	if [ "$newans" == "n" ]; then
		ans=$newans
	fi

	if [ "$ans" == "y" ]; then
		/bin/sh data/kmfinstall.sh install ${SYSTEMTYPE} ${INITPATH} ${RCDEFAULTPATH} ${INITSCRIPT} data/kmyfirewall.sh
	else
		echo "Installation aborted!"
		exit 1
	fi
}

uninstall() {
	ans="y"
	echo "Do you relly want to uninstall the KMyFirewall configuration"
	echo "form this computer? [Y/n]"
	read newans

	if [ "$newans" == "n" ]; then
		ans=$newans
	fi

	if [ "$ans" == "y" ]; then
		/bin/sh data/kmfinstall.sh uninstall ${SYSTEMTYPE} ${INITPATH} ${RCDEFAULTPATH}
	else 
		echo "Uninstallation aborted!"
		exit 1
	
	fi
}

askRun() {
	ans="y"

    echo "Run the script? [Y/n]"
	read newans

	if [ "$newans" == "n" ]; then
		ans=$newans
	fi
    
	if [ "$ans" == "y" ]; then
        ${INITPATH}/kmyfirewall start
    else
    	echo 
    	echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        echo "!!! YOU SYSTEM STAYS UNPROTECTED !!!"
	echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        echo 
	echo "You need to manualy start the firewall after intsllation"
        echo "to appy the configurtion you have installed."
        echo 
	echo "Run: '${INITPATH}/kmyfirewall start' to start the firewall"
    fi
}

askStop() {
    echo "Flush all rules? [y/N]"
    read ans

    if [ "$ans" == "y" ]; then
        ${INITPATH}/kmyfirewall stop
    
    	echo 
    	echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        echo "!!! YOU IS NOW UNPROTECTED !!!"
	echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        echo 
    fi
}

printHello() {
    echo "KMyFirewall Package Installer"
    echo "Plesae report bugs to: %maintainer%"
    echo
}

#
# Execution starts here
#

readSetting
printHello

case $1 in
    uninstall)
    askStop
    uninstall
    ;;
    *)
    install
    askRun
    ;;
esac

