Ubuntu Install Script

#!/bin/bash

# UniFi Controller Updater auto installation script.
# Version  | 2.0
# Author   | Glenn Rietveld
# Email    | glennrietveld8@hotmail.nl
# Website  | https://GlennR.nl

if [ "$EUID" -ne 0 ]
  then
	clear
	echo "#####################################"
	echo -e "#  \e[91mPlease run this script as root.\e[0m  #"
	echo "#####################################"
  exit
fi

##########################################################################################################################################################################

unifi=$(dpkg -s unifi | grep "Version:")
IP=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1')

##########################################################################################################################################################################

if [ -f /etc/apt/sources.list.d/100-ubnt-unifi.list ]; then
    rm /etc/apt/sources.list.d/100-ubnt-unifi.list
	echo -e "\e[91m################################################\e[0m"
	echo ""
	echo " UniFi source files were detected on your system!"
	echo " The script will remove the source files, so your upgrade will be successful."
	echo " When the script finishes up you will be prompted to add the source files back!"
	echo ""
	echo -e "\e[91m################################################\e[0m"
	sleep 8
	clear
fi

if [ -f ~/unifi_sysvinit_all.deb ]; then
    rm ~/unifi_sysvinit_all.deb
	echo -e "\e[91m################################################\e[0m"
	echo ""
	echo " UniFi Installation file was detected on your system!"
	echo " The script will remove the installation file, so your upgrade will be successful."
	echo ""
	echo -e "\e[91m################################################\e[0m"
	sleep 8
	clear
fi

if (whiptail --title "UniFi Easy Update" --yesno "Did you download a backup of your controller?" 8 78) then
    clear
	echo -e "\e[92m################################################\e[0m"
	echo ""
    echo " You downloaded a backup! Awesome!"
	echo " Starting the Easy Update Script!"
	echo ""
	echo -e "\e[92m################################################\e[0m"
	sleep 2
else
    clear
    echo -e "\e[91m################################################\e[0m"
	echo ""
    echo -e "\e[91m You did not download a backup!\e[0m"
    echo -e "\e[91m Please download a backup and rerun the script!\e[0m"
	echo ""
	echo -e "\e[91m################################################\e[0m"
	exit 0
fi

if [[ $(java -version 2>&1) == *"1.8.0"* ]]; then
    clear
    echo -e "\e[92m################################################\e[0m"
	echo ""
    echo " JAVA 8 is installed"
	echo ""
	echo -e "\e[92m################################################\e[0m"
	sleep 2
else
    clear
    echo -e "\e[91m################################################\e[0m"
	echo ""
    echo " JAVA 8 is not installed"
    echo " Installing JAVA 8 now"
	echo ""
	echo -e "\e[91m################################################\e[0m"
	echo ""
	echo ""
	sleep 2
    add-apt-repository ppa:webupd8team/java -y
    apt-get update
    echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections
    apt-get install oracle-java8-installer -y
    apt-get install oracle-java8-set-default -y
    echo "JAVA_HOME="/usr/lib/jvm/java-8-oracle"" >> /etc/environment
    source /etc/environment
fi

##########################################################################################################################################################################
#																																										 #
#																       5.0.x																							 #
#																																										 #
##########################################################################################################################################################################

if dpkg -s unifi | grep "5.0.*"; then
OPTION=$(whiptail --title "UniFi Easy Update" --menu "\n      To what controller version would you like to update?\n      Current $unifi" 15 70 4 \
"5.6.40" " |  Support for: UAP-AC | UAP-AC v2 | UAP-AC-OD" \
"5.8.30" "" \
"5.9.29" "" 3>&2 2>&1 1>&3)

exitstatus=$?
if [ $exitstatus = 0 ]; then
    echo "You chose to update to:" $OPTION
else
    echo "You chose Cancel."
fi

