#!/bin/bash

#The purpose of ./Quick-Quagga is to simplify the installation and configuration of Quagga, eliminating the tedious and error-prone nature of setting-up each routing daemon seperately, by generating an immediately tangible configuration file for each of your chosen routing protocols. - This script is ideal for those intending to be self-taught or teach others Computer Networking

#This script requires a Debian derived distribution

#Instructions:	wget http://congruent-networks.au/Jonathan-Ferguson/Quick-Quagga && chmod u+x ./Quick-Quagga && ./Quick-Quagga

#########################################################################################
#                                                                                       #
#        Computer Program          ./Quick-Quagga                                       #
#        Version        24         15 September, 2019                                   #
#        Author                    Jonathan Ferguson                                    #
#        Copyright Act 1968        https://www.comlaw.gov.au/Current/C2019C00042        #
#                                                                                       #
#########################################################################################

case "$1" in
	'')
		if [[ -f /etc/quagga/bgpd.conf && -f /etc/quagga/isisd.conf && -f /etc/quagga/ospf6d.conf && -f /etc/quagga/ospfd.conf && -f /etc/quagga/pimd.conf && -f /etc/quagga/ripd.conf && -f /etc/quagga/ripngd.conf && -f /etc/quagga/vtysh.conf && -f /etc/quagga/zebra.conf ]]
		then
			declare currently="Installed"
		elif [[ -f /etc/quagga/bgpd.conf || -f /etc/quagga/isisd.conf || -f /etc/quagga/ospf6d.conf || -f /etc/quagga/ospfd.conf || -f /etc/quagga/pimd.conf || -f /etc/quagga/ripd.conf || -f /etc/quagga/ripngd.conf || -f /etc/quagga/vtysh.conf || -f /etc/quagga/zebra.conf ]]
		then
			declare currently="Needs to be reinstalled"
		else
			declare currently="Not installed"
		fi

		echo -e "\nCurrently:\t"$currently"\n"
		echo -e "Install:\tsudo ./Quick-Quagga install"
		echo -e "Reinstall:\tsudo ./Quick-Quagga install"
		echo -e "Uninstall:\tsudo ./Quick-Quagga remove\n"
	;;

	'install')
		sudo apt-get -y install quagga \
		&& sudo unlink /etc/systemd/system/multi-user.target.wants/bgpd.service  2> /dev/null || true \
		&& sudo unlink /etc/systemd/system/multi-user.target.wants/isisd.service  2> /dev/null || true \
		&& sudo unlink /etc/systemd/system/multi-user.target.wants/ospf6d.service  2> /dev/null || true \
		&& sudo unlink /etc/systemd/system/multi-user.target.wants/ospfd.service  2> /dev/null || true \
		&& sudo unlink /etc/systemd/system/multi-user.target.wants/pimd.service  2> /dev/null || true \
		&& sudo unlink /etc/systemd/system/multi-user.target.wants/ripd.service  2> /dev/null || true \
		&& sudo unlink /etc/systemd/system/multi-user.target.wants/ripngd.service  2> /dev/null || true \
		&& sudo unlink /etc/systemd/system/multi-user.target.wants/zebra.service  2> /dev/null || true \
		&& sudo mkdir -p /var/log/quagga \
		&& sudo chown quagga:quagga /var/log/quagga
		if [ $? -eq 0 ]
		then
			echo -e "\n\t[ Good ]\tWe have installed quagga\n"
		else
			echo -e "\n\t[ Bad ]\t\tWe failed to install quagga\n"
			exit 1
		fi

		sleep 5 \
		&& sudo wget --no-cache --no-check-certificate -O /tmp/bgpd.conf "https://wiki.ubuntu.com/JonathanFerguson/Quagga?action=AttachFile&do=get&target=bgpd.conf" \
		&& sudo wget --no-cache --no-check-certificate -O /tmp/isisd.conf "https://wiki.ubuntu.com/JonathanFerguson/Quagga?action=AttachFile&do=get&target=isisd.conf" \
		&& sudo wget --no-cache --no-check-certificate -O /tmp/ospf6d.conf "https://wiki.ubuntu.com/JonathanFerguson/Quagga?action=AttachFile&do=get&target=ospf6d.conf" \
		&& sudo wget --no-cache --no-check-certificate -O /tmp/ospfd.conf "https://wiki.ubuntu.com/JonathanFerguson/Quagga?action=AttachFile&do=get&target=ospfd.conf" \
		&& sudo wget --no-cache --no-check-certificate -O /tmp/pimd.conf "https://wiki.ubuntu.com/JonathanFerguson/Quagga?action=AttachFile&do=get&target=pimd.conf" \
		&& sudo wget --no-cache --no-check-certificate -O /tmp/ripd.conf "https://wiki.ubuntu.com/JonathanFerguson/Quagga?action=AttachFile&do=get&target=ripd.conf" \
		&& sudo wget --no-cache --no-check-certificate -O /tmp/ripngd.conf "https://wiki.ubuntu.com/JonathanFerguson/Quagga?action=AttachFile&do=get&target=ripngd.conf" \
		&& sudo wget --no-cache --no-check-certificate -O /tmp/vtysh.conf "https://wiki.ubuntu.com/JonathanFerguson/Quagga?action=AttachFile&do=get&target=vtysh.conf" \
		&& sudo wget --no-cache --no-check-certificate -O /tmp/zebra.conf "https://wiki.ubuntu.com/JonathanFerguson/Quagga?action=AttachFile&do=get&target=zebra.conf"
		if [ $? -eq 0 ]
		then
			echo -e "\t[ Good ]\tWe have downloaded the configuration files for quagga\n"
		else
			echo -e "\n\t[ Bad ]\t\tWe failed to download the configuration files for quagga\n"
			exit 1
		fi

		sleep 5 \
		&& declare files=`ls -1 /tmp/*.conf` interfaces=`/sbin/ip link | awk '$2 ~ /:$/ && $2 !~ /^lo:$/ { print $2 }' | sed 's/:$//g'`
		for file in $files
		do
			for interface in $interfaces
			do
				sudo sed -i "/redistribute bgp/ N; /# redistribute connected/i\\`sed -e '1,/!1/d' -e '/!1/,$d' "$file" | sed "1,/\*/s/eth0/$interface/"`" "$file" \
				&& sed -e '1,/!2/d' -e '/!2/,$d' "$file" | sudo sed "1,/\*/s/eth0/$interface/" >> "$file" \
				&& declare secondoctet=`od -A n -N 1 -t x1 < /dev/urandom` thirdandfourthoctet=`od -A n -N 2 -t x2 < /dev/urandom` fifthandsixthoctet=`od -A n -N 2 -t x2 < /dev/urandom` seventhandeighthoctet=`od -A n -N 2 -t x2 < /dev/urandom` \
				&& sudo sed -i "0,/prefix fd00::/s//prefix `echo fd$secondoctet:$thirdandfourthoctet:$fifthandsixthoctet:$seventhandeighthoctet:: | sed 's/ //g'`/" "$file" \
				&& mapfile -t < <(echo -n fd$secondoctet:$thirdandfourthoctet:$fifthandsixthoctet:$seventhandeighthoctet: | sed 's/ //g' && /sbin/ip address show $interface | awk '$2 ~ /^fe80/ { print $2 }' | sed -e 's/fe80:://' -e 's/\//\\\//') \
				&& sudo sed -i "0,/address fd00::\/64/s//`printf %b address\ $MAPFILE`/" "$file"
			done \
			&& sudo sed -i '/\!1/,/\!1/d' "$file" \
			&& sudo sed -i '/\!2/,/\!2/d' "$file"
		done
		if [ $? -eq 0 ]
		then
			echo -e "\t[ Good ]\tWe have configured the use of all attached interfaces\n"
		else
			echo -e "\n\t[ Bad ]\t\tYou did not initiate this script as root\n"
			exit 1
		fi

		sleep 5 \
		&& sudo sed -i "s/hostname IS-IS/hostname `hostname`_IS-IS/g" /tmp/isisd.conf \
		&& sudo sed -i "s/ffffffffffff/`/sbin/ip link show $interface | awk '$1 ~ /link\/ether/ { print $2 }' | grep -v - | head -n 1 | sed 's/://g'`/g" /tmp/isisd.conf
		if [ $? -eq 0 ]
		then
			echo -e "\t[ Good ]\tWe have altered isisd.conf\n"
		else
			echo -e "\t[ Bad ]\t\tWe failed to alter isisd.conf\n"
			exit 1
		fi

		sleep 5 \
		&& declare password="Quagga" verifypassword=""
		until [[ "$password" == $verifypassword && "$verifypassword" != "" ]]
		do
			read -s -p "Enter a password that you want to use to access the quagga daemons with: " password \
			&& echo \
			&& read -s -p "Please enter your desired password again for the purpose of verification: " verifypassword \
			&& echo
		done \
		&& sudo sed -i "s/password Quagga/password `echo "$verifypassword"`/g" /tmp/*.conf
		if [ $? -eq 0 ]
		then
			echo -e "\n\t[ Good ]\tWe have set your desired password to the quagga daemons\n"
		else
			echo -e "\n\t[ Bad ]\t\tWe failed to set your desired password to the quagga daemons\n"
			exit 1
		fi

		sleep 5 \
		&& sudo mv -f /tmp/bgpd.conf /etc/quagga/bgpd.conf \
		&& sudo mv -f /tmp/isisd.conf /etc/quagga/isisd.conf \
		&& sudo mv -f /tmp/ospf6d.conf /etc/quagga/ospf6d.conf \
		&& sudo mv -f /tmp/ospfd.conf /etc/quagga/ospfd.conf \
		&& sudo mv -f /tmp/pimd.conf /etc/quagga/pimd.conf \
		&& sudo mv -f /tmp/ripd.conf /etc/quagga/ripd.conf \
		&& sudo mv -f /tmp/ripngd.conf /etc/quagga/ripngd.conf \
		&& sudo mv -f /tmp/vtysh.conf /etc/quagga/vtysh.conf \
		&& sudo mv -f /tmp/zebra.conf /etc/quagga/zebra.conf
		if [ $? -eq 0 ]
		then
			echo -e "\t[ Good ]\tWe have moved the configuration files to /etc/quagga\n"
		else
			echo -e "\t[ Bad ]\t\tWe failed to move the configuration files to /etc/quagga\n"
			exit 1
		fi

		sleep 5 \
		&& sudo chown quagga:quagga /etc/quagga/bgpd.conf \
		&& sudo chown quagga:quagga /etc/quagga/isisd.conf \
		&& sudo chown quagga:quagga /etc/quagga/ospf6d.conf \
		&& sudo chown quagga:quagga /etc/quagga/ospfd.conf \
		&& sudo chown quagga:quagga /etc/quagga/pimd.conf \
		&& sudo chown quagga:quagga /etc/quagga/ripd.conf \
		&& sudo chown quagga:quagga /etc/quagga/ripngd.conf \
		&& sudo chown quagga:quaggavty /etc/quagga/vtysh.conf \
		&& sudo chown quagga:quagga /etc/quagga/zebra.conf
		if [ $? -eq 0 ]
		then
			echo -e "\t[ Good ]\tWe have made Quagga the owner of his configuration files\n"
		else
			echo -e "\t[ Bad ]\t\tWe failed to make Quagga the owner of his configuration files\n"
			exit 1
		fi

		sleep 5 \
		&& sudo chmod 640 /etc/quagga/bgpd.conf \
		&& sudo chmod 640 /etc/quagga/isisd.conf \
		&& sudo chmod 640 /etc/quagga/ospf6d.conf \
		&& sudo chmod 640 /etc/quagga/ospfd.conf \
		&& sudo chmod 640 /etc/quagga/pimd.conf \
		&& sudo chmod 640 /etc/quagga/ripd.conf \
		&& sudo chmod 640 /etc/quagga/ripngd.conf \
		&& sudo chmod 660 /etc/quagga/vtysh.conf \
		&& sudo chmod 640 /etc/quagga/zebra.conf
		if [ $? -eq 0 ]
		then
			echo -e "\t[ Good ]\tWe have changed the mode of Quagga's configuration files\n"
		else
			echo -e "\t[ Bad ]\t\tWe failed to change the mode of Quagga's configuration files\n"
			exit 1
		fi

		sleep 5 \
		&& declare bgp=""
		until [[ "$bgp" == no || "$bgp" == yes ]]
		do
			read -p "Do you want to run Border Gateway Protocol on this End System? " bgp \
			&& declare bgp=`echo "$bgp" | tr '[:upper:]' '[:lower:]'`
		done
		if [ "$bgp" == yes ]
		then
			sudo ln -st /etc/systemd/system/multi-user.target.wants /lib/systemd/system/bgpd.service
		fi
		if [ $? -eq 0 ]
		then
			echo -e "\n\t[ Good ]\tWe have performed your request of \""$bgp"\" to BGP\n"
		else
			echo -e "\n\t[ Bad ]\t\tWe failed to perform your request concerning BGP\n"
			exit 1
		fi

		sleep 5 \
		&& declare pim=""
		until [[ "$pim" == no || "$pim" == yes ]]
		do
			read -p "Do you want to run IPv4 Protocol Independent Multicast on this End System? " pim \
			&& declare pim=`echo "$pim" | tr '[:upper:]' '[:lower:]'`
		done
		if [[ "$pim" == yes ]]
		then
			sudo ln -st /etc/systemd/system/multi-user.target.wants /lib/systemd/system/pimd.service
		fi
		if [ $? -eq 0 ]
		then
			echo -e "\n\t[ Good ]\tWe have performed your request of \""$pim"\" to PIM\n"
		else
			echo -e "\n\t[ Bad ]\t\tWe failed to perform your request concerning PIM\n"
			exit 1
		fi

		sleep 5 \
		&& grep net.ipv4.conf.all.forwarding=1 /etc/sysctl.conf
		if [ $? -eq 1 ]
		then
			echo "net.ipv4.conf.all.forwarding=1" | sudo tee -a /etc/sysctl.conf 1> /dev/null
		fi \
		&& grep net.ipv4.conf.default.forwarding=1 /etc/sysctl.conf
		if [ $? -eq 1 ]
		then
			echo "net.ipv4.conf.default.forwarding=1" | sudo tee -a /etc/sysctl.conf 1> /dev/null
		fi \
		&& sed 's/#net.ipv6.conf.all.forwarding=1/net.ipv6.conf.all.forwarding=1/g' /etc/sysctl.conf | sudo tee /etc/sysctl.conf 1> /dev/null \
		&& grep net.ipv6.conf.default.forwarding=1 /etc/sysctl.conf
		if [ $? -eq 1 ]
		then
			echo "net.ipv6.conf.default.forwarding=1" | sudo tee -a /etc/sysctl.conf 1> /dev/null
		fi \
		&& sudo sysctl -p
		if [ $? -eq 0 ]
		then
			echo -e "\n\t[ Good ]\tWe have enabled IP unicast forwarding\n"
		else
			echo -e "\n\t[ Bad ]\t\tWe failed to enable IP unicast forwarding\n"
			exit 1
		fi

		if [ "$pim" == yes ]
		then
			sleep 5 \
			&& grep net.ipv4.conf.all.mc_forwarding=1 /etc/sysctl.conf
			if [ $? -eq 1 ]
			then
				echo "net.ipv4.conf.all.mc_forwarding=1" | sudo tee -a /etc/sysctl.conf 1> /dev/null
			fi \
			&& grep net.ipv4.conf.default.mc_forwarding=1 /etc/sysctl.conf
			if [ $? -eq 1 ]
			then
				echo "net.ipv4.conf.default.mc_forwarding=1" | sudo tee -a /etc/sysctl.conf 1> /dev/null
			fi \
			&& sudo sysctl -p
			if [ $? -eq 0 ]
			then
				echo -e "\n\t[ Good ]\tWe have enabled IPv4 multicast forwarding\n"
			else
				echo -e "\n\t[ Bad ]\t\tWe failed to enable IPv4 multicast forwarding\n"
				exit 1
			fi
		fi

		sleep 5 \
		&& declare igp="" \
		&& declare sure="" \
		&& while [[ "$igp" == "" && "$sure" != "yes" ]]
		do
			echo "Interior Gateway Protocols, any or all of: IS-IS OSPFv2 OSPFv3 RIP RIPng" \
			&& read -p "Which Interior Gateway Protocols do you want to run on this End System? " daemons \
			&& echo "The following is a list of Interior Gateway Protocols that will be enabled:"
			for igp in $daemons
			do
				if [ "$igp" == IS-IS ]
				then
					sudo ln -st /etc/systemd/system/multi-user.target.wants /lib/systemd/system/isisd.service \
					&& echo "IS-IS" \
					&& declare isis="yes"
				fi
				if [ "$igp" == OSPFv2 ]
				then
					sudo ln -st /etc/systemd/system/multi-user.target.wants /lib/systemd/system/ospfd.service \
					&& echo "OSPFv2" \
					&& declare ospf="yes"
				fi
				if [ "$igp" == OSPFv3 ]
				then
					sudo ln -st /etc/systemd/system/multi-user.target.wants /lib/systemd/system/ospf6d.service \
					&& echo "OSPFv3" \
					&& declare ospf6="yes"
				fi
				if [ "$igp" == RIP ]
				then
					sudo ln -st /etc/systemd/system/multi-user.target.wants /lib/systemd/system/ripd.service \
					&& echo "RIP" \
					&& declare rip="yes"
				fi
				if [ "$igp" == RIPng ]
				then
					sudo ln -st /etc/systemd/system/multi-user.target.wants /lib/systemd/system/ripngd.service \
					&& echo "RIPng" \
					&& declare ripng="yes"
				fi
				sleep 1
			done
			if [ "$igp" == "" ]
			then
				read -p "Are you sure that you want to proceed without an Interior Gateway Protocol? " sure \
				&& declare sure=`echo "$sure" | tr '[:upper:]' '[:lower:]'`
			fi
		done
		if [ $? -eq 0 ]
		then
			echo -e "\n\t[ Good ]\tWe have successfully enacted upon your chosen IGP\n"
		else
			echo -e "\n\t[ Bad ]\t\tWe failed to perform your request concerning IGP\n"
			exit 1
		fi

		sleep 5 \
		&& declare proceed="" \
		&& echo "Next you will be presented with the files in nano of the quagga daemons you have selected to use, where you will be able to make alterations you deem necessary." \
		&& echo "If you make a mistake you will again be presented with the file, where you will need to rectify the fault before proceeding."
		until [ "$proceed" == yes ]
		do
			read -p "Are you ready to proceed? " proceed \
			&& declare proceed=`echo "$proceed" | tr '[:upper:]' '[:lower:]'`
		done \
		&& sudo ln -st /etc/systemd/system/multi-user.target.wants /lib/systemd/system/zebra.service
		while
			echo "sudo nano /etc/quagga/zebra.conf" \
			&& sleep 2 \
			&& sudo nano /etc/quagga/zebra.conf \
			&& sudo systemctl restart zebra.service
			[ $? -ne 0 ] || break
		do true
		done
		if [ "$bgp" == yes ]
		then
			while
				echo "sudo nano /etc/quagga/bgpd.conf" \
				&& sleep 2 \
				&& sudo nano /etc/quagga/bgpd.conf \
				&& sudo systemctl restart bgpd.service
				[ $? -ne 0 ] || break
			do true
			done
		fi
		if [ "$pim" == yes ]
		then
			while
				echo "sudo nano /etc/quagga/pimd.conf" \
				&& sleep 2 \
				&& sudo nano /etc/quagga/pimd.conf \
				&& sudo systemctl restart pimd.service
				[ $? -ne 0 ] || break
			do true
			done
		fi
		if [ "$igp" == "" ]
		then
			echo "You chose to forego an Interior Gateway Protocol" \
			&& sleep 2
		else
			if [ "$isis" == yes ]
			then
				while
					echo "sudo nano /etc/quagga/isisd.conf" \
					&& sleep 2 \
					&& sudo nano /etc/quagga/isisd.conf \
					&& sudo systemctl restart isisd.service
					[ $? -ne 0 ] || break
				do true
				done
			fi
			if [ "$ospf" == yes ]
			then
				while
					echo "sudo nano /etc/quagga/ospfd.conf" \
					&& sleep 2 \
					&& sudo nano /etc/quagga/ospfd.conf \
					&& sudo systemctl restart ospfd.service
					[ $? -ne 0 ] || break
					do true
				done
			fi
			if [ "$ospf6" == yes ]
			then
				while
					echo "sudo nano /etc/quagga/ospf6d.conf" \
					&& sleep 2 \
					&& sudo nano /etc/quagga/ospf6d.conf \
					&& sudo systemctl restart ospf6d.service
					[ $? -ne 0 ] || break
				do true
				done
			fi
			if [ "$rip" == yes ]
			then
				while
					echo "sudo nano /etc/quagga/ripd.conf" \
					&& sleep 2 \
					&& sudo nano /etc/quagga/ripd.conf \
					&& sudo systemctl restart ripd.service
					[ $? -ne 0 ] || break
				do true
				done
			fi
			if [ "$ripng" == yes ]
			then
				while
					echo "sudo nano /etc/quagga/ripngd.conf" \
					&& sleep 2 \
					&& sudo nano /etc/quagga/ripngd.conf \
					&& sudo systemctl restart ripngd.service
					[ $? -ne 0 ] || break
				do true
				done
			fi
		fi
		if [ $? -eq 0 ]
		then
			echo -e "\n\t[ Good ]\t./Quick-Quagga has fulfilled its purpose\n"
		else
			echo -e "\n\t[ Bad ]\t\t./Quick-Quagga failed to fulfill its obligations\n"
			exit 1
		fi
	;;

	'remove')
		sudo unlink /etc/systemd/system/multi-user.target.wants/bgpd.service 2> /dev/null || true \
		&& sudo unlink /etc/systemd/system/multi-user.target.wants/isisd.service 2> /dev/null || true \
		&& sudo unlink /etc/systemd/system/multi-user.target.wants/ospf6d.service 2> /dev/null || true \
		&& sudo unlink /etc/systemd/system/multi-user.target.wants/ospfd.service 2> /dev/null || true \
		&& sudo unlink /etc/systemd/system/multi-user.target.wants/pimd.service 2> /dev/null || true \
		&& sudo unlink /etc/systemd/system/multi-user.target.wants/ripd.service 2> /dev/null || true \
		&& sudo unlink /etc/systemd/system/multi-user.target.wants/ripngd.service 2> /dev/null || true \
		&& sudo unlink /etc/systemd/system/multi-user.target.wants/zebra.service 2> /dev/null \
		&& sudo systemctl stop bgpd.service \
		&& sudo systemctl stop isisd.service \
		&& sudo systemctl stop ospf6d.service \
		&& sudo systemctl stop ospfd.service \
		&& sudo systemctl stop pimd.service \
		&& sudo systemctl stop ripd.service \
		&& sudo systemctl stop ripngd.service \
		&& sudo systemctl stop zebra.service
		if [ $? -eq 0 ]
		then
			echo -e "\n\t[ Good ]\tWe have stopped the quagga daemons\n"
		else
			echo -e "\n\t[ Bad ]\t\tWe failed to stop the quagga daemons\n"
			echo -e "\t[ Fix ]\t\tYou may want to use the 'install' argument first\n"
			exit 1
		fi

		sleep 5 \
		&& declare forwarding=""
		until [[ "$forwarding" == no || "$forwarding" == yes ]]
		do
			read -p "Do you require IP unicast forwarding for another daemon? " forwarding \
			&& declare forwarding=`echo "$forwarding" | tr '[:upper:]' '[:lower:]'`
		done
		if [ "$forwarding" == yes ]
		then
			echo "IP unicast forwarding will remain in effect"
		elif [ "$forwarding" == no ]
		then
			echo "IP unicast forwarding is being deconfigured" \
			&& sudo sed -i '/net.ipv6.conf.default.forwarding=1/d' /etc/sysctl.conf \
			&& sed 's/net.ipv6.conf.all.forwarding=1/#net.ipv6.conf.all.forwarding=1/g' /etc/sysctl.conf | sudo tee /etc/sysctl.conf 1> /dev/null \
			&& sudo sed -i '/net.ipv4.conf.default.forwarding=1/d' /etc/sysctl.conf \
			&& sudo sed -i '/net.ipv4.conf.all.forwarding=1/d' /etc/sysctl.conf \
			&& sudo sysctl -p
		fi
		if [ $? -eq 0 ]
		then
			echo -e "\n\t[ Good ]\tWe have performed your request of \""$forwarding"\" to IP unicast forwarding\n"
		else
			echo -e "\n\t[ Bad ]\t\tWe failed to perform your request concerning IP unicast forwarding\n"
			exit 1
		fi

		sleep 5 \
		&& declare forwarding=""
		until [[ "$forwarding" == no || "$forwarding" == yes ]]
		do
			read -p "Do you require IPv4 multicast forwarding for another daemon? " forwarding \
			&& declare forwarding=`echo "$forwarding" | tr '[:upper:]' '[:lower:]'`
		done
		if [ "$forwarding" == yes ]
		then
			echo "IPv4 multicast forwarding will remain in effect"
		elif [ "$forwarding" == no ]
		then
			echo "IPv4 multicast forwarding is being deconfigured" \
			&& sudo sed -i '/net.ipv4.conf.all.mc_forwarding=1/d' /etc/sysctl.conf \
			&& sudo sed -i '/net.ipv4.conf.default.mc_forwarding=1/d' /etc/sysctl.conf \
			&& sudo sysctl -p
		fi
		if [ $? -eq 0 ]
		then
			echo -e "\n\t[ Good ]\tWe have performed your request of \""$forwarding"\" to IPv4 multicast forwarding\n"
		else
			echo -e "\n\t[ Bad ]\t\tWe failed to perform your request concerning IPv4 multicast forwarding\n"
			exit 1
		fi

		sleep 5 \
		sudo rm /etc/quagga/babeld.conf 2> /dev/null || true \
		&& sudo rm /etc/quagga/bgpd.conf 2> /dev/null \
		&& sudo rm /etc/quagga/isisd.conf 2> /dev/null \
		&& sudo rm /etc/quagga/ospf6d.conf 2> /dev/null \
		&& sudo rm /etc/quagga/ospfd.conf 2> /dev/null \
		&& sudo rm /etc/quagga/pimd.conf 2> /dev/null \
		&& sudo rm /etc/quagga/ripd.conf 2> /dev/null \
		&& sudo rm /etc/quagga/ripngd.conf 2> /dev/null  \
		&& sudo rm /etc/quagga/vtysh.conf 2> /dev/null \
		&& sudo rm /etc/quagga/zebra.conf 2> /dev/null
		if [ $? -eq 0 ]
		then
			echo -e "\t[ Good ]\tWe have deleted Quagga's configuration files\n"
		else
			echo -e "\t[ Bad ]\t\tWe failed to delete Quagga's configuration files\n"
			echo -e "\t[ Fix ]\t\tYou may want to invoke 'sudo ./Quick-Quagga install' first\n"
			exit 1
		fi

		sleep 5 \
		&& sudo dpkg --purge quagga \
		&& sudo rm -r /var/log/quagga
		if [ $? -eq 0 ]
		then
			echo -e "\n\t[ Good ]\tWe have removed quagga\n"
		else
			echo -e "\n\t[ Bad ]\t\tWe failed to uninstall quagga\n"
			exit 1
		fi
	;;

	*)
		clear && head -16 $0
	;;
esac

#########################################################################################
#                                                                                       #
#        Computer Program          ./Quick-Quagga                                       #
#        Version        24         15 September, 2019                                   #
#        Author                    Jonathan Ferguson                                    #
#        Copyright Act 1968        https://www.comlaw.gov.au/Current/C2019C00042        #
#                                                                                       #
#########################################################################################