case "$OPTION" in
    5.6.40) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			if dpkg -s unifi | grep "5.0.7"; then
			    clear
			else
			    wget https://www.ubnt.com/downloads/unifi/5.0.7/unifi_sysvinit_all.deb || exit 1
			    dpkg -i unifi_sysvinit_all.deb || exit 1
			    rm unifi_sysvinit_all.deb || exit 1
				clear
			    echo -e "\e[91m################################################\e[0m"
			    echo " "
			    echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			    echo " "
			    echo " If you have conerns that this is not long enough please cancel further execution of the script"
			    echo " By pressing CTRL+C on your keyboard."
			    echo " "
			    echo " For example if you have many sites migrations can take a while."
			    echo " You can run the script again (if canceled) when your migration finished."
			    echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			    echo " "
			    echo -e "\e[91m################################################\e[0m"
			    sleep 30
			    clear
			fi
			wget https://www.ubnt.com/downloads/unifi/5.2.9/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://www.ubnt.com/downloads/unifi/5.3.11/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.4.19/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.5.24/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.6.40/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.6.40"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
			exit 0;;
    5.8.30) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			if dpkg -s unifi | grep "5.0.7"; then
			    clear
			else
			    wget https://www.ubnt.com/downloads/unifi/5.0.7/unifi_sysvinit_all.deb || exit 1
			    dpkg -i unifi_sysvinit_all.deb || exit 1
			    rm unifi_sysvinit_all.deb || exit 1
				clear
			    echo -e "\e[91m################################################\e[0m"
			    echo " "
			    echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			    echo " "
			    echo " If you have conerns that this is not long enough please cancel further execution of the script"
			    echo " By pressing CTRL+C on your keyboard."
			    echo " "
			    echo " For example if you have many sites migrations can take a while."
			    echo " You can run the script again (if canceled) when your migration finished."
			    echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			    echo " "
			    echo -e "\e[91m################################################\e[0m"
			    sleep 30
			    clear
			fi
			wget https://www.ubnt.com/downloads/unifi/5.2.9/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://www.ubnt.com/downloads/unifi/5.3.11/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.4.19/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.5.24/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.6.40/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.8.30/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.8.30"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
			exit 0;;
    5.9.29) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			if dpkg -s unifi | grep "5.0.7"; then
			    clear
			else
			    wget https://www.ubnt.com/downloads/unifi/5.0.7/unifi_sysvinit_all.deb || exit 1
			    dpkg -i unifi_sysvinit_all.deb || exit 1
			    rm unifi_sysvinit_all.deb || exit 1
				clear
			    echo -e "\e[91m################################################\e[0m"
			    echo " "
			    echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			    echo " "
			    echo " If you have conerns that this is not long enough please cancel further execution of the script"
			    echo " By pressing CTRL+C on your keyboard."
			    echo " "
			    echo " For example if you have many sites migrations can take a while."
			    echo " You can run the script again (if canceled) when your migration finished."
			    echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			    echo " "
			    echo -e "\e[91m################################################\e[0m"
			    sleep 30
			    clear
			fi
			wget https://www.ubnt.com/downloads/unifi/5.2.9/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://www.ubnt.com/downloads/unifi/5.3.11/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.4.19/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.5.24/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.6.40/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.8.30/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.9.29-04b5d20997/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.9.29"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
			exit 0;;
    *) echo "You chose Cancel.";;
esac
fi

##########################################################################################################################################################################
#																																										 #
#																       5.2.x																							 #
#																																										 #
##########################################################################################################################################################################

if dpkg -s unifi | grep "5.2.*"; then
OPTION=$(whiptail --title "UniFi Easy Update" --menu "\n      To what controller version would you like to update?\n      Current $unifi" 15 70 4 \
"5.6.40" " |  Support for: UAP-AC | UAP-AC v2 | UAP-AC-OD" \
"5.8.30" "" \
"5.9.29" "" 3>&2 2>&1 1>&3)

exitstatus=$?
if [ $exitstatus = 0 ]; then
    echo "You chose to update to:" $OPTION
else
    echo "You chose Cancel."
fi

case "$OPTION" in
    5.6.40) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			if dpkg -s unifi | grep "5.2.9"; then
			    clear
			else
			    wget https://www.ubnt.com/downloads/unifi/5.2.9/unifi_sysvinit_all.deb || exit 1
			    dpkg -i unifi_sysvinit_all.deb || exit 1
			    rm unifi_sysvinit_all.deb || exit 1
				clear
			    echo -e "\e[91m################################################\e[0m"
			    echo " "
			    echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			    echo " "
			    echo " If you have conerns that this is not long enough please cancel further execution of the script"
			    echo " By pressing CTRL+C on your keyboard."
			    echo " "
			    echo " For example if you have many sites migrations can take a while."
			    echo " You can run the script again (if canceled) when your migration finished."
			    echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			    echo " "
			    echo -e "\e[91m################################################\e[0m"
			    sleep 30
			    clear
			fi
			wget https://www.ubnt.com/downloads/unifi/5.3.11/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.4.19/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.5.24/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.6.40/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.6.40"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
		    exit 0;;
    5.8.30) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			if dpkg -s unifi | grep "5.2.9"; then
			    clear
			else
			    wget https://www.ubnt.com/downloads/unifi/5.2.9/unifi_sysvinit_all.deb || exit 1
			    dpkg -i unifi_sysvinit_all.deb || exit 1
			    rm unifi_sysvinit_all.deb || exit 1
				clear
			    echo -e "\e[91m################################################\e[0m"
			    echo " "
			    echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			    echo " "
			    echo " If you have conerns that this is not long enough please cancel further execution of the script"
			    echo " By pressing CTRL+C on your keyboard."
			    echo " "
			    echo " For example if you have many sites migrations can take a while."
			    echo " You can run the script again (if canceled) when your migration finished."
			    echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			    echo " "
			    echo -e "\e[91m################################################\e[0m"
			    sleep 30
			    clear
			fi
			wget https://www.ubnt.com/downloads/unifi/5.3.11/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.4.19/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.5.24/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.6.40/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.8.30/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.8.30"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
			exit 0;;
    5.9.29) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			if dpkg -s unifi | grep "5.2.9"; then
			    clear
			else
			    wget https://www.ubnt.com/downloads/unifi/5.2.9/unifi_sysvinit_all.deb || exit 1
			    dpkg -i unifi_sysvinit_all.deb || exit 1
			    rm unifi_sysvinit_all.deb || exit 1
				clear
			    echo -e "\e[91m################################################\e[0m"
			    echo " "
			    echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			    echo " "
			    echo " If you have conerns that this is not long enough please cancel further execution of the script"
			    echo " By pressing CTRL+C on your keyboard."
			    echo " "
			    echo " For example if you have many sites migrations can take a while."
			    echo " You can run the script again (if canceled) when your migration finished."
			    echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			    echo " "
			    echo -e "\e[91m################################################\e[0m"
			    sleep 30
			    clear
			fi
			wget https://www.ubnt.com/downloads/unifi/5.3.11/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.4.19/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.5.24/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.6.40/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.8.30/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.9.29-04b5d20997/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.9.29"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
			exit 0;;
    *) echo "You chose Cancel.";;
esac
fi

##########################################################################################################################################################################
#																																										 #
#																       5.3.x																							 #
#																																										 #
##########################################################################################################################################################################

if dpkg -s unifi | grep "5.3.*"; then
OPTION=$(whiptail --title "UniFi Easy Update" --menu "\n      To what controller version would you like to update?\n      Current $unifi" 15 70 4 \
"5.6.40" " |  Support for: UAP-AC | UAP-AC v2 | UAP-AC-OD" \
"5.8.30" "" \
"5.9.29" "" 3>&2 2>&1 1>&3)

exitstatus=$?
if [ $exitstatus = 0 ]; then
    echo "You chose to update to:" $OPTION
else
    echo "You chose Cancel."
fi

case "$OPTION" in
    5.6.40) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			if dpkg -s unifi | grep "5.3.11"; then
			    clear
			else
			    wget https://www.ubnt.com/downloads/unifi/5.3.11/unifi_sysvinit_all.deb || exit 1
			    dpkg -i unifi_sysvinit_all.deb || exit 1
			    rm unifi_sysvinit_all.deb || exit 1
				clear
			    echo -e "\e[91m################################################\e[0m"
			    echo " "
			    echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			    echo " "
			    echo " If you have conerns that this is not long enough please cancel further execution of the script"
			    echo " By pressing CTRL+C on your keyboard."
			    echo " "
			    echo " For example if you have many sites migrations can take a while."
			    echo " You can run the script again (if canceled) when your migration finished."
			    echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			    echo " "
			    echo -e "\e[91m################################################\e[0m"
			    sleep 30
			    clear
			fi
			wget https://dl.ubnt.com/unifi/5.4.19/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.5.24/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.6.40/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.6.40"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
			exit 0;;
    5.8.30) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			if dpkg -s unifi | grep "5.3.11"; then
			    clear
			else
			    wget https://www.ubnt.com/downloads/unifi/5.3.11/unifi_sysvinit_all.deb || exit 1
			    dpkg -i unifi_sysvinit_all.deb || exit 1
			    rm unifi_sysvinit_all.deb || exit 1
				clear
			    echo -e "\e[91m################################################\e[0m"
			    echo " "
			    echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			    echo " "
			    echo " If you have conerns that this is not long enough please cancel further execution of the script"
			    echo " By pressing CTRL+C on your keyboard."
			    echo " "
			    echo " For example if you have many sites migrations can take a while."
			    echo " You can run the script again (if canceled) when your migration finished."
			    echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			    echo " "
			    echo -e "\e[91m################################################\e[0m"
			    sleep 30
			    clear
			fi
			wget https://dl.ubnt.com/unifi/5.4.19/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.5.24/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.6.40/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.8.30/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.8.30"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
			exit 0;;
    5.9.29) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			if dpkg -s unifi | grep "5.3.11"; then
			    clear
			else
			    wget https://www.ubnt.com/downloads/unifi/5.3.11/unifi_sysvinit_all.deb || exit 1
			    dpkg -i unifi_sysvinit_all.deb || exit 1
			    rm unifi_sysvinit_all.deb || exit 1
				clear
			    echo -e "\e[91m################################################\e[0m"
			    echo " "
			    echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			    echo " "
			    echo " If you have conerns that this is not long enough please cancel further execution of the script"
			    echo " By pressing CTRL+C on your keyboard."
			    echo " "
			    echo " For example if you have many sites migrations can take a while."
			    echo " You can run the script again (if canceled) when your migration finished."
			    echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			    echo " "
			    echo -e "\e[91m################################################\e[0m"
			    sleep 30
			    clear
			fi
			wget https://dl.ubnt.com/unifi/5.4.19/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.5.24/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.6.40/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.8.30/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.9.29-04b5d20997/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.9.29"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
			exit 0;;
    *) echo "You chose Cancel.";;
esac
fi

##########################################################################################################################################################################
#																																										 #
#																       5.4.x																							 #
#																																										 #
##########################################################################################################################################################################

if dpkg -s unifi | grep "5.4.*"; then
OPTION=$(whiptail --title "UniFi Easy Update" --menu "\n      To what controller version would you like to update?\n      Current $unifi" 15 70 4 \
"5.6.40" " |  Support for: UAP-AC | UAP-AC v2 | UAP-AC-OD" \
"5.8.30" "" \
"5.9.29" "" 3>&2 2>&1 1>&3)

exitstatus=$?
if [ $exitstatus = 0 ]; then
    echo "You chose to update to:" $OPTION
else
    echo "You chose Cancel."
fi

case "$OPTION" in
    5.6.40) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			if dpkg -s unifi | grep "5.4.19"; then
			    clear
			else
			    wget https://dl.ubnt.com/unifi/5.4.19/unifi_sysvinit_all.deb || exit 1
			    dpkg -i unifi_sysvinit_all.deb || exit 1
			    rm unifi_sysvinit_all.deb || exit 1
				clear
			    echo -e "\e[91m################################################\e[0m"
			    echo " "
			    echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			    echo " "
			    echo " If you have conerns that this is not long enough please cancel further execution of the script"
			    echo " By pressing CTRL+C on your keyboard."
			    echo " "
			    echo " For example if you have many sites migrations can take a while."
			    echo " You can run the script again (if canceled) when your migration finished."
			    echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			    echo " "
			    echo -e "\e[91m################################################\e[0m"
			    sleep 30
			    clear
			fi
			wget https://dl.ubnt.com/unifi/5.5.24/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.6.40/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.6.40"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
			exit 0;;
    5.8.30) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			if dpkg -s unifi | grep "5.4.19"; then
			    clear
			else
			    wget https://dl.ubnt.com/unifi/5.4.19/unifi_sysvinit_all.deb || exit 1
			    dpkg -i unifi_sysvinit_all.deb || exit 1
			    rm unifi_sysvinit_all.deb || exit 1
				clear
			    echo -e "\e[91m################################################\e[0m"
			    echo " "
			    echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			    echo " "
			    echo " If you have conerns that this is not long enough please cancel further execution of the script"
			    echo " By pressing CTRL+C on your keyboard."
			    echo " "
			    echo " For example if you have many sites migrations can take a while."
			    echo " You can run the script again (if canceled) when your migration finished."
			    echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			    echo " "
			    echo -e "\e[91m################################################\e[0m"
			    sleep 30
			    clear
			fi
			wget https://dl.ubnt.com/unifi/5.5.24/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.6.40/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.8.30/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.8.30"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
			exit 0;;
    5.9.29) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			if dpkg -s unifi | grep "5.4.19"; then
			    clear
			else
			    wget https://dl.ubnt.com/unifi/5.4.19/unifi_sysvinit_all.deb || exit 1
			    dpkg -i unifi_sysvinit_all.deb || exit 1
			    rm unifi_sysvinit_all.deb || exit 1
				clear
			    echo -e "\e[91m################################################\e[0m"
			    echo " "
			    echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			    echo " "
			    echo " If you have conerns that this is not long enough please cancel further execution of the script"
			    echo " By pressing CTRL+C on your keyboard."
			    echo " "
			    echo " For example if you have many sites migrations can take a while."
			    echo " You can run the script again (if canceled) when your migration finished."
			    echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			    echo " "
			    echo -e "\e[91m################################################\e[0m"
			    sleep 30
			    clear
			fi
			wget https://dl.ubnt.com/unifi/5.5.24/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.6.40/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.8.30/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.9.29-04b5d20997/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.9.29"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
			exit 0;;
    *) echo "You chose Cancel.";;
esac
fi

##########################################################################################################################################################################
#																																										 #
#																       5.5.x																							 #
#																																										 #
##########################################################################################################################################################################

if dpkg -s unifi | grep "5.5.*"; then
OPTION=$(whiptail --title "UniFi Easy Update" --menu "\n      To what controller version would you like to update?\n      Current $unifi" 15 70 4 \
"5.6.40" " |  Support for: UAP-AC | UAP-AC v2 | UAP-AC-OD" \
"5.8.30" "" \
"5.9.29" "" 3>&2 2>&1 1>&3)

exitstatus=$?
if [ $exitstatus = 0 ]; then
    echo "You chose to update to:" $OPTION
else
    echo "You chose Cancel."
fi

case "$OPTION" in
    5.6.40) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			if dpkg -s unifi | grep "5.5.24"; then
			    clear
			else
			    wget https://dl.ubnt.com/unifi/5.5.24/unifi_sysvinit_all.deb || exit 1
			    dpkg -i unifi_sysvinit_all.deb || exit 1
			    rm unifi_sysvinit_all.deb || exit 1
				clear
			    echo -e "\e[91m################################################\e[0m"
			    echo " "
			    echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			    echo " "
			    echo " If you have conerns that this is not long enough please cancel further execution of the script"
			    echo " By pressing CTRL+C on your keyboard."
			    echo " "
			    echo " For example if you have many sites migrations can take a while."
			    echo " You can run the script again (if canceled) when your migration finished."
			    echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			    echo " "
			    echo -e "\e[91m################################################\e[0m"
			    sleep 30
			    clear
			fi
			wget https://dl.ubnt.com/unifi/5.6.40/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.6.40"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
			exit 0;;
    5.8.30) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			if dpkg -s unifi | grep "5.5.24"; then
			    clear
			else
			    wget https://dl.ubnt.com/unifi/5.5.24/unifi_sysvinit_all.deb || exit 1
			    dpkg -i unifi_sysvinit_all.deb || exit 1
			    rm unifi_sysvinit_all.deb || exit 1
				clear
			    echo -e "\e[91m################################################\e[0m"
			    echo " "
			    echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			    echo " "
			    echo " If you have conerns that this is not long enough please cancel further execution of the script"
			    echo " By pressing CTRL+C on your keyboard."
			    echo " "
			    echo " For example if you have many sites migrations can take a while."
			    echo " You can run the script again (if canceled) when your migration finished."
			    echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			    echo " "
			    echo -e "\e[91m################################################\e[0m"
			    sleep 30
			    clear
			fi
			wget https://dl.ubnt.com/unifi/5.6.40/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.8.30/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.8.30"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
			exit 0;;
    5.9.29) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			if dpkg -s unifi | grep "5.5.24"; then
			    clear
			else
			    wget https://dl.ubnt.com/unifi/5.5.24/unifi_sysvinit_all.deb || exit 1
			    dpkg -i unifi_sysvinit_all.deb || exit 1
			    rm unifi_sysvinit_all.deb || exit 1
				clear
			    echo -e "\e[91m################################################\e[0m"
			    echo " "
			    echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			    echo " "
			    echo " If you have conerns that this is not long enough please cancel further execution of the script"
			    echo " By pressing CTRL+C on your keyboard."
			    echo " "
			    echo " For example if you have many sites migrations can take a while."
			    echo " You can run the script again (if canceled) when your migration finished."
			    echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			    echo " "
			    echo -e "\e[91m################################################\e[0m"
			    sleep 30
			    clear
			fi
			wget https://dl.ubnt.com/unifi/5.6.40/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.8.30/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.9.29-04b5d20997/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.9.29"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
			exit 0;;
    *) echo "You chose Cancel.";;
esac
fi

##########################################################################################################################################################################
#																																										 #
#																       5.6.x																							 #
#																																										 #
##########################################################################################################################################################################

if dpkg -s unifi | grep "5.6.*"; then
OPTION=$(whiptail --title "UniFi Easy Update" --menu "\n      To what controller version would you like to update?\n      Current $unifi" 15 70 4 \
"5.6.40" " |  Support for: UAP-AC | UAP-AC v2 | UAP-AC-OD" \
"5.8.30" "" \
"5.9.29" "" 3>&2 2>&1 1>&3)

exitstatus=$?
if [ $exitstatus = 0 ]; then
    echo "You chose to update to:" $OPTION
else
    echo "You chose Cancel."
fi

case "$OPTION" in
    5.6.40) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			if dpkg -s unifi | grep "5.6.40"; then
			    clear
    		    echo -e "\e[92m################################################\e[0m"
			    echo ""
			    echo " Your controller is already on 5.6.40"
			    echo ""
			    echo -e "\e[92m################################################\e[0m"
				exit 0
			    rm $0
			else
			    wget https://dl.ubnt.com/unifi/5.6.40/unifi_sysvinit_all.deb || exit 1
			    dpkg -i unifi_sysvinit_all.deb || exit 1
			    rm unifi_sysvinit_all.deb || exit 1
			fi
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.6.40"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
			exit 0;;
    5.8.30) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			if dpkg -s unifi | grep "5.6.40"; then
			    clear
			else
			    wget https://dl.ubnt.com/unifi/5.6.40/unifi_sysvinit_all.deb || exit 1
			    dpkg -i unifi_sysvinit_all.deb || exit 1
			    rm unifi_sysvinit_all.deb || exit 1
				clear
			    echo -e "\e[91m################################################\e[0m"
			    echo " "
			    echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			    echo " "
			    echo " If you have conerns that this is not long enough please cancel further execution of the script"
			    echo " By pressing CTRL+C on your keyboard."
			    echo " "
			    echo " For example if you have many sites migrations can take a while."
			    echo " You can run the script again (if canceled) when your migration finished."
			    echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			    echo " "
			    echo -e "\e[91m################################################\e[0m"
			    sleep 30
			    clear
			fi
			wget https://dl.ubnt.com/unifi/5.8.30/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.8.30"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
			exit 0;;
    5.9.29) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			if dpkg -s unifi | grep "5.6.40"; then
			    clear
			else
			    wget https://dl.ubnt.com/unifi/5.6.40/unifi_sysvinit_all.deb || exit 1
			    dpkg -i unifi_sysvinit_all.deb || exit 1
			    rm unifi_sysvinit_all.deb || exit 1
				clear
			    echo -e "\e[91m################################################\e[0m"
			    echo " "
			    echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			    echo " "
			    echo " If you have conerns that this is not long enough please cancel further execution of the script"
			    echo " By pressing CTRL+C on your keyboard."
			    echo " "
			    echo " For example if you have many sites migrations can take a while."
			    echo " You can run the script again (if canceled) when your migration finished."
			    echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			    echo " "
			    echo -e "\e[91m################################################\e[0m"
			    sleep 30
			    clear
			fi
			wget https://dl.ubnt.com/unifi/5.8.30/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.9.29-04b5d20997/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.9.29"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
			exit 0;;
    *) echo "You chose Cancel.";;
esac
fi

##########################################################################################################################################################################
#																																										 #
#																       5.7.x																							 #
#																																										 #
##########################################################################################################################################################################

if dpkg -s unifi | grep "5.7.*"; then
OPTION=$(whiptail --title "UniFi Easy Update" --menu "\n      To what controller version would you like to update?\n      Current $unifi" 15 70 4 \
"5.8.30" "" \
"5.9.29" "" 3>&2 2>&1 1>&3)

exitstatus=$?
if [ $exitstatus = 0 ]; then
    echo "You chose to update to:" $OPTION
else
    echo "You chose Cancel."
fi

case "$OPTION" in
    5.8.30) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			clear
			wget https://dl.ubnt.com/unifi/5.8.30/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.8.30"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
			exit 0;;
    5.9.29) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			clear
			wget https://dl.ubnt.com/unifi/5.8.30/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
			echo -e "\e[91m################################################\e[0m"
			echo " "
			echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			echo " "
			echo " If you have conerns that this is not long enough please cancel further execution of the script"
			echo " By pressing CTRL+C on your keyboard."
			echo " "
			echo " For example if you have many sites migrations can take a while."
			echo " You can run the script again (if canceled) when your migration finished."
			echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			echo " "
			echo -e "\e[91m################################################\e[0m"
			sleep 30
			clear
			wget https://dl.ubnt.com/unifi/5.9.29-04b5d20997/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.9.29"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
			exit 0;;
    *) echo "You chose Cancel.";;
esac
fi

##########################################################################################################################################################################
#																																										 #
#																       5.8.x																							 #
#																																										 #
##########################################################################################################################################################################

if dpkg -s unifi | grep "5.8.*"; then
OPTION=$(whiptail --title "UniFi Easy Update" --menu "\n      To what controller version would you like to update?\n      Current $unifi" 15 70 4 \
"5.8.30" "" \
"5.9.29" "" 3>&2 2>&1 1>&3)

exitstatus=$?
if [ $exitstatus = 0 ]; then
    echo "You chose to update to:" $OPTION
else
    echo "You chose Cancel."
fi

case "$OPTION" in
    5.8.30) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			if dpkg -s unifi | grep "5.8.30"; then
			    clear
    		    echo -e "\e[92m################################################\e[0m"
			    echo ""
			    echo " Your controller is already on 5.8.30"
			    echo ""
			    echo -e "\e[92m################################################\e[0m"
				exit 0
			    rm $0
			else
			    wget https://dl.ubnt.com/unifi/5.8.30/unifi_sysvinit_all.deb || exit 1
			    dpkg -i unifi_sysvinit_all.deb || exit 1
			    rm unifi_sysvinit_all.deb || exit 1
			fi
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.8.30"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
			exit 0;;
    5.9.29) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			if dpkg -s unifi | grep "5.8.30"; then
			    clear
			else
			    wget https://dl.ubnt.com/unifi/5.8.30/unifi_sysvinit_all.deb || exit 1
			    dpkg -i unifi_sysvinit_all.deb || exit 1
			    rm unifi_sysvinit_all.deb || exit 1
				clear
			    echo -e "\e[91m################################################\e[0m"
			    echo " "
			    echo -e " \e[91mThe script will pause for 30 seconds, so the controller can do its migrations.\e[0m"
			    echo " "
			    echo " If you have conerns that this is not long enough please cancel further execution of the script"
			    echo " By pressing CTRL+C on your keyboard."
			    echo " "
			    echo " For example if you have many sites migrations can take a while."
			    echo " You can run the script again (if canceled) when your migration finished."
			    echo " You can check the migration progress when going to the controller panel <https://$IP:8443>"
			    echo " "
			    echo -e "\e[91m################################################\e[0m"
			    sleep 30
			    clear
			fi
			wget https://dl.ubnt.com/unifi/5.9.29-04b5d20997/unifi_sysvinit_all.deb || exit 1
			dpkg -i unifi_sysvinit_all.deb || exit 1
			rm unifi_sysvinit_all.deb || exit 1
			clear
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.9.29"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
			exit 0;;
    *) echo "You chose Cancel.";;
esac
fi

##########################################################################################################################################################################
#																																										 #
#																       5.9.x																							 #
#																																										 #
##########################################################################################################################################################################

if dpkg -s unifi | grep "5.9.*"; then
OPTION=$(whiptail --title "UniFi Easy Update" --menu "\n      To what controller version would you like to update?\n      Current $unifi" 15 70 4 \
"5.9.29" "" 3>&2 2>&1 1>&3)

exitstatus=$?
if [ $exitstatus = 0 ]; then
    echo "You chose to update to:" $OPTION
else
    echo "You chose Cancel."
fi

case "$OPTION" in
    5.9.29) clear
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo " You chose to update the unifi controller!"
	        echo " Starting the controller update!"
	        echo ""
	        echo -e "\e[92m################################################\e[0m"
	        echo ""
	        echo ""
			sleep 2
			if dpkg -s unifi | grep "5.9.29"; then
			    clear
    		    echo -e "\e[92m################################################\e[0m"
			    echo ""
			    echo " Your controller is already on 5.9.29"
			    echo ""
			    echo -e "\e[92m################################################\e[0m"
			    rm $0
				exit 0
			else
				wget https://dl.ubnt.com/unifi/5.9.29-04b5d20997/unifi_sysvinit_all.deb || exit 1
				dpkg -i unifi_sysvinit_all.deb || exit 1
				rm unifi_sysvinit_all.deb || exit 1
			fi
    		echo -e "\e[92m################################################\e[0m"
			echo ""
			echo " Your controller has been upgraded to 5.9.29"
			echo ""
			echo -e "\e[92m################################################\e[0m"
			echo ""
			echo ""
			rm $0
			exit 0;;
    *) echo "You chose Cancel.";;
esac
fi