#!/bin/bash
{
	#////////////////////////////////////
	# DietPi Software
	#
	#////////////////////////////////////
	# Created by Daniel Knight / daniel.knight@dietpi.com / dietpi.com
	#
	#////////////////////////////////////
	#
	# Info:
	# - filename /DietPi/dietpi/dietpi-software
	# - Installs "ready to run" software with optimizations unique to the device.
	# - Runs dietpi-update during 1st run setup.
	# - Generates and uses /DietPi/dietpi/.installed (software list) # 0=not installed, 1=selected for install, 2=installed
	#
	# Usage:
	# - dietpi-software
	# - /DietPi/dietpi/dietpi-software install			iUNIQUEID (OR) sINDEX_{SSHSERVER,FILESERVER,LOGGING,WEBSERVER}_TARGET=-int
	# - /DietPi/dietpi/dietpi-software reinstall		#Same as installed, however, only reinstalls if state =2. Does not uninstall due to package removal danger (eg: xserver removes kodi), simply flags to be installed (=1).
	# - /DietPi/dietpi/dietpi-software uninstall		iUNIQUEID
	# - /DietPi/dietpi/dietpi-software list				#Lists UNIQUEIDs for software.
	# - /DietPi/dietpi/dietpi-software setpermissions	#Sets shared permissions for /var/www and userdata folders.
	#////////////////////////////////////

	#Import DietPi-Globals ---------------------------------------------------------------
	. /DietPi/dietpi/func/dietpi-globals
	G_CHECK_ROOT_USER
	G_CHECK_ROOTFS_RW
	export G_PROGRAM_NAME='DietPi-Software'
	#Import DietPi-Globals ---------------------------------------------------------------

	#/////////////////////////////////////////////////////////////////////////////////////
	#Filepath
	#/////////////////////////////////////////////////////////////////////////////////////
	FP_INSTALLED_FILE='/DietPi/dietpi/.installed'
	FP_INSTALLED_FILE_TEMP='/tmp/dietpi-software.installed'

	FP_DIETPIAUTOMATION_LOG='/root/DietPi-Automation.log'

	#Used to set user/personal data directories (eg: usbdrive)
	FP_DIETPI_DEDICATED_USBDRIVE=''

	#Uninstall temp file
	UNINSTALL_FILE='/tmp/dietpi_uninstall_list'

	#Default user content folders used in DietPi.
	FOLDER_MUSIC='Music'
	FOLDER_PICTURES='Pictures'
	FOLDER_VIDEO='Video'
	FOLDER_DOWNLOADS='downloads'

	Write_InstallFileList(){

		local write_software_in_pending_state=0

		local fp_target="$FP_INSTALLED_FILE"

		if [ "$1" = "temp" ]; then

			fp_target="$FP_INSTALLED_FILE_TEMP"
			write_software_in_pending_state=1

		fi

		rm "$fp_target" &> /dev/null

		#Save installed states
		for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
		do

			# - Never save pending state for software (=1). Excluding temp saves.
			if (( ${aSOFTWARE_INSTALL_STATE[$i]} == 1 && ! $write_software_in_pending_state )); then

				echo -e "aSOFTWARE_INSTALL_STATE[$i]=0" >> "$fp_target"

			else

				echo -e "aSOFTWARE_INSTALL_STATE[$i]=${aSOFTWARE_INSTALL_STATE[$i]}" >> "$fp_target"

			fi

		done

		#Misc
		cat << _EOF_ >> "$fp_target"

#DietPi Choice System: SSH Server
INDEX_SSHSERVER_CURRENT=$INDEX_SSHSERVER_CURRENT
INDEX_SSHSERVER_TARGET=$INDEX_SSHSERVER_TARGET

#DietPi Choice System: File Server
INDEX_FILESERVER_CURRENT=$INDEX_FILESERVER_CURRENT
INDEX_FILESERVER_TARGET=$INDEX_FILESERVER_TARGET

#DietPi Choice System: Logging
INDEX_LOGGING_CURRENT=$INDEX_LOGGING_CURRENT
INDEX_LOGGING_TARGET=$INDEX_LOGGING_TARGET

#DietPi Preference System: Webserver base
INDEX_WEBSERVER_CURRENT=$INDEX_WEBSERVER_CURRENT
INDEX_WEBSERVER_TARGET=$INDEX_WEBSERVER_TARGET

_EOF_

	}

	Read_InstallFileList(){

		local fp_target="$FP_INSTALLED_FILE"

		if [ "$1" = "temp" ]; then

			fp_target="$FP_INSTALLED_FILE_TEMP"

		fi

		#Load Software states
		G_DIETPI-NOTIFY 2 "Reading database, please wait..."

		#Load
		if [ -f "$fp_target" ]; then

			. "$fp_target"

		fi

		#Always reset choice system during first run to defaults: https://github.com/Fourdee/DietPi/issues/1122
		if (( $G_DIETPI_INSTALL_STAGE == 0 )); then

			INDEX_SSHSERVER_CURRENT=-1
			INDEX_SSHSERVER_TARGET=-1

			INDEX_FILESERVER_CURRENT=0
			INDEX_FILESERVER_TARGET=0

			INDEX_LOGGING_CURRENT=-1
			INDEX_LOGGING_TARGET=-1

			INDEX_WEBSERVER_CURRENT=-2
			INDEX_WEBSERVER_TARGET=-2

		fi

	}

	Reset_NTPD(){

		killall -w /DietPi/dietpi/func/run_ntpd &> /dev/null
		killall -w ntpd &> /dev/null
		rm /var/lib/dietpi/.ntpd_exit_status &> /dev/null

	}

	Check_NTPD_Status(){

		if (( $(route | awk '{print $4}' | grep -ci -m1 'UG') )); then

			while true
			do

				/DietPi/dietpi/func/run_ntpd status
				if (( $? != 0 )); then

					#	Endless retry
					if (( ! $G_USER_INPUTS )); then

						Reset_NTPD

					#	Ask
					else

						whiptail --title "NTPD update failed" --yesno "NTPD timesync has not yet completed, or, failed to update. To prevent issues with outdated system time during installations, you must either:\n\n - Retry NTPD update (recommended)\nThis will kill the current NTPD process and retry NTPD update. If this fails again, please use option below.\n\n - Override (last resort)\nThis will override NTPD update checks, however, your system time will be out of sync and may cause issues during installations.\n\nYou can check the NTPD logs for debugging purposes with:\n   cat /var/log/ntpd.log" --yes-button "Override" --no-button "Retry" --defaultno --backtitle "$WHIP_BACKTITLE" 20 80
						if (( $? == 1 )); then

							Reset_NTPD

						else

							Reset_NTPD
							echo 0 > /var/lib/dietpi/.ntpd_exit_status
							echo 1 > /var/lib/dietpi/.ntpd_override

						fi

					fi

				else

					break

				fi

			done

		fi

	}

	#/////////////////////////////////////////////////////////////////////////////////////
	# Installation System
	#/////////////////////////////////////////////////////////////////////////////////////
	#Reboot after installation has finished.
	DISABLE_REBOOT=0

	#Global Password: Exception to AUTO first run init.
	GLOBAL_PW=$(cat /DietPi/dietpi.txt | grep -m1 '^AUTO_SETUP_GLOBAL_PASSWORD=' | sed 's/.*=//')
	if [ ! -n "$GLOBAL_PW" ]; then

		GLOBAL_PW='dietpi'

	fi

	#Total system RAM (used to calculate percentage based value for software cache levels, eg: opcache/apcu max sizes)
	RAM_TOTAL=$(free -m | grep -m1 'Mem:' | awk '{print $2}')

	#Run Installation Flag (1 = run installs)
	GOSTARTINSTALL=0
	INSTALL_URL_ADDRESS=''
	INSTALL_DESCRIPTION='DietPi'

	#Special installation Vars
	USER_EMONHUB_APIKEY_COMPLETED=0
	USER_EMONHUB_APIKEY_CURRENT=0
	WIFIHOTSPOT_RTL8188C_DEVICE=0
	USER_LINUX_AUTOINSTALL_PROMPT_DISPLAYED=0

	#PHP5/7 specific directories, apt package-, module- and command names
	FP_PHP_BASE_DIR='/etc/php/7.0'
	PHP_APT_PACKAGE_NAME='php'
	if (( $G_DISTRO < 4 )); then

		FP_PHP_BASE_DIR='/etc/php5'
		PHP_APT_PACKAGE_NAME='php5'

	fi

	#
	USBDRIVE=0

	#Choices Made?
	INSTALL_DIETPI_CHOICESMADE=0
	INSTALL_LINUX_CHOICESMADE=0

	#DietPi Choice System: SSH Server
	#NB: Update Read_InstallFileList with defaults
	INSTALL_SSHSERVER_CHOICESMADE=0
	INDEX_SSHSERVER_CURRENT=-1
	INDEX_SSHSERVER_TARGET=-1

	#DietPi Choice System: Fileserver
	#NB: Update Read_InstallFileList with defaults
	INSTALL_FILESERVER_CHOICESMADE=0
	INDEX_FILESERVER_CURRENT=0
	INDEX_FILESERVER_TARGET=0

	#DietPi Choice System: Logging
	#NB: Update Read_InstallFileList with defaults
	INSTALL_LOGGING_CHOICESMADE=0
	INDEX_LOGGING_CURRENT=-1
	INDEX_LOGGING_TARGET=-1

	#DietPi Preference System: Webserver base
	#NB: Update Read_InstallFileList with defaults
	INDEX_WEBSERVER_CURRENT=-2
	INDEX_WEBSERVER_TARGET=-2

	#Create DietPi-Software Arrays
	# - Categories
	aSOFTWARE_CATEGORIES_DIETPI=0 		#List of cats
	MAX_SOFTWARE_CATEGORIES_DIETPI=0

	aSOFTWARE_CATEGORIES_LINUX=0
	MAX_SOFTWARE_CATEGORIES_LINUX=0

	# - Software
	#NB: All software has a unique index that must not be changed (eg: DESKTOP_LXDE = 23)
	TOTAL_SOFTWARE_INDEXS=0
	TOTAL_SOFTWARE_INDEXS_HARDLIMIT=171	#Increase as needed. Must be higher than TOTAL_SOFTWARE_INDEXS once calculated in Software_Arrays_Init

	INSTALLING_INDEX=0					#Which software index is currently being installed?

	aSOFTWARE_CATEGORY_INDEX=0			#Category index
	aSOFTWARE_TYPE=0					#0=DietPi 1=Linux | -1=Hidden from install menu, visible in uninstall menu | -2 Hidden from all menus

	aSOFTWARE_INSTALL_STATE=0			#0=not / 1=tobe, or not tobe that is the... / 2=installed

	aSOFTWARE_WHIP_NAME=0				#Item name eg: Kodi
	aSOFTWARE_WHIP_DESC=0				#Blah blah

	FP_ONLINEDOC_URL='http://dietpi.com/phpbb/viewtopic.php?'
	aSOFTWARE_ONLINEDOC_URL=0

	# - Disable software installation, if user input is required for automated installs
	aSOFTWARE_REQUIRES_USERINPUT=0

	# - Optional pre req software that needs to be installed
	aSOFTWARE_REQUIRES_ALSA=0
	aSOFTWARE_REQUIRES_XSERVERXORG=0
	aSOFTWARE_REQUIRES_MYSQL=0
	aSOFTWARE_REQUIRES_SQLITE=0
	aSOFTWARE_REQUIRES_WEBSERVER=0
	aSOFTWARE_REQUIRES_DESKTOP=0
	aSOFTWARE_REQUIRES_GIT=0
	aSOFTWARE_REQUIRES_BUILDESSENTIAL=0
	aSOFTWARE_REQUIRES_RSYSLOG=0
	aSOFTWARE_REQUIRES_FFMPEG=0
	aSOFTWARE_REQUIRES_ORACLEJAVA=0
	aSOFTWARE_REQUIRES_NODEJS=0

	# - Available for
	MAX_G_HW_MODEL=71		#This needs to match highest G_HW_MODEL value in dietpi-obtain_hw_model
	MAX_G_HW_ARCH=10		#This needs to match highest G_HW_ARCH value in dietpi-obtain_hw_model
	#	2D array (well, bash style)
	declare -A aSOFTWARE_AVAIL_G_HW_MODEL
	declare -A aSOFTWARE_AVAIL_G_HW_ARCH

	#/////////////////////////////////////////////////////////////////////////////////////
	# This function generates the array for all the software avaliable to be installed.
	#
	# Reference:
	# - Adding new software to DietPi-Software
	#   https://github.com/Fourdee/DietPi/issues/490#issuecomment-244416570
	#
	# Adding Software to the Install List:
	# ------------------------------------
	# - index_current:
	#   This is the next number in the sequence. Each software install has a unique number,
	#   so it can be referenced in all arrays. This has to be the same for install, uninstall
	#   and setting up the service. Run "dietpi-software list | grep 'index Current'" to
	#   get the next number in the sequence. Ensure that you are running a testing build, as
	#   release may be behind the testing branch and avaliable software packages.
	#
	# - aSOFTWARE_WHIP_NAME:
	#   This is the name to display in the UI.
	#
	# - aSOFTWARE_WHIP_DESC:
	#   This is the description to place next to the name in the UI.
	#
	# - aSOFTWARE_CATEGORY_INDEX:
	#   If you are adding a new peice of software, first choose the category it belongs to
	#   (see aSOFTWARE_CATEGORIES_DIETPI and aSOFTWARE_CATEGORIES_LINUX below), which will
	#   give you the aSOFTWARE_CATEGORY_INDEX to set. In the example below this is 0.
	#
	# - aSOFTWARE_TYPE:
	#   If this is aSOFTWARE_CATEGORIES_DIETPI then aSOFTWARE_TYPE=0, if it is
	#   aSOFTWARE_CATEGORIES_LINUX then it is 1. In the example it is 0.
	#
	# - aSOFTWARE_ONLINEDOC_URL:
	#   This is appeneded to FP_ONLINEDOC_URL to make a URL for help on this software.
	#
	# Specifying other software as dependencies:
	#   If your software needs other software to be available, look under the 'Requires software
	#   to be installed' heading and then add that to the section you create. In the example
	#   below ALSA and XSERVERXORG are needed. The system will check their presence
	#   and install as needed.
	#
	# Dealing with Hardware types:
	#   If you have hardware requirements, like must not/only be installed on a Pi, then you need
	#   to add something like below. Look for other examples in the existing software
	#   installations. Full list of models can be found in 'dietpi-obtain_hw_model'.
	#
	#	# - Disabled for All non-rpi
	#	for ((i=10; i<=$MAX_G_HW_MODEL; i++))
	#	do
	#		aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0
	#	done
	#
	# Example:
	#  #------------------ Desktops: LXDE ------------------
	#  index_current=23
	# 		       aSOFTWARE_WHIP_NAME[$index_current]='LXDE'
	#	           aSOFTWARE_WHIP_DESC[$index_current]='ultra lightweight desktop'
	#         aSOFTWARE_CATEGORY_INDEX[$index_current]=0
	#			        aSOFTWARE_TYPE[$index_current]=0
	#	       aSOFTWARE_REQUIRES_ALSA[$index_current]=1
  	#   aSOFTWARE_REQUIRES_XSERVERXORG[$index_current]=1
	#	       aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5#p42'
	#
	#/////////////////////////////////////////////////////////////////////////////////////
	Software_Arrays_Init(){

		#--------------------------------------------------------------------------------
		#Categories
		#NB: Unique Indexs, do not re-arrange or re-order.
		#--------------------------------------------------------------------------------
		#DietPi software
		aSOFTWARE_CATEGORIES_DIETPI=(

			"────Desktops──────────────────────────────────────────────" #0
			"────Remote Desktop Access─────────────────────────────────" #1
			"────Media Systems─────────────────────────────────────────" #2
			"────BitTorrent / Download Tools───────────────────────────" #3
			"────Cloud / Backups───────────────────────────────────────" #4
			"────Emulation & Gaming────────────────────────────────────" #5
			"────Social / Search───────────────────────────────────────" #6
			"────Camera / Surveillance─────────────────────────────────" #7
			"────WiFi Hotspot──────────────────────────────────────────" #8
			"────System Stats / Management─────────────────────────────" #9
			"────Remote Access─────────────────────────────────────────" #10
			"────Hardware Projects─────────────────────────────────────" #11
			"────System Security───────────────────────────────────────" #12
			"────Webserver Stacks──────────────────────────────────────" #13
			"────Pi-hole───────────────────────────────────────────────" #14
			"────File Servers──────────────────────────────────────────" #15
			"────VPN Servers───────────────────────────────────────────" #16
			"────Advanced Networking───────────────────────────────────" #17
			"────Home Automation───────────────────────────────────────" #18
			"────Printing──────────────────────────────────────────────" #19

		)

		MAX_SOFTWARE_CATEGORIES_DIETPI=${#aSOFTWARE_CATEGORIES_DIETPI[@]}

		#Linux software
		aSOFTWARE_CATEGORIES_LINUX=(

			"────SSH Clients───────────────────────────────────────────" #0
			"────Fileserver Clients────────────────────────────────────" #1
			"────File Managers─────────────────────────────────────────" #2
			"────System────────────────────────────────────────────────" #3
			"────Shared Libraries──────────────────────────────────────" #4
			"────Networking / Tools────────────────────────────────────" #5
			"────Development / Programming─────────────────────────────" #6
			"────Text Editors──────────────────────────────────────────" #7
			"────Desktop Utilities─────────────────────────────────────" #8

		)

		MAX_SOFTWARE_CATEGORIES_LINUX=${#aSOFTWARE_CATEGORIES_LINUX[@]}

		#--------------------------------------------------------------------------------
		#Init | Available For
		#--------------------------------------------------------------------------------
		#Set available by default for all devices and arch

		local debug_array_count=0
		for ((i=0; i<$TOTAL_SOFTWARE_INDEXS_HARDLIMIT; i++))
		do

			for ((j=0; j<=$MAX_G_HW_MODEL; j++))
			do

				aSOFTWARE_AVAIL_G_HW_MODEL[$i,$j]=1
				# ((debug_array_count++))
				# echo -e "$debug_array_count ${aSOFTWARE_AVAIL_G_HW_MODEL[$i,$j]}"

			done

		done

		for ((i=0; i<$TOTAL_SOFTWARE_INDEXS_HARDLIMIT; i++))
		do

			for ((j=0; j<=$MAX_G_HW_ARCH; j++))
			do

				aSOFTWARE_AVAIL_G_HW_ARCH[$i,$j]=1
				# ((debug_array_count++))
				# echo -e "$debug_array_count ${aSOFTWARE_AVAIL_G_HW_ARCH[$i,$j]}"

			done

		done

		#--------------------------------------------------------------------------------
		#Int Online Docs
		#--------------------------------------------------------------------------------
		for ((i=0; i<$TOTAL_SOFTWARE_INDEXS_HARDLIMIT; i++))
		do

			aSOFTWARE_ONLINEDOC_URL[$i]=''

		done

		#--------------------------------------------------------------------------------
		#Requires software to be installed
		#--------------------------------------------------------------------------------
		#As we don't define this for all software, init the arrays to 0
		for ((i=0; i<$TOTAL_SOFTWARE_INDEXS_HARDLIMIT; i++))
		do

			aSOFTWARE_REQUIRES_USERINPUT[$i]=0

			aSOFTWARE_REQUIRES_ALSA[$i]=0
			aSOFTWARE_REQUIRES_XSERVERXORG[$i]=0
			aSOFTWARE_REQUIRES_MYSQL[$i]=0
			aSOFTWARE_REQUIRES_SQLITE[$i]=0
			aSOFTWARE_REQUIRES_WEBSERVER[$i]=0
			aSOFTWARE_REQUIRES_DESKTOP[$i]=0
			aSOFTWARE_REQUIRES_GIT[$i]=0
			aSOFTWARE_REQUIRES_BUILDESSENTIAL[$i]=0
			aSOFTWARE_REQUIRES_RSYSLOG[$i]=0
			aSOFTWARE_REQUIRES_FFMPEG[$i]=0
			aSOFTWARE_REQUIRES_ORACLEJAVA[$i]=0
			aSOFTWARE_REQUIRES_NODEJS[$i]=0

		done


		#--------------------------------------------------------------------------------
		#DietPi software items
		#--------------------------------------------------------------------------------
		#Assign UNIQUE index to each item
		local index_current=0

		#Desktops
		#--------------------------------------------------------------------------------
		index_current=23

				 aSOFTWARE_WHIP_NAME[$index_current]='LXDE'
				 aSOFTWARE_WHIP_DESC[$index_current]='ultra lightweight desktop'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=0
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
	  aSOFTWARE_REQUIRES_XSERVERXORG[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5#p42'

		#------------------
		index_current=24
				 aSOFTWARE_WHIP_NAME[$index_current]='MATE'
				 aSOFTWARE_WHIP_DESC[$index_current]='desktop enviroment'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=0
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
	  aSOFTWARE_REQUIRES_XSERVERXORG[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=60#p2073'

		#------------------
		index_current=25

				 aSOFTWARE_WHIP_NAME[$index_current]='XFCE'
				 aSOFTWARE_WHIP_DESC[$index_current]='lightweight desktop environment'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=0
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
	  aSOFTWARE_REQUIRES_XSERVERXORG[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=70#p2203'

		#------------------
		index_current=26

				 aSOFTWARE_WHIP_NAME[$index_current]='GNUStep'
				 aSOFTWARE_WHIP_DESC[$index_current]='lightweight based on OpenStep'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=0
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
	  aSOFTWARE_REQUIRES_XSERVERXORG[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=60#p2072'

		#------------------
		index_current=113

				 aSOFTWARE_WHIP_NAME[$index_current]='Chromium'
				 aSOFTWARE_WHIP_DESC[$index_current]='(Optional) web browser'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=0
					  aSOFTWARE_TYPE[$index_current]=0
		  aSOFTWARE_REQUIRES_DESKTOP[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='http://dietpi.com/phpbb/viewtopic.php?f=8&t=5&p=3011#p3011'

		# - ARMv6
		aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,1]=0

		# - VM
		aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,20]=0

		#Remote Desktops
		#--------------------------------------------------------------------------------
		index_current=27

				 aSOFTWARE_WHIP_NAME[$index_current]='TightVNC Server'
				 aSOFTWARE_WHIP_DESC[$index_current]='desktop for remote connection'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=1
					  aSOFTWARE_TYPE[$index_current]=0
		  aSOFTWARE_REQUIRES_DESKTOP[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=30#p408'

		# - ARMv8
		aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,3]=0

		# - Disable for Stretch, replaced by tigervnc (vnc4)
		if (( $G_DISTRO >= 4 )); then

			for ((i=0; i<$MAX_G_HW_MODEL; i++))
			do

				aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

			done

		fi

		#------------------
		index_current=28

				 aSOFTWARE_WHIP_NAME[$index_current]='VNC4 Server'
				 aSOFTWARE_WHIP_DESC[$index_current]='desktop for remote connection'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=1
					  aSOFTWARE_TYPE[$index_current]=0
		  aSOFTWARE_REQUIRES_DESKTOP[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=30#p408'

		#------------------
		index_current=29

				 aSOFTWARE_WHIP_NAME[$index_current]='XRDP'
				 aSOFTWARE_WHIP_DESC[$index_current]='remote desktop protocol (rdp) server'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=1
					  aSOFTWARE_TYPE[$index_current]=0
		  aSOFTWARE_REQUIRES_DESKTOP[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=70#p2074'

		#------------------
		index_current=30

				 aSOFTWARE_WHIP_NAME[$index_current]='NoMachine'
				 aSOFTWARE_WHIP_DESC[$index_current]='multi-platform server and client access'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=1
					  aSOFTWARE_TYPE[$index_current]=0
		  aSOFTWARE_REQUIRES_DESKTOP[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=60#p2071'

		# - ARMv8
		aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,3]=0

		#------------------
		index_current=120

				 aSOFTWARE_WHIP_NAME[$index_current]='RealVNC Server'
				 aSOFTWARE_WHIP_DESC[$index_current]='desktop for remote connection'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=1
					  aSOFTWARE_TYPE[$index_current]=0
		  aSOFTWARE_REQUIRES_DESKTOP[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=4149#p4149'

		# - License RPi only
		for ((i=10; i<$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		#Media Systems
		#--------------------------------------------------------------------------------
		index_current=31

				 aSOFTWARE_WHIP_NAME[$index_current]='Kodi'
				 aSOFTWARE_WHIP_DESC[$index_current]='the media centre for linux'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
	  aSOFTWARE_REQUIRES_XSERVERXORG[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5#p43'

		# - Disabled for All non-RPi/Odroid boards
		for ((i=20; i<$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		#------------------
		index_current=32

				 aSOFTWARE_WHIP_NAME[$index_current]='YMPD'
				 aSOFTWARE_WHIP_DESC[$index_current]='lightweight web interface music player for mpd'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5#p50'

		#------------------
		index_current=119

				 aSOFTWARE_WHIP_NAME[$index_current]='CAVA'
				 aSOFTWARE_WHIP_DESC[$index_current]='optional: console audio vis for mpd'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=3928#p3928'

		# - X86_64
		aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,10]=0

		#------------------
		index_current=33

				 aSOFTWARE_WHIP_NAME[$index_current]='SubSonic 5'
				 aSOFTWARE_WHIP_DESC[$index_current]='web interface media streaming server'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
		   aSOFTWARE_REQUIRES_FFMPEG[$index_current]=1
	   aSOFTWARE_REQUIRES_ORACLEJAVA[$index_current]=1
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=30#p213'

		#------------------
		index_current=34

				 aSOFTWARE_WHIP_NAME[$index_current]='SubSonic 6'
				 aSOFTWARE_WHIP_DESC[$index_current]='web interface media streaming server'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
		   aSOFTWARE_REQUIRES_FFMPEG[$index_current]=1
	   aSOFTWARE_REQUIRES_ORACLEJAVA[$index_current]=1
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=30#p213'

		#------------------
		index_current=35

				 aSOFTWARE_WHIP_NAME[$index_current]='SqueezeBox'
				 aSOFTWARE_WHIP_DESC[$index_current]='logitech media server (lms)'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=1009#p1009'

		#------------------
		index_current=36

				 aSOFTWARE_WHIP_NAME[$index_current]='SqueezeLite'
				 aSOFTWARE_WHIP_DESC[$index_current]='audio player for lms & squeezebox'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=1009#p1009'

		#------------------
		index_current=37

				 aSOFTWARE_WHIP_NAME[$index_current]='Shairport Sync'
				 aSOFTWARE_WHIP_DESC[$index_current]='airplay audio player with multiroom sync'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=1221#p1221'

		# - x86_64
		aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,10]=0

		#------------------
		index_current=38

				 aSOFTWARE_WHIP_NAME[$index_current]='BruteFIR'
				 aSOFTWARE_WHIP_DESC[$index_current]='eq and digital room correction via alsa'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=57#p57'

		# - Disabled for All non-rpi
		for ((i=10; i<=$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		#------------------
		index_current=39

				 aSOFTWARE_WHIP_NAME[$index_current]='ReadyMedia'
				 aSOFTWARE_WHIP_DESC[$index_current]='(MiniDLNA) media streaming server (dlna, upnp)'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5#p49'

		#------------------
		index_current=40

				 aSOFTWARE_WHIP_NAME[$index_current]='Ampache'
				 aSOFTWARE_WHIP_DESC[$index_current]='web interface media streaming server'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
			  aSOFTWARE_REQUIRES_GIT[$index_current]=1
		   aSOFTWARE_REQUIRES_FFMPEG[$index_current]=1
		aSOFTWARE_REQUIRES_WEBSERVER[$index_current]=1
			aSOFTWARE_REQUIRES_MYSQL[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=40#p554'

		#------------------
		index_current=41

				 aSOFTWARE_WHIP_NAME[$index_current]='Emby Server'
				 aSOFTWARE_WHIP_DESC[$index_current]='web interface media streaming server'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
		   aSOFTWARE_REQUIRES_FFMPEG[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=1789#p1789'

		#disable ARMv6: https://github.com/Fourdee/DietPi/issues/534
		aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,1]=0

		#disable ARMv8: https://github.com/Fourdee/DietPi/issues/1059#issuecomment-313661959
		aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,3]=0

		#------------------
		index_current=42

				 aSOFTWARE_WHIP_NAME[$index_current]='Plex Media Server'
				 aSOFTWARE_WHIP_DESC[$index_current]='web interface media streaming server'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=1949#p1949'

		#disable ARMv6: https://github.com/Fourdee/DietPi/issues/648
		aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,1]=0

		#------------------
		index_current=43

				 aSOFTWARE_WHIP_NAME[$index_current]='Murmur'
				 aSOFTWARE_WHIP_DESC[$index_current]='mumble voip server'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=1691#p1691'

		#------------------
		index_current=118

				 aSOFTWARE_WHIP_NAME[$index_current]='Mopidy'
				 aSOFTWARE_WHIP_DESC[$index_current]='web interface music & radio player'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=80#p3611'
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1

		#------------------
		index_current=121

				 aSOFTWARE_WHIP_NAME[$index_current]='Roon Bridge'
				 aSOFTWARE_WHIP_DESC[$index_current]='Turns device into Roon capable audio player'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=80#p4153'
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1

		# - Currently ARMv7/64 only, so disable all archs
		for ((i=0; i<=$MAX_G_HW_ARCH; i++))
		do

			aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,$i]=0

		done

		#	renable for armv7/64
		for ((i=2; i<=10; i++))
		do

			aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,$i]=1

		done

		#------------------
		index_current=124

				 aSOFTWARE_WHIP_NAME[$index_current]='NAA daemon'
				 aSOFTWARE_WHIP_DESC[$index_current]='signalyst network audio adaptor (naa)'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=90#p4294'
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1

		# - Currently ARMv7+ only, so disable all archs
		for ((i=0; i<=$MAX_G_HW_ARCH; i++))
		do

			aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,$i]=0

		done

		#	renable for armv7+
		aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,2]=1

		#------------------
		index_current=128

				 aSOFTWARE_WHIP_NAME[$index_current]='MPD'
				 aSOFTWARE_WHIP_DESC[$index_current]='music player daemon'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]=''

		#------------------
		index_current=129

				 aSOFTWARE_WHIP_NAME[$index_current]='O!MPD'
				 aSOFTWARE_WHIP_DESC[$index_current]='feature-rich, web interface audio player for mpd'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=5171#p5171'
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
		aSOFTWARE_REQUIRES_WEBSERVER[$index_current]=1
 			aSOFTWARE_REQUIRES_MYSQL[$index_current]=1

		# - VM
		aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,20]=0

		#------------------
		index_current=135

				 aSOFTWARE_WHIP_NAME[$index_current]='IceCast'
				 aSOFTWARE_WHIP_DESC[$index_current]='Shoutcast streaming server (+DarkIce)'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=6526#p6526'

		# - VM
		aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,20]=0

		#------------------
		index_current=141

				 aSOFTWARE_WHIP_NAME[$index_current]='Spotify Connect Web'
				 aSOFTWARE_WHIP_DESC[$index_current]='web interface for spotify premium'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=7013#p7013'
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1

		# - Currently ARMv7+ only, so disable all archs
		for ((i=0; i<=$MAX_G_HW_ARCH; i++))
		do

			aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,$i]=0

		done

		#	renable for armv7+
		aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,2]=1

		#------------------
		index_current=143

				 aSOFTWARE_WHIP_NAME[$index_current]='Koel'
				 aSOFTWARE_WHIP_DESC[$index_current]='web interface audio streamer'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=7305#p7305'
		aSOFTWARE_REQUIRES_WEBSERVER[$index_current]=1
 			aSOFTWARE_REQUIRES_MYSQL[$index_current]=1
		   aSOFTWARE_REQUIRES_NODEJS[$index_current]=1
   aSOFTWARE_REQUIRES_BUILDESSENTIAL[$index_current]=1
		   aSOFTWARE_REQUIRES_FFMPEG[$index_current]=1

		#------------------
		index_current=146

				 aSOFTWARE_WHIP_NAME[$index_current]='PlexPy'
				 aSOFTWARE_WHIP_DESC[$index_current]='monitoring and tracking tool for Plex'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=7463#p7463'
 			  aSOFTWARE_REQUIRES_GIT[$index_current]=1

		# - Disabled for ARM64
		aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,3]=0


		#------------------
		index_current=148

				 aSOFTWARE_WHIP_NAME[$index_current]='JRiver MC'
				 aSOFTWARE_WHIP_DESC[$index_current]='media centre'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
	  aSOFTWARE_REQUIRES_XSERVERXORG[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=110#p7536'

		# - Disabled for All non-rpi
		for ((i=10; i<=$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		#------------------
		index_current=154

				 aSOFTWARE_WHIP_NAME[$index_current]='Roon Server'
				 aSOFTWARE_WHIP_DESC[$index_current]='Roon capable audio player and core'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=7966#p7966'
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
		   aSOFTWARE_REQUIRES_FFMPEG[$index_current]=1

		# - x86_64
		for ((i=0; i<=$MAX_G_HW_ARCH; i++))
		do

			aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,$i]=0

		done

		aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,10]=1

		#------------------
		index_current=159

				 aSOFTWARE_WHIP_NAME[$index_current]='Allo'
				 aSOFTWARE_WHIP_DESC[$index_current]='web interface'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=-1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]=''
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
		aSOFTWARE_REQUIRES_WEBSERVER[$index_current]=1
 			aSOFTWARE_REQUIRES_MYSQL[$index_current]=1

		#------------------
		index_current=160

				 aSOFTWARE_WHIP_NAME[$index_current]='Allo_update'
				 aSOFTWARE_WHIP_DESC[$index_current]='quick reinstall/update web only'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=-1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]=''

		#------------------
		index_current=163

				 aSOFTWARE_WHIP_NAME[$index_current]='Gmediarender'
				 aSOFTWARE_WHIP_DESC[$index_current]='DLNA audio render/endpoint'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=9012#p9012'

		#------------------
		index_current=167

				 aSOFTWARE_WHIP_NAME[$index_current]='Raspotify'
				 aSOFTWARE_WHIP_DESC[$index_current]='spotify connect client'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=9368#p9368'

		#disable ARMv8:
		aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,3]=0

		#disable x86_64:
		aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,10]=0

		#------------------
		index_current=168

				 aSOFTWARE_WHIP_NAME[$index_current]='moOde'
				 aSOFTWARE_WHIP_DESC[$index_current]='audiophile-quality music playback'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=-1
		aSOFTWARE_REQUIRES_WEBSERVER[$index_current]=1
		   aSOFTWARE_REQUIRES_SQLITE[$index_current]=1
   aSOFTWARE_REQUIRES_BUILDESSENTIAL[$index_current]=1
			  aSOFTWARE_REQUIRES_GIT[$index_current]=1
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='xxxxxxxxxxxxxxxxx'

		# - Disabled for All non-rpi
		for ((i=10; i<=$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		 #BitTorrent
		#--------------------------------------------------------------------------------
		index_current=44

				 aSOFTWARE_WHIP_NAME[$index_current]='Transmission'
				 aSOFTWARE_WHIP_DESC[$index_current]='bittorrent server with web interface (c)'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=3
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5#p46'

		#------------------
		index_current=45

				 aSOFTWARE_WHIP_NAME[$index_current]='Deluge'
				 aSOFTWARE_WHIP_DESC[$index_current]='bittorrent server with web interface (python)'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=3
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=10#p61'

		#------------------
		index_current=46

				 aSOFTWARE_WHIP_NAME[$index_current]='qBitTorrent'
				 aSOFTWARE_WHIP_DESC[$index_current]='bittorrent server with web interface (c++)'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=3
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=70#p2272'

		#------------------
		index_current=107

				 aSOFTWARE_WHIP_NAME[$index_current]='rTorrent'
				 aSOFTWARE_WHIP_DESC[$index_current]='bittorrent server with rutorrent web interface'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=3
					  aSOFTWARE_TYPE[$index_current]=0
		aSOFTWARE_REQUIRES_WEBSERVER[$index_current]=1
		   #aSOFTWARE_REQUIRES_FFMPEG[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=2603#p2603'

		#------------------
		index_current=116

				 aSOFTWARE_WHIP_NAME[$index_current]='SickRage'
				 aSOFTWARE_WHIP_DESC[$index_current]='automatically download TV shows'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=3
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=3327#p3327'


		#------------------
		index_current=132

				 aSOFTWARE_WHIP_NAME[$index_current]='Aria2'
				 aSOFTWARE_WHIP_DESC[$index_current]='download manager with web interface'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=3
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=6177#p6177'
		aSOFTWARE_REQUIRES_WEBSERVER[$index_current]=1
		   aSOFTWARE_REQUIRES_SQLITE[$index_current]=1

		#------------------
		index_current=139

				 aSOFTWARE_WHIP_NAME[$index_current]='SABnzbd'
				 aSOFTWARE_WHIP_DESC[$index_current]='nzb download manager'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=3
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=6747#p6747'
   aSOFTWARE_REQUIRES_BUILDESSENTIAL[$index_current]=1

		#------------------
		index_current=142

				 aSOFTWARE_WHIP_NAME[$index_current]='CouchPotato'
				 aSOFTWARE_WHIP_DESC[$index_current]='automatically download movies'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=3
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=6747#p6747'
   aSOFTWARE_REQUIRES_BUILDESSENTIAL[$index_current]=1
			  aSOFTWARE_REQUIRES_GIT[$index_current]=1

		#------------------
		index_current=144

				 aSOFTWARE_WHIP_NAME[$index_current]='Sonarr'
				 aSOFTWARE_WHIP_DESC[$index_current]='automatically download TV shows'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=3
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=7455#p7455'

		#------------------
		index_current=145

				 aSOFTWARE_WHIP_NAME[$index_current]='Radarr'
				 aSOFTWARE_WHIP_DESC[$index_current]='automatically download movies'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=3
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=7457#p7457'

		#------------------
		index_current=147

				 aSOFTWARE_WHIP_NAME[$index_current]='Jackett'
				 aSOFTWARE_WHIP_DESC[$index_current]='api Support for your torrent trackers.'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=3
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=7503#p7503'

		#------------------
		index_current=149

				 aSOFTWARE_WHIP_NAME[$index_current]='NZBget'
				 aSOFTWARE_WHIP_DESC[$index_current]='nzb download manager'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=3
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=7575#p7575'

		#------------------ BitTorrent: HTPC Manager ------------------
		index_current=155

				 aSOFTWARE_WHIP_NAME[$index_current]='HTPC Manager'
				 aSOFTWARE_WHIP_DESC[$index_current]='manage your HTPC from anywhere'
			  aSOFTWARE_REQUIRES_GIT[$index_current]=1
			aSOFTWARE_CATEGORY_INDEX[$index_current]=3
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=8043#p8043'

		#Cloud / Backups
		#--------------------------------------------------------------------------------
		index_current=47

				 aSOFTWARE_WHIP_NAME[$index_current]='ownCloud'
				 aSOFTWARE_WHIP_DESC[$index_current]='your very own cloud (eg: dropbox)'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=4
					  aSOFTWARE_TYPE[$index_current]=0
		aSOFTWARE_REQUIRES_WEBSERVER[$index_current]=1
			aSOFTWARE_REQUIRES_MYSQL[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5#p47'

		#------------------
		index_current=114

				 aSOFTWARE_WHIP_NAME[$index_current]='Nextcloud'
				 aSOFTWARE_WHIP_DESC[$index_current]='A safe home for all your data'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=4
					  aSOFTWARE_TYPE[$index_current]=0
		aSOFTWARE_REQUIRES_WEBSERVER[$index_current]=1
			aSOFTWARE_REQUIRES_MYSQL[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=3026#p3026'

		#------------------
		index_current=48

				 aSOFTWARE_WHIP_NAME[$index_current]='Pydio'
				 aSOFTWARE_WHIP_DESC[$index_current]='feature-rich backup and sync server'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=4
					  aSOFTWARE_TYPE[$index_current]=0
		aSOFTWARE_REQUIRES_WEBSERVER[$index_current]=1
			aSOFTWARE_REQUIRES_MYSQL[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=1064#p1064'

		#------------------
		index_current=111

				 aSOFTWARE_WHIP_NAME[$index_current]='UrBackup server'
				 aSOFTWARE_WHIP_DESC[$index_current]='full system backup server'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=4
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=65#p65'

		#No deb packages for ARMv6:
		aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,1]=0

		#------------------
		index_current=49

				 aSOFTWARE_WHIP_NAME[$index_current]='Gogs'
				 aSOFTWARE_WHIP_DESC[$index_current]='personal github server with web interface'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=4
					  aSOFTWARE_TYPE[$index_current]=0
			  aSOFTWARE_REQUIRES_GIT[$index_current]=1
			aSOFTWARE_REQUIRES_MYSQL[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=70#p2187'

		# - ARMv8
		aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,3]=0

		#------------------
		index_current=50

				 aSOFTWARE_WHIP_NAME[$index_current]='Syncthing'
				 aSOFTWARE_WHIP_DESC[$index_current]='backup and sync server with web interface'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=4
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=70#p2363'

		#------------------
		index_current=134

				 aSOFTWARE_WHIP_NAME[$index_current]='Tonido'
				 aSOFTWARE_WHIP_DESC[$index_current]='lightweight cloud based backup system'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=4
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=6476#p6476'

		# - ARMv6
		aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,1]=0

		# - ARMv8
		aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,3]=0

		#------------------
		index_current=158
				 aSOFTWARE_WHIP_NAME[$index_current]='Minio'
				 aSOFTWARE_WHIP_DESC[$index_current]='S3 compatible distributed object server'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=4
					  aSOFTWARE_TYPE[$index_current]=0

		#------------------
 		index_current=161
 				 aSOFTWARE_WHIP_NAME[$index_current]='FuguHub'
 				 aSOFTWARE_WHIP_DESC[$index_current]='Lightweight WebDAV cloud (eg: dropbox) with a CMS'
 			aSOFTWARE_CATEGORY_INDEX[$index_current]=4
					  aSOFTWARE_TYPE[$index_current]=0

 		 # - x86_64
 		 #aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,10]=0

		 # - ARMv8
 		 aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,3]=0

		 #------------------
		 index_current=165

					aSOFTWARE_WHIP_NAME[$index_current]='Gitea'
					aSOFTWARE_WHIP_DESC[$index_current]='Git with a cup of tea'
			 aSOFTWARE_CATEGORY_INDEX[$index_current]=4
						 aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_GIT[$index_current]=1
			 aSOFTWARE_REQUIRES_MYSQL[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=9863#p9863'


		#Emulation / Gaming
		#--------------------------------------------------------------------------------
		index_current=108

				 aSOFTWARE_WHIP_NAME[$index_current]='AmiBerry'
				 aSOFTWARE_WHIP_DESC[$index_current]='amiga emulator'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=5
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=64#p64'
	  aSOFTWARE_REQUIRES_XSERVERXORG[$index_current]=1

		# - Disabled for All non-rpi
		for ((i=10; i<=$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		#------------------
		index_current=51

				 aSOFTWARE_WHIP_NAME[$index_current]='OpenTyrian'
				 aSOFTWARE_WHIP_DESC[$index_current]='a classic retro game, addictive'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=5
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
	  aSOFTWARE_REQUIRES_XSERVERXORG[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5#p45'

		# - Disabled for All non-rpi
		for ((i=10; i<=$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		#------------------
		index_current=112

				 aSOFTWARE_WHIP_NAME[$index_current]='DXX-Rebirth'
				 aSOFTWARE_WHIP_DESC[$index_current]='Descent 1/2'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=5
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=2963#p2963'

		# - Disabled for All non-rpi
		for ((i=10; i<=$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		#------------------
		index_current=52

				 aSOFTWARE_WHIP_NAME[$index_current]='Cuberite'
				 aSOFTWARE_WHIP_DESC[$index_current]='minecraft server with web interface (c++)'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=5
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=60#p2068'

		# - ARMv8
		aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,3]=0

		#------------------
		index_current=53

				 aSOFTWARE_WHIP_NAME[$index_current]='MineOS'
				 aSOFTWARE_WHIP_DESC[$index_current]='minecraft servers with web interface (java)'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=5
					  aSOFTWARE_TYPE[$index_current]=0
   aSOFTWARE_REQUIRES_BUILDESSENTIAL[$index_current]=1
			  aSOFTWARE_REQUIRES_GIT[$index_current]=1
	   aSOFTWARE_REQUIRES_ORACLEJAVA[$index_current]=1
		   aSOFTWARE_REQUIRES_NODEJS[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=60#p2069'

		#------------------
		index_current=156

				 aSOFTWARE_WHIP_NAME[$index_current]='Steam'
				 aSOFTWARE_WHIP_DESC[$index_current]='client'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=5
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=8016#p8016'
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
	  aSOFTWARE_REQUIRES_XSERVERXORG[$index_current]=1
		  aSOFTWARE_REQUIRES_DESKTOP[$index_current]=1

		#Native PC only
		for ((i=0; i<=$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,21]=1

		#------------------
		index_current=164
				 aSOFTWARE_WHIP_NAME[$index_current]='Nukkit'
				 aSOFTWARE_WHIP_DESC[$index_current]='A nuclear-powered server for Minecraft Pocket Edition'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=5
						aSOFTWARE_TYPE[$index_current]=0
				aSOFTWARE_REQUIRES_ORACLEJAVA[$index_current]=1

		#Social Media
		#--------------------------------------------------------------------------------
		index_current=54

				 aSOFTWARE_WHIP_NAME[$index_current]='Forums'
				 aSOFTWARE_WHIP_DESC[$index_current]='phpbb forums'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=6
					  aSOFTWARE_TYPE[$index_current]=0
		aSOFTWARE_REQUIRES_WEBSERVER[$index_current]=1
			aSOFTWARE_REQUIRES_MYSQL[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=5#p51'

		#------------------
		index_current=55

				 aSOFTWARE_WHIP_NAME[$index_current]='Wordpress'
				 aSOFTWARE_WHIP_DESC[$index_current]='website blog and publishing platform'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=6
					  aSOFTWARE_TYPE[$index_current]=0
		aSOFTWARE_REQUIRES_WEBSERVER[$index_current]=1
			aSOFTWARE_REQUIRES_MYSQL[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=30#p395'

		#------------------
		index_current=56

				 aSOFTWARE_WHIP_NAME[$index_current]='Image Gallery'
				 aSOFTWARE_WHIP_DESC[$index_current]='website to host / browse your images'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=6
					  aSOFTWARE_TYPE[$index_current]=0
		aSOFTWARE_REQUIRES_WEBSERVER[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=40#p480'

		#------------------
		index_current=57

				 aSOFTWARE_WHIP_NAME[$index_current]='BaiKal'
				 aSOFTWARE_WHIP_DESC[$index_current]='lightweight caldav + carddav server'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=6
					  aSOFTWARE_TYPE[$index_current]=0
		aSOFTWARE_REQUIRES_WEBSERVER[$index_current]=1
			aSOFTWARE_REQUIRES_MYSQL[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=50#p1502'

		#------------------
		index_current=58

				 aSOFTWARE_WHIP_NAME[$index_current]='OpenBazaar'
				 aSOFTWARE_WHIP_DESC[$index_current]='decentralized peer to peer bitcoin market'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=6
					  aSOFTWARE_TYPE[$index_current]=0
   aSOFTWARE_REQUIRES_BUILDESSENTIAL[$index_current]=1
			  aSOFTWARE_REQUIRES_GIT[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=1796#p1796'

		#------------------
		index_current=133

				 aSOFTWARE_WHIP_NAME[$index_current]='YaCy'
				 aSOFTWARE_WHIP_DESC[$index_current]='decentralized open source search engine'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=6
					  aSOFTWARE_TYPE[$index_current]=0
	   aSOFTWARE_REQUIRES_ORACLEJAVA[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=6202#p6202'

		#------------------

		#Camera
		#--------------------------------------------------------------------------------
		index_current=59

				 aSOFTWARE_WHIP_NAME[$index_current]='DietPi Cam'
				 aSOFTWARE_WHIP_DESC[$index_current]='web interface & controls for your rpi camera'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=7
					  aSOFTWARE_TYPE[$index_current]=0
		aSOFTWARE_REQUIRES_WEBSERVER[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5#p48'

		# - Disabled for All non-rpi
		for ((i=10; i<=$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		#------------------
		index_current=136

				 aSOFTWARE_WHIP_NAME[$index_current]='MotionEye'
				 aSOFTWARE_WHIP_DESC[$index_current]='web interface & surveillance for your camera'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=7
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=6610#p6610'
 		   aSOFTWARE_REQUIRES_FFMPEG[$index_current]=1

		# - Disabled for All non-rpi
		for ((i=10; i<=$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		#------------------

		#WiFi Hotspot
		#--------------------------------------------------------------------------------
		index_current=60

				 aSOFTWARE_WHIP_NAME[$index_current]='WiFi Hotspot'
				 aSOFTWARE_WHIP_DESC[$index_current]='turn your device into a wifi hotspot'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=8
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=1207#p1207'

		# - VM
		aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,20]=0

		#------------------
		index_current=61

				 aSOFTWARE_WHIP_NAME[$index_current]='Tor Hotspot'
				 aSOFTWARE_WHIP_DESC[$index_current]='optional: route hotspot traffic through tor'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=8
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=1529#p1529'

		# - VM
		aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,20]=0

		#------------------

		#System stats
		#--------------------------------------------------------------------------------
		index_current=62

				 aSOFTWARE_WHIP_NAME[$index_current]='DietPi-Cloudshell'
				 aSOFTWARE_WHIP_DESC[$index_current]='system stats displayed on lcd/panel'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=9
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=20#p204'

		#------------------
		index_current=63

				 aSOFTWARE_WHIP_NAME[$index_current]='LinuxDash'
				 aSOFTWARE_WHIP_DESC[$index_current]='web interface system stats'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=9
					  aSOFTWARE_TYPE[$index_current]=0
		aSOFTWARE_REQUIRES_WEBSERVER[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=20#p108'

		#------------------
		index_current=64

				 aSOFTWARE_WHIP_NAME[$index_current]='PhpSysInfo'
				 aSOFTWARE_WHIP_DESC[$index_current]='web interface system stats'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=9
					  aSOFTWARE_TYPE[$index_current]=0
		aSOFTWARE_REQUIRES_WEBSERVER[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=30#p451'

		#------------------
		index_current=65

				 aSOFTWARE_WHIP_NAME[$index_current]='NetData'
				 aSOFTWARE_WHIP_DESC[$index_current]='real-time performance monitoring'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=9
					  aSOFTWARE_TYPE[$index_current]=0
		   aSOFTWARE_REQUIRES_NODEJS[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=60#p1611'

		#------------------
		index_current=66

				 aSOFTWARE_WHIP_NAME[$index_current]='RPi-Monitor'
				 aSOFTWARE_WHIP_DESC[$index_current]='web interface system stats'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=9
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=50#p1503'

		# - Disabled for All non-rpi
		for ((i=10; i<=$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		#------------------
		index_current=106

				 aSOFTWARE_WHIP_NAME[$index_current]='Raspcontrol'
				 aSOFTWARE_WHIP_DESC[$index_current]='web interface system stats'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=9
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=20#p89'

		# - Disabled for All non-rpi
		for ((i=10; i<=$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		#------------------
		index_current=115

				 aSOFTWARE_WHIP_NAME[$index_current]='Webmin'
				 aSOFTWARE_WHIP_DESC[$index_current]='web interface system management'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=9
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=80#p3047'
		  aSOFTWARE_REQUIRES_RSYSLOG[$index_current]=1

		#------------------
		index_current=126

				 aSOFTWARE_WHIP_NAME[$index_current]='OpenMediaVault'
				 aSOFTWARE_WHIP_DESC[$index_current]='nas solution with web interface'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=9
					  aSOFTWARE_TYPE[$index_current]=-1 #:https://github.com/Fourdee/DietPi/issues/851
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=4859#p4859'
		aSOFTWARE_REQUIRES_WEBSERVER[$index_current]=1
		aSOFTWARE_REQUIRES_USERINPUT[$index_current]=1

		#------------------
		index_current=162

				 aSOFTWARE_WHIP_NAME[$index_current]='Docker'
				 aSOFTWARE_WHIP_DESC[$index_current]='Build, ship, and run distributed applications'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=9
					  aSOFTWARE_TYPE[$index_current]=0

		# - ARMv8
		aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,3]=0

		#Remote Access
		#--------------------------------------------------------------------------------
		index_current=67

				 aSOFTWARE_WHIP_NAME[$index_current]='NoIp'
				 aSOFTWARE_WHIP_DESC[$index_current]='url website address for your device'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=10
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=10#p58'

		#------------------
		index_current=68

				 aSOFTWARE_WHIP_NAME[$index_current]='Remot3.it'
				 aSOFTWARE_WHIP_DESC[$index_current]='(Weaved) access your device over the internet'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=10
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=20#p188'

		# - Currently ARMv7+ only, so disable all archs
		for ((i=0; i<=$MAX_G_HW_ARCH; i++))
		do

			aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,$i]=0

		done

		#	renable for armv6/7
		aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,1]=1
		aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,2]=1

		#------------------
		index_current=138

				 aSOFTWARE_WHIP_NAME[$index_current]='VirtualHere'
				 aSOFTWARE_WHIP_DESC[$index_current]='server: share USB devices over the network'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=10
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=6709#p6709'

		#------------------

		#Hardware projects
		#--------------------------------------------------------------------------------
		index_current=69

				 aSOFTWARE_WHIP_NAME[$index_current]='RPi.GPIO'
				 aSOFTWARE_WHIP_DESC[$index_current]='gpio interface library for rpi (python)'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=11
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=40#p1065'

		# - Disabled for All non-rpi
		for ((i=10; i<=$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		#------------------
		index_current=70

				 aSOFTWARE_WHIP_NAME[$index_current]='WiringPi'
				 aSOFTWARE_WHIP_DESC[$index_current]='gpio interface library (c)'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=11
					  aSOFTWARE_TYPE[$index_current]=0
   aSOFTWARE_REQUIRES_BUILDESSENTIAL[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=1066#p1066'

		# - RPi / Odroids
		for ((i=20; i<=$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		#+ BPi Pro
		aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,51]=1

		#------------------
		index_current=71

				 aSOFTWARE_WHIP_NAME[$index_current]='WebIOPi'
				 aSOFTWARE_WHIP_DESC[$index_current]='web interface to control rpi.gpio'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=11
					  aSOFTWARE_TYPE[$index_current]=0
   aSOFTWARE_REQUIRES_BUILDESSENTIAL[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=20#p189'

		# - Disabled for All non-rpi and RPi3
		for ((i=3; i<=$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		#------------------
		index_current=72

				 aSOFTWARE_WHIP_NAME[$index_current]='I2c'
				 aSOFTWARE_WHIP_DESC[$index_current]='enables support for i2c based hardware'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=11
					  aSOFTWARE_TYPE[$index_current]=0

		# - Disabled for All non-rpi
		for ((i=10; i<=$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		#------------------
		index_current=122

				 aSOFTWARE_WHIP_NAME[$index_current]='Node-Red'
				 aSOFTWARE_WHIP_DESC[$index_current]='tool for wiring devices, APIs and online services'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=11
					  aSOFTWARE_TYPE[$index_current]=0
		   aSOFTWARE_REQUIRES_NODEJS[$index_current]=1
   aSOFTWARE_REQUIRES_BUILDESSENTIAL[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=80#p4292'

		#------------------
		index_current=123

				 aSOFTWARE_WHIP_NAME[$index_current]='Mosquitto '
				 aSOFTWARE_WHIP_DESC[$index_current]='MQTT messaging broker'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=11
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=90#p4293'

		#------------------
		index_current=131

				 aSOFTWARE_WHIP_NAME[$index_current]='Blynk Server'
				 aSOFTWARE_WHIP_DESC[$index_current]='msg controller for blynk mobile app and sbcs'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=11
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=5901#p5901'
	   aSOFTWARE_REQUIRES_ORACLEJAVA[$index_current]=1
		   aSOFTWARE_REQUIRES_NODEJS[$index_current]=1
   aSOFTWARE_REQUIRES_BUILDESSENTIAL[$index_current]=1

		#------------------
		index_current=166

				 aSOFTWARE_WHIP_NAME[$index_current]='PI-SPC'
				 aSOFTWARE_WHIP_DESC[$index_current]='audiophonics pi-spc power control module'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=11
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=9359#p9359'

		# - Disabled for All non-rpi
		for ((i=10; i<=$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		#------------------
		index_current=169

				 aSOFTWARE_WHIP_NAME[$index_current]='Google AIY'
				 aSOFTWARE_WHIP_DESC[$index_current]='voice kit'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=11
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_REQUIRES_ALSA[$index_current]=1
 			  aSOFTWARE_REQUIRES_GIT[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=9486#p9486'

		# - Disabled for All non-rpi
		for ((i=10; i<=$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		#System security
		#--------------------------------------------------------------------------------
		index_current=73

				 aSOFTWARE_WHIP_NAME[$index_current]='Fail2Ban'
				 aSOFTWARE_WHIP_DESC[$index_current]='prevents brute-force attacks with ip ban'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=12
					  aSOFTWARE_TYPE[$index_current]=0
		  aSOFTWARE_REQUIRES_RSYSLOG[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=30#p452'
		#------------------

		#Webserver stacks
		#--------------------------------------------------------------------------------
		index_current=75

				 aSOFTWARE_WHIP_NAME[$index_current]='LASP'
				 aSOFTWARE_WHIP_DESC[$index_current]='apache2  | sqlite  | php'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=13
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=10#p52'

		#------------------
		index_current=76

				 aSOFTWARE_WHIP_NAME[$index_current]='LAAP'
				 aSOFTWARE_WHIP_DESC[$index_current]='apache2  | mariadb | php'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=13
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=10#p52'

		#------------------
		index_current=78

				 aSOFTWARE_WHIP_NAME[$index_current]='LESP'
				 aSOFTWARE_WHIP_DESC[$index_current]='nginx    | sqlite  | php'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=13
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5#p5'

		#------------------
		index_current=79

				 aSOFTWARE_WHIP_NAME[$index_current]='LEAP'
				 aSOFTWARE_WHIP_DESC[$index_current]='nginx    | mariadb | php'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=13
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5#p5'

		#------------------
		index_current=81

				 aSOFTWARE_WHIP_NAME[$index_current]='LLSP'
				 aSOFTWARE_WHIP_DESC[$index_current]='lighttpd | sqlite  | php'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=13
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=1335#p1335'

		#------------------
		index_current=82

				 aSOFTWARE_WHIP_NAME[$index_current]='LLAP'
				 aSOFTWARE_WHIP_DESC[$index_current]='lighttpd | mariadb | php'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=13
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=1335#p1335'

		#------------------
		index_current=83

				 aSOFTWARE_WHIP_NAME[$index_current]='Apache2'
				 aSOFTWARE_WHIP_DESC[$index_current]='webserver'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=13
					  aSOFTWARE_TYPE[$index_current]=-1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=10#p52'

		#------------------
		index_current=84

				 aSOFTWARE_WHIP_NAME[$index_current]='Lighttpd'
				 aSOFTWARE_WHIP_DESC[$index_current]='webserver'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=13
					  aSOFTWARE_TYPE[$index_current]=-1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=1335#p1335'

		#------------------
		index_current=85

				 aSOFTWARE_WHIP_NAME[$index_current]='Nginx'
				 aSOFTWARE_WHIP_DESC[$index_current]='webserver'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=13
					  aSOFTWARE_TYPE[$index_current]=-1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5#p5'

		#------------------
		index_current=87

				 aSOFTWARE_WHIP_NAME[$index_current]='SQlite'
				 aSOFTWARE_WHIP_DESC[$index_current]='database'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=13
					  aSOFTWARE_TYPE[$index_current]=-1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=1335#p1335'

		#------------------
		index_current=88

				 aSOFTWARE_WHIP_NAME[$index_current]='MariaDB'
				 aSOFTWARE_WHIP_DESC[$index_current]='database'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=13
					  aSOFTWARE_TYPE[$index_current]=-1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=1335#p1335'

		#------------------
		index_current=89

				 aSOFTWARE_WHIP_NAME[$index_current]='PHP'
				 aSOFTWARE_WHIP_DESC[$index_current]='webserver'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=13
					  aSOFTWARE_TYPE[$index_current]=-1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=1335#p1335'

		#------------------
		index_current=90

				 aSOFTWARE_WHIP_NAME[$index_current]='phpMyAdmin'
				 aSOFTWARE_WHIP_DESC[$index_current]='optional mysql admin tools'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=13
					  aSOFTWARE_TYPE[$index_current]=0
		aSOFTWARE_REQUIRES_WEBSERVER[$index_current]=1
			aSOFTWARE_REQUIRES_MYSQL[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=10#p54'

		#------------------
		index_current=91

				 aSOFTWARE_WHIP_NAME[$index_current]='Redis'
				 aSOFTWARE_WHIP_DESC[$index_current]='optional non-sql database store'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=13
					  aSOFTWARE_TYPE[$index_current]=0

		#------------------
		index_current=92

				 aSOFTWARE_WHIP_NAME[$index_current]='CertBot'
				 aSOFTWARE_WHIP_DESC[$index_current]='free, ssl cert install allowing https://'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=13
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=1061#p1062'

		#------------------
		index_current=125

				 aSOFTWARE_WHIP_NAME[$index_current]='Tomcat8'
				 aSOFTWARE_WHIP_DESC[$index_current]='apache tomcat server'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=13
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=4316#p4316'
 	   aSOFTWARE_REQUIRES_ORACLEJAVA[$index_current]=1

		#PiHole
		#--------------------------------------------------------------------------------
		index_current=93

				 aSOFTWARE_WHIP_NAME[$index_current]='Pi-hole'
				 aSOFTWARE_WHIP_DESC[$index_current]='block adverts for any device on your network'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=14
					  aSOFTWARE_TYPE[$index_current]=0
			  aSOFTWARE_REQUIRES_GIT[$index_current]=1
		aSOFTWARE_REQUIRES_WEBSERVER[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=20#p174'
		aSOFTWARE_REQUIRES_USERINPUT[$index_current]=1

		#------------------

		#File servers
		#--------------------------------------------------------------------------------
		index_current=94

				 aSOFTWARE_WHIP_NAME[$index_current]='ProFTP'
				 aSOFTWARE_WHIP_DESC[$index_current]='lightweight ftp server'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=15
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=10#p55'

		#------------------
		index_current=95

				 aSOFTWARE_WHIP_NAME[$index_current]='vsFTPD'
				 aSOFTWARE_WHIP_DESC[$index_current]='alternative ftp server'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=15
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='?f=8&t=5&p=2820#p2820'

		#------------------
		index_current=96

				 aSOFTWARE_WHIP_NAME[$index_current]='Samba'
				 aSOFTWARE_WHIP_DESC[$index_current]='feature-rich file server'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=15
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=10#p56'

		#------------------
		index_current=109

				 aSOFTWARE_WHIP_NAME[$index_current]='NFS'
				 aSOFTWARE_WHIP_DESC[$index_current]='network file system server'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=15
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=10#p56'

		#------------------

		#VPN servers
		#--------------------------------------------------------------------------------
		index_current=97

				 aSOFTWARE_WHIP_NAME[$index_current]='OpenVPN'
				 aSOFTWARE_WHIP_DESC[$index_current]='vpn server'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=16
					  aSOFTWARE_TYPE[$index_current]=0
		  aSOFTWARE_REQUIRES_RSYSLOG[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=613#p613'

		#------------------
		index_current=117

				 aSOFTWARE_WHIP_NAME[$index_current]='PiVPN'
				 aSOFTWARE_WHIP_DESC[$index_current]='openvpn installer & management tool'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=16
					  aSOFTWARE_TYPE[$index_current]=0
		  aSOFTWARE_REQUIRES_RSYSLOG[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='http://dietpi.com/phpbb/viewtopic.php?f=8&t=5&p=3469#p3469'
		aSOFTWARE_REQUIRES_USERINPUT[$index_current]=1

		#------------------


		#Advanced Networking
		#--------------------------------------------------------------------------------
		index_current=98

				 aSOFTWARE_WHIP_NAME[$index_current]='HaProxy'
				 aSOFTWARE_WHIP_DESC[$index_current]='high performance tcp/http load balancer'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=17
					  aSOFTWARE_TYPE[$index_current]=0
   aSOFTWARE_REQUIRES_BUILDESSENTIAL[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=30#p221'

		#Home automation
		#--------------------------------------------------------------------------------
		index_current=99

				 aSOFTWARE_WHIP_NAME[$index_current]='EmonPi'
				 aSOFTWARE_WHIP_DESC[$index_current]='energy usage addon board with web interface'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=18
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=1529#p1525'

		# - Disabled for All non-rpi
		for ((i=10; i<=$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		#------------------
		index_current=100

				 aSOFTWARE_WHIP_NAME[$index_current]='Grasshopper'
				 aSOFTWARE_WHIP_DESC[$index_current]='web app to control bticino myhome'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=18
					  aSOFTWARE_TYPE[$index_current]=0
		aSOFTWARE_REQUIRES_WEBSERVER[$index_current]=1
		   aSOFTWARE_REQUIRES_SQLITE[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=20#p70'

		# - Disabled for All non-rpi
		for ((i=10; i<=$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		#------------------ Home Automation: Home Assistant ------------------
		index_current=157

				 aSOFTWARE_WHIP_NAME[$index_current]='Home Assistant'
				 aSOFTWARE_WHIP_DESC[$index_current]='open-source home automation platform'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=18
					  aSOFTWARE_TYPE[$index_current]=0
		      aSOFTWARE_REQUIRES_GIT[$index_current]=1
   aSOFTWARE_REQUIRES_BUILDESSENTIAL[$index_current]=1
		   aSOFTWARE_REQUIRES_SQLITE[$index_current]=1
		   aSOFTWARE_REQUIRES_FFMPEG[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=20#p70'

		#------------------

		#Printing
		#--------------------------------------------------------------------------------
		index_current=137

				 aSOFTWARE_WHIP_NAME[$index_current]='CloudPrint'
				 aSOFTWARE_WHIP_DESC[$index_current]='print server for google cloud print'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=19
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=6630#p6630'
 		  aSOFTWARE_REQUIRES_RSYSLOG[$index_current]=1 #Not required, but comes in as package dep

		#Disabled for ARMv8 on Jessie only: https://github.com/Fourdee/DietPi/issues/855#issuecomment-292712002
		if (( $G_DISTRO == 3 )); then

			aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,3]=0

		fi

		#------------------
		index_current=153

				 aSOFTWARE_WHIP_NAME[$index_current]='OctoPrint'
				 aSOFTWARE_WHIP_DESC[$index_current]='web interface for controlling 3d printers'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=19
					  aSOFTWARE_TYPE[$index_current]=0
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=7958#p7958'
   aSOFTWARE_REQUIRES_BUILDESSENTIAL[$index_current]=1
   			  aSOFTWARE_REQUIRES_GIT[$index_current]=1 # Required for updates

		#--------------------------------------------------------------------------------
		#Additional linux software items
		#--------------------------------------------------------------------------------

		#SSH clients
		#--------------------------------------------------------------------------------
		index_current=0

				 aSOFTWARE_WHIP_NAME[$index_current]='OpenSSH Client'
				 aSOFTWARE_WHIP_DESC[$index_current]=''
			aSOFTWARE_CATEGORY_INDEX[$index_current]=0
					  aSOFTWARE_TYPE[$index_current]=1
		#------------------

		#File server clients
		#--------------------------------------------------------------------------------
		index_current=1

				 aSOFTWARE_WHIP_NAME[$index_current]='Samba Client'
				 aSOFTWARE_WHIP_DESC[$index_current]='access network shares'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=1
					  aSOFTWARE_TYPE[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]=' dietpi-config > Network Options: NAS/Misc'
		#------------------
		index_current=2

				 aSOFTWARE_WHIP_NAME[$index_current]='Curlftpfs'
				 aSOFTWARE_WHIP_DESC[$index_current]='ftp client with filesystem mount'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=1
					  aSOFTWARE_TYPE[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]=' dietpi-config > Network Options: NAS/Misc'
		#------------------
		index_current=110

				 aSOFTWARE_WHIP_NAME[$index_current]='NFS Client'
				 aSOFTWARE_WHIP_DESC[$index_current]='network file system client'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=1
					  aSOFTWARE_TYPE[$index_current]=1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]=' dietpi-config > Network Options: NAS/Misc'
		#------------------

		#File managers
		#--------------------------------------------------------------------------------
		index_current=3

				 aSOFTWARE_WHIP_NAME[$index_current]='MC'
				 aSOFTWARE_WHIP_DESC[$index_current]='midnight commander, powerful file manager'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=1
		#------------------
		index_current=4

				 aSOFTWARE_WHIP_NAME[$index_current]='ViFM'
				 aSOFTWARE_WHIP_DESC[$index_current]='file manager with vi bindings'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=2
					  aSOFTWARE_TYPE[$index_current]=1
		#------------------

		#System
		#--------------------------------------------------------------------------------
		index_current=5

				 aSOFTWARE_WHIP_NAME[$index_current]='ALSA'
				 aSOFTWARE_WHIP_DESC[$index_current]='linux sound system'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=3
					  aSOFTWARE_TYPE[$index_current]=1
		#------------------
		index_current=6

				 aSOFTWARE_WHIP_NAME[$index_current]='Xserver'
				 aSOFTWARE_WHIP_DESC[$index_current]='linux display system'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=3
					  aSOFTWARE_TYPE[$index_current]=1

		#------------------
		index_current=151

				 aSOFTWARE_WHIP_NAME[$index_current]='Nvidia'
				 aSOFTWARE_WHIP_DESC[$index_current]='display driver'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=3
					  aSOFTWARE_TYPE[$index_current]=1
	  aSOFTWARE_REQUIRES_XSERVERXORG[$index_current]=1

		for ((i=0; i<$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,21]=1

		#------------------
		index_current=170

				 aSOFTWARE_WHIP_NAME[$index_current]='NTP'
				 aSOFTWARE_WHIP_DESC[$index_current]='date and time sync'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=3
					  aSOFTWARE_TYPE[$index_current]=-1 #Hidden, use dietpi-config > advanced > timesync to setup

		#Shared Libs
		#--------------------------------------------------------------------------------
		index_current=7

				 aSOFTWARE_WHIP_NAME[$index_current]='FFmpeg'
				 aSOFTWARE_WHIP_DESC[$index_current]='audio & visual libary'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=4
					  aSOFTWARE_TYPE[$index_current]=1
		#------------------
		index_current=8

				 aSOFTWARE_WHIP_NAME[$index_current]='Java'
				 aSOFTWARE_WHIP_DESC[$index_current]='OpenJDK 8 + JRE libary'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=4
					  aSOFTWARE_TYPE[$index_current]=1
		#------------------
		index_current=9

				 aSOFTWARE_WHIP_NAME[$index_current]='Node.js'
				 aSOFTWARE_WHIP_DESC[$index_current]='javascript runtime'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=4
					  aSOFTWARE_TYPE[$index_current]=1
		#------------------
		index_current=130

				 aSOFTWARE_WHIP_NAME[$index_current]='Python Pip'
				 aSOFTWARE_WHIP_DESC[$index_current]='python pip package installer'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=4
					  aSOFTWARE_TYPE[$index_current]=1
		#------------------
		index_current=140

				 aSOFTWARE_WHIP_NAME[$index_current]='SDL2'
				 aSOFTWARE_WHIP_DESC[$index_current]='simple direct layer 2'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=4
					  aSOFTWARE_TYPE[$index_current]=1

		# - Disabled for All non-rpi
		for ((i=10; i<=$MAX_G_HW_MODEL; i++))
		do

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$i]=0

		done

		#------------------
		index_current=150

				 aSOFTWARE_WHIP_NAME[$index_current]='Mono'
				 aSOFTWARE_WHIP_DESC[$index_current]='runtime libraries and repo'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=4
					  aSOFTWARE_TYPE[$index_current]=1


		#Networking
		#--------------------------------------------------------------------------------
		index_current=10

				 aSOFTWARE_WHIP_NAME[$index_current]='iftop'
				 aSOFTWARE_WHIP_DESC[$index_current]='displays bandwidth usage information'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=5
					  aSOFTWARE_TYPE[$index_current]=1
		#------------------
		index_current=11

				 aSOFTWARE_WHIP_NAME[$index_current]='IPTraf'
				 aSOFTWARE_WHIP_DESC[$index_current]='interactive colorful ip lan monitor'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=5
					  aSOFTWARE_TYPE[$index_current]=1
		#------------------
		index_current=12

				 aSOFTWARE_WHIP_NAME[$index_current]='Iperf'
				 aSOFTWARE_WHIP_DESC[$index_current]='internet protocol bandwidth measuring tool'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=5
					  aSOFTWARE_TYPE[$index_current]=1
		#------------------
		index_current=13

				 aSOFTWARE_WHIP_NAME[$index_current]='MTR-Tiny'
				 aSOFTWARE_WHIP_DESC[$index_current]='full screen ncurses traceroute tool'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=5
					  aSOFTWARE_TYPE[$index_current]=1
		#------------------
		index_current=14

				 aSOFTWARE_WHIP_NAME[$index_current]='nLoad'
				 aSOFTWARE_WHIP_DESC[$index_current]='realtime console network usage monitor'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=5
					  aSOFTWARE_TYPE[$index_current]=1
		#------------------
		index_current=15

				 aSOFTWARE_WHIP_NAME[$index_current]='tcpdump'
				 aSOFTWARE_WHIP_DESC[$index_current]='command-line network traffic analyzer'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=5
					  aSOFTWARE_TYPE[$index_current]=1
		#------------------
		index_current=152

				 aSOFTWARE_WHIP_NAME[$index_current]='Avahi-Daemon'
				 aSOFTWARE_WHIP_DESC[$index_current]='hostname broadcast (mac, pc bonjour)'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=5
					  aSOFTWARE_TYPE[$index_current]=1


		#Development / Programming
		#--------------------------------------------------------------------------------
		index_current=16

				 aSOFTWARE_WHIP_NAME[$index_current]='Build-Essentials'
				 aSOFTWARE_WHIP_DESC[$index_current]='common packages for compile'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=6
					  aSOFTWARE_TYPE[$index_current]=1
		#------------------
		index_current=17

				 aSOFTWARE_WHIP_NAME[$index_current]='Git Client'
				 aSOFTWARE_WHIP_DESC[$index_current]='git clone etc'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=6
					  aSOFTWARE_TYPE[$index_current]=1
		#------------------

		#Text Editors
		#--------------------------------------------------------------------------------
		index_current=18

				 aSOFTWARE_WHIP_NAME[$index_current]='Emacs'
				 aSOFTWARE_WHIP_DESC[$index_current]='gnu emacs editor'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=7
					  aSOFTWARE_TYPE[$index_current]=1
		#------------------
		index_current=19

				 aSOFTWARE_WHIP_NAME[$index_current]='Jed'
				 aSOFTWARE_WHIP_DESC[$index_current]='editor for programmers'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=7
					  aSOFTWARE_TYPE[$index_current]=1
		#------------------
		index_current=20

				 aSOFTWARE_WHIP_NAME[$index_current]='Vim'
				 aSOFTWARE_WHIP_DESC[$index_current]='vi enhanced text editor'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=7
					  aSOFTWARE_TYPE[$index_current]=1
		#------------------
		index_current=21

				 aSOFTWARE_WHIP_NAME[$index_current]='Vim-Tiny'
				 aSOFTWARE_WHIP_DESC[$index_current]='compact release of vim'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=7
					  aSOFTWARE_TYPE[$index_current]=1
		#------------------
		index_current=127

				 aSOFTWARE_WHIP_NAME[$index_current]='NeoVim'
				 aSOFTWARE_WHIP_DESC[$index_current]='heavily refactored vim fork'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=7
					  aSOFTWARE_TYPE[$index_current]=1

		# - Stretch only
		if (( $G_DISTRO < 4 )); then

			aSOFTWARE_AVAIL_G_HW_MODEL[$index_current,$G_HW_MODEL]=0

		fi

		#------------------

		#Desktop Utilities
		#--------------------------------------------------------------------------------
		index_current=22

				 aSOFTWARE_WHIP_NAME[$index_current]='QuiteRSS'
				 aSOFTWARE_WHIP_DESC[$index_current]='cross-platform, free rss reader'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=8
					  aSOFTWARE_TYPE[$index_current]=1
		  aSOFTWARE_REQUIRES_DESKTOP[$index_current]=1

		#------------------

		#--------------------------------------------------------------------------------
		#Logging (hidden)
		#--------------------------------------------------------------------------------
		index_current=101

				 aSOFTWARE_WHIP_NAME[$index_current]='Log Rotate'
				 aSOFTWARE_WHIP_DESC[$index_current]='rotates log files'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=0
					  aSOFTWARE_TYPE[$index_current]=-1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=20#p68'
		#------------------
		index_current=102

				 aSOFTWARE_WHIP_NAME[$index_current]='Rsyslog'
				 aSOFTWARE_WHIP_DESC[$index_current]='system logging'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=0
					  aSOFTWARE_TYPE[$index_current]=-1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=20#p68'
		#------------------
		index_current=103

				 aSOFTWARE_WHIP_NAME[$index_current]='DietPi-Ramlog'
				 aSOFTWARE_WHIP_DESC[$index_current]='minimal, optimized logging'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=0
					  aSOFTWARE_TYPE[$index_current]=-1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=20#p68'
		#------------------

		#--------------------------------------------------------------------------------
		#SSH servers (hidden from install menu)
		#--------------------------------------------------------------------------------
		index_current=104

				 aSOFTWARE_WHIP_NAME[$index_current]='Dropbear'
				 aSOFTWARE_WHIP_DESC[$index_current]='ssh server'
			aSOFTWARE_CATEGORY_INDEX[$index_current]=0
					  aSOFTWARE_TYPE[$index_current]=-1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=10#p62'
		#------------------
		index_current=105

				 aSOFTWARE_WHIP_NAME[$index_current]='OpenSSH Server'
				 aSOFTWARE_WHIP_DESC[$index_current]=''
			aSOFTWARE_CATEGORY_INDEX[$index_current]=0
					  aSOFTWARE_TYPE[$index_current]=-1
			 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&start=10#p63'
		#------------------

		#--------------------------------------------------------------------------------
		#Free indexes (due to removal of MySQL)
		#--------------------------------------------------------------------------------
		index_current=74
			aSOFTWARE_WHIP_NAME[$index_current]='free index'
			aSOFTWARE_WHIP_DESC[$index_current]=''
			aSOFTWARE_CATEGORY_INDEX[$index_current]=0
			aSOFTWARE_TYPE[$index_current]=-1
		index_current=77
			aSOFTWARE_WHIP_NAME[$index_current]='free index'
			aSOFTWARE_WHIP_DESC[$index_current]=''
			aSOFTWARE_CATEGORY_INDEX[$index_current]=0
			aSOFTWARE_TYPE[$index_current]=-1
		index_current=80
			aSOFTWARE_WHIP_NAME[$index_current]='free index'
			aSOFTWARE_WHIP_DESC[$index_current]=''
			aSOFTWARE_CATEGORY_INDEX[$index_current]=0
			aSOFTWARE_TYPE[$index_current]=-1
		index_current=86
			aSOFTWARE_WHIP_NAME[$index_current]='free index'
			aSOFTWARE_WHIP_DESC[$index_current]=''
			aSOFTWARE_CATEGORY_INDEX[$index_current]=0
			aSOFTWARE_TYPE[$index_current]=-1

		#--------------------------------------------------------------------------------
		#Total software installations
		TOTAL_SOFTWARE_INDEXS=${#aSOFTWARE_TYPE[@]}
		#--------------------------------------------------------------------------------
		#Init Installed state - 0=not 1=to be 2=installed
		for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
		do

			aSOFTWARE_INSTALL_STATE[$i]=0

		done

		#Installed software on DietPi image by default.
		aSOFTWARE_INSTALL_STATE[103]=2
		aSOFTWARE_INSTALL_STATE[104]=2
		#--------------------------------------------------------------------------------

	}

	Software_Arrays_Destroy(){

		unset aSOFTWARE_CATEGORIES_DIETPI
		unset aSOFTWARE_CATEGORIES_LINUX

		unset aSOFTWARE_CATEGORY_INDEX
		unset aSOFTWARE_TYPE
		unset aSOFTWARE_WHIP_NAME
		unset aSOFTWARE_WHIP_DESC
		unset aSOFTWARE_ONLINEDOC_URL
		unset aSOFTWARE_INSTALL_STATE

		unset aSOFTWARE_REQUIRES_USERINPUT

		unset aSOFTWARE_REQUIRES_ALSA
		unset aSOFTWARE_REQUIRES_XSERVERXORG
		unset aSOFTWARE_REQUIRES_MYSQL
		unset aSOFTWARE_REQUIRES_SQLITE
		unset aSOFTWARE_REQUIRES_WEBSERVER
		unset aSOFTWARE_REQUIRES_DESKTOP
		unset aSOFTWARE_REQUIRES_GIT
		unset aSOFTWARE_REQUIRES_BUILDESSENTIAL
		unset aSOFTWARE_REQUIRES_RSYSLOG
		unset aSOFTWARE_REQUIRES_FFMPEG
		unset aSOFTWARE_REQUIRES_ORACLEJAVA
		unset aSOFTWARE_REQUIRES_NODEJS

		unset aSOFTWARE_AVAIL_G_HW_MODEL
		unset aSOFTWARE_AVAIL_G_HW_ARCH

	}

	#Disable software installation, if user input is required for automated installs
	Install_Disable_Requires_UserInput(){

		if (( ! $G_USER_INPUTS )); then

			for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
			do

				if (( ${aSOFTWARE_INSTALL_STATE[$i]} == 1 &&
					${aSOFTWARE_REQUIRES_USERINPUT[$i]} )); then

					# - Disable
					aSOFTWARE_INSTALL_STATE[$i]=0

					G_DIETPI-NOTIFY 2 "${aSOFTWARE_WHIP_NAME[$i]}: Requires user input and can not be automated."
					G_DIETPI-NOTIFY 1 "${aSOFTWARE_WHIP_NAME[$i]}: Will not be installed. Please run 'dietpi-software' to install."

				fi

			done

		fi

	}

	#Work out which additional software we need to install
	Install_Flag_Prereq_Software(){

		G_DIETPI-NOTIFY 3 DietPi-Software "Checking for prerequisite software"

		#-------------------------------------------------------------------------
		#Pre-req software, for items that do not have their own array aSOFTWARE_REQUIRES_SOFTWARENAME
		local index=0

		#Additional software that requires WiringPi
		#	AudioPhonics Pi-SPC
		if (( ${aSOFTWARE_INSTALL_STATE[166]} == 1 )); then

			aSOFTWARE_INSTALL_STATE[70]=1

		fi

		#Additional Software required by Allo Web Interface
		if (( ${aSOFTWARE_INSTALL_STATE[159]} == 1 )); then

			aSOFTWARE_INSTALL_STATE[36]=1 # Squeezelite
			aSOFTWARE_INSTALL_STATE[37]=1 # Shairport Sync

			# if (( $G_HW_MODEL == 70 )); then

				# aSOFTWARE_INSTALL_STATE[60]=1 # WiFi Hotspot

			# fi

			aSOFTWARE_INSTALL_STATE[65]=1 # Netdata
			aSOFTWARE_INSTALL_STATE[96]=1 # Samba

			aSOFTWARE_INSTALL_STATE[121]=1 # Roon Bridge
			aSOFTWARE_INSTALL_STATE[124]=1 # NAA Daemon
			#aSOFTWARE_INSTALL_STATE[128]=1 # MPD
			aSOFTWARE_INSTALL_STATE[129]=1 # O!MPD
			#aSOFTWARE_INSTALL_STATE[152]=1 # Avahi (pulled in by O!MPD)
			aSOFTWARE_INSTALL_STATE[163]=1 # Gmrender

		fi

		#Additional Software required by moOde
		if (( ${aSOFTWARE_INSTALL_STATE[168]} == 1 )); then

			#aSOFTWARE_INSTALL_STATE[36]=1 # Squeezelite # Disabled/optional
			#aSOFTWARE_INSTALL_STATE[37]=1 # Shairport Sync # Disabled/optional
			#aSOFTWARE_INSTALL_STATE[60]=1 # WiFi Hotspot # Installed as per moOde docs

			G_DIETPI-NOTIFY 2 "${aSOFTWARE_WHIP_NAME[128]} will be installed"
			aSOFTWARE_INSTALL_STATE[128]=1 # MPD

			G_DIETPI-NOTIFY 2 "${aSOFTWARE_WHIP_NAME[78]} will be installed"
			aSOFTWARE_INSTALL_STATE[78]=1 # LESP, override user choice for now.

			G_DIETPI-NOTIFY 2 "${aSOFTWARE_WHIP_NAME[1]} will be installed"
			aSOFTWARE_INSTALL_STATE[1]=1 # Samba Client

			G_DIETPI-NOTIFY 2 "${aSOFTWARE_WHIP_NAME[96]} will be installed"
			aSOFTWARE_INSTALL_STATE[96]=1 # Samba Server

		fi

		#Additional Software required by Google AIY
		if (( ${aSOFTWARE_INSTALL_STATE[169]} == 1 )); then

			aSOFTWARE_INSTALL_STATE[69]=1 # RPi.GPIO
			#aSOFTWARE_INSTALL_STATE[130]=1 # python-pip, enabled in #Software that requires Python-Pip

		fi

		#Software that requires Avahi-Daemon
		index=152
		if (( ${aSOFTWARE_INSTALL_STATE[31]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[37]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[128]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[138]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[163]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[168]} == 1 )); then

			if (( ${aSOFTWARE_INSTALL_STATE[$index]} == 0 )); then

				aSOFTWARE_INSTALL_STATE[$index]=1

				#aSOFTWARE_WHIP_NAME
				G_DIETPI-NOTIFY 2 "${aSOFTWARE_WHIP_NAME[$index]} will be installed"

			fi

		fi

		#Software that requires Mono
		if (( ${aSOFTWARE_INSTALL_STATE[41]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[144]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[145]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[147]} == 1 )); then

			if (( ${aSOFTWARE_INSTALL_STATE[150]} == 0 )); then

				aSOFTWARE_INSTALL_STATE[150]=1

				G_DIETPI-NOTIFY 2 "Mono runtime libary will be installed"

			fi

		fi

		#Software that requires SDL2:
		if (( ${aSOFTWARE_INSTALL_STATE[108]} == 1 )); then

			if (( ${aSOFTWARE_INSTALL_STATE[140]} == 0 )); then

				aSOFTWARE_INSTALL_STATE[140]=1

				G_DIETPI-NOTIFY 2 "SDL2 will be installed"

			fi

		fi

		#Software that requires Python-Pip: https://github.com/Fourdee/DietPi/issues/784
		if (( ${aSOFTWARE_INSTALL_STATE[58]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[99]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[118]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[136]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[139]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[142]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[153]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[169]} == 1 )); then

			if (( ${aSOFTWARE_INSTALL_STATE[130]} == 0 )); then

				aSOFTWARE_INSTALL_STATE[130]=1

				G_DIETPI-NOTIFY 2 "Python-Pip will be installed"

			fi

		fi

		#Software that requires MPD
		#	YMPD
		#	Cava
		#	OMPD
		if (( ${aSOFTWARE_INSTALL_STATE[32]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[119]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[129]} == 1 )); then

			if (( ${aSOFTWARE_INSTALL_STATE[128]} == 0 )); then

				# - Flag for install
				aSOFTWARE_INSTALL_STATE[128]=1

				G_DIETPI-NOTIFY 2 "MPD will be installed"

			fi

		fi

		#OMV (requires Samba, Proftpd)
		if (( ${aSOFTWARE_INSTALL_STATE[126]} == 1 )); then

			#Proftpd
			if (( ${aSOFTWARE_INSTALL_STATE[94]} == 0 )); then

				aSOFTWARE_INSTALL_STATE[94]=1

				G_DIETPI-NOTIFY 2 "ProFTP will be installed"

			fi

			#Samba
			if (( ${aSOFTWARE_INSTALL_STATE[96]} == 0 )); then

				aSOFTWARE_INSTALL_STATE[96]=1

				G_DIETPI-NOTIFY 2 "Samba Server will be installed"

			fi

		fi

		#Software that requires Redis
		if (( ${aSOFTWARE_INSTALL_STATE[47]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[114]} == 1 )); then

			if (( ${aSOFTWARE_INSTALL_STATE[91]} == 0 )); then

				aSOFTWARE_INSTALL_STATE[91]=1

				G_DIETPI-NOTIFY 2 "Redis will be installed"

			fi

		fi

		#-------------------------------------------------------------------------
		#Pre-req software, for items that do DO have their own array aSOFTWARE_REQUIRES_SOFTWARENAME
		#	WEBSERVER - Manual stack install
		#	 - Define extra DietPi install flags for WEBSERVER_STACKS
		#LLAP
		if (( ${aSOFTWARE_INSTALL_STATE[82]} == 1 )); then
			aSOFTWARE_INSTALL_STATE[84]=1
			aSOFTWARE_INSTALL_STATE[88]=1
			aSOFTWARE_INSTALL_STATE[89]=1
		fi

		#LLSP
		if (( ${aSOFTWARE_INSTALL_STATE[81]} == 1 )); then
			aSOFTWARE_INSTALL_STATE[84]=1
			aSOFTWARE_INSTALL_STATE[87]=1
			aSOFTWARE_INSTALL_STATE[89]=1
		fi

		#LEAP
		if (( ${aSOFTWARE_INSTALL_STATE[79]} == 1 )); then
			aSOFTWARE_INSTALL_STATE[85]=1
			aSOFTWARE_INSTALL_STATE[88]=1
			aSOFTWARE_INSTALL_STATE[89]=1
		fi

		#LESP
		if (( ${aSOFTWARE_INSTALL_STATE[78]} == 1 )); then
			aSOFTWARE_INSTALL_STATE[85]=1
			aSOFTWARE_INSTALL_STATE[87]=1
			aSOFTWARE_INSTALL_STATE[89]=1
		fi

		#LAAP
		if (( ${aSOFTWARE_INSTALL_STATE[76]} == 1 )); then
			aSOFTWARE_INSTALL_STATE[83]=1
			aSOFTWARE_INSTALL_STATE[88]=1
			aSOFTWARE_INSTALL_STATE[89]=1
		fi

		#LASP
		if (( ${aSOFTWARE_INSTALL_STATE[75]} == 1 )); then
			aSOFTWARE_INSTALL_STATE[83]=1
			aSOFTWARE_INSTALL_STATE[87]=1
			aSOFTWARE_INSTALL_STATE[89]=1
		fi

		#WEBSERVER - Auto install via choice system
		for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
		do

			if (( ${aSOFTWARE_REQUIRES_WEBSERVER[$i]} &&
				${aSOFTWARE_INSTALL_STATE[$i]} == 1 )); then

				# - Check for existing webserver base (eg: apache2/nginx) installation
				#FOURDEE: We may want to check dpkg for installed packages also?
				if (( ! ${aSOFTWARE_INSTALL_STATE[83]} &&
					! ${aSOFTWARE_INSTALL_STATE[84]} &&
					! ${aSOFTWARE_INSTALL_STATE[85]} )); then

					# - None found, Select one for Install, based on user preference
					if (( $INDEX_WEBSERVER_TARGET == 0 )); then

						#WEBSERVER_APACHE
						aSOFTWARE_INSTALL_STATE[83]=1
						G_DIETPI-NOTIFY 2 "Apache2 will be installed"

					elif (( $INDEX_WEBSERVER_TARGET == -1 )); then

						#WEBSERVER_NGINX
						aSOFTWARE_INSTALL_STATE[85]=1
						G_DIETPI-NOTIFY 2 "Nginx will be installed"

					elif (( $INDEX_WEBSERVER_TARGET == -2 )); then

						#WEBSERVER_LIGHTTPD
						aSOFTWARE_INSTALL_STATE[84]=1
						G_DIETPI-NOTIFY 2 "Lighttpd will be installed"

					fi

					# - Always install WEBSERVER_PHP
					aSOFTWARE_INSTALL_STATE[89]=1
					G_DIETPI-NOTIFY 2 "PHP will be installed"

				fi

				break

			fi

		done

		#WEBSERVER_MYSQL
		for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
		do

			if (( ${aSOFTWARE_REQUIRES_MYSQL[$i]} &&
				${aSOFTWARE_INSTALL_STATE[$i]} == 1 )); then

				# - Check for existing MariaDB installations
				if (( ! ${aSOFTWARE_INSTALL_STATE[88]} )); then

					#WEBSERVER_MARIADB as new default
					aSOFTWARE_INSTALL_STATE[88]=1

					G_DIETPI-NOTIFY 2 "MariaDB will be installed"

				fi

				break

			fi

		done

		#WEBSERVER_SQLITE
		for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
		do

			if (( ${aSOFTWARE_REQUIRES_SQLITE[$i]} &&
				${aSOFTWARE_INSTALL_STATE[$i]} == 1 )); then

				#WEBSERVER_SQLITE
				aSOFTWARE_INSTALL_STATE[87]=1

				G_DIETPI-NOTIFY 2 "SQlite will be installed"

				break

			fi

		done

		#WEBSERVER - Check for stacks and flag as installing
		#WEBSERVER_APACHE
		if (( ${aSOFTWARE_INSTALL_STATE[83]} >= 1 )); then

			#SQLite
			if (( ${aSOFTWARE_INSTALL_STATE[87]} >= 1 )); then

				#WEBSERVER_LASP
				aSOFTWARE_INSTALL_STATE[75]=1

			fi

			#MariaDB
			if (( ${aSOFTWARE_INSTALL_STATE[88]} >= 1 )); then

				#WEBSERVER_LAAP
				aSOFTWARE_INSTALL_STATE[76]=1

			fi


		#WEBSERVER_NGINX
		elif (( ${aSOFTWARE_INSTALL_STATE[85]} >= 1 )); then

			#SQLite
			if (( ${aSOFTWARE_INSTALL_STATE[87]} >= 1 )); then

				#WEBSERVER_LESP
				aSOFTWARE_INSTALL_STATE[78]=1

			fi

			#MariaDB
			if (( ${aSOFTWARE_INSTALL_STATE[88]} >= 1 )); then

				#WEBSERVER_LEAP
				aSOFTWARE_INSTALL_STATE[79]=1

			fi

		#WEBSERVER_LIGHTTPD
		elif (( ${aSOFTWARE_INSTALL_STATE[84]} >= 1 )); then

			#SQLite
			if (( ${aSOFTWARE_INSTALL_STATE[87]} >= 1 )); then

				#WEBSERVER_LLSP
				aSOFTWARE_INSTALL_STATE[81]=1

			fi

			#MariaDB
			if (( ${aSOFTWARE_INSTALL_STATE[88]} >= 1 )); then

				#WEBSERVER_LLAP
				aSOFTWARE_INSTALL_STATE[82]=1

			fi


		fi

		#DESKTOP
		for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
		do

			if (( ${aSOFTWARE_REQUIRES_DESKTOP[$i]} &&
				${aSOFTWARE_INSTALL_STATE[$i]} == 1 )); then

				# - If no desktop is selected or installed (0), default to LXDE
				if (( ! ${aSOFTWARE_INSTALL_STATE[23]} &&
					! ${aSOFTWARE_INSTALL_STATE[24]} &&
					! ${aSOFTWARE_INSTALL_STATE[25]} &&
					! ${aSOFTWARE_INSTALL_STATE[26]} )); then

					aSOFTWARE_INSTALL_STATE[23]=1
					G_DIETPI-NOTIFY 2 "LXDE desktop will be installed"

				fi

				break

			fi

		done

		#GIT
		for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
		do

			if (( ${aSOFTWARE_REQUIRES_GIT[$i]} &&
				${aSOFTWARE_INSTALL_STATE[$i]} == 1 )); then

				# - Flag for install
				aSOFTWARE_INSTALL_STATE[17]=1

				G_DIETPI-NOTIFY 2 "Git will be installed"

				break

			fi

		done

		#BUILDESSENTIAL
		for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
		do

			if (( ${aSOFTWARE_REQUIRES_BUILDESSENTIAL[$i]} &&
				${aSOFTWARE_INSTALL_STATE[$i]} == 1 )); then

				# - Flag for install
				aSOFTWARE_INSTALL_STATE[16]=1

				G_DIETPI-NOTIFY 2 "Build-Essential will be installed"

				break

			fi

		done

		#RSYSLOG
		for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
		do

			if (( ${aSOFTWARE_REQUIRES_RSYSLOG[$i]} &&
				${aSOFTWARE_INSTALL_STATE[$i]} == 1 )); then

				# - Flag for install
				aSOFTWARE_INSTALL_STATE[102]=1

				G_DIETPI-NOTIFY 2 "Rsyslog will be installed"

				break

			fi

		done

		#FFMPEG
		for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
		do

			if (( ${aSOFTWARE_REQUIRES_FFMPEG[$i]} &&
				${aSOFTWARE_INSTALL_STATE[$i]} == 1 )); then

				# - Flag for install
				aSOFTWARE_INSTALL_STATE[7]=1

				G_DIETPI-NOTIFY 2 "FFmpeg will be installed"

				break

			fi

		done

		#ORACLEJAVA
		for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
		do

			if (( ${aSOFTWARE_REQUIRES_ORACLEJAVA[$i]} &&
				${aSOFTWARE_INSTALL_STATE[$i]} == 1 )); then

				# - Flag for install
				aSOFTWARE_INSTALL_STATE[8]=1

				G_DIETPI-NOTIFY 2 "OpenJDK 8 will be installed"

				break

			fi

		done

		#NODEJS
		for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
		do

			if (( ${aSOFTWARE_REQUIRES_NODEJS[$i]} &&
				${aSOFTWARE_INSTALL_STATE[$i]} == 1 )); then

				# - Flag for install
				aSOFTWARE_INSTALL_STATE[9]=1

				G_DIETPI-NOTIFY 2 "NodeJS will be installed"

				break

			fi

		done

		#ALSA
		for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
		do

			if (( ${aSOFTWARE_REQUIRES_ALSA[$i]} &&
				${aSOFTWARE_INSTALL_STATE[$i]} == 1 )); then

				# - Flag for install
				aSOFTWARE_INSTALL_STATE[5]=1

				G_DIETPI-NOTIFY 2 "Alsa will be installed"

				break

			fi

		done

		#XSERVERXORG
		for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
		do

			if (( ${aSOFTWARE_REQUIRES_XSERVERXORG[$i]} &&
				${aSOFTWARE_INSTALL_STATE[$i]} == 1 )); then

				# - Flag for install
				aSOFTWARE_INSTALL_STATE[6]=1

				G_DIETPI-NOTIFY 2 "Xserver will be installed"

				break

			fi

		done

	}

	Create_Desktop_Shared_Items(){

		#Copy DietPi favourite links
		wget http://dietpi.com/downloads/conf/desktop/.gtk-bookmarks -O "$HOME"/.gtk-bookmarks

		#Create Desktop SymLinks
		mkdir -p "$HOME"/Desktop
		ln -sf /usr/share/applications/htop.desktop "$HOME"/Desktop/htop.desktop

		#DietPi Menu symlinks
		mkdir -p /usr/share/applications
		wget http://dietpi.com/downloads/conf/desktop/dietpi-software.desktop -O /usr/share/applications/dietpi-software.desktop
		wget http://dietpi.com/downloads/conf/desktop/dietpi-update.desktop -O /usr/share/applications/dietpi-update.desktop
		wget http://dietpi.com/downloads/conf/desktop/dietpi-config.desktop -O /usr/share/applications/dietpi-config.desktop
		wget http://dietpi.com/downloads/conf/desktop/dietpi-backup.desktop -O /usr/share/applications/dietpi-backup.desktop
		wget http://dietpi.com/downloads/conf/desktop/dietpi-sync.desktop -O /usr/share/applications/dietpi-sync.desktop
		wget http://dietpi.com/downloads/conf/desktop/dietpi-bugreport.desktop -O /usr/share/applications/dietpi-bugreport.desktop
		wget http://dietpi.com/downloads/conf/desktop/dietpi-process_tool.desktop -O /usr/share/applications/dietpi-process_tool.desktop
		wget http://dietpi.com/downloads/conf/desktop/dietpi-cleaner.desktop -O /usr/share/applications/dietpi-cleaner.desktop
		wget http://dietpi.com/downloads/conf/desktop/dietpi-cron.desktop -O /usr/share/applications/dietpi-cron.desktop
		wget http://dietpi.com/downloads/conf/desktop/dietpi-launcher.desktop -O /usr/share/applications/dietpi-launcher.desktop
		wget http://dietpi.com/downloads/conf/desktop/dietpi-justboom.desktop -O /usr/share/applications/dietpi-justboom.desktop

		#DietPi Desktop symlinks
		ln -sf /usr/share/applications/dietpi-software.desktop "$HOME"/Desktop/dietpi-software.desktop
		ln -sf /usr/share/applications/dietpi-config.desktop "$HOME"/Desktop/dietpi-config.desktop
		ln -sf /usr/share/applications/dietpi-launcher.desktop "$HOME"/Desktop/dietpi-launcher.desktop

		#Download icons
		mkdir -p /var/lib/dietpi/dietpi-software/installed/desktop_icons
		wget http://dietpi.com/downloads/conf/desktop/dietpi-icon.png -O /var/lib/dietpi/dietpi-software/installed/desktop_icons/dietpi-icon.png
		wget http://dietpi.com/downloads/conf/desktop/grey_16x16.png -O /var/lib/dietpi/dietpi-software/installed/desktop_icons/grey_16x16.png
		wget http://dietpi.com/downloads/conf/desktop/kodi-icon.png -O /var/lib/dietpi/dietpi-software/installed/desktop_icons/kodi-icon.png
		wget http://dietpi.com/downloads/conf/desktop/justboom.png -O /var/lib/dietpi/dietpi-software/installed/desktop_icons/justboom.png

		# - Replace icon dir in .desktop from /etc/dietpi/desktop_icons
		sed -i 's#^Icon=/etc/dietpi/desktop_icons#Icon=/var/lib/dietpi/dietpi-software/installed/desktop_icons#g' /usr/share/applications/*.desktop

		# - Set execute to prevent "untrusted" prompt in Mate, and possibily other desktops.
		chmod +x /usr/share/applications/*
		chmod +x "$HOME"/Desktop/*

	}

	Create_UserContent_Folders(){

		mkdir -p "$G_FP_DIETPI_USERDATA"/"$FOLDER_MUSIC"
		mkdir -p "$G_FP_DIETPI_USERDATA"/"$FOLDER_PICTURES"
		mkdir -p "$G_FP_DIETPI_USERDATA"/"$FOLDER_VIDEO"
		mkdir -p "$G_FP_DIETPI_USERDATA"/"$FOLDER_DOWNLOADS"

	}

	Download_Test_Media(){

		if [ ! -f "$G_FP_DIETPI_USERDATA/$FOLDER_MUSIC"/fourdee_tech.ogg ]; then

			#Grab My test music
			wget http://dietpi.com/downloads/audio/fourdee_tech.ogg -O "$G_FP_DIETPI_USERDATA/$FOLDER_MUSIC"/fourdee_tech.ogg
			#wget http://dietpi.com/downloads/audio/fourdee_space.mp3 -O "$G_FP_DIETPI_USERDATA/$FOLDER_MUSIC"/fourdee_space.mp3

			#Grab Absolute Radio Streams
			wget http://network.absoluteradio.co.uk/core/audio/ogg/live.pls?service=vrbb -O "$G_FP_DIETPI_USERDATA/$FOLDER_MUSIC"/Absolute-Radio.pls
			wget http://network.absoluteradio.co.uk/core/audio/ogg/live.pls?service=a8bb -O "$G_FP_DIETPI_USERDATA/$FOLDER_MUSIC"/Absolute-Radio-80s.pls
			wget http://network.absoluteradio.co.uk/core/audio/ogg/live.pls?service=a9bb -O "$G_FP_DIETPI_USERDATA/$FOLDER_MUSIC"/Absolute-Radio-90s.pls
			wget http://network.absoluteradio.co.uk/core/audio/ogg/live.pls?service=a0bb -O "$G_FP_DIETPI_USERDATA/$FOLDER_MUSIC"/Absolute-Radio-00s.pls

		fi

	}

	#Return optimization values for BitTorrent servers based on device and hardware capabilities.
	Optimize_BitTorrent(){

		local output=0

		local gigabit_device=1
		# - Lets hope the next RPi device is finally gigabit capable. I'll cry if it is not.
		if (( $G_HW_MODEL <= 3 || $G_HW_MODEL == 30 || $G_HW_MODEL == 32 || $G_HW_MODEL == 40 || $G_HW_MODEL == 60 || $G_HW_MODEL == 70 )); then

			gigabit_device=0

		fi

		#Cache size (MB) 1/10th of total mem
		if (( $1 == 0 )); then

			output=$(( $RAM_TOTAL / 10 ))

		#Max active downloads
		elif (( $1 == 1 )); then

			output=2

			# - Bump up for VM's
			if (( $G_HW_MODEL == 20 || $G_HW_MODEL == 21 )); then

				output=3

			fi

		#Max global connections
		elif (( $1 == 2 )); then

			output=20

			# - Bump up for VM's
			if (( $G_HW_MODEL == 20 || $G_HW_MODEL == 21 )); then

				output=40

			# - 1Gbit SBC's
			elif (( $gigabit_device )); then

				output=30

			# - Reduce for RPi's. This is due to the USB bus ethernet in the ARM SoC, which cripples network throughput/performance/latency.
			# - RPi v3
			elif (( $G_HW_MODEL == 3 )); then

				output=15

			# - RPi v2
			elif (( $G_HW_MODEL == 2 )); then

				output=13

			# - RPi v1 256/512
			elif (( $G_HW_MODEL <= 1 )); then

				output=7

			fi

		#Max upload slots
		elif (( $1 == 3 )); then

			output=3

			# - Bump up for VM's
			if (( $G_HW_MODEL == 20 || $G_HW_MODEL == 21 )); then

				output=5

			# - 1Gbit devices
			elif (( $gigabit_device )); then

				output=4

			# - Reduce for RPi's. This is due to the USB bus ethernet in the ARM SoC, which cripples network throughput/performance/latency.
			elif (( $G_HW_MODEL <= 3 )); then

				output=2

			fi

		fi

		echo $output

	}

	#/////////////////////////////////////////////////////////////////////////////////////
	# This function handles the installation of the selected software.
	#
	# Reference:
	# - Adding new software to DietPi-Software
	#   https://github.com/Fourdee/DietPi/issues/490#issuecomment-244416570
	#
	# Installing the software:
	# ------------------------------------
	# - INSTALLING_INDEX:
	#   This has to be the same number as index_current for the software list above.
	#
	# - INSTALL_URL_ADDRESS:
	#   This can be used to check conectivity to items you need to download later.
	#   A good example would also be a git repo.
	#
	# Example:
	#	#------------------ Bittorrent: HTPC Manager ------------------
	#	INSTALLING_INDEX=155
	#	if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then
	#
	#		Banner_Installing
	#
	#		INSTALL_URL_ADDRESS='https://github.com/Hellowlol/HTPC-Manager.git'
	#
	#		G_CHECK_URL "$INSTALL_URL_ADDRESS"
	#
	#		#Install Python and PIP
	#		G_AGI python python-pip python-imaging
	#
	#		cd "$HOME"
	#		git clone --depth=1 "$INSTALL_URL_ADDRESS"
	#
	#		# - Move HTPC Manager to a 'better' location
	#		mkdir -p "$G_FP_DIETPI_USERDATA"/htpc-manager
	#		mv "$HOME"/HTPC-Manager/* "$G_FP_DIETPI_USERDATA"/htpc-manager/
	#		rm -R "$HOME"/HTPC-Manager
	#
	#	fi
	#
	#/////////////////////////////////////////////////////////////////////////////////////
	Install_Dietpi_Software(){

		#--------------------------------------------------------------
		#Install Software

		#Desktop LXDE
		INSTALLING_INDEX=23
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			# - For desktop entries/icons hosted on dietpi.com
			INSTALL_URL_ADDRESS='http://dietpi.com/downloads/conf/desktop'

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			G_AGI lxde upower policykit-1 iceweasel p7zip-full --no-install-recommends
			#upower policykit-1. Needed for LXDE logout menu item to show shutdown/restart ......

		fi

		#Desktop MATE
		INSTALLING_INDEX=24
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			# - For desktop entries/icons hosted on dietpi.com
			INSTALL_URL_ADDRESS='http://dietpi.com/downloads/conf/desktop'

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			G_AGI mate-desktop-environment-extras upower policykit-1 iceweasel p7zip-full --no-install-recommends

		fi

		#Desktop GNUStep
		INSTALLING_INDEX=26
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			# - For desktop entries/icons hosted on dietpi.com
			INSTALL_URL_ADDRESS='http://dietpi.com/downloads/conf/desktop'

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			G_AGI x-window-system-core wmaker gnustep gnustep-devel gnustep-games libc-dbg upower policykit-1 iceweasel p7zip-full --no-install-recommends

		fi

		#DESKTOP_XFCE
		INSTALLING_INDEX=25
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			# - For desktop entries/icons hosted on dietpi.com
			INSTALL_URL_ADDRESS='http://dietpi.com/downloads/conf/desktop'

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			G_AGI xfce4 xfce4-terminal gnome-icon-theme tango-icon-theme iceweasel p7zip-full --no-install-recommends

		fi

		#XRDP
		INSTALLING_INDEX=29
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			G_AGI xrdp

		fi

		#NOMACHINE
		INSTALLING_INDEX=30
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			INSTALL_DESCRIPTION="NoMachine (Secure RDP Server & Client)"

			#x86_64
			if (( $G_HW_ARCH == 10 )); then

				INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/nomachine_5.1.44_1_amd64.deb'

			#arm6 (RPi1)
			elif (( $G_HW_ARCH == 1 )); then

				INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/nomachine_5.1.44_3_armv6hf.deb'

			#arm7+ (RPi 2/3)
			elif (( $G_HW_ARCH == 2 )); then

				INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/nomachine_5.1.44_armhf.deb'

			fi

			# Now, check that the links are legitimate
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget "$INSTALL_URL_ADDRESS" -O package.deb
			dpkg -i package.deb
			rm package.deb

		fi

		#BitTorrent Transmission
		INSTALLING_INDEX=44
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI transmission-daemon

		fi

		#ProFTPd
		INSTALLING_INDEX=94
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			echo -e "proftpd-basic shared/proftpd/inetd_or_standalone select standalone" | debconf-set-selections
			G_AGI proftpd-basic

		fi

		#Samba Server
		INSTALLING_INDEX=96
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI samba samba-common-bin --no-install-recommends

		fi

		#vsFTPD
		INSTALLING_INDEX=95
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			G_AGI vsftpd --no-install-recommends

		fi

		#NFS_SERVER
		INSTALLING_INDEX=109
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			G_AGI nfs-kernel-server nfs-common ucf rpcbind

		fi

		#WEBSERVER_APACHE
		INSTALLING_INDEX=83
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI apache2

		fi

		#WEBSERVER_NGINX
		INSTALLING_INDEX=85
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI nginx xml-core --no-install-recommends

		fi

		#WEBSERVER_LIGHTTPD
		INSTALLING_INDEX=84
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI lighttpd

		fi

		#WEBSERVER_MARIADB
		INSTALLING_INDEX=88
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			# In case remove old symlink, created by DietPi MariaDB installation, otherwise installation will fail.
			# This will not remove the folder in case, without "-R".
			[ "$(readlink /var/lib/mysql)" ] && [ ! -d "$(readlink /var/lib/mysql)/mysql" ] && rm /var/lib/mysql
			G_AGI mariadb-server

		fi

		#WEBSERVER_SQLITE
		INSTALLING_INDEX=87
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI sqlite3

		fi

		#WEBSERVER_REDIS
		INSTALLING_INDEX=91
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI redis-server
			#Redis php module | == 2 to check for existing installs, if == 1, then module will be installed together with PHP, to prevent dependency installations
			if (( ${aSOFTWARE_INSTALL_STATE[89]} == 2 )); then

				G_AGI "$PHP_APT_PACKAGE_NAME"-redis

			fi

		fi

		#WEBSERVER_PHP
		INSTALLING_INDEX=89
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#Install base PHP packages/modules.
			if (( ${aSOFTWARE_INSTALL_STATE[83]} >= 1 )); then

				G_AGI "$PHP_APT_PACKAGE_NAME" libapache2-mod-"$PHP_APT_PACKAGE_NAME"

			else

				G_AGI "$PHP_APT_PACKAGE_NAME"-fpm "$PHP_APT_PACKAGE_NAME"-cgi
				# 'php-xsl' does not exist for >= Stretch, 'php7.0-xsl' is just dummy for 'php7.0-xml': https://github.com/Fourdee/DietPi/issues/1286
				(( $G_DISTRO < 4 )) && G_AGI php5-xsl

			fi

			#php-common modules, used by most web software
			G_AGI "$PHP_APT_PACKAGE_NAME"-curl "$PHP_APT_PACKAGE_NAME"-gd "$PHP_APT_PACKAGE_NAME"-apcu "$PHP_APT_PACKAGE_NAME"-mcrypt

			# + stretch extras
			if (( $G_DISTRO >= 4 )); then

				G_AGI "$PHP_APT_PACKAGE_NAME"-mbstring "$PHP_APT_PACKAGE_NAME"-zip "$PHP_APT_PACKAGE_NAME"-xml

			fi

			#php-SQL modules
			if (( ${aSOFTWARE_INSTALL_STATE[86]} >= 1 )); then

				G_AGI "$PHP_APT_PACKAGE_NAME"-mysql

			fi

			if (( ${aSOFTWARE_INSTALL_STATE[88]} >= 1 )); then

				if (( $G_DISTRO < 4 )); then
					#For <= Jessie, php5-mysqlnd provides the newer mysql client libraries compared to php5-mysql.
					G_AGI "$PHP_APT_PACKAGE_NAME"-mysqlnd

				else
					#For >= Stretch, php(7.X)-mysqlnd does not exist, thus php-mysql need to be installed: https://packages.debian.org/de/stretch/php-mysql
					G_AGI "$PHP_APT_PACKAGE_NAME"-mysql

				fi

			fi

			if (( ${aSOFTWARE_INSTALL_STATE[87]} >= 1 )); then

				G_AGI "$PHP_APT_PACKAGE_NAME"-sqlite* #wildcard for version (eg:3)

			fi

			#Redis php module
			if (( ${aSOFTWARE_INSTALL_STATE[91]} >= 1 )); then

				G_AGI "$PHP_APT_PACKAGE_NAME"-redis

			fi

		fi

		#WEBSERVER_MYADMINPHP
		INSTALLING_INDEX=90
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#MySQL must be running during install to allow debconf setup.
			G_RUN_CMD systemctl start mysql

			# Set password parameters before installing
			debconf-set-selections <<< "phpmyadmin phpmyadmin/dbconfig-install boolean true"
			debconf-set-selections <<< "phpmyadmin phpmyadmin/mysql/app-pass password $GLOBAL_PW"
			debconf-set-selections <<< "phpmyadmin phpmyadmin/app-password-confirm password $GLOBAL_PW"

			if (( ${aSOFTWARE_INSTALL_STATE[83]} == 1 )); then

				debconf-set-selections <<< "phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2"

			elif (( ${aSOFTWARE_INSTALL_STATE[84]} == 1 )); then

				debconf-set-selections <<< "phpmyadmin phpmyadmin/reconfigure-webserver multiselect lighttpd"

			else

				debconf-set-selections <<< "phpmyadmin phpmyadmin/reconfigure-webserver multiselect none"

			fi

			G_AGI phpmyadmin

		fi

		#MPD
		INSTALLING_INDEX=128
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#Jessie
			if (( $G_DISTRO == 3 )); then

				#MPD not available in Jessie Repo for ARMv8
				if (( $G_HW_ARCH == 3 )); then

					INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/mpd_0.19.21_arm64.deb'
					G_CHECK_URL "$INSTALL_URL_ADDRESS"

					#libupnp6 for net discov with upnp/avahi
					G_AGI libupnp6
					G_AGI libmpdclient2 libao-common libao4 libasound2 libasound2-data libasyncns0 libaudiofile1 libavahi-client3 libavahi-common-data libavahi-common3 libavcodec56 libavformat56 libavresample2 libavutil54 libbinio1ldbl libcaca0 libcdio-cdda1 libcdio-paranoia1 libcdio13 libcups2 libcurl3-gnutls libdirectfb-1.2-9 libdnet libfaad2 libflac8 libfluidsynth1 libgme0 libgomp1 libgsm1 libice6 libid3tag0 libiso9660-8 libjack-jackd2-0 libjson-c2 libldb1 libmad0 libmikmod3 libmms0 libmodplug1 libmp3lame0 libmpcdec6 libmpg123-0 libnfs4 libntdb1 libogg0 libopenal-data libopenal1 libopenjpeg5 libopus0 liborc-0.4-0 libpulse0 libresid-builder0c2a libroar2 libsamplerate0 libschroedinger-1.0-0 libsdl1.2debian libshout3 libsidplay2 libsidutils0 libslp1 libsm6 libsmbclient libsndfile1 libsoxr0 libspeex1 libspeexdsp1 libsqlite3-0 libtalloc2 libtdb1 libtevent0 libtheora0 libupnp6 libva1 libvorbis0a libvorbisenc2 libvorbisfile3 libvpx1 libwavpack1 libwbclient0 libwildmidi-config libwildmidi1 libx11-6 libx11-data libx11-xcb1 libx264-142 libxau6 libxcb1 libxdmcp6 libxext6 libxi6 libxtst6 libxvidcore4 libyajl2 libzzip-0-13 mime-support python python-talloc python2.7 samba-libs x11-common file --no-install-recommends

					wget "$INSTALL_URL_ADDRESS" -O package.deb
					dpkg -i package.deb
					rm package.deb

				else

					G_AGI mpd

				fi

			#Stretch+
			else

				INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/mpd_0.20.11-1_'

				#armv6
				if (( $G_HW_ARCH == 1 )); then

					INSTALL_URL_ADDRESS+='armv6'

				#armv7+
				elif (( $G_HW_ARCH == 2 )); then

					INSTALL_URL_ADDRESS+='armv7'

				#ARMv8
				elif (( $G_HW_ARCH == 3 )); then

					INSTALL_URL_ADDRESS+='armv8'

				#x86_64
				elif (( $G_HW_ARCH == 10 )); then

					INSTALL_URL_ADDRESS+='amd64'

				fi

				INSTALL_URL_ADDRESS+='.deb'

				G_CHECK_URL "$INSTALL_URL_ADDRESS"

				#Prereqs
				G_AGI libmpdclient2 libflac8 libyajl2 libavahi-client3 libvorbisfile3 libwavpack1 libmad0 libmpg123-0 libopus0 libavformat57 libfaad2 libcdio-paranoia1 libiso9660-8 libshout3 libid3tag0

				apt-mark unhold mpd &> /dev/null #??? Not required for dpkg -i installs

				wget "$INSTALL_URL_ADDRESS" -O package.deb
				dpkg -i package.deb
				rm package.deb

				apt-mark hold mpd # prevent repo updates from overwriting

			fi

		fi

		#Forums PHPBB
		INSTALLING_INDEX=54
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://www.phpbb.com/files/release/phpBB-3.2.1.zip'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget "$INSTALL_URL_ADDRESS" -O package.zip
			unzip -o package.zip -d /var/www
			rm package.zip

		fi

		#OPENBAZAAR
		INSTALLING_INDEX=58
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://github.com/OpenBazaar/OpenBazaar-Server.git'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			G_AGI libsodium-dev automake autoconf pkg-config libtool libssl-dev libffi-dev python-dev openssl libzmq3-dev

			#Not required.
			#G_AGI software-properties-common
			#add-apt-repository -y ppa:chris-lea/libsodium
			#G_AGUP

			pip install cryptography

			cd "$HOME"
			git clone --depth=1 https://github.com/zeromq/libzmq
			git clone --depth=1 https://github.com/pyca/pynacl/
			git clone --depth=1 "$INSTALL_URL_ADDRESS"

			# - compile
			cd "$HOME"/libzmq
			./autogen.sh && ./configure && make -j $G_HW_CPU_CORES
			make check && make install && ldconfig

			cd "$HOME"/pynacl
			python setup.py build && python setup.py install

			cd "$HOME"

			# - Move OpenBazaar to a 'better' location
			mkdir -p /etc/openbazaar-server
			mv "$HOME"/OpenBazaar-Server/* /etc/openbazaar-server/
			rm -R "$HOME"/OpenBazaar-Server

			# - install OpenBazaar
			cd /etc/openbazaar-server
			pip install -r requirements.txt

			cd "$HOME"

			# - Clean up, remove source libraries
			rm -R "$HOME"/libzmq
			rm -R "$HOME"/pynacl

		fi

		#YACY
		INSTALLING_INDEX=133
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='http://yacy.net/release/yacy_v1.92_20161226_9000.tar.gz'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget "$INSTALL_URL_ADDRESS" -O package.tar.gz
			tar xvf package.tar.gz -C /etc/
			rm package.tar.gz

		fi

		#ownCloud
		INSTALLING_INDEX=47
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			G_DIETPI-NOTIFY 2 'Installing needed PHP modules: https://doc.owncloud.org/server/latest/admin_manual/installation/source_installation.html#php-extensions'
			G_AGI "$PHP_APT_PACKAGE_NAME"-intl "$PHP_APT_PACKAGE_NAME"-redis

			if [ -f /var/www/owncloud/occ ]; then

				G_DIETPI-NOTIFY 2 'Existing ownCloud installation found, will NOT overwrite...'

			else

				local datadir="$(grep -m1 '^[[:blank:]]*SOFTWARE_OWNCLOUD_DATADIR=' /DietPi/dietpi.txt | sed 's/^.*=//')"
				[ -n "$datadir" ] || datadir="$G_FP_DIETPI_USERDATA/owncloud_data"
				if [ -f "$datadir"/dietpi-owncloud-installation-backup/occ ]; then

					G_DIETPI-NOTIFY 2 'ownCloud installation backup found, starting recovery...'
					G_RUN_CMD cp -a "$datadir"/dietpi-owncloud-installation-backup/. /var/www/owncloud

				else

					INSTALL_URL_ADDRESS='https://download.owncloud.org/community/owncloud-latest.zip'
					G_CHECK_URL "$INSTALL_URL_ADDRESS"
					G_RUN_CMD wget "$INSTALL_URL_ADDRESS" -O package.zip
					G_RUN_CMD unzip -o package.zip -d /var/www
					rm package.zip

				fi

			fi

		fi

		#Nextcloud
		INSTALLING_INDEX=114
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			G_DIETPI-NOTIFY 2 'Installing needed PHP modules: https://docs.nextcloud.com/server/12/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation'
			G_AGI "$PHP_APT_PACKAGE_NAME"-intl "$PHP_APT_PACKAGE_NAME"-redis

			if [ -f /var/www/nextcloud/occ ]; then

				G_DIETPI-NOTIFY 2 'Existing Nextcloud installation found, will NOT overwrite...'

			else

				local datadir="$(grep -m1 '^[[:blank:]]*SOFTWARE_NEXTCLOUD_DATADIR=' /DietPi/dietpi.txt | sed 's/^.*=//')"
				[ -n "$datadir" ] || datadir="$G_FP_DIETPI_USERDATA/nextcloudcloud_data"
				if [ -f "$datadir"/dietpi-nextcloud-installation-backup/occ ]; then

					G_DIETPI-NOTIFY 2 'Nextcloud installation backup found, starting recovery...'
					G_RUN_CMD cp -a "$datadir"/dietpi-nextcloud-installation-backup/. /var/www/nextcloud

				else

					INSTALL_URL_ADDRESS='https://download.nextcloud.com/server/releases/latest.zip'
					G_CHECK_URL "$INSTALL_URL_ADDRESS"
					G_RUN_CMD wget "$INSTALL_URL_ADDRESS" -O package.zip
					G_RUN_CMD unzip -o package.zip -d /var/www
					rm package.zip

				fi

			fi

		fi

		#YMPD
		INSTALLING_INDEX=32
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/ympd_1.2.3.7z'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget "$INSTALL_URL_ADDRESS" -O package.7z
			7z x -y package.7z

			local binary_name='ympd_'
			# - armv6
			if (( $G_HW_ARCH == 1 )); then

				binary_name+='armv6'

			# - armv7
			elif (( $G_HW_ARCH == 2 )); then

				binary_name+='armv7'

			# - arm64
			elif (( $G_HW_ARCH == 3 )); then

				binary_name+='armv8'

			# - x86_64
			elif (( $G_HW_ARCH == 10 )); then

				binary_name+='amd64'

			fi

			binary_name+="_$G_DISTRO_NAME"

			mv "$binary_name" /usr/bin/ympd
			chmod +x /usr/bin/ympd

			rm ympd_*
			rm package.7z

		fi

		#Roon Bridge
		INSTALLING_INDEX=121
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#x86_64
			if (( $G_HW_ARCH == 10 )); then

				INSTALL_URL_ADDRESS='http://download.roonlabs.com/builds/RoonBridge_linuxx64.tar.bz2'

			#ARMv8
			elif (( $G_HW_ARCH == 3 )); then

				INSTALL_URL_ADDRESS='http://download.roonlabs.com/builds/RoonBridge_linuxarmv8.tar.bz2'

			#ARMv7
			else

				INSTALL_URL_ADDRESS='http://download.roonlabs.com/builds/RoonBridge_linuxarmv7hf.tar.bz2'

			fi

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget "$INSTALL_URL_ADDRESS" -O package.tar.bz2
			tar xvf package.tar.bz2
			rm package.tar.bz2

			# - reinstall, clear dir, prevent mv fail on non-empty dir
			rm -R /etc/roonbridge &> /dev/null

			mkdir -p /etc/roonbridge
			mv RoonBridge/* /etc/roonbridge
			rm -R RoonBridge

		fi

		#CAVA
		INSTALLING_INDEX=119
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			# - armv6
			if (( $G_HW_ARCH == 1 )); then

				INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/cava_0.4.2_armv6.deb'

			# - armv7
			elif (( $G_HW_ARCH == 2 )); then

				INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/cava_0.4.2_armv7.deb'

			# - arm64
			elif (( $G_HW_ARCH == 3 )); then

				INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/cava_0.4.2_arm64.deb'

			fi

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			G_AGI libpulse0 libfftw3-3

			wget "$INSTALL_URL_ADDRESS" -O package.deb
			dpkg -i package.deb
			rm package.deb

			# + Font for cava, nice bars
			wget http://dietpi.com/downloads/binaries/all/cava.psf -O "$HOME"/cava.psf

		fi

		#Mopidy
		INSTALLING_INDEX=118
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://apt.mopidy.com/mopidy.gpg'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget -q -O - "$INSTALL_URL_ADDRESS" | apt-key add -
			# No Buster list available yet, use stretch.list for testing:
			if (( $G_DISTRO > 4 )); then

				wget https://apt.mopidy.com/stretch.list -O /etc/apt/sources.list.d/mopidy.list

			else

				wget https://apt.mopidy.com/"$G_DISTRO_NAME".list -O /etc/apt/sources.list.d/mopidy.list

			fi
			G_AGUP
			G_AGI mopidy

			#ARMv8
			#NB: No ARM64 packages currently exist in mopidy repo. So it will throw a minor error when updating apt.
			#Mopidy web client extensions not loading in webpage...
			# if (( $G_HW_ARCH == 3 )); then

				# G_AGI build-essential python-dev
				# pip install mopidy #no effect, claims already upto date.

			# fi

			pip install Mopidy-MusicBox-Webclient Mopidy-Local-Images

		fi

		#Kodi
		INSTALLING_INDEX=31
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#Odroids
			if (( $G_HW_MODEL >= 10 )) && (( $G_HW_MODEL < 20 )); then

				G_AGI kodi-odroid

				#XU4 - requires pulse audio (fixes corrupt sound)
				if (( $G_HW_MODEL == 11 )); then

					G_AGI pulseaudio --no-install-recommends

				fi

			#Everything else
			else

				G_AGI kodi

			fi

			# - libcurl3-gnutls required for C2. But lets apply to all: https://github.com/Fourdee/DietPi/issues/446
			G_AGI libcurl3-gnutls

			# - NFS/CEC support
			if (( $G_DISTRO >= 4 )); then

				G_AGI libnfs8 libcec4

			else

				G_AGI libnfs4 libcec3v4

			fi

		fi

		#MINIDLNA
		INSTALLING_INDEX=39
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI minidlna

		fi

		#NoIp
		INSTALLING_INDEX=67
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#x32 x64
			if (( $G_HW_MODEL == 20 || $G_HW_MODEL == 21 )); then

				INSTALL_URL_ADDRESS="http://dietpi.com/downloads/binaries/all/noip_x32_x64.zip"

			#ARMv8
			elif (( ( $G_HW_MODEL == 12 ) || ( $G_HW_MODEL >=40 && $G_HW_MODEL < 50 ) )); then

				INSTALL_URL_ADDRESS="http://dietpi.com/downloads/binaries/all/noip_arm64.zip"

			#armv6+
			else

				INSTALL_URL_ADDRESS="http://dietpi.com/downloads/binaries/all/noip_armhf.zip"

			fi
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			#NoIp Binary install
			wget "$INSTALL_URL_ADDRESS" -O dietpi-noip.zip
			unzip -o dietpi-noip.zip
			rm dietpi-noip.zip
			mv noip_binary /usr/local/bin/noip2
			chmod +x /usr/local/bin/noip2

		fi

		#amiberry
		INSTALLING_INDEX=108
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/amiberry-rpi_v2.1.1.7z'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			G_AGI alsa-oss joystick libsdl-image1.2 libsdl-ttf2.0-0 libsdl-gfx1.2-5 libguichan-0.8.1-1* libguichan-allegro-0.8.1-1* libguichan-sdl-0.8.1-1* libguichan-opengl-0.8.1-1* libjpgalleg4.4 libxml2 libmpg123-0

			#libmpeg2-4 # Required for dev branch

			# + SDL2
			G_AGI libpng12-0 libflac8 libmpg123-0 libgoogle-perftools4 libfreetype6 libxxf86vm1

			#Download binaries
			# - Backup existing autostart.uae for user
			mv "$G_FP_DIETPI_USERDATA"/amiberry/conf/autostart.uae "$G_FP_DIETPI_USERDATA"/amiberry/conf/autostart_pre-dietpi-update.uae &> /dev/null

			wget "$INSTALL_URL_ADDRESS" -O package.7z
			7z x -y package.7z -o/etc
			rm package.7z

		fi

		#dxx-rebirth
		INSTALLING_INDEX=112
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/rpi/dxx-rebirth.7z'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			G_AGI libsdl-mixer1.2 libsdl1.2debian libphysfs1

			wget "$INSTALL_URL_ADDRESS" -O package.7z
			7z x -y package.7z -o"$G_FP_DIETPI_USERDATA"
			rm package.7z

		fi

		#urbackup server
		INSTALLING_INDEX=111
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			if (( $G_HW_ARCH == 10 )); then

				INSTALL_URL_ADDRESS='http://hndl.urbackup.org/Server/2.1.20/urbackup-server_2.1.20_amd64.deb'

			elif (( $G_HW_ARCH == 1 || $G_HW_ARCH == 2 )); then

				INSTALL_URL_ADDRESS='http://hndl.urbackup.org/Server/2.1.20/urbackup-server_2.1.20_armhf.deb'

			#ARMv8 sourcebuild
			elif (( $G_HW_ARCH == 3 )); then

				INSTALL_URL_ADDRESS='http://hndl.urbackup.org/Server/2.1.20/urbackup-server-2.1.20.tar.gz'

			fi

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			#ARMv8 source build
			if (( $G_HW_ARCH == 3 )); then

				G_AGI build-essential zlib1g-dev libcurl4-openssl-dev libcrypto++-dev sqlite3

				wget "$INSTALL_URL_ADDRESS" -O package.tar
				tar xzvf package.tar
				rm package.tar

				cd urbackup-server-*

				./configure
				make -j $G_HW_CPU_CORES
				make install

				sed -i "/ExecStart=/c ExecStart=/usr/local/bin/urbackupsrv run --config /etc/default/urbackupsrv --no-consoletime" urbackup-server.service
				cp urbackup-server.service /etc/systemd/system/urbackupsrv.service
				cp defaults_server /etc/default/urbackupsrv
				cp logrotate_urbackupsrv /etc/logrotate.d/urbackupsrv

				cd ..

				rm -R urbackup-server-*

			#Deb
			else

				wget "$INSTALL_URL_ADDRESS" -O package.deb

				echo -e "urbackup-server urbackup/backuppath string $G_FP_DIETPI_USERDATA/urbackup" | debconf-set-selections
				dpkg -i package.deb

				apt-get -f install -y

				rm package.deb

			fi

		fi

		#OpenTyrian
		INSTALLING_INDEX=51
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS="http://dietpi.com/downloads/binaries/rpi/opentyrian_armhf.zip"
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			G_AGI ibsdl1.2debian libsdl-net1.2 --no-install-recommends

			#Download binaries
			wget "$INSTALL_URL_ADDRESS" -O package.zip
			unzip -o package.zip -d /
			rm package.zip
			chmod +x /usr/local/games/opentyrian/opentyrian

		fi

		#DietPi Cam
		INSTALLING_INDEX=59
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://github.com/Fourdee/RPi_Cam_Web_Interface/archive/6.2.29.zip'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			#Install pre-reqs
			G_AGI gpac motion

			#Get source/binaries and extract
			wget "$INSTALL_URL_ADDRESS" -O package.zip
			unzip -o package.zip
			rm package.zip

			cd RPi_Cam*

			#Config /etc/motion
			mkdir -p /etc/motion
			cp etc/motion/motion.conf.1 /etc/motion/motion.conf

			#Config /etc/raspimjpeg
			cp etc/raspimjpeg/raspimjpeg.1 /etc/raspimjpeg

			#Setup /var/www/dietpicam
			mkdir -p /var/www/dietpicam/media
			cp -R www/* /var/www/dietpicam/
			chmod +x /var/www/dietpicam/raspizip.sh
			mknod /var/www/dietpicam/FIFO p
			mknod /var/www/dietpicam/FIFO1 p

			#symlink cam preview and status
			ln -sf /run/shm/mjpeg/cam.jpg /var/www/dietpicam/cam.jpg
			ln -sf /run/shm/mjpeg/status_mjpeg.txt /var/www/dietpicam/status_mjpeg.txt

			#Setup Raspimjpeg binary
			cp bin/raspimjpeg /opt/vc/bin/raspimjpeg
			chmod +x /opt/vc/bin/raspimjpeg
			ln -s /opt/vc/bin/raspimjpeg /usr/bin/raspimjpeg

			#Cleanup / remove extracted source
			cd "$HOME"
			rm -R "$HOME"/RPi_Cam*

		fi

		#DELUGE
		INSTALLING_INDEX=45
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI deluged deluge-web deluge-webui deluge-console

		fi

		#GRASSHOPPER
		INSTALLING_INDEX=100
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			G_AGI python

			#Download Grasshopper
			local grasshopper_directory='/var/www'
			INSTALL_URL_ADDRESS='http://sourceforge.net/projects/grasshopperwebapp/files/grasshopper_v5_application.zip/download'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget "$INSTALL_URL_ADDRESS" -O grasshopper.zip
			unzip -o grasshopper.zip -d "$grasshopper_directory"
			rm grasshopper.zip

			#Install
			chmod +x "$grasshopper_directory"/install/install.sh
			"$grasshopper_directory"/install/install.sh

		fi

		#RASPCONTROL
		INSTALLING_INDEX=106
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://github.com/harmon25/raspcontrol/archive/master.zip'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget "$INSTALL_URL_ADDRESS" -O package.zip

			unzip -o package.zip
			rm package.zip
			mkdir -p /var/www/raspcontrol
			mv raspcontrol-master/* /var/www/raspcontrol
			rm -R raspcontrol-master

		fi

		#WEBMIN
		INSTALLING_INDEX=115
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='http://www.webmin.com/download/deb/webmin-current.deb'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget "$INSTALL_URL_ADDRESS" -O package.deb
			dpkg -i package.deb

			G_AGF

			rm package.deb

		fi

		#OMV
		INSTALLING_INDEX=126
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='http://packages.openmediavault.org/public'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			echo -e "deb $INSTALL_URL_ADDRESS erasmus main" > /etc/apt/sources.list.d/openmediavault.list
			G_AGUP

			G_AGI openmediavault-keyring

			debconf-set-selections <<< "openmediavault openmediavault/run-initsystem note"
			debconf-set-selections <<< "postfix postfix/main_mailer_type select No configuration"

			G_AGUP
			G_AGI openmediavault postfix

		fi

		#O!MPD
		INSTALLING_INDEX=129
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://github.com/ArturSierzant/OMPD/archive/master.zip'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget "$INSTALL_URL_ADDRESS" -O package.zip
			unzip -o package.zip -d /var/www/

			rm -R /var/www/ompd &> /dev/null #Replace/upgrade existing installs
			mv /var/www/OMPD* /var/www/ompd
			rm package.zip

		fi

		#IceCast + DarkIce
		INSTALLING_INDEX=135
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			G_AGI darkice icecast2

		fi

		#LINUXDASH
		INSTALLING_INDEX=63
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://github.com/afaqurk/linux-dash/archive/master.zip'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget "$INSTALL_URL_ADDRESS" -O package.zip

			unzip -o package.zip
			rm package.zip
			mkdir -p /var/www/linuxdash
			mv linux-dash-master/* /var/www/linuxdash
			rm -R linux-dash-master

		fi

		#PIHOLE
		INSTALLING_INDEX=93
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='http://install.pi-hole.net'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			# - Pre-reqs: https://github.com/Fourdee/DietPi/issues/1282#issuecomment-350490524
			G_AGI "$PHP_APT_PACKAGE_NAME"-cgi "$PHP_APT_PACKAGE_NAME"-sqlite*

			# - Check free available memory. Increase swapfile size to prevent gravity running out of mem.
			if (( $(free -m | grep -m1 'Mem:' | awk '{print $4}') < 512 )); then

				if [ -f /etc/dphys-swapfile ] &&
					(( $(grep 'CONF_SWAPSIZE=' /etc/dphys-swapfile | sed 's/.*=//') < 512 )); then

					G_DIETPI-NOTIFY 2 "Increasing swapfile size to 512MB before running gravity.sh, please wait...\n"
					/DietPi/dietpi/func/dietpi-set_dphys-swapfile 512

				fi

			fi

			#	NB: PiHole currently replaces the lighttpd.conf file entirly and restricts webserver use to PiHole only. We dont want a limited webserver dedicated to PiHole, so lets avoid it.
			mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.bak &> /dev/null

			# - Install
			wget "$INSTALL_URL_ADDRESS" -O install.sh
			chmod +x install.sh
			./install.sh
			local exit_code=$?
			if (( $exit_code != 0 )); then

				G_DIETPI-NOTIFY 1 "Pi-Hole exited with code ($exit_code) and is not installed."
				aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]=0

			fi

			mv /etc/lighttpd/lighttpd.conf.bak /etc/lighttpd/lighttpd.conf &> /dev/null

		fi

		#SUBSONIC 5
		INSTALLING_INDEX=33
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://sourceforge.net/projects/subsonic/files/subsonic/5.3/subsonic-5.3.deb/download'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			#G_AGI lame #conflicts with our ffmpeg package: https://github.com/Fourdee/DietPi/issues/946#issuecomment-300738228

			#Install SubSonic 5.3
			wget "$INSTALL_URL_ADDRESS" -O package.deb
			dpkg -i package.deb
			rm package.deb

		fi

		#SUBSONIC 6
		INSTALLING_INDEX=34
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://sourceforge.net/projects/subsonic/files/subsonic/6.1.3/subsonic-6.1.3.deb/download'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			#G_AGI lame #conflicts with our ffmpeg package: https://github.com/Fourdee/DietPi/issues/946#issuecomment-300738228

			#Install SubSonic 6.0
			wget "$INSTALL_URL_ADDRESS" -O package.deb
			dpkg -i package.deb
			rm package.deb

		fi

		#WEAVED
		INSTALLING_INDEX=68
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://github.com/weaved/installer/raw/master/Raspbian%20deb/1.3-07/weavedconnectd_1.3-07v_armhf.deb'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			#Install WEAVED
			wget "$INSTALL_URL_ADDRESS" -O package.deb
			dpkg -i package.deb
			rm package.deb

		fi

		#WEBIOPI requires RPIGPIO
		if (( ${aSOFTWARE_INSTALL_STATE[71]} == 1 )); then

			aSOFTWARE_INSTALL_STATE[69]=1

		fi

		#RPIGPIO
		INSTALLING_INDEX=69
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			# >= v111 image
			if [ -f /etc/.dietpi_image_version ]; then

				G_AGI python-rpi.gpio python3-rpi.gpio

			# - < v111 Bug in older DietPi images with sources.list | Use pip, as offical repo = python3-rpi.gpio: Depends: python3 (< 3.3) but 3.4.2-2 is to be installed
			else

				G_AGI python3-pip
				pip3 install RPi.GPIO

			fi

		fi

		#WIRINGPI
		INSTALLING_INDEX=70
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			# - RPi
			if (( $G_HW_MODEL < 10 )); then

				#	http://git.drogon.net/?p=wiringPi;a=shortlog;h=refs/heads/master snapshot
				INSTALL_URL_ADDRESS='http://git.drogon.net/?p=wiringPi;a=snapshot;h=HEAD;sf=tgz'

			# - Odroid's
			elif (( $G_HW_MODEL >= 10 && $G_HW_MODEL < 20 )); then

				INSTALL_URL_ADDRESS='https://github.com/hardkernel/wiringPi/archive/master.zip'

			# - BPiPro
			elif (( $G_HW_MODEL == 51 )); then

				INSTALL_URL_ADDRESS='https://github.com/LeMaker/WiringBP/archive/bananapro.zip'

			fi

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			# - RPi
			if (( $G_HW_MODEL < 10 )); then

				wget "$INSTALL_URL_ADDRESS" -O package.tar
				tar xfz package.tar
				rm package.tar

			# - Odroid's / BPI
			else

				wget "$INSTALL_URL_ADDRESS" -O package.zip
				unzip package.zip
				rm package.zip

			fi

			if (( $G_HW_MODEL == 51 )); then

				mv WiringBP* wiringPi

			fi

			cd wiringPi*
			chmod +x build
			./build
			cd "$HOME"

			#rm -R /root/wiringPi* #Also Contains example code for users.

		fi

		#RPII2C
		INSTALLING_INDEX=72
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			/DietPi/dietpi/func/dietpi-set_hardware i2c enable

		fi

		#nodered
		INSTALLING_INDEX=122
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			G_AGI python python3

			# - RPi, pre-reqs GPIO control for Node-Red
			if (( $G_HW_MODEL < 10 )); then

				G_AGI python-rpi.gpio

			fi

			# - Serialport fails to build unless below flags are provided
			npm install -g node-red --unsafe-perm

		fi

		#mosquitto
		INSTALLING_INDEX=123
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			if (( $G_DISTRO > 4 )); then

				# On Buster, we can use current APT package from Debian repo
				G_AGI mosquitto

			else

				# - ARMv8
				if (( $G_HW_ARCH == 3 )); then

					dpkg --add-architecture armhf
					G_AGUP

				fi

				#Pre-Req
				# - libssl1.0.0 no longer available: https://github.com/Fourdee/DietPi/issues/1299
				INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/'

				# - ARMv6/7/8
				if (( $G_HW_ARCH >= 1 && $G_HW_ARCH <= 3 )); then

					INSTALL_URL_ADDRESS+='libssl1.0.0_1.0.1t-1+deb8u7_armhf.deb'

				# - x86_64
				elif (( $G_HW_ARCH == 10 )); then

					INSTALL_URL_ADDRESS+='libssl1.0.0_1.0.1t-1+deb8u7_amd64.deb'

				fi
				G_CHECK_URL "$INSTALL_URL_ADDRESS"

				wget "$INSTALL_URL_ADDRESS" -O package.deb
				dpkg -i package.deb
				rm package.deb

				INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/mosquitto_1.4.14-0mosquitto1_nows1_armhf.deb'
				if (( $G_HW_ARCH == 10 )); then

					INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/mosquitto_1.4.14-0mosquitto1_nows1_amd64.deb'

				fi
				G_CHECK_URL "$INSTALL_URL_ADDRESS"

				wget "$INSTALL_URL_ADDRESS" -O package.deb

				#Install deb
				#	Allow error, so we can install additional required packages automatically
				dpkg -i package.deb
				G_AGF
				rm package.deb

			fi

		fi

		#Blynk Server
		INSTALLING_INDEX=131
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#Binary URL fails connection test, so we need to parent back a little: https://github.com/Fourdee/DietPi/issues/445#issuecomment-283400449
			INSTALL_URL_ADDRESS='https://github.com/blynkkk/blynk-server/releases'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			mkdir -p /etc/blynkserver

			INSTALL_URL_ADDRESS='https://github.com/blynkkk/blynk-server/releases/download/v0.29.7/server-0.29.7-java8.jar'
			wget "$INSTALL_URL_ADDRESS" -O /etc/blynkserver/server.jar

			# - Install Blynk JS Libary
			G_AGI python
			npm install -g onoff
			npm install -g blynk-library

		fi

		#NAA Daemon
		INSTALLING_INDEX=124
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			# - Skip license for NAA daemon if needed:
			if (( ! $G_USER_INPUTS )); then

				debconf-set-selections <<< "networkaudiod networkaudiod/license note false"

			fi

			#Packages
			local apackages=()

			#	Jessie - requires stretch packages
			if (( $G_DISTRO == 3 )); then

				apackages+=('http://dietpi.com/downloads/binaries/all/gcc-6-base_6.3.0-6_armhf.deb')
				apackages+=('http://dietpi.com/downloads/binaries/all/libstdc++6_6.3.0-6_armhf.deb')

			fi

			apackages+=('https://www.signalyst.eu/bins/naa/linux/stretch/networkaudiod_3.5.2-36_armhf.deb')

			# - check online
			for ((i=0; i<${#apackages[@]}; i++))
			do

				INSTALL_URL_ADDRESS="${apackages[$i]}"
				G_CHECK_URL "$INSTALL_URL_ADDRESS"

			done

			# - Prereqs
			G_AGI libasound2

			# - Stretch, install additional packages
			if (( $G_DISTRO >= 4 )); then

				G_AGI gcc-6-base libstdc++6

			fi

			for ((i=0; i<${#apackages[@]}; i++))
			do

				wget "${apackages[$i]}" -O package.deb
				dpkg -i package.deb
				rm package.deb

			done

			unset apackages

			#Enable logging for NAA Daemon
			#echo -e "NETWORKAUDIOD_LOGFILE='/var/log/naadaemon.log'" > /etc/default/networkaudiod

		fi

		#Tomcat8
		INSTALLING_INDEX=125
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			G_AGI tomcat8

		fi

		#WEBIOPI
		INSTALLING_INDEX=71
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://sourceforge.net/projects/webiopi/files/WebIOPi-0.7.1.tar.gz/download'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			#Python dev, pre-reqs
			G_AGI python-dev python-setuptools --no-install-recommends

			#Install WEBIOPI
			wget "$INSTALL_URL_ADDRESS" -O package.tar
			tar xvzf package.tar
			rm package.tar

			cd WebIOPi*

			#Automate Weaved prompt
			sed -i '/read response/c\response="n"' setup.sh

			#Run setup script
			./setup.sh
			clear

			cd ..

			#Cleanup
			rm -R WebIOPi*

		fi

		#DIETPICLOUDSHELL
		INSTALLING_INDEX=62
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#LCD panels can be enabled in Dietpi-config > display options
			#	XU4 enable cloudshell
			if (( $G_HW_MODEL == 11 )); then

				/DietPi/dietpi/func/dietpi-set_hardware lcdpanel odroid-cloudshell

			fi

		fi

		#HAPROXY
		INSTALLING_INDEX=98
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing


			INSTALL_URL_ADDRESS='https://www.haproxy.org/download/1.8/src/haproxy-1.8.2.tar.gz'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			#Download HAPROXY
			wget "$INSTALL_URL_ADDRESS" -O package.tar
			tar -xvf package.tar
			rm package.tar

			cd haproxy-*

			#Pre-reqs
			G_AGI libpcre3-dev libssl-dev zlib1g-dev
			#Compile and install
			make -j $G_HW_CPU_CORES TARGET=linux2628 CPU=generic USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_LINUX_SPLICE=1
			make install

			mkdir /etc/haproxy

			#Exit directory
			cd ..

			#Clean up
			rm -R haproxy-*

			#Install init script as service
			cp /DietPi/dietpi/conf/haproxy_init /etc/init.d/haproxy
			chmod +x /etc/init.d/haproxy
			update-rc.d haproxy defaults

		fi

		#SQUEEZEBOXSERVER
		INSTALLING_INDEX=35
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#Stretch
			if (( $G_DISTRO >= 4 )); then

				#Untested ARMv8
				if (( $G_HW_ARCH == 3 )); then

					dpkg --add-architecture armhf
					G_AGUP

				fi

				INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/logitechmediaserver_7.9.1_armv7-(stretch).deb'
				wget "$INSTALL_URL_ADDRESS" -O package.deb
				dpkg -i package.deb
				rm package.deb
				G_AGF

			else

				INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/logitechmediaserver_7.9.0_all.deb'
				G_CHECK_URL "$INSTALL_URL_ADDRESS"

				wget "$INSTALL_URL_ADDRESS" -O package.deb
				dpkg -i package.deb
				rm package.deb

				#https://github.com/Fourdee/DietPi/issues/736
				G_AGF

				#Stop service
				service logitechmediaserver stop

				# + ARMv6 cpan
				if (( $G_HW_ARCH == 1 )); then

					wget http://dietpi.com/downloads/binaries/all/logitechmediaserver_7.9.0_CPAN_5.20_armv6hf.tar.gz -O package.tar
					tar xvzf package.tar -C /
					rm package.tar

				# + ARM64 cpan
				elif (( $G_HW_ARCH == 3 )); then

					G_AGI libxml-parser-perl
					G_AGI zlib1g-dev libjpeg-dev libpng-dev libjpeg62-turbo-dev # shared libs needed for Image::Scale@0.08

					wget http://dietpi.com/downloads/binaries/all/DietPi-LMS7.9-CPAN_arm64.zip -O package.zip
					unzip -o package.zip -d /usr/share/squeezeboxserver
					rm package.zip

				fi

			fi

		fi

		#WORDPRESS
		INSTALLING_INDEX=55
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://wordpress.org/latest.zip'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget "$INSTALL_URL_ADDRESS" -O package.zip
			unzip -o package.zip -d /var/www/
			rm package.zip

		fi

		#TIGHTVNCSERVER
		INSTALLING_INDEX=27
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			G_AGI tightvncserver x11vnc --no-install-recommends

		fi

		#VNC4SERVER
		INSTALLING_INDEX=28
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			G_AGI vnc4server x11vnc --no-install-recommends

			# - Stretch+
			if (( $G_DISTRO >= 4 )); then

				G_AGI tigervnc-common

			fi

		fi

		#REALVNCSERVER
		INSTALLING_INDEX=120
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			# INSTALL_URL_ADDRESS='https://www.realvnc.com/download/binary/latest/debian/arm/'
			# G_CHECK_URL "$INSTALL_URL_ADDRESS"

			# wget "$INSTALL_URL_ADDRESS" -O package.tar.gz
			# tar xvf package.tar.gz
			# rm package.tar.gz

			# dpkg -i VNC*.deb

			# rm VNC*.deb

			# - Available in Raspbian apt
			G_AGI realvnc-vnc-server

		fi

		#FAIL2BAN
		INSTALLING_INDEX=73
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			touch /var/log/auth.log #: https://github.com/Fourdee/DietPi/issues/475#issuecomment-310873879

			G_AGI fail2ban --no-install-recommends

		fi

		#PHPSYSINFO
		INSTALLING_INDEX=64
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing


			INSTALL_URL_ADDRESS='https://github.com/phpsysinfo/phpsysinfo/archive/master.zip'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget "$INSTALL_URL_ADDRESS" -O package.zip
			unzip -o package.zip -d /var/www/
			rm package.zip
			mv /var/www/phpsysinfo-* /var/www/phpsysinfo

		fi

		#PHPIMAGEGALLERY
		INSTALLING_INDEX=56
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing


			INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/Single_File_PHP_Gallery_4.6.1.zip'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget "$INSTALL_URL_ADDRESS" -O package.zip
			unzip -o package.zip -d /var/www/gallery
			rm package.zip

		fi

		#AMPACHE
		INSTALLING_INDEX=40
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://github.com/ampache/ampache/archive/master.zip'

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget "$INSTALL_URL_ADDRESS" -O package.zip
			unzip -o package.zip
			rm package.zip
			mv ampache-* /var/www/ampache

			#composer install required for 3.8.2
			php -r "readfile('https://getcomposer.org/installer');" > composer-setup.php
			php composer-setup.php
			php -r "unlink('composer-setup.php');"

			mv composer.phar /usr/local/bin/composer

			cd /var/www/ampache
			composer install --prefer-source --no-interaction
			cd "$HOME"

		fi

		#OPENVPNSERVER
		INSTALLING_INDEX=97
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			G_AGI openvpn easy-rsa iptables

		fi

		#PiVPN
		INSTALLING_INDEX=117
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://install.pivpn.io'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			G_AGI lsb-release

			# - Requires underpriv user: https://github.com/Fourdee/DietPi/issues/570#issuecomment-255588307
			useradd pivpn
			mkdir -p /home/pivpn

			while true
			do

				wget "$INSTALL_URL_ADDRESS" -O pivpn_install.sh
				chmod +x pivpn_install.sh

				# - Disable reboot
				sed -i '/shutdown[[:space:]]/d' pivpn_install.sh

				./pivpn_install.sh
				if (( $? != 0 )); then

					whiptail --title "PiVPN failed/aborted" --yesno "The PiVPN installer was not successful and/or canceled prior to its completion.\n\nWould you like DietPi to run the PiVPN installer again?" --backtitle "$WHIP_BACKTITLE" --defaultno 12 70
					if (( $? != 0 )); then

						aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]=0
						break

					fi

				else

					rm pivpn_install.sh
					break

				fi

			done

		fi

		#LETSENCRYPT
		INSTALLING_INDEX=92
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			if (( $G_DISTRO >= 4 )); then

				G_AGI certbot

				if (( ${aSOFTWARE_INSTALL_STATE[83]} >= 1 )); then

  					G_AGI python-certbot-apache

				fi

				if (( ${aSOFTWARE_INSTALL_STATE[85]} >= 1 )); then

  					G_AGI python-certbot-nginx

				fi

			else

				INSTALL_URL_ADDRESS='https://github.com/certbot/certbot/archive/master.zip'
				G_CHECK_URL "$INSTALL_URL_ADDRESS"

				wget "$INSTALL_URL_ADDRESS" -O package.zip
				unzip -o package.zip -d /root
				rm package.zip
				mv certbot* /etc/certbot_scripts

				# - Install packages
				cd /etc/certbot_scripts
				./certbot-auto -n --os-packages-only
				cd ~/

			fi

		fi

		#TORHOTSPOT requires WIFIHOTSPOT:
		if (( ${aSOFTWARE_INSTALL_STATE[61]} == 1 )); then

			aSOFTWARE_INSTALL_STATE[60]=1

		fi

		#WIFIHOTSPOT
		INSTALLING_INDEX=60
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/hostapd_2.5_all.zip'

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			# - Prereqs
			G_AGI hostapd isc-dhcp-server iptables libnl-3-200

			wget "$INSTALL_URL_ADDRESS" -O package.zip
			unzip -o package.zip
			rm package.zip

			# - Check for RTL8188C* device, use the patched binary I compiled: https://github.com/pritambaral/hostapd-rtl871xdrv#why
			if (( $(lsusb | grep -ci -m1 'RTL8188C') ||
				$G_HW_MODEL == 70 )); then #Force RTL for allo provided WiFi dongle

				WIFIHOTSPOT_RTL8188C_DEVICE=1

			fi

			#Which binary to install
			local filename_hostapd=''
			local filename_hostapd_cli=''

			# - armv6
			if (( $G_HW_ARCH == 1 )); then

				filename_hostapd='hostapd-nl80211-armv6'
				filename_hostapd_cli='hostapd_cli-armv6'

				if (( $WIFIHOTSPOT_RTL8188C_DEVICE )); then

					filename_hostapd='hostapd-rtl8188c-armv6'

				fi

			# - armv7+
			elif (( $G_HW_ARCH == 2 )); then

				filename_hostapd='hostapd-nl80211-armv7'
				filename_hostapd_cli='hostapd_cli-armv7'

				if (( $WIFIHOTSPOT_RTL8188C_DEVICE )); then

					filename_hostapd='hostapd-rtl8188c-armv7'

				fi

			# - arm64
			elif (( $G_HW_ARCH == 3 )); then

				filename_hostapd='hostapd-nl80211-arm64'
				filename_hostapd_cli='hostapd_cli-arm64'

				if (( $WIFIHOTSPOT_RTL8188C_DEVICE )); then

					filename_hostapd='hostapd-rtl8188c-arm64'

				fi

			fi

			mv "$filename_hostapd" /usr/sbin/hostapd
			mv "$filename_hostapd_cli" /usr/sbin/hostapd_cli

			chmod +x /usr/sbin/hostapd
			chmod +x /usr/sbin/hostapd_cli

			rm hostapd-*

			#Enable wifi modules
			/DietPi/dietpi/func/dietpi-set_hardware wifimodules enable

			# - Stretch, libssl1.0.0 no longer available: https://github.com/Fourdee/DietPi/issues/1299
			#	Possibly only needed for RPi, however, no harm in installing, cover all bases.
			if (( $G_DISTRO >= 4 )); then

				INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/'

				# - ARMv6/7
				if (( $G_HW_ARCH == 1 || $G_HW_ARCH == 2 )); then

					INSTALL_URL_ADDRESS+='libssl1.0.0_1.0.1t-1+deb8u7_armhf.deb'

				# - ARM64
				elif (( $G_HW_ARCH == 3 )); then

					INSTALL_URL_ADDRESS+='libssl1.0.0_1.0.1t-1+deb8u7_arm64.deb'

				# - x86_64
				elif (( $G_HW_ARCH == 10 )); then

					INSTALL_URL_ADDRESS+='libssl1.0.0_1.0.1t-1+deb8u7_amd64.deb'

				fi

				G_CHECK_URL "$INSTALL_URL_ADDRESS"

				wget "$INSTALL_URL_ADDRESS" -O package.deb
				dpkg -i package.deb
				rm package.deb

			fi

		fi


		#TORHOTSPOT
		INSTALLING_INDEX=61
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			# - Prereqs
			G_AGI tor

		fi

		#SHAIRPORTSYNC
		INSTALLING_INDEX=37
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/shairport-sync_3.1.3_'

			# - ARMv6
			if (( $G_HW_ARCH == 1 )); then

				INSTALL_URL_ADDRESS+='armv6.7z'

			# - ARMv7
			elif (( $G_HW_ARCH == 2 )); then

				INSTALL_URL_ADDRESS+='armv7.7z'

			# - ARM64
			elif (( $G_HW_ARCH == 3 )); then

				INSTALL_URL_ADDRESS+='arm64.7z'

			# - x86_64
			# elif (( $G_HW_ARCH == 10 )); then

				# INSTALL_URL_ADDRESS+='amd64.7z'

			fi

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			# - Prereqs
			G_AGI openssl libsoxr0 libavahi-client3 libtool libconfig9 libpopt0 libdaemon0 --no-install-recommends

			# This occured on C2: shairport-sync : Depends: libpopt-dev but it is not installed
			#G_AGI libpopt-dev

			wget "$INSTALL_URL_ADDRESS" -O package.7z
			7z x -y package.7z -o/
			rm package.7z

			# - Stretch, libssl1.0.0 no longer available
			if (( $G_DISTRO >= 4 )); then

				INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/'

				# - ARMv6/7
				if (( $G_HW_ARCH == 1 || $G_HW_ARCH == 2 )); then

					INSTALL_URL_ADDRESS+='libssl1.0.0_1.0.1t-1+deb8u7_armhf.deb'

				# - ARM64
				elif (( $G_HW_ARCH == 3 )); then

					INSTALL_URL_ADDRESS+='libssl1.0.0_1.0.1t-1+deb8u7_arm64.deb'

				# - x86_64
				elif (( $G_HW_ARCH == 10 )); then

					INSTALL_URL_ADDRESS+='libssl1.0.0_1.0.1t-1+deb8u7_amd64.deb'

				fi

				G_CHECK_URL "$INSTALL_URL_ADDRESS"

				wget "$INSTALL_URL_ADDRESS" -O package.deb
				dpkg -i package.deb
				rm package.deb

			fi

		fi

		#BRUTEFIR
		INSTALLING_INDEX=38
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#check folder is online
			INSTALL_URL_ADDRESS='http://dietpi.com/downloads/conf/BruteFIR/'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			# - Prereqs
			G_AGI brutefir

			wget -r -nH --cut-dirs=2 --no-parent --reject="index.htm*" -e robots=off "$INSTALL_URL_ADDRESS"
			mv BruteFIR /etc/

		fi

		#PYDIO
		INSTALLING_INDEX=48
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#check folder is online
			INSTALL_URL_ADDRESS='https://download.pydio.com/pub/core/archives/pydio-core-8.0.2.zip'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget "$INSTALL_URL_ADDRESS" -O package.zip
			unzip -o package.zip -d /var/www
			mv /var/www/pydio-core-* /var/www/pydio
			rm package.zip

		fi

		#SQUEEZELITE
		INSTALLING_INDEX=36
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/squeezelite-1.8_all.7z'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			# - Prereqs
			G_AGI squeezelite

			# - Overwrite binary with latest version:
			wget "$INSTALL_URL_ADDRESS" -O package.7z
			7z x -y package.7z -o/usr/bin
			rm package.7z

			rm /usr/bin/squeezelite

			local target_binary=''

			if (( $G_HW_ARCH == 1 )); then

				target_binary='squeezelite_armv6'

			# - ARMv7
			elif (( $G_HW_ARCH == 2 )); then

				target_binary='squeezelite_armv7'

			# - ARM64
			elif (( $G_HW_ARCH == 3 )); then

				target_binary='squeezelite_arm64'

			# - x86_64
			elif (( $G_HW_ARCH == 10 )); then

				target_binary='squeezelite_amd64'

			fi

			ln -sf /usr/bin/"$target_binary" /usr/bin/squeezelite
			chmod +x /usr/bin/squeezelite

		fi

		#EMONHUB
		INSTALLING_INDEX=99
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#check, is online
			INSTALL_URL_ADDRESS='https://github.com/Fourdee/emonhub/archive/emon-pi.zip'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			# - Prereqs
			G_AGI minicom python-serial python-configobj --no-install-recommends
			pip install paho-mqtt pydispatcher

			wget "$INSTALL_URL_ADDRESS" -O package.zip
			unzip -o package.zip
			rm package.zip

			# - move everything to /etc/emonhub
			rm -R /etc/emonhub
			mkdir -p /etc/emonhub
			mv emonhub-*/* /etc/emonhub/
			rm -R emonhub-*

		fi

		#RPIMONITOR
		INSTALLING_INDEX=66
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#check, is online
			INSTALL_URL_ADDRESS='https://github.com/XavierBerger/RPi-Monitor-deb/raw/master/packages/rpimonitor_2.12-r0_all.deb'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget "$INSTALL_URL_ADDRESS" -O package.deb
			dpkg -i package.deb
			rm package.deb

			# - Prereqs
			apt-get -f -y install

		fi

		#NETDATA
		INSTALLING_INDEX=65
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/netdata_1.6.0_'

			#armv6
			if (( $G_HW_ARCH == 1 )); then

				INSTALL_URL_ADDRESS+='armv6.deb'

			#armv7+
			elif (( $G_HW_ARCH == 2 )); then

				INSTALL_URL_ADDRESS+='armv7.deb'

			#ARMv8
			elif (( $G_HW_ARCH == 3 )); then

				INSTALL_URL_ADDRESS+='arm64.deb'

			#amd64
			elif (( $G_HW_ARCH == 10 )); then

				INSTALL_URL_ADDRESS+='amd64.deb'

			fi

			#check, is online
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			# - For compression
			G_AGI --no-install-recommends zlib1g-dev

			wget "$INSTALL_URL_ADDRESS" -O package.deb
			dpkg -i package.deb
			rm package.deb

		fi

		#BAIKAL
		INSTALLING_INDEX=57
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#check folder is online
			INSTALL_URL_ADDRESS='https://github.com/fruux/Baikal/archive/master.zip'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget "$INSTALL_URL_ADDRESS" -O package.zip
			unzip -o package.zip -d /var/www
			rm package.zip
			mv /var/www/Baikal* /var/www/baikal

		fi

		#MUMBLESERVER
		INSTALLING_INDEX=43
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			G_AGI mumble-server

		fi

		#EMBYSERVER
		INSTALLING_INDEX=41
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#ARM packages only available in 14.04 repo: https://github.com/Fourdee/DietPi/issues/1059#issuecomment-313661959
			INSTALL_URL_ADDRESS='http://download.opensuse.org/repositories/home:/emby/xUbuntu_14.04/'

			#	x86_64, use Debian repos
			if (( $G_HW_ARCH == 10 )); then

				INSTALL_URL_ADDRESS='http://download.opensuse.org/repositories/home:/emby/Debian_'

				if (( $G_DISTRO == 3 )); then

					INSTALL_URL_ADDRESS+='8.0'

				elif (( $G_DISTRO == 4 )); then

					INSTALL_URL_ADDRESS+='9.0'

				elif (( $G_DISTRO == 5 )); then

					# http://download.opensuse.org/repositories/home:/emby/Debian_Next/
					INSTALL_URL_ADDRESS+='Next'

				fi

				INSTALL_URL_ADDRESS+='/'

			fi

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			echo -e "deb $INSTALL_URL_ADDRESS /" > /etc/apt/sources.list.d/emby-server.list
			wget "$INSTALL_URL_ADDRESS"Release.key
			apt-key add - < Release.key
			rm Release.key
			G_AGUP

			#ARMv7, Grab required pre-reqs from various sources: https://github.com/Fourdee/DietPi/issues/1128#issuecomment-326743471 / https://github.com/Fourdee/DietPi/issues/1150#issuecomment-330291298
			if (( $G_HW_ARCH == 2 )); then

				wget http://ftp.us.debian.org/debian/pool/main/libj/libjpeg8/libjpeg8_8d-1+deb7u1_armhf.deb -O package.deb
				dpkg -i package.deb
				rm package.deb

				wget http://ftp.us.debian.org/debian/pool/main/libp/libpng/libpng12-0_1.2.50-2+deb8u3_armhf.deb -O package.deb
				dpkg -i package.deb
				rm package.deb

				wget http://ftp.us.debian.org/debian/pool/main/libw/libwebp/libwebp5_0.4.1-1.2+b2_armhf.deb -O package.deb
				dpkg -i package.deb
				rm package.deb

			#ARMv8
			elif (( $G_HW_ARCH == 3 )); then

				wget http://ftp.us.debian.org/debian/pool/main/libp/libpng/libpng12-0_1.2.50-2+deb8u3_arm64.deb -O package.deb
				dpkg -i package.deb
				rm package.deb

				wget http://ftp.us.debian.org/debian/pool/main/libw/libwebp/libwebp5_0.4.1-1.2+b2_arm64.deb -O package.deb
				dpkg -i package.deb
				rm package.deb

				wget https://mirror.i-novus.ru/ubuntu-ports/pool/main/libj/libjpeg-turbo/libjpeg-turbo8_1.3.0-0ubuntu2_arm64.deb -O package.deb
				dpkg -i package.deb
				rm package.deb

				wget http://turul.canonical.com/pool/main/libj/libjpeg8-empty/libjpeg8_8c-2ubuntu8_arm64.deb -O package.deb
				dpkg -i package.deb
				rm package.deb

			fi

			G_AGI emby-server embymagick

		fi

		#PLEXMEDIASERVER
		INSTALLING_INDEX=42
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#check folder is online

			#x86_64
			if (( $G_HW_ARCH == 10 )); then

				INSTALL_URL_ADDRESS='https://downloads.plex.tv/plex-media-server/1.10.1.4602-f54242b6b/plexmediaserver_1.10.1.4602-f54242b6b_amd64.deb'

			#ARM
			else

				INSTALL_URL_ADDRESS='http://dev2day.de/pms/'

			fi

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			#x86_64
			if (( $G_HW_ARCH == 10 )); then

				wget "$INSTALL_URL_ADDRESS" -O package.deb
				dpkg -i package.deb
				rm package.deb

			#ARM
			else

				echo -e "deb [arch=armhf] $INSTALL_URL_ADDRESS $G_DISTRO_NAME main" > /etc/apt/sources.list.d/plex.list
				wget -O - "$INSTALL_URL_ADDRESS"dev2day-pms.gpg.key | apt-key add -
				G_AGUP

				#ARMv8: Install 32bit binaries
				if (( $G_HW_ARCH == 3 )); then

					dpkg --add-architecture armhf
					G_AGUP
					G_AGI binutils:armhf plexmediaserver-installer:armhf

				#ARM32
				else

					G_AGI plexmediaserver-installer

				fi

			fi

		fi

		#CUBERITE
		INSTALLING_INDEX=52
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#x86_64
			if (( $G_HW_ARCH == 10 )); then

				INSTALL_URL_ADDRESS='http://builds.cuberite.org/job/Cuberite%20Linux%20x64%20Master/lastSuccessfulBuild/artifact/Cuberite.tar.gz'

			#32bit ARM
			elif (( $G_HW_ARCH == 1 || $G_HW_ARCH == 2 )); then

				INSTALL_URL_ADDRESS='http://builds.cuberite.org/job/Cuberite%20Linux%20raspi-armhf%20Master/lastSuccessfulBuild/artifact/Cuberite.tar.gz'

			fi
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget "$INSTALL_URL_ADDRESS" -O package.tar
			mkdir -p /etc/cubrite
			tar xzvf package.tar -C /etc/cubrite
			rm package.tar

			# - Move everything into base directory (cuberite)
			mv /etc/cubrite/Server/* /etc/cubrite/
			rm -R /etc/cuberite/Server

		fi

		#MINEOS
		INSTALLING_INDEX=53
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#check folder is online

			INSTALL_URL_ADDRESS='https://github.com/hexparrot/mineos-node.git'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			#prereqs
			G_AGI python python3 supervisor rdiff-backup screen rsync

			mkdir -p "$G_FP_DIETPI_USERDATA"/mineos
			cd "$G_FP_DIETPI_USERDATA"/mineos
			git clone https://github.com/hexparrot/mineos-node.git minecraft

			cd minecraft
			git config core.filemode false
			chmod +x service.js mineos_console.js generate-sslcert.sh webui.js

			npm install

			cd "$HOME"

		fi

		#GOGS
		INSTALLING_INDEX=49
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/gogs_'

			#armv6
			if (( $G_HW_ARCH == 1 )); then

				INSTALL_URL_ADDRESS+='armv6.zip'

			#armv7+
			elif (( $G_HW_ARCH == 2 )); then

				INSTALL_URL_ADDRESS+='armv7.zip'

			#x86_64
			elif (( $G_HW_ARCH == 10 )); then

				INSTALL_URL_ADDRESS+='amd64.zip'
			fi

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget "$INSTALL_URL_ADDRESS" -O package.zip
			unzip -o package.zip
			rm package.zip

			mv gogs* /etc/gogs

		fi

		#QBITTORRENT
		INSTALLING_INDEX=46
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			G_AGI qbittorrent-nox

		fi

		#RTORRENT
		INSTALLING_INDEX=107
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='http://bintray.com/novik65/generic/download_file?file_path=ruTorrent-3.7.zip'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			G_AGI rtorrent screen #mediainfo

			#Raspbian unrar free
			if (( $G_HW_MODEL < 10 )); then

				G_AGI unrar-free #https://github.com/Fourdee/DietPi/issues/176#issuecomment-240101365

			else

				G_AGI unrar #https://github.com/Fourdee/DietPi/issues/176#issuecomment-240101365

			fi


			wget "$INSTALL_URL_ADDRESS" -O package.zip
			unzip -o package.zip
			rm package.zip

			mkdir -p /var/www/rutorrent
			mv ruTorrent-*/* /var/www/rutorrent/
			rm -R ruTorrent-*

		fi

		#Aria2
		INSTALLING_INDEX=132
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			if (( $G_DISTRO >= 4 )); then

				G_AGI aria2

			else

				#aria2 binary
				INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/aria2_'

				# - armv6
				if (( $G_HW_ARCH == 1 )); then

					INSTALL_URL_ADDRESS+='armv6.7z'

				# - armv7+
				elif (( $G_HW_ARCH == 2 )); then

					INSTALL_URL_ADDRESS+='armv7.7z'

				# - arm64
				elif (( $G_HW_ARCH == 3 )); then

					INSTALL_URL_ADDRESS+='arm64.7z'

				# - x86_64
				elif (( $G_HW_ARCH == 10 )); then

					INSTALL_URL_ADDRESS+='x86_64.7z'

				fi

				G_CHECK_URL "$INSTALL_URL_ADDRESS"

				# - prereqs
				G_AGI libc-ares2

				wget "$INSTALL_URL_ADDRESS" -O package.7z
				7z x -y package.7z
				rm package.7z

				mv aria2_* /usr/local/bin/aria2c
				chmod +x /usr/local/bin/aria2c

			fi

			#Web interface
			INSTALL_URL_ADDRESS='https://github.com/ziahamza/webui-aria2/archive/master.zip'

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget "$INSTALL_URL_ADDRESS" -O package.zip
			unzip -o package.zip
			rm package.zip

			cp -R webui-aria2* /var/www/aria2
			rm -R webui-aria2*

		fi

 		#SICKRAGE
		INSTALLING_INDEX=116
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://github.com/SickRage/SickRage/archive/master.zip'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			G_AGI python libxslt1.1 libxml2 python-openssl python-xmltodict

			#Raspbian unrar free
			if (( $G_HW_MODEL < 10 )); then

				G_AGI unrar-free

			else

				G_AGI unrar

			fi

			wget "$INSTALL_URL_ADDRESS" -O package.zip
			unzip -o package.zip
			rm package.zip

			mkdir -p /etc/sickrage

			mv SickRage-*/* /etc/sickrage/
			rm -R SickRage-*

		fi

		#SYNCTHING
		INSTALLING_INDEX=50
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			# - armv6+
			if (( $G_HW_ARCH == 1 || $G_HW_ARCH == 2 )); then

				INSTALL_URL_ADDRESS='https://github.com/syncthing/syncthing/releases/download/v0.14.42/syncthing-linux-arm-v0.14.42.tar.gz'

			# - arm64
			elif (( $G_HW_ARCH == 3 )); then

				INSTALL_URL_ADDRESS='https://github.com/syncthing/syncthing/releases/download/v0.14.42/syncthing-linux-arm64-v0.14.42.tar.gz'

			# - x86_64
			elif (( $G_HW_ARCH == 10 )); then

				INSTALL_URL_ADDRESS='https://github.com/syncthing/syncthing/releases/download/v0.14.42/syncthing-linux-amd64-v0.14.42.tar.gz'

			fi

			#??
			#For some reason checking connection (spider) against the files above fails.

			#G_CHECK_URL "$INSTALL_URL_ADDRESS"
			G_CHECK_URL https://github.com/syncthing/syncthing

			wget "$INSTALL_URL_ADDRESS" -O package.tar
			tar xzvf package.tar
			rm package.tar

			mkdir -p /etc/syncthing
			cp -R syncthing-*/syncthing /etc/syncthing/
			rm -R syncthing-*

		fi

		#TONIDO
		INSTALLING_INDEX=134
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			### Pre-reqs
			## libjpeg8, libpng12, libssl1.0.0
			# https://github.com/Fourdee/DietPi/issues/1428#issuecomment-361099496
			# - armv6/7
			if (( $G_HW_ARCH == 1 || $G_HW_ARCH == 2 )); then

				INSTALL_URL_ADDRESS1='http://dietpi.com/downloads/binaries/all/libjpeg8_8d1-2_armhf.deb'
				(( $G_DISTRO > 3 )) && INSTALL_URL_ADDRESS2='http://dietpi.com/downloads/binaries/all/libssl1.0.0_1.0.2l-1_bpo8+1_armhf.deb'
				G_AGI libpng12-0

			# - x86_64
			elif (( $G_HW_ARCH == 10 )); then

				INSTALL_URL_ADDRESS1='http://dietpi.com/downloads/binaries/all/libjpeg8_8d1-2_amd64.deb'
				(( $G_DISTRO > 3 )) && INSTALL_URL_ADDRESS2='http://dietpi.com/downloads/binaries/all/libpng12-0_1.2.50-2+deb8u3_amd64.deb' || AGI libpng12-0

			fi

			G_CHECK_URL "$INSTALL_URL_ADDRESS1"
			wget "$INSTALL_URL_ADDRESS1" -O package.deb
			dpkg -i package.deb
			rm package.deb

			if (( $G_DISTRO > 3 )); then

				G_CHECK_URL "$INSTALL_URL_ADDRESS2"
				wget "$INSTALL_URL_ADDRESS2" -O package.deb
				dpkg -i package.deb
				rm package.deb

			fi

			## libfontconfig1
			G_AGI libfontconfig1

			### Tonido
			# - armv6+
			if (( $G_HW_ARCH == 1 || $G_HW_ARCH == 2 )); then

				INSTALL_URL_ADDRESS='http://patch.codelathe.com/tonido/live/installer/armv6l-rpi/tonido.tar.gz'

			# - x86_64
			elif (( $G_HW_ARCH == 10 )); then

				INSTALL_URL_ADDRESS='http://www.tonido.com/download.php?tonido64.tar.gz'

			fi

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget "$INSTALL_URL_ADDRESS" -O package.tar
			mkdir /etc/tonido
			tar xvf package.tar -C /etc/tonido
			rm package.tar

		fi

		#CHROMIUM
		INSTALLING_INDEX=113
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#Stretch via apt
			if (( $G_DISTRO >= 4 )); then

				if (( $G_HW_MODEL < 10 )); then

					G_AGI chromium-browser

				else

					G_AGI chromium

				fi

			else

				#armv6+
				if (( $G_HW_ARCH == 1 || $G_HW_ARCH == 2 )); then

					INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/chromium_52.0.2743.116-1-deb8u1.1_armhf.deb'

				#ARMv8
				elif (( $G_HW_ARCH == 3 )); then

					INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/chromium_52.0.2743.116-1-deb8u1.1_arm64.deb'

				fi

				G_CHECK_URL "$INSTALL_URL_ADDRESS"

				wget "$INSTALL_URL_ADDRESS" -O package.deb
				dpkg -i package.deb
				rm package.deb

				# - Odroid's, 'apt-get install -f' removes chromium package, rather than install required deps...
				if (( $G_HW_MODEL >= 10 && $G_HW_MODEL < 20 )); then

					G_AGI libgnome-keyring0 libnspr4 libnss3 libnss3-1d libspeechd2 libxslt1.1 libxss1 xdg-utils libgnome-keyring-common libltdl7

				else

					G_AGF

				fi

				wget http://dietpi.com/downloads/binaries/all/chromium-l10n_52.0.2743.116-1-deb8u1.1_all.deb -O package.deb
				dpkg -i package.deb

				#	armv6+
				if (( $G_HW_ARCH == 1 || $G_HW_ARCH == 2 )); then

					wget http://dietpi.com/downloads/binaries/all/chromedriver_52.0.2743.116-1-deb8u1.1_armhf.deb -O package.deb
					dpkg -i package.deb

				#	arm64
				elif (( $G_HW_ARCH == 3 )); then

					wget http://dietpi.com/downloads/binaries/all/chromedriver_52.0.2743.116-1-deb8u1.1_arm64.deb -O package.deb
					dpkg -i package.deb

				fi

				rm package.deb

				# - Prevent Debian repo from replacing our chromium packages: https://github.com/Fourdee/DietPi/issues/658
				apt-mark hold chromium chromedriver

			fi

		fi

		#MotionEye
		INSTALLING_INDEX=136
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#Jessie, prefer latest motion release.
			if (( $G_DISTRO == 3 )); then

				INSTALL_URL_ADDRESS='https://github.com/Motion-Project/motion/releases/download/release-4.1.1/pi_jessie_motion_4.1.1-1_armhf.deb'

				#url/redireect always fails wget spider test...
				G_CHECK_URL "http://github.com/Motion-Project/motion"

				# - Prereqs
				G_AGI v4l-utils python python-dev curl libssl-dev libcurl4-openssl-dev libjpeg-dev zlib1g-dev libx264-142 libavcodec56 libavformat56 libmysqlclient18 libswscale3 libpq5

				# - Motion
				wget "$INSTALL_URL_ADDRESS" -O package.deb
				dpkg -i package.deb
				rm package.deb

				# - Motioneye
				pip install motioneye

			#Stretch
			else

				# - Prereqs
				G_AGI v4l-utils python python-dev curl libssl-dev libcurl4-openssl-dev libjpeg-dev zlib1g-dev

				G_AGI motion

				# - Motioneye
				pip install motioneye

			fi

		fi

		#CloudPrint
		INSTALLING_INDEX=137
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			if (( $G_DISTRO == 3 )); then #https://github.com/Fourdee/DietPi/issues/855#issuecomment-292712002

				INSTALL_URL_ADDRESS='http://davesteele.github.io/cloudprint-service'

				#url/redirect fails wget spider test...
				G_CHECK_URL "$INSTALL_URL_ADDRESS"

				INSTALL_URL_ADDRESS+='/repo'

				echo -e "deb $INSTALL_URL_ADDRESS cloudprint-jessie main" > /etc/apt/sources.list.d/cloudprint.list
				wget -q -O - https://davesteele.github.io/key-366150CE.pub.txt | apt-key add -
				G_AGUP

				G_AGI cloudprint-service

			else

				G_AGI cloudprint-service

			fi

		fi

		#VirtualHere
		INSTALLING_INDEX=138
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://virtualhere.com/sites/default/files/usbserver/vhusbd'

			#armv6+
			if (( $G_HW_ARCH == 1 || $G_HW_ARCH == 2 )); then

				INSTALL_URL_ADDRESS+='arm'

			#ARMv8
			elif (( $G_HW_ARCH == 3 )); then

				INSTALL_URL_ADDRESS+='arm64'

			#x86_64
			elif (( $G_HW_ARCH == 10 )); then

				INSTALL_URL_ADDRESS+='x86_64'

			fi

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			mkdir -p /etc/vhusbd

			wget "$INSTALL_URL_ADDRESS" -O /etc/vhusbd/vhusbd
			chmod +x /etc/vhusbd/vhusbd

		fi

		#sabnzbd
		INSTALLING_INDEX=139
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			local version='2.3.2'

			INSTALL_URL_ADDRESS="https://github.com/sabnzbd/sabnzbd/archive/$version.zip"

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			#prereqs
			G_AGI par2 python-dev libffi-dev libssl-dev

			if (( $G_HW_MODEL < 10 )); then

				G_AGI unrar-free

			else

				G_AGI unrar

			fi

			wget "$INSTALL_URL_ADDRESS" -O package.zip
			mkdir -p /etc/sabnzbd
			unzip -o package.zip -d /etc/sabnzbd
			rm package.zip

			mv /etc/sabnzbd/sabnzbd-"$version"/* /etc/sabnzbd/
			rm -R /etc/sabnzbd/sabnzbd-"$version"

			pip install cheetah cryptography sabyenc

		fi

		#spotifyconnectweb
		INSTALLING_INDEX=141
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://github.com/Fornoth/spotify-connect-web/releases' #full path fails wget spider test...
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			INSTALL_URL_ADDRESS+='/download/0.0.3-alpha/spotify-connect-web_0.0.3-alpha.tar.gz'

			wget "$INSTALL_URL_ADDRESS" -O package.tar
			tar zxvf package.tar -C "$G_FP_DIETPI_USERDATA"/
			rm package.tar

		fi

		#couchpotato
		INSTALLING_INDEX=142
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://github.com/CouchPotato/CouchPotatoServer/archive/master.zip'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			G_AGI libffi-dev libssl-dev python-lxml python3-lxml

			wget "$INSTALL_URL_ADDRESS" -O package.zip
			unzip -o package.zip
			rm package.zip

			rm -R /etc/couchpotato &> /dev/null
			mv CouchPotato* /etc/couchpotato

			pip install --upgrade pyopenssl

		fi

		#Koel
		INSTALLING_INDEX=143
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://github.com/phanan/koel/archive/v3.7.0.zip'

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			G_AGI python

			wget "$INSTALL_URL_ADDRESS" -O package.zip
			unzip -o package.zip
			rm package.zip
			mv koel-* /var/www/koel

			php -r "readfile('https://getcomposer.org/installer');" > composer-setup.php
			php composer-setup.php
			php -r "unlink('composer-setup.php');"

			mv composer.phar /usr/local/bin/composer

			cd /var/www/koel
			npm install yarn -g --unsafe-perm
			composer install
			npm install
			cd "$HOME"

		fi

		#Sonarr
		INSTALLING_INDEX=144
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			apt-key adv --keyserver keyserver.ubuntu.com --recv-keys FDA5DFFC
			if (( $G_HW_ARCH == 3 )); then

				echo -e "deb [arch=armhf] https://apt.sonarr.tv/ master main" > /etc/apt/sources.list.d/sonarr.list
				dpkg --add-architecture armhf

			else

				echo -e "deb https://apt.sonarr.tv/ master main" > /etc/apt/sources.list.d/sonarr.list

			fi
			G_AGUP

			G_AGI nzbdrone

		fi

		#Radarr
		INSTALLING_INDEX=145
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://api.github.com/repos/Radarr/Radarr/releases'

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			G_AGI mono-devel mediainfo sqlite3 libmono-cil-dev

			wget $( curl -s "$INSTALL_URL_ADDRESS" | grep linux.tar.gz | grep browser_download_url | head -1 | cut -d \" -f 4 ) -O package.tar
			tar -xf package.tar -C /opt/
			rm package.tar

		fi

		#PlexPy
		INSTALLING_INDEX=146
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://github.com/JonnyWong16/plexpy.git'

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			G_AGI python

			git clone --depth=1 "$INSTALL_URL_ADDRESS"

			mv plexpy /opt/

		fi

		#Jackett
		INSTALLING_INDEX=147
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://api.github.com/repos/Jackett/Jackett/releases'

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			G_AGI mono-devel

			wget $( curl -s "$INSTALL_URL_ADDRESS" | grep Jackett.Binaries.Mono.tar.gz | grep browser_download_url | head -1 | cut -d \" -f 4 ) -O package.tar
			tar -xvf package.tar
			rm package.tar

			mkdir /opt/jackett

			mv Jackett/* /opt/jackett

			rm -R Jackett

		fi

		#JRiver
		INSTALLING_INDEX=148
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='http://dist.jriver.com/latest/mediacenter/mediacenter22native.list'

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget -q -O - http://dist.jriver.com/mediacenter@jriver.com.gpg.key | apt-key add -
			wget "$INSTALL_URL_ADDRESS" -O /etc/apt/sources.list.d/mediacenter22.list

			G_AGUP

			G_AGI mediacenter22

		fi

		#NZBget
		INSTALLING_INDEX=149
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://nzbget.net'

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			INSTALL_URL_ADDRESS+='/download/nzbget-latest-bin-linux.run'

			wget "$INSTALL_URL_ADDRESS"  -O package.run
			mkdir -p "$G_FP_DIETPI_USERDATA"/nzbget
			sh package.run --destdir "$G_FP_DIETPI_USERDATA"/nzbget
			rm package.run

		fi

		#------------------ Bittorrent: HTPC Manager ------------------
		INSTALLING_INDEX=155
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://github.com/Hellowlol/HTPC-Manager.git'

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			#Install Python and PIP
			G_AGI python python-pip python-imaging python-dev

			cd "$HOME"
			git clone --depth=1 "$INSTALL_URL_ADDRESS"

			# - Move HTPC Manager to a 'better' location
			mkdir -p "$G_FP_DIETPI_USERDATA"/htpc-manager
			mv "$HOME"/HTPC-Manager/* "$G_FP_DIETPI_USERDATA"/htpc-manager/
			rm -R "$HOME"/HTPC-Manager

			# - psutil for system stats
			pip install psutil

		fi

		#OctoPrint
		INSTALLING_INDEX=153
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://github.com/foosel/OctoPrint.git'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			G_AGI python python-dev

			git clone "$INSTALL_URL_ADDRESS"
			mv OctoPrint* "$G_FP_DIETPI_USERDATA"/octoprint

			cd "$G_FP_DIETPI_USERDATA"/octoprint
			python setup.py install
			cd "$HOME"

		fi

		#RoonServer
		INSTALLING_INDEX=154
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='http://download.roonlabs.com/builds/RoonServer_linuxx64.tar.bz2'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			G_AGI libav-tools cifs-utils

			wget "$INSTALL_URL_ADDRESS" -O package.tar
			tar xvf package.tar
			rm package.tar

			mv RoonServer "$G_FP_DIETPI_USERDATA"/roonserver

		fi

		#Steam
		INSTALLING_INDEX=156
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			debconf-set-selections <<< "steam steam/question select I AGREE"

			G_AGI steam

		fi

		#Minio
		INSTALLING_INDEX=158
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			# Download the proper Minio executable and put it in the proper location

			# Check to see if this is a n x86 or x64 box. If so download the x86 Minio if not download 32bit ARM linux version
			if (( $G_HW_ARCH == 10 )); then

				INSTALL_URL_ADDRESS='https://dl.minio.io/server/minio/release/linux-amd64/minio'

			else

				INSTALL_URL_ADDRESS='https://dl.minio.io/server/minio/release/linux-arm/minio'

			fi

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			#Download executable
			wget -O /usr/local/bin/minio $INSTALL_URL_ADDRESS
			chmod +x /usr/local/bin/minio

			# Check, Download, Install startup script
			INSTALL_URL_ADDRESS='https://github.com/minio/minio-service/raw/master/linux-systemd/minio.service'

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			# Download the systemd service script
			wget -O /etc/systemd/system/minio.service $INSTALL_URL_ADDRESS

			# Create no login, with home directory, with group of same name, user to run Minio in
			adduser --system --group minio-user

			# Create default data directory & grant minio-user proper access
			mkdir "$G_FP_DIETPI_USERDATA"/minio-data

		fi

		#Docker
		INSTALLING_INDEX=162
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://get.docker.com'

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			# Offical Docker recommended install command
			wget -O DockerInstall.sh "$INSTALL_URL_ADDRESS"
			chmod +x DockerInstall.sh
			./DockerInstall.sh
			#rm DockerInstall.sh

		fi

		#FuguHub
		INSTALLING_INDEX=161
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			if (( $G_HW_ARCH == 10 )); then

				INSTALL_URL_ADDRESS='http://FuguHub.com/install/FuguHub.linux.install'

			else

				INSTALL_URL_ADDRESS='http://FuguHub.com/releases/raspberrypi/install.sh'

			fi

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget -O FHinstall.sh "$INSTALL_URL_ADDRESS"
			chmod +x FHinstall.sh
			./FHinstall.sh
			rm FHinstall.sh
			wget http://fuguhub.com/box.zip -O /home/bd/applications/box.zip

		fi

		#Nukkit
		INSTALLING_INDEX=164
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='http://ci.mengcraft.com:8080/job/nukkit/lastStableBuild/artifact/target/nukkit-1.0-SNAPSHOT.jar'

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			mkdir /usr/local/bin/nukkit
			wget -O /usr/local/bin/nukkit/nukkit.jar "$INSTALL_URL_ADDRESS"

		fi

		#GITEA
		INSTALLING_INDEX=165
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://dl.gitea.io/gitea/1.3.2/gitea-1.3.2-'

			#armv6
			if (( $G_HW_ARCH == 1 )); then

				INSTALL_URL_ADDRESS+='linux-arm-6'

			#armv7
			elif (( $G_HW_ARCH == 2 )); then

				INSTALL_URL_ADDRESS+='linux-arm-7'

			#armv8
			elif (( $G_HW_ARCH == 3 )); then

				INSTALL_URL_ADDRESS+='linux-arm64'

			#x86_64
			elif (( $G_HW_ARCH == 10 )); then

				INSTALL_URL_ADDRESS+='linux-amd64'

			fi

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			# - Data storage / user data
			mkdir -p "$G_FP_DIETPI_USERDATA"/gitea/gitea-repositories

			wget "$INSTALL_URL_ADDRESS" -O "$G_FP_DIETPI_USERDATA"/gitea/gitea
			chmod +x "$G_FP_DIETPI_USERDATA"/gitea/gitea

		fi

		#Allo Web Interface
		INSTALLING_INDEX=159 #160 for quick reinstall
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[160]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/allo_web_interface_v5.7z'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget "$INSTALL_URL_ADDRESS" -O package.7z
			7z x -y package.7z -o/var/www/
			rm package.7z

		fi

		#Gmediarender
		INSTALLING_INDEX=163
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/gmrender_1_'
			if (( $G_HW_ARCH == 10 )); then

				INSTALL_URL_ADDRESS+='amd64.deb'

			elif (( $G_HW_ARCH == 3 )); then

				INSTALL_URL_ADDRESS+='arm64.deb'

			elif (( $G_HW_ARCH == 2 )); then

				INSTALL_URL_ADDRESS+='armv7.deb'

			elif (( $G_HW_ARCH == 1 )); then

				INSTALL_URL_ADDRESS+='armv6.deb'

			fi

			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			G_AGI libupnp6 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-alsa

			wget "$INSTALL_URL_ADDRESS" -O package.deb
			dpkg -i package.deb
			rm package.deb

		fi

		#AudioPhonics Pi-SPC
		INSTALLING_INDEX=166
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#NB: Please see configuration section

		fi

		#Raspotify
		INSTALLING_INDEX=167
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://dtcooper.github.io/raspotify/key.asc'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			wget -O - "$INSTALL_URL_ADDRESS" | apt-key add -
			echo -e "deb https://dtcooper.github.io/raspotify jessie main" > /etc/apt/sources.list.d/raspotify.list
			G_AGUP

			G_AGI raspotify

		fi

		#moOde
		INSTALLING_INDEX=168
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/moode/rel-stretch-r40b9.zip'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			cd "$HOME"
			wget "$INSTALL_URL_ADDRESS" -O package.zip
			unzip -o package.zip

			#Pre-Reqs -----------------------------------------------------------------------
			#	Core packages
			G_AGI rpi-update mpc memcached $PHP_APT_PACKAGE_NAME-memcache \
bs2b-ladspa libbs2b0 libasound2-plugin-equal telnet automake sysstat tcpdump shellinabox \
udisks-glue exfat-fuse inotify-tools libav-tools

#php5-memcached

			#	WiFi Hotspot
			G_AGI dnsmasq hostapd

			#	BT
			G_AGI bluez bluez-firmware \
dh-autoreconf expect libortp-dev libbluetooth-dev libasound2-dev \
libusb-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev libsbc1 libsbc-dev

			if (( $G_HW_MODEL < 10 )); then

				G_AGI pi-bluetooth

			fi

			#Disable Shell in box --------------------------------------------------------------------
			systemctl stop shellinabox
			systemctl disable shellinabox

			#HostAPD/BT -------------------------------------------------------------------------------
			systemctl disable hostapd
			systemctl disable dnsmasq

			cd "$HOME"
			git clone https://github.com/Arkq/bluez-alsa.git --depth=1
			cd bluez-alsa
			autoreconf --install
			mkdir build
			cd build
			../configure --disable-hcitop --with-alsaplugindir=/usr/lib/arm-linux-gnueabihf/alsa-lib
			make -j $(nproc --all)
			make install
			cd "$HOME"
			rm -rf bluez-alsa

			systemctl daemon-reload
			systemctl disable bluetooth.service
			systemctl disable bluealsa.service
			systemctl disable hciuart.service

			mkdir -p /var/run/bluealsa

			#Wiring Pi -------------------------------------------------------------------------------
			#??? Use/test with DietPi WP install
			cd "$HOME"
			cp ./rel-stretch/other/wiringpi/wiringPi-*.tar.gz ./
			tar xfz ./wiringPi-*.tar.gz
			cd wiringPi-96344ff
			./build
			cd "$HOME"
			rm -rf ./wiringPi-*

			#Rotary encoder driver --------------------------------------------------------------------
			cp ./rel-stretch/other/rotenc/rotenc.c ./
			gcc -std=c99 rotenc.c -orotenc -lwiringPi
			cp ./rotenc /usr/local/bin
			rm ./rotenc*

			#Compile and install MPD ------------------------------------------------------------------
			#	Installed via DietPi pre-built binaries.

		fi

		#Google AIY
		INSTALLING_INDEX=169
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://github.com/google/aiyprojects-raspbian.git'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			git clone -b voicekit "$INSTALL_URL_ADDRESS" "$G_FP_DIETPI_USERDATA"/voice-recognizer-raspi
			cd "$G_FP_DIETPI_USERDATA"/voice-recognizer-raspi

			pip3 install --upgrade pip virtualenv
			virtualenv --system-site-packages -p python3 env
			env/bin/pip install -r requirements.txt

			#??? ARMv7 only
			if (( $G_HW_ARCH == 2 )); then

				env/bin/pip install google-assistant-library==0.0.3

			fi

			# - Services
			sed -i "s#/home/pi#$G_FP_DIETPI_USERDATA#g" systemd/voice-recognizer.service
			sed -i "/^User=/c\User=dietpi" systemd/voice-recognizer.service

			cp systemd/voice-recognizer.service /etc/systemd/system/
			cp systemd/alsa-init.service /etc/systemd/system/
			#cp systemd/ntpdate.service /etc/systemd/system/

			source env/bin/activate

			# - Enable default app for service start
			cp src/assistant_library_with_button_demo.py src/main.py

			cd "$HOME"

		fi

		#-------------------------------------------------------------------
		#Reset error handler (eg: for usermsg clear set in Banner_Installing)
		G_ERROR_HANDLER_RESET
		#-------------------------------------------------------------------

	}

	Install_Linux_Software(){

		INSTALLING_INDEX=5
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			G_AGI alsa-utils

			#Apply soundcard
			local soundcard=$(cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_SOUNDCARD=' | sed 's/.*=//')

			# - RPi enable internal HDMI+Analogue if currently set to 'none'
			if (( $G_HW_MODEL < 10 )) &&
				[ "$soundcard" = "none" ] || [ "$soundcard" = "default" ]; then

				soundcard='rpi-bcm2835'

			fi

			# - Apply
			/DietPi/dietpi/func/dietpi-set_hardware soundcard "$soundcard"

		fi

		INSTALLING_INDEX=6
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#Xserver Prereqs (ALL)
			G_AGI xcompmgr xterm xinit xauth xserver-xorg dbus-x11 xfonts-base x11-xserver-utils x11-common x11-utils --no-install-recommends

			#Improve performance on all desktops and devices (eg: removes window lag in desktops) by limiting compositions
			mkdir -p /etc/xdg/autostart
			cat << _EOF_ > /etc/xdg/autostart/xcompmgr.desktop
[Desktop Entry]
Type=Application
Name=xcompmgr
NoDisplay=true
Exec=xcompmgr -a
_EOF_

			#RPI
			if (( $G_HW_MODEL < 10 )); then

				sleep 1

			#Odroid C2
			elif (( $G_HW_MODEL == 12 )); then

				G_AGI aml-libs-odroid mali450-odroid xf86-video-mali-odroid libump-odroid --no-install-recommends
				#cp /DietPi/dietpi/conf/xorg_c2.conf /etc/X11/xorg.conf

				#	FBTURBO C2, provides much better desktop performance over Mali DDX: http://forum.odroid.com/viewtopic.php?f=138&t=19948&p=169808#p169808
				G_AGI xf86-video-fbturbo-odroid
				cat << _EOF_ > /etc/X11/xorg.conf
Section "Device"
        Identifier      "FBTurbo"
        Driver          "fbturbo"
        Option          "fbdev" "/dev/fb0"
        Option          "SwapbuffersWait" "true"
        #Option          "Rotate" "CCW"
EndSection
_EOF_

			#Odroid XU4
			elif (( $G_HW_MODEL == 11 )); then

				G_AGI firmware-samsung xf86-video-armsoc-odroid malit628-odroid --no-install-recommends

				cp /DietPi/dietpi/conf/xorg_xu4.conf /etc/X11/xorg.conf

			#Odroid C1
			elif (( $G_HW_MODEL == 10 )); then

				G_AGI aml-libs-odroid xf86-video-mali-odroid libump-odroid mali450-odroid --no-install-recommends

				cp /DietPi/dietpi/conf/xorg_c1.conf /etc/X11/xorg.conf

			#Pine64
			elif (( $G_HW_MODEL == 40 )); then

				INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/all/libump_1-1_arm64.deb'
				G_CHECK_URL "$INSTALL_URL_ADDRESS"

				wget "$INSTALL_URL_ADDRESS" -O package.deb
				dpkg -i package.deb
				rm package.deb

				wget http://dietpi.com/downloads/binaries/all/xf86-video-fbturbo_1-1_arm64.deb -O package.deb
				dpkg -i package.deb
				rm package.deb

				cat << _EOF_ > /etc/X11/xorg.conf
Section "Device"
        Identifier      "Allwinner A10/A13 FBDEV"
        Driver          "fbturbo"
        Option          "fbdev" "/dev/fb0"
        Option          "SwapbuffersWait" "true"
EndSection
_EOF_

			#Asus TB
			# elif (( $G_HW_MODEL == 52 )); then

				# cat << _EOF_ > /etc/X11/xorg.conf
# Section "Device"
    # Identifier  "Rockchip Graphics"
    # Driver      "modesetting"
    # Option      "AccelMethod"    "glamor"
    # Option      "DRI"            "2"
# EndSection
# _EOF_

			fi

		fi

		#Nvidia driver
		INSTALLING_INDEX=151
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#Install
			G_AGI nvidia-driver nvidia-xconfig

			# + i386 OpenGL
			G_AGI libgl1-nvidia-glx:i386

		fi

		#Avahi-Daemon
		INSTALLING_INDEX=152
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			G_AGI avahi-daemon

		fi

		INSTALLING_INDEX=16
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI build-essential make autoconf automake --no-install-recommends

		fi

		INSTALLING_INDEX=170
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI ntp

			#	Remove service, as DietPi ntpd-mode launches the binary with custom commands
			systemctl stop ntp
			rm /etc/init.d/ntp

			Reset_NTPD

		fi

		INSTALLING_INDEX=17
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI git --no-install-recommends

		fi

		INSTALLING_INDEX=4
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI vifm

		fi

		INSTALLING_INDEX=20
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI vim

		fi

		INSTALLING_INDEX=21
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI vim-tiny

		fi

		INSTALLING_INDEX=127
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI neovim

		fi

		INSTALLING_INDEX=18
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI emacs

		fi

		INSTALLING_INDEX=12
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI iperf

		fi

		INSTALLING_INDEX=3
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI mc

		fi

		INSTALLING_INDEX=19
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI jed

		fi

		INSTALLING_INDEX=10
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI iftop

		fi

		INSTALLING_INDEX=11
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI iptraf

		fi

		INSTALLING_INDEX=13
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI mtr-tiny

		fi

		INSTALLING_INDEX=14
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI nload

		fi

		INSTALLING_INDEX=15
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI tcpdump

		fi

		INSTALLING_INDEX=0
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI openssh-client

		fi

		INSTALLING_INDEX=1
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#Remove Information file
			rm /mnt/samba/readme.txt &> /dev/null

			G_AGI smbclient cifs-utils --no-install-recommends

		fi

		INSTALLING_INDEX=2
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#Remove information file
			rm /mnt/ftp_client/readme.txt &> /dev/null

			G_AGI curlftpfs

		fi

		INSTALLING_INDEX=110
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#Remove information file
			rm /mnt/nfs_client/readme.txt &> /dev/null

			G_AGI nfs-common

		fi

		INSTALLING_INDEX=104
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI dropbear

			#set to start on next boot
			sed -i '/NO_START=1/c\NO_START=0' /etc/default/dropbear

		fi

		INSTALLING_INDEX=105
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI openssh-server --no-install-recommends


			# - Remove all references before adding the entry: https://github.com/Fourdee/DietPi/issues/604
			sed -i '/PermitRootLogin[[:space:]]/d' /etc/ssh/sshd_config
			echo -e "\n\n#Allow root login over SSH\nPermitRootLogin yes" >> /etc/ssh/sshd_config

			#Generate host keys
			# - remove all previous
			rm /etc/ssh/ssh_host_key
			rm /etc/ssh/ssh_host_rsa_key
			rm /etc/ssh/ssh_host_dsa_key

			# - Generate
			ssh-keygen -f /etc/ssh/ssh_host_key -N '' -t rsa1
			ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
			ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa

			# - Set permissions
			chmod -R 700 /etc/ssh/

			#Restart ssh server now so root users can login during setup.
			systemctl restart ssh

			#SSH server package also installs client.
			aSOFTWARE_INSTALL_STATE[0]=2

		fi

		INSTALLING_INDEX=103
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#Install (add tmpfs mount to fstab)
			sed -i '/\/var\/log/c\tmpfs                   \/var\/log                tmpfs   defaults,size=20m,noatime,nodev,nosuid,mode=1777  0 0' /etc/fstab

		fi

		INSTALLING_INDEX=101
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI logrotate --no-install-recommends

		fi

		INSTALLING_INDEX=102
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing
			G_AGI rsyslog --no-install-recommends

		fi

		INSTALLING_INDEX=7
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#RPi + OpenMAX HW Encoding: https://github.com/Fourdee/DietPi/issues/869
			if (( $G_HW_MODEL < 10 )); then

				INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/rpi/ffmpeg_rpi.7z'

				G_CHECK_URL "$INSTALL_URL_ADDRESS"

				wget "$INSTALL_URL_ADDRESS" -O package.7z
				7z x -y package.7z -offmpeg_rpi
				dpkg -i ffmpeg_rpi/*.deb
				rm -R ffmpeg_rpi
				rm package.7z

			#Everything else
			else

				G_AGI ffmpeg

			fi

		fi

		INSTALLING_INDEX=8
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			# On Jessie use backports repo:
			if (( $G_DISTRO == 3 )); then

				cat << _EOF_ > /etc/apt/preferences.d/99-dietpi-openjdk-8-jdk
Package: openjdk-8-jdk
Pin: release a=jessie-backports
Pin-Priority: 990
_EOF_

				G_AGI openjdk-8-jdk -t jessie-backports

			else

				G_AGI openjdk-8-jdk

			fi

		fi

		INSTALLING_INDEX=9
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			#check, is online
			INSTALL_URL_ADDRESS='http://raw.githubusercontent.com/taaem/nodejs-linux-installer/master/node-install.sh'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			# - Preqs
			wget "$INSTALL_URL_ADDRESS" -O node_install.sh
			chmod +x node_install.sh
			./node_install.sh

			rm node_install.sh

		fi

		INSTALLING_INDEX=130
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='https://bootstrap.pypa.io/get-pip.py'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			# - Preqs
			G_AGI python python-dev

			wget "$INSTALL_URL_ADDRESS" -O install.py
			python ./install.py
			rm install.py

			G_AGI python-pip python3-pip

		fi

		#SDL2
		INSTALLING_INDEX=140
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			INSTALL_URL_ADDRESS='http://dietpi.com/downloads/binaries/rpi/sdl2_rpi.7z'
			G_CHECK_URL "$INSTALL_URL_ADDRESS"

			#G_AGI libxss1 #if using SDL2+rpi5

			wget "$INSTALL_URL_ADDRESS" -O package.7z
			7z x -y package.7z -osdl2_rpi
			rm package.7z

			dpkg -i sdl2_rpi/no_opengl_x11/*.deb
			rm -R sdl2_rpi

		fi

		#Mono repo
		INSTALLING_INDEX=150
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Installing

			apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF

			#ARMv6 only available in raspbian repo: https://github.com/Fourdee/DietPi/issues/1023
			if (( $G_HW_ARCH == 1 )); then

				echo -e "deb http://download.mono-project.com/repo/debian raspbian$G_DISTRO_NAME main" > /etc/apt/sources.list.d/mono-xamarin.list

			else

				echo -e "deb http://download.mono-project.com/repo/debian $G_DISTRO_NAME main" > /etc/apt/sources.list.d/mono-xamarin.list

			fi

			G_AGUP

			G_AGI mono-runtime

		fi

		#------------------ Home Automation: Home Assistant ------------------
		INSTALLING_INDEX=157
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

            Banner_Installing

            HA_USER="homeassistant"
            HA_USERROOT="/home/$HA_USER"
            HA_SRVROOT="/srv/homeassistant"
            HA_PYENV_ACTIVATION="export PATH=\"$HA_USERROOT/.pyenv/bin:\$PATH\"; eval \"\$(pyenv init -)\"; eval \"\$(pyenv virtualenv-init -)\""
            HA_PYTHON_VERSION="3.6.3"

            G_DIETPI-NOTIFY 2 "HA_USER: $HA_USER"
            G_DIETPI-NOTIFY 2 "HA_USERROOT: $HA_USERROOT"
            G_DIETPI-NOTIFY 2 "HA_SRVROOT: $HA_SRVROOT"
            G_DIETPI-NOTIFY 2 "HA_PYENV_ACTIVATION: $HA_PYENV_ACTIVATION"
            G_DIETPI-NOTIFY 2 "HA_PYTHON_VERSION: $HA_PYTHON_VERSION"

            # Install needed libraries
            G_AGI libssl-dev git cmake libc-ares-dev uuid-dev daemon curl libgnutls28-dev libgnutlsxx28 nmap net-tools sudo libglib2.0-dev libudev-dev swig libssl-dev libusb-1.0-0 gcc libssl-dev libffi-dev libbz2-dev zlib1g-dev libreadline-dev libsqlite3-dev libncurses5-dev libncursesw5-dev
			if (( $G_DISTRO < 4 )); then

				G_AGI libmysqlclient-dev

			else

				G_AGI libmariadbclient-dev

			fi

            # Setup the user account information
            adduser --system $HA_USER
            addgroup $HA_USER
            usermod -G dialout -a $HA_USER
            # this allows the dietpi user to edit the files along with HA.
            usermod -G dietpi -a $HA_USER
            mkdir $HA_SRVROOT
            chown $HA_USER:$HA_USER $HA_SRVROOT

            # Install pyenv
            su --shell /bin/bash --command "cd $HA_USERROOT; curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash" $HA_USER

            # Install Python which is needed for HA.
            su --shell /bin/bash --command "cd $HA_USERROOT; $HA_PYENV_ACTIVATION; pyenv install $HA_PYTHON_VERSION" $HA_USER

            # Make the virtual environment.
            su --shell /bin/bash --command "cd $HA_SRVROOT; $HA_PYENV_ACTIVATION; pyenv virtualenv $HA_PYTHON_VERSION homeassistant-$HA_PYTHON_VERSION" $HA_USER
            su --shell /bin/bash --command "cd $HA_SRVROOT; $HA_PYENV_ACTIVATION; pyenv local homeassistant-$HA_PYTHON_VERSION" $HA_USER
            su --shell /bin/bash --command "cd $HA_SRVROOT; $HA_PYENV_ACTIVATION; pyenv local" $HA_USER

            # Install Home Assistant and extra modules.
            su --shell /bin/bash --command "cd $HA_SRVROOT; $HA_PYENV_ACTIVATION; pyenv activate homeassistant-$HA_PYTHON_VERSION; pip3 install colorlog PyMySQL mysqlclient" $HA_USER
            su --shell /bin/bash --command "cd $HA_SRVROOT; $HA_PYENV_ACTIVATION; pyenv activate homeassistant-$HA_PYTHON_VERSION; pip3 install --upgrade homeassistant" $HA_USER

            # Generate the scripts to launch HA using pyenv.
            echo '#!/bin/bash' > $HA_SRVROOT/homeassistant-start.sh
            echo "cd $HA_SRVROOT" >> $HA_SRVROOT/homeassistant-start.sh
            echo "$HA_PYENV_ACTIVATION" >> $HA_SRVROOT/homeassistant-start.sh
            echo "pyenv activate homeassistant-$HA_PYTHON_VERSION" >> $HA_SRVROOT/homeassistant-start.sh
            echo "hass -c \"$HA_USERROOT/.homeassistant\"" >> $HA_SRVROOT/homeassistant-start.sh
            #su --shell /bin/bash --command "/srv/homeassistant/homeassistant-start.sh" homeassistant
            chmod +x /srv/homeassistant/homeassistant-start.sh

		fi

		#-------------------------------------------------------------------
		#Reset error handler (eg: for usermsg clear set in Banner_Installing)
		G_ERROR_HANDLER_RESET
		#-------------------------------------------------------------------

	}

	Uninstall_NonSelected_Choices(){

		#Uninstall software using our temp uninstall list
		if [ -f "$UNINSTALL_FILE" ]; then

			#Run the temp uninstall script
			while read -r line
			do
				Uninstall_Software "$line"

			done < $UNINSTALL_FILE
			rm $UNINSTALL_FILE

		fi

	}

	Apply_SSHServer_Choices(){

		#Work out which SSH Server needs installing from Indexs (if any)
		#Work out which SSH server needs removing (if any), and, create a temp script file
		if (( $INDEX_SSHSERVER_TARGET != $INDEX_SSHSERVER_CURRENT )); then

			# - No SSH server
			if (( $INDEX_SSHSERVER_TARGET == 0 )); then

				echo -e "104" >> "$UNINSTALL_FILE"
				echo -e "105" >> "$UNINSTALL_FILE"

			# - Dropbear
			elif (( $INDEX_SSHSERVER_TARGET == -1 )); then

				aSOFTWARE_INSTALL_STATE[104]=1
				echo -e "105" >> "$UNINSTALL_FILE"

			# - Openssh
			elif (( $INDEX_SSHSERVER_TARGET == -2 )); then

				aSOFTWARE_INSTALL_STATE[105]=1
				echo -e "104" >> "$UNINSTALL_FILE"

			fi

			#Inform user (From testing, stopping SSH server services does not disconnect user, however, just incase it does in the future)
			G_DIETPI-NOTIFY 3 DietPi-Software "Stopping SSH servers"

			#stop all SSH server services
			service ssh stop &> /dev/null
			service dropbear stop &> /dev/null

			#Update Current SSHSERVER index
			INDEX_SSHSERVER_CURRENT=$INDEX_SSHSERVER_TARGET

		fi

	}

	Apply_FileServer_Choices(){

		#Work out which File Server needs installing from Indexs (if any)
		#Work out which File server needs removing (if any), and, create a temp script file
		if (( $INDEX_FILESERVER_TARGET != $INDEX_FILESERVER_CURRENT )); then

			#No File server
			if (( $INDEX_FILESERVER_TARGET == 0 )); then
				echo -e "96" >> "$UNINSTALL_FILE"
				echo -e "94" >> "$UNINSTALL_FILE"
				#echo -e "95" >> "$UNINSTALL_FILE"

			#ProFTP
			elif (( $INDEX_FILESERVER_TARGET == -1 )); then

				aSOFTWARE_INSTALL_STATE[94]=1
				echo -e "96" >> "$UNINSTALL_FILE"

			#Samba
			elif (( $INDEX_FILESERVER_TARGET == -2 )); then

				aSOFTWARE_INSTALL_STATE[96]=1
				echo -e "94" >> "$UNINSTALL_FILE"

			fi

			#Update Current SSHSERVER index
			INDEX_FILESERVER_CURRENT=$INDEX_FILESERVER_TARGET

		fi

	}

	Apply_Logging_Choices(){

		#Work out which Logging system needs installing from Indexs (if any)
		#Work out which Logging system needs removing (if any), and, create a temp script file
		if (( $INDEX_LOGGING_TARGET != $INDEX_LOGGING_CURRENT )); then

			#None
			if (( $INDEX_LOGGING_TARGET == 0 )); then

				echo -e "101" >> "$UNINSTALL_FILE"
				echo -e "103" >> "$UNINSTALL_FILE"
				echo -e "102" >> "$UNINSTALL_FILE"

			#Ramlog - clear every 24H
			elif (( $INDEX_LOGGING_TARGET == -1 )); then

				aSOFTWARE_INSTALL_STATE[103]=1
				echo -e "101" >> "$UNINSTALL_FILE"
				echo -e "102" >> "$UNINSTALL_FILE"

			#Ramlog - backup every 1H to $HOME/logfile_storage, then clear.
			elif (( $INDEX_LOGGING_TARGET == -2 )); then

				aSOFTWARE_INSTALL_STATE[103]=1
				echo -e "101" >> "$UNINSTALL_FILE"
				echo -e "102" >> "$UNINSTALL_FILE"

			#Logrotate + rsyslog - logs to disk
			elif (( $INDEX_LOGGING_TARGET == -3 )); then

				aSOFTWARE_INSTALL_STATE[101]=1
				aSOFTWARE_INSTALL_STATE[102]=1
				echo -e "103" >> "$UNINSTALL_FILE"

			fi

			#Update Current Logging index
			INDEX_LOGGING_CURRENT=$INDEX_LOGGING_TARGET

		fi

	}

	Apply_Webserver_Preference(){

		if (( $INDEX_WEBSERVER_TARGET != $INDEX_WEBSERVER_CURRENT )); then

			#Update Current to Target
			INDEX_WEBSERVER_CURRENT=$INDEX_WEBSERVER_TARGET

		fi

	}

	Install_Apply_Permissions(){

		#Not all permissions are listed here.
		# - Only ones which are shared across programs, and/or located inside G_FP_DIETPI_USERDATA that require non-root permissions.

		#- /var/www / www-data
		chown -R www-data:www-data /var/www
		chmod -R 775 /var/www

		# - O!MPD, requires write permissions
		chmod -R 777 /var/www/ompd/tmp #(required for database update)
		chmod -R 777 /var/www/ompd/stream #(required for streaming files)
		chmod -R 777 /var/www/ompd/cache #(required for downloading files)

		#Apply non-root permissions for files and folders in G_FP_DIETPI_USERDATA

		# - dietpi user
		chown -R dietpi:dietpi /home/dietpi
		chown -R dietpi:dietpi "$G_FP_DIETPI_USERDATA"
		chmod -R 775 "$G_FP_DIETPI_USERDATA"
		#	+ for symlinked locations
		chown -R dietpi:dietpi "$G_FP_DIETPI_USERDATA"/*
		chmod -R 775 "$G_FP_DIETPI_USERDATA"/*

		# - MPD
		chown -R mpd:audio "$G_FP_DIETPI_USERDATA"/.mpd_cache

		# - MySQL data store
		chown -R mysql:mysql "$G_FP_DIETPI_USERDATA"/mysql
		chmod -R 770 "$G_FP_DIETPI_USERDATA"/mysql

		chown -R mineos:mineos "$G_FP_DIETPI_USERDATA"/mineos/serverdata
		chown -R urbackup:urbackup "$G_FP_DIETPI_USERDATA"/urbackup
		#chown -R couchpotato:couchpotato "$G_FP_DIETPI_USERDATA"/couchpotato

		# - www-data
		chown -R www-data:www-data "$G_FP_DIETPI_USERDATA"/dietpicam
		chown -R www-data:www-data "$G_FP_DIETPI_USERDATA"/pydio_data

		local datadir=$(cat /DietPi/dietpi.txt | grep -m1 '^SOFTWARE_OWNCLOUD_DATADIR=' | sed 's/.*=//')
		[ ! -n "$datadir" ] && datadir="$G_FP_DIETPI_USERDATA/owncloud_data"
		chown -R www-data:www-data "$datadir"

		datadir=$(cat /DietPi/dietpi.txt | grep -m1 '^SOFTWARE_NEXTCLOUD_DATADIR=' | sed 's/.*=//')
		[ ! -n "$datadir" ] && datadir="$G_FP_DIETPI_USERDATA/nextcloud_data"
		chown -R www-data:www-data "$datadir"

		# - Home Assistant Permissions
		#chown -R homeassistant:dietpi /home/homeassistant/.homeassistant
		#chown -R dietpi:dietpi "$G_FP_DIETPI_USERDATA"/homeassistant

		# - Minio
		chown -R minio-user:minio-user "$G_FP_DIETPI_USERDATA"/minio-data

		# - FuguHub
		chown -R bd:bd "$G_FP_DIETPI_USERDATA"/fuguhub-data/

		# - Nodered
		chown -R nodered:nodered "$G_FP_DIETPI_USERDATA"/node-red

	}

	#/////////////////////////////////////////////////////////////////////////////////////
	# Configuration post installation goes here.
	#
	# Reference:
	# - Adding new software to DietPi-Software
	#   https://github.com/Fourdee/DietPi/issues/490#issuecomment-244416570
	#
	# Adding post installation steps.
	# ------------------------------------
	# - INSTALLING_INDEX:
	#   This has to be the same number as index_current for the software list above.
	#
	# Here you can add any configuration changes or addtions to systemd. After this
	# has run it will reload the systemd environment and start any services installed
	# and referenced in 'dietpi-services'
	#
	# Example:
	#	#------------------ Desktop: MATE ------------------
	#	INSTALLING_INDEX=24
	#	if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then
	#
	#		# - file manager desktop icon
	#		ln -sf /usr/share/applications/caja.desktop "$HOME"/Desktop/caja.desktop
	#
	#		Create_Desktop_Shared_Items
	#
	#		#Odroid C2, define default pulseaudio sink: https://github.com/Fourdee/DietPi/issues/415
	#		if (( $G_HW_MODEL == 12 &&
	#			! $(cat /etc/pulse/default.pa | grep -ci -m1 '^set-default-sink alsa_output.platform-odroid_hdmi.37.analog-stereo') )); then
	#
	#			echo -e "set-default-sink alsa_output.platform-odroid_hdmi.37.analog-stereo" >> /etc/pulse/default.pa
	#
	#		fi
	#
	#	fi
	#
	#/////////////////////////////////////////////////////////////////////////////////////
	Install_Apply_Configs(){

		# Copy/Set optimised Software settings.
		# Set install states to 2 (installed).

		#DESKTOP_LXDE
		INSTALLING_INDEX=23
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Remove Lxrandr Menu item (monitor configuration tool as we set res in dietpi-config)
			rm /usr/share/applications/lxrandr.desktop &> /dev/null

			#Copy PCmanFM configs
			mkdir -p "$HOME"/.config/pcmanfm/LXDE
			wget http://dietpi.com/downloads/conf/desktop/pcmanfm.conf -O "$HOME"/.config/pcmanfm/LXDE/pcmanfm.conf
			wget http://dietpi.com/downloads/conf/desktop/pcmanfm-desktopitems.conf -O "$HOME"/.config/pcmanfm/LXDE/desktop-items-0.conf

			#Disable Trash
			sed -i '/use_trash=/c\use_trash=0' /etc/xdg/libfm/libfm.conf

			#Copy DietPi Panel config
			mkdir -p "$HOME"/.config/lxpanel/LXDE/panels
			wget http://dietpi.com/downloads/conf/desktop/panel -O "$HOME"/.config/lxpanel/LXDE/panels/panel

			#Openbox config
			mkdir -p "$HOME"/.config/openbox
			wget http://dietpi.com/downloads/conf/desktop/lxde-rc.xml -O "$HOME"/.config/openbox/lxde-rc.xml

			# - file manager desktop icon
			ln -sf /usr/share/applications/pcmanfm.desktop "$HOME"/Desktop/pcmanfm.desktop

			Create_Desktop_Shared_Items

		fi

		#Desktop MATE
		INSTALLING_INDEX=24
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# - file manager desktop icon
			ln -sf /usr/share/applications/caja.desktop "$HOME"/Desktop/caja.desktop

			Create_Desktop_Shared_Items

			#Odroid C2, define default pulseaudio sink: https://github.com/Fourdee/DietPi/issues/415
			if (( $G_HW_MODEL == 12 &&
				! $(cat /etc/pulse/default.pa | grep -ci -m1 '^set-default-sink alsa_output.platform-odroid_hdmi.37.analog-stereo') )); then

				echo -e "set-default-sink alsa_output.platform-odroid_hdmi.37.analog-stereo" >> /etc/pulse/default.pa

			fi

		fi

		#Desktop GNUStep
		INSTALLING_INDEX=26
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			Create_Desktop_Shared_Items

		fi

		#DESKTOP_XFCE
		INSTALLING_INDEX=25
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			Create_Desktop_Shared_Items

		fi

		#WEBSERVER_APACHE
		INSTALLING_INDEX=83
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#create www directory
			mkdir -p /var/www

			#Apache2 confs
			cp /DietPi/dietpi/conf/apache2_jessie.conf /etc/apache2/apache2.conf
			cat << _EOF_ > /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
_EOF_

			cat << _EOF_ > /etc/apache2/mods-available/mpm_event.conf
<IfModule mpm_event_module>
StartServers		 $G_HW_CPU_CORES
MinSpareThreads		 1
MaxSpareThreads		 8
ThreadLimit		 	16
ThreadsPerChild		 4
MaxRequestWorkers	 50
MaxConnectionsPerChild   0
</IfModule>
_EOF_

			cat << _EOF_ > /etc/apache2/mods-available/mpm_prefork.conf
<IfModule mpm_prefork_module>
StartServers		 $G_HW_CPU_CORES
MinSpareServers		 1
MaxSpareServers		 $G_HW_CPU_CORES
MaxRequestWorkers	 50
MaxConnectionsPerChild   0
</IfModule>
_EOF_

			cat << _EOF_ > /etc/apache2/mods-available/mpm_worker.conf
<IfModule mpm_worker_module>
StartServers		 $G_HW_CPU_CORES
MinSpareThreads		 1
MaxSpareThreads		 8
ThreadLimit		 	16
ThreadsPerChild		 4
MaxRequestWorkers	 50
MaxConnectionsPerChild   0
</IfModule>
_EOF_

			#Use /var/www as default webfolder
			mv /var/www/html/index.html /var/www/index.html &> /dev/null
			rm -R /var/www/html &> /dev/null

			#Sites-Available settings. Disable access log, set error log level
			sed -i "/CustomLog /c\        #CustomLog "'${APACHE_LOG_DIR}'"/access.log combined" /etc/apache2/sites-available/*
			sed -i "/LogLevel /c\        LogLevel error" /etc/apache2/sites-available/*

		fi

		#WEBSERVER_NGINX
		INSTALLING_INDEX=85
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#create www directory
			mkdir -p /var/www

			#Nginx confs
			mkdir /etc/nginx/sites-dietpi

			cp /DietPi/dietpi/conf/nginx.conf /etc/nginx/nginx.conf
			# - Stretch , set php7.0
			if (( $G_DISTRO >= 4 )); then
				sed -i "s#/run/php5-fpm.sock#/run/php/php7.0-fpm.sock#g" /etc/nginx/nginx.conf
			fi

			# - CPU core count
			sed -i "/worker_processes/c\worker_processes $G_HW_CPU_CORES;" /etc/nginx/nginx.conf

			#Default site
			cp /DietPi/dietpi/conf/nginx.site-available-default /etc/nginx/sites-available/default
			# - Stretch , set php7.0
			if (( $G_DISTRO >= 4 )); then
				sed -i "s#/run/php5-fpm.sock#/run/php/php7.0-fpm.sock#g" /etc/nginx/sites-available/default
			fi

			# - Nginx index page
			cp /usr/share/nginx/html/index.html /var/www/index.html

		fi

		#WEBSERVER_LIGHTTPD
		INSTALLING_INDEX=84
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#create www directory
			mkdir -p /var/www

			#www path
			sed -i '/^server.document-root/c\server.document-root        = "/var/www"' /etc/lighttpd/lighttpd.conf

			#Configure fastcgi for PHP-FPM
			local fp_php_fpm_sock='/var/run/php/php7.0-fpm.sock'
			if (( $G_DISTRO == 3 )); then

				fp_php_fpm_sock='/var/run/php5-fpm.sock'

			fi

			cat << _EOF_ > /etc/lighttpd/conf-available/15-fastcgi-php.conf
# -*- depends: fastcgi -*-
# /usr/share/doc/lighttpd/fastcgi.txt.gz
# http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ConfigurationOptions#mod_fastcgi-fastcgi

## Start an FastCGI server using php-fpm
fastcgi.server += ( ".php" =>
        ((
                "socket" => "$fp_php_fpm_sock",
                "broken-scriptfilename" => "enable"
        ))
)
_EOF_

			#enable cgi/php
			lighttpd-enable-mod fastcgi
			lighttpd-enable-mod fastcgi-php

			#Move default page
			mv /var/www/html/index.lighttpd.html /var/www/

			service lighttpd force-reload

		fi

		#WEBSERVER_PHP
		INSTALLING_INDEX=89
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# - Apache2 has its own PHP module
			if (( ${aSOFTWARE_INSTALL_STATE[83]} >= 1 )); then

				# https://github.com/Fourdee/DietPi/issues/1144
				local php_service='/lib/systemd/system/apache2.service'

			# - All other webservers (eg: Nginx/Lighttpd) use PHP-FPM
			else

				local php_service='/lib/systemd/system/php*-fpm.service'

				# - PHP-FPM confs
				sed -i '/cgi.fix_pathinfo=/c\cgi.fix_pathinfo=1' "$FP_PHP_BASE_DIR"/fpm/php.ini

				# - PHP-FPM optimizations based on total cores
				sed -i "/pm.max_children = /c\pm.max_children = $(( $G_HW_CPU_CORES * 3 ))" "$FP_PHP_BASE_DIR"/fpm/pool.d/www.conf
				sed -i "/pm.start_servers = /c\pm.start_servers = $G_HW_CPU_CORES" "$FP_PHP_BASE_DIR"/fpm/pool.d/www.conf
				sed -i "/pm.min_spare_servers = /c\pm.min_spare_servers = $G_HW_CPU_CORES" "$FP_PHP_BASE_DIR"/fpm/pool.d/www.conf
				sed -i "/pm.max_spare_servers = /c\pm.max_spare_servers = $G_HW_CPU_CORES" "$FP_PHP_BASE_DIR"/fpm/pool.d/www.conf

				# - Enviroment PHP settings:
				sed -i "/env\[HOSTNAME\]/c\env\[HOSTNAME\] = \$HOSTNAME" "$FP_PHP_BASE_DIR"/fpm/pool.d/www.conf
				sed -i "/env\[PATH\]/c\env\[PATH\] = /usr/local/bin:/usr/bin:/bin" "$FP_PHP_BASE_DIR"/fpm/pool.d/www.conf

				#	/tmp is mounted to RAM, so use DISK (/var/tmp) instead
				sed -i "/env\[TMP\]/c\env\[TMP\] = /var/tmp" "$FP_PHP_BASE_DIR"/fpm/pool.d/www.conf
				sed -i "/env\[TMPDIR\]/c\env\[TMPDIR\] = /var/tmp" "$FP_PHP_BASE_DIR"/fpm/pool.d/www.conf
				sed -i "/env\[TEMP\]/c\env\[TEMP\] = /var/tmp" "$FP_PHP_BASE_DIR"/fpm/pool.d/www.conf

			fi

			# PHP cache settings
			local target_php_ini=0
			local target_php_cachesize=$(( $RAM_TOTAL / 30 ))
			if (( $target_php_cachesize < 10 )); then

				target_php_cachesize=10

			fi

			# - OPcache
			if (( ${aSOFTWARE_INSTALL_STATE[83]} >= 1 )); then

				target_php_ini="$FP_PHP_BASE_DIR/apache2/php.ini"

			else

				target_php_ini="$FP_PHP_BASE_DIR/fpm/php.ini"

			fi

			sed -i "/opcache.enable=/c\opcache.enable=1" $target_php_ini
			sed -i "/opcache.memory_consumption=/c\opcache.memory_consumption=$target_php_cachesize" $target_php_ini
			sed -i "/opcache.revalidate_freq=/c\opcache.revalidate_freq=60" $target_php_ini

			# - APCu
			target_php_ini="$FP_PHP_BASE_DIR/mods-available/apcu.ini"
			# - - apc.shm_size= requires M at end to prevent warning: https://github.com/Fourdee/DietPi/issues/218
			target_php_cachesize+="M"
			# - - 3days TTL
			local target_apc_ttl='259200'

			cat << _EOF_ > "$target_php_ini"
extension=apcu.so
apc.shm_size=$target_php_cachesize
apc.ttl=$target_apc_ttl
_EOF_


			# We create our own PHP mod to add DietPi specific configs.
			local dietpi_php_ini="$FP_PHP_BASE_DIR/mods-available/dietpi.ini"
			touch $dietpi_php_ini

			# - Set tmp_upload_dir to sd. Can't be /tmp as its ramdisk and limited size. Also used by ownCloud/Nextcloud uploads
			# - If PHP uses PrivateTmp, we must not use own subfolder: https://github.com/Fourdee/DietPi/issues/1144
			if grep -q '^\s*PrivateTmp=true' $php_service &> /dev/null; then

				local tmp_upload_dir="/var/tmp"

			else

				local tmp_upload_dir="/var/tmp/php_upload_tmp"
				mkdir -p "$tmp_upload_dir"
				chown -R www-data:www-data "$tmp_upload_dir"

			fi
			grep -q 'upload_tmp_dir' $dietpi_php_ini &&
			sed -i "/upload_tmp_dir/c\upload_tmp_dir = $tmp_upload_dir" $dietpi_php_ini ||
			echo "upload_tmp_dir = $tmp_upload_dir" >> $dietpi_php_ini

			# - max upload size
			local php_max_upload_size="$(( $(php -r 'print(PHP_INT_MAX);') / 1024 / 1024))M"

			# - - upload_max_filesize
			grep -q 'upload_max_filesize' $dietpi_php_ini &&
			sed -i "/upload_max_filesize/c\upload_max_filesize = $php_max_upload_size" $dietpi_php_ini ||
			echo "upload_max_filesize = $php_max_upload_size" >> $dietpi_php_ini

			# - - post_max_size
			grep -q 'post_max_size' $dietpi_php_ini &&
			sed -i "/post_max_size/c\post_max_size = $php_max_upload_size" $dietpi_php_ini ||
			echo "post_max_size = $php_max_upload_size" >> $dietpi_php_ini

			# - - Nginx - Set client_max_body_size to avoid 2MB upload error: https://github.com/Fourdee/DietPi/issues/546
			if (( ${aSOFTWARE_INSTALL_STATE[85]} >= 1 )); then

				sed -i "/client_max_body_size/c\    client_max_body_size $php_max_upload_size;" /etc/nginx/nginx.conf

			fi

			# - Set UTF-8
			grep -q 'default_charset' $dietpi_php_ini &&
			sed -i '/default_charset/c\default_charset = "UTF-8"' $dietpi_php_ini ||
			echo 'default_charset = "UTF-8"' >> $dietpi_php_ini

			# Enable all installed and available PHP modules.
			local modules_to_enable=$(ls "$FP_PHP_BASE_DIR"/mods-available | grep '.ini' | sed 's/.ini//')
			${PHP_APT_PACKAGE_NAME}enmod "$modules_to_enable"

			# PHP info page
			echo "<?php phpinfo(); ?>" > /var/www/phpinfo.php

			# OPcache info page
			wget https://raw.githubusercontent.com/rlerdorf/opcache-status/master/opcache.php -O /var/www/opcache.php

			# APC info page
			wget https://github.com/krakjoe/apcu/raw/master/apc.php -O /var/www/apc.php

		fi

		#WEBSERVER_MARIADB
		INSTALLING_INDEX=88
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# Move SQL store to userdata location: https://github.com/Fourdee/DietPi/issues/672
			if [ "$(readlink /var/lib/mysql)" != "$G_FP_DIETPI_USERDATA/mysql/" ]; then

				G_RUN_CMD systemctl stop mysql

				# - Create target dir
				mkdir -p "$G_FP_DIETPI_USERDATA"/mysql

				# - copy
				cp -a /var/lib/mysql/* "$G_FP_DIETPI_USERDATA"/mysql/
				if (( $? != 0 )); then

					G_DIETPI-NOTIFY 1 "Moving of MySQL data store failed to $G_FP_DIETPI_USERDATA/mysql. DietPi-Software will now exit"
					Exit_Destroy

				fi

				rm -R /var/lib/mysql &> /dev/null || rm /var/lib/mysql &> /dev/null

				# - Symlink
				ln -sf "$G_FP_DIETPI_USERDATA"/mysql /var/lib/mysql

				chown mysql:mysql /var/lib/mysql

				# - Set permissions on data store directory NOW.
				Install_Apply_Permissions &> /dev/null

			fi

			# On Jessie assure unix_socket authentication:
			if (( $G_DISTRO < 4 )); then

				G_RUN_CMD systemctl start mysql
				mysql -e "install plugin unix_socket soname 'auth_socket';" &> /dev/null
				mysql -e "grant all privileges on *.* to 'root'@'localhost' identified via unix_socket with grant option;flush privileges"
				# Drop unnecessary root user children.
				mysql -e "drop user 'root'@'dietpi';drop user 'root'@'127.0.0.1';drop user 'root'@'::1'" &> /dev/null

			fi

			### Also for MariaDB?
			# Optimize for reduced memory use: https://github.com/Fourdee/DietPi/issues/605#issue-188930987
			#cat << _EOF_ > /etc/mysql/conf.d/reduce_resources.cnf
#[mysqld]
#key_buffer_size=8M
#max_connections=30
#query_cache_size=8M
#query_cache_limit=512K
#thread_stack=128K
#_EOF_

		fi

		#WEBSERVER_MYADMINPHP
		INSTALLING_INDEX=90
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#NGINX LIGHTTPD symlink to var www
			if (( ${aSOFTWARE_INSTALL_STATE[84]} >= 1 ||
				${aSOFTWARE_INSTALL_STATE[85]} >= 1 )); then

				ln -sf /usr/share/phpmyadmin /var/www

			fi

			# Due to MariaDB unix_socket authentication, "root" cannot be used to login the web ui.
			# Thus default "phpmyadmin" user need to be used, who on Jessie does not have all privileges:
			# http://dietpi.com/phpbb/viewtopic.php?f=8&t=5&p=54#p54
			mysql -e "grant all privileges on *.* to phpmyadmin@localhost with grant option"

		fi

		#WEBSERVER_REDIS
		INSTALLING_INDEX=91
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# Enable redis php module, if installed:
			"$PHP_APT_PACKAGE_NAME"enmod redis 2> /dev/null

		fi

		#OPENBAZAAR
		INSTALLING_INDEX=58
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# - service
			cat << _EOF_ > /etc/systemd/system/openbazaar.service
[Unit]
Description=openbazaar

[Service]
Type=simple
WorkingDirectory=/etc/openbazaar-server
ExecStart=$(which python) openbazaard.py start -a 0.0.0.0

[Install]
WantedBy=multi-user.target
_EOF_

		fi

		#YaCy
		INSTALLING_INDEX=133
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			chmod +x -R /etc/yacy

			cat << _EOF_ > /etc/systemd/system/yacy.service
[Unit]
Description=DietPi YaCy Service

[Service]
Type=simple
RemainAfterExit=yes
ExecStart=/bin/bash -c '/etc/yacy/startYACY.sh'
ExecStop=/bin/bash -c '/etc/yacy/stopYACY.sh'

[Install]
WantedBy=multi-user.target
_EOF_
			systemctl daemon-reload

			#	Create admin login account:
			/etc/yacy/bin/passwd.sh "$GLOBAL_PW"

		fi

		#ownCloud
		INSTALLING_INDEX=47
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			G_DIETPI-NOTIFY 2 'Enabling needed PHP modules: https://doc.owncloud.org/server/latest/admin_manual/installation/source_installation.html#php-extensions'
			"$PHP_APT_PACKAGE_NAME"enmod curl gd intl json pdo_mysql opcache apcu redis
			# Following modules are switchable since Stretch:
			if (( $G_DISTRO > 3 )); then

				phpenmod ctype dom fileinfo iconv mbstring posix simplexml xmlwriter xmlreader zip exif

			fi

			# APCu configuration: To prevent cli (cron.php) producing ownCloud log entries.
			grep -q 'apc.enable_cli=' $FP_PHP_BASE_DIR/mods-available/apcu.ini && sed -i '/apc.enable_cli=/c\apc.enable_cli=1' $FP_PHP_BASE_DIR/mods-available/apcu.ini || echo 'apc.enable_cli=1' >> $FP_PHP_BASE_DIR/mods-available/apcu.ini

			if (( ${aSOFTWARE_INSTALL_STATE[83]} >= 1 )); then

				G_DIETPI-NOTIFY 2 'Apache webserver found, enable ownCloud specific configuration: "https://doc.owncloud.org/server/latest/admin_manual/installation/source_installation.html#configure-apache-web-server"'
				a2enmod rewrite headers env dir mime 1> /dev/null
				local owncloud_conf='/etc/apache2/sites-available/owncloud.conf'
				if [ -f $owncloud_conf ]; then

					G_DIETPI-NOTIFY 2 'Existing ownCloud configuration found, will save the new one for review and comparison to: /etc/apache2/sites-available/owncloud.conf.dietpi-new'
					owncloud_conf='/etc/apache2/sites-available/owncloud.conf.dietpi-new'

				fi
				cp /DietPi/dietpi/conf/apache.ownnextcloud.conf $owncloud_conf
				sed -i 's/nextcloud/owncloud/g' $owncloud_conf
				# OPcache adjustment is just needed by Nextcloud
				sed -i 's/php_admin_value/#php_admin_value/' $owncloud_conf
				a2ensite owncloud 1> /dev/null

			fi

			if (( ${aSOFTWARE_INSTALL_STATE[85]} >= 1 )); then

				G_DIETPI-NOTIFY 2 'Nginx webserver found, enable ownCloud specific configuration: "https://doc.owncloud.org/server/latest/admin_manual/installation/nginx_configuration.html#owncloud-in-a-subdir-of-nginx"'
				local owncloud_config='/etc/nginx/sites-dietpi/owncloud.config'
				if [ -f $owncloud_config ]; then

					G_DIETPI-NOTIFY 2 'Existing ownCloud configuration found, will save the new one for review and comparison to: /etc/nginx/sites-dietpi/owncloud.config.dietpi-new'
					owncloud_config='/etc/nginx/sites-dietpi/owncloud.config.dietpi-new'

				fi
				cp /DietPi/dietpi/conf/nginx.sites-dietpi.owncloud.config $owncloud_config

				# Stretch: Use PHP7.0 socket and set 'fastcgi_request_buffering off';
				if (( $G_DISTRO > 3 )); then

					sed -i 's|/run/php5-fpm.sock|/run/php/php7.0-fpm.sock|g' $owncloud_config
					sed -i 's/#fastcgi_request_buffering off;/fastcgi_request_buffering off;/g' $owncloud_config

				fi

				# Set HTTPS on, if SSL connection is available, even with self-signed/untrusted certificate.
				wget -q --spider --timeout=10 --tries=2 https://localhost &> /dev/null
				if (( $? == 0 || $? == 5)); then

					sed -i 's/#fastcgi_param HTTPS on;/fastcgi_param HTTPS on;/g' $owncloud_config

				fi

			fi

			# Enable 4-byte support for MariaDB: https://doc.owncloud.org/server/latest/admin_manual/configuration/database/linux_database_configuration.html#configure-mysql-for-4-byte-unicode-support
			cat << _EOF_ > /etc/mysql/mariadb.conf.d/99-dietpi-4byte.cnf
[mysqld]
innodb_large_prefix=1
innodb_file_format=barracuda
innodb_file_per_table=1
_EOF_
			G_RUN_CMD systemctl restart mysql

			# Reload dietpi-globals to enable occ command shortcut:
			. /DietPi/dietpi/func/dietpi-globals

			# Adjusting config file:
			local config_php='/var/www/owncloud/config/config.php'

			local datadir="$(grep -m1 '^[[:blank:]]*SOFTWARE_OWNCLOUD_DATADIR=' /DietPi/dietpi.txt | sed 's/^.*=//')"
			[ -n "$datadir" ] || datadir="$G_FP_DIETPI_USERDATA/owncloud_data"
			mkdir -p "$datadir"
			Install_Apply_Permissions &> /dev/null

			if [ -d "$G_FP_DIETPI_USERDATA"/mysql/owncloud ]; then

				G_DIETPI-NOTIFY 2 'ownCloud database found, will NOT overwrite.'

			else

				if [ -f "$datadir"/dietpi-owncloud-database-backup.sql ]; then

					G_DIETPI-NOTIFY 2 'ownCloud database backup found, starting recovery...'
					local dbuser=$(grep -m1 "^[[:blank:]]*'dbuser'" $config_php | awk '{print $3}' | sed "s/[',]//g")
					local dbpass=$(grep -m1 "^[[:blank:]]*'dbpassword'" $config_php | awk '{print $3}' | sed "s/[',]//g")
					/DietPi/dietpi/func/create_mysql_db owncloud "$dbuser" "$dbpass"
					mysql -uroot owncloud < "$datadir"/dietpi-owncloud-database-backup.sql

				else

					local username="$(cat /DietPi/dietpi.txt | grep -m1 '^[[:blank:]]*SOFTWARE_OWNCLOUD_NEXTCLOUD_USERNAME=' | sed 's/^.*=//')"
					[ -n "$username" ] || username='admin'

					# For MariaDB, temporary database admin user needs to be created, as 'root' uses unix_socket login, which cannot be accessed by sudo -u www-data.
					mysql -e "grant all privileges on *.* to 'tmp_root'@'localhost' identified by '$GLOBAL_PW' with grant option"
					grep -q "'installed' => true," $config_php 2>/dev/null || occ maintenance:install --no-interaction --database "mysql" --database-name "owncloud" --database-user "tmp_root" --database-pass "$GLOBAL_PW" --admin-user "$username" --admin-pass "$GLOBAL_PW" --data-dir "$datadir"
					mysql -e "drop user 'tmp_root'@'localhost'"

				fi

			fi

			# Enable ownCloud to use 4-byte database
			grep -q "^[[:blank:]]*'mysql.utf8mb4'" $config_php || sed -i "/^[[:blank:]]*'dbpassword'/a \ \ 'mysql.utf8mb4' => true," $config_php

			# Add local IP and hostname to trusted domains.
			# If "1 => '" does not exist, the config.php is not copied e.g. from older instance, so we add entries.
			if (( ! $(cat $config_php | grep -ci -m1 "1 => '") )); then

				sed -i "/0 => 'localhost'/a     1 => '$(sed -n 4p /DietPi/dietpi/.network)'," $config_php
				sed -i "/1 => '/a     2 => '$(cat /etc/hostname)'," $config_php

			fi

			# Set CLI URL to ownCloud sub directory:
			sed -i "s|'http://localhost'|'http://localhost/owncloud'|g" $config_php

			# Set pretty URLs (without /index.php/) on Apache:
			if (( ${aSOFTWARE_INSTALL_STATE[83]} >= 1 )); then

				grep -q "^[[:blank:]]*'htaccess.RewriteBase'" $config_php || sed -i "/^[[:blank:]]*'overwrite.cli.url'/a \ \ 'htaccess.RewriteBase' => '/owncloud'," $config_php
				occ maintenance:update:htaccess

			fi

			# APCu Memcache
			grep -q "^[[:blank:]]*'memcache.local'" $config_php || sed -i "/^[[:blank:]]*'version'/a \ \ 'memcache.local' => '\\\OC\\\Memcache\\\APCu'," $config_php

			# Redis for transactional file locking:
			# https://doc.owncloud.org/server/latest/admin_manual/configuration/server/caching_configura$
			# - Enable Redis socket and grant www-data access to it:
			local redis_conf="/etc/redis/redis*.conf"
			grep -q "^[[:blank:]]*unixsocket /" $redis_conf || grep -q '^[[:blank:]]*#unixsocket /' $redis_conf && sed -i 's|^[[:blank:]]*#unixsocket /|unixsocket /|' $redis_conf || echo 'unixsocket /var/run/redis/redis.sock' >> $redis_conf
			grep -q "^[[:blank:]]*#?unixsocketperm " $redis_conf && sed -i "/^[[:blank:]]*#?unixsocketperm /c\unixsocketperm 770" $redis_conf || echo 'unixsocketperm 770' >> $redis_conf
			local redis_sock=$(grep "^[[:blank:]]*unixsocket /" $redis_conf | sed "s/^[[:blank:]]*unixsocket //")
			usermod -a -G redis www-data
			# - Enable ownCloud to use Redis socket:
			if (( ! $(cat $config_php | grep -ci -m1 "'memcache.locking'") )); then

				sed -i "\#'memcache.local'#a \ \ 'filelocking.enabled' => true,\n\
  'memcache.locking' => '\\\OC\\\Memcache\\\Redis',\n\
  'redis' => [\n\
    'host' => '$redis_sock',\n\
    'port' => 0,\n\
  ]," $config_php

			fi

			# Enable ownCloud background cron job:
			crontab -u www-data -l 2>/dev/null | grep -q '/var/www/owncloud/cron.php' || ( crontab -u www-data -l 2>/dev/null ; echo "*/15 * * * * php /var/www/owncloud/cron.php" ) | crontab -u www-data -
			occ background:cron

			# Enable maintenance mode to allow handling by dietpi-services:
			grep -q "^[[:blank:]]*'maintenance' => true," $config_php || occ maintenance:mode --on

		fi

		#Nextcloud
		INSTALLING_INDEX=114
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			G_DIETPI-NOTIFY 2 'Enabling needed PHP modules: https://docs.nextcloud.com/server/12/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation'
			"$PHP_APT_PACKAGE_NAME"enmod curl gd intl json pdo_mysql opcache apcu redis
			# Following modules are switchable since Stretch:
			if (( $G_DISTRO > 3 )); then

				phpenmod ctype dom fileinfo iconv mbstring posix simplexml xmlwriter xmlreader zip exif

			fi

			# APCu configuration: To prevent cli (cron.php) producing Nextcloud log [info] entries.
			grep -q 'apc.enable_cli=' $FP_PHP_BASE_DIR/mods-available/apcu.ini && sed -i '/apc.enable_cli=/c\apc.enable_cli=1' $FP_PHP_BASE_DIR/mods-available/apcu.ini || echo 'apc.enable_cli=1' >> $FP_PHP_BASE_DIR/mods-available/apcu.ini

			# OPCache configuration: https://docs.nextcloud.com/server/12/admin_manual/configuration_server/server_tuning.html?highlight=opcache#enable-php-opcache
			grep -q 'opcache.enable=' $FP_PHP_BASE_DIR/mods-available/opcache.ini && sed -i '/opcache.enable=/c\opcache.enable=1' $FP_PHP_BASE_DIR/mods-available/opcache.ini || echo 'opcache.enable=1' >> $FP_PHP_BASE_DIR/mods-available/opcache.ini
			grep -q 'opcache.enable_cli=' $FP_PHP_BASE_DIR/mods-available/opcache.ini && sed -i '/opcache.enable_cli=/c\opcache.enable_cli=1' $FP_PHP_BASE_DIR/mods-available/opcache.ini || echo 'opcache.enable_cli=1' >> $FP_PHP_BASE_DIR/mods-available/opcache.ini
			grep -q 'opcache.interned_strings_buffer=' $FP_PHP_BASE_DIR/mods-available/opcache.ini && sed -i '/opcache.interned_strings_buffer=/c\opcache.interned_strings_buffer=8' $FP_PHP_BASE_DIR/mods-available/opcache.ini || echo 'opcache.interned_strings_buffer=8' >> $FP_PHP_BASE_DIR/mods-available/opcache.ini
			grep -q 'opcache.max_accelerated_files=' $FP_PHP_BASE_DIR/mods-available/opcache.ini && sed -i '/opcache.max_accelerated_files=/c\opcache.max_accelerated_files=10000' $FP_PHP_BASE_DIR/mods-available/opcache.ini || echo 'opcache.max_accelerated_files=10000' >> $FP_PHP_BASE_DIR/mods-available/opcache.ini
			grep -q 'opcache.save_comments=' $FP_PHP_BASE_DIR/mods-available/opcache.ini && sed -i '/opcache.save_comments=/c\opcache.save_comments=1' $FP_PHP_BASE_DIR/mods-available/opcache.ini || echo 'opcache.save_comments=1' >> $FP_PHP_BASE_DIR/mods-available/opcache.ini
			grep -q 'opcache.revalidate_freq=' $FP_PHP_BASE_DIR/mods-available/opcache.ini && sed -i '/opcache.revalidate_freq=/c\opcache.revalidate_freq=1' $FP_PHP_BASE_DIR/mods-available/opcache.ini || echo 'opcache.revalidate_freq=1' >> $FP_PHP_BASE_DIR/mods-available/opcache.ini

			if (( ${aSOFTWARE_INSTALL_STATE[83]} >= 1 )); then

				G_DIETPI-NOTIFY 2 'Apache webserver found, enable Nextcloud specific configuration: "https://docs.nextcloud.com/server/12/admin_manual/installation/source_installation.html#apache-web-server-configuration"'
				a2enmod rewrite headers env dir mime 1> /dev/null
				local nextcloud_conf='/etc/apache2/sites-available/nextcloud.conf'
				if [ -f $nextcloud_conf ]; then

					G_DIETPI-NOTIFY 2 'Existing Nextcloud configuration found, will save the new one for review and comparison to: /etc/apache2/sites-available/nextcloud.conf.dietpi-new'
					nextcloud_conf='/etc/apache2/sites-available/nextcloud.conf.dietpi-new'

				fi
				cp /DietPi/dietpi/conf/apache.ownnextcloud.conf $nextcloud_conf
				a2ensite nextcloud 1> /dev/null

			fi

			if (( ${aSOFTWARE_INSTALL_STATE[85]} >= 1 )); then

				G_DIETPI-NOTIFY 2 'Nginx webserver found, enable Nextcloud specific configuration: "https://docs.nextcloud.com/server/12/admin_manual/installation/nginx.html#nextcloud-in-a-subdir-of-nginx"'
				local nextcloud_config='/etc/nginx/sites-dietpi/nextcloud.config'
				if [ -f $nextcloud_config ]; then

					G_DIETPI-NOTIFY 2 'Existing Nextcloud configuration found, will save the new one for review and comparison to: /etc/nginx/sites-dietpi/nextcloud.config.dietpi-new'
					nextcloud_config='/etc/nginx/sites-dietpi/nextcloud.config.dietpi-new'

				fi
				cp /DietPi/dietpi/conf/nginx.sites-dietpi.nextcloud.config $nextcloud_config

				# Stretch: Use PHP7.0 socket and set 'fastcgi_request_buffering off';
				if (( $G_DISTRO > 3 )); then

					sed -i 's|/run/php5-fpm.sock|/run/php/php7.0-fpm.sock|g' $nextcloud_config
					sed -i 's/#fastcgi_request_buffering off;/fastcgi_request_buffering off;/g' $nextcloud_config

				fi

				# Set HTTPS on, if SSL connection is available, even with self-signed/untrusted certificate.
				wget -q --spider --timeout=10 --tries=2 https://localhost &> /dev/null
				if (( $? == 0 || $? == 5)); then

					sed -i 's/#fastcgi_param HTTPS on;/fastcgi_param HTTPS on;/g' $nextcloud_config

				fi

			fi

			if (( ${aSOFTWARE_INSTALL_STATE[84]} >= 1 )); then

				G_DIETPI-NOTIFY 2 'Lighttpd webserver found, enable Nextcloud specific configuration.'
				local lighttpd_conf='/etc/lighttpd/lighttpd.conf'

				# Enable mod_setenv
				grep -q '^[[:blank:]]*"mod_setenv",' $lighttpd_conf ||
				grep -q '^[[:blank:]#;]*"mod_setenv",' $lighttpd_conf &&
				sed -i '/^[[:blank:]#;]*"mod_setenv",/c\	"mod_setenv",' $lighttpd_conf ||
				sed -i '/^[[:blank:]]*server.modules = (/a\	"mod_setenv",' $lighttpd_conf

				# Move Nextcloud configuration file in place and activate it
				[ ! -f /etc/lighttpd/conf-available/99-dietpi-nextcloud.conf ] && cp /DietPi/dietpi/conf/lighttpd.nextcloud.conf /etc/lighttpd/conf-available/99-dietpi-nextcloud.conf
				lighttpd-enable-mod dietpi-nextcloud
				service lighttpd force-reload

			fi

			# Enable 4-byte support for MariaDB: https://docs.nextcloud.com/server/12/admin_manual/configuration_database/mysql_4byte_support.html
			cat << _EOF_ > /etc/mysql/mariadb.conf.d/99-dietpi-4byte.cnf
[mysqld]
innodb_large_prefix=1
innodb_file_format=barracuda
innodb_file_per_table=1
_EOF_
			G_RUN_CMD systemctl restart mysql

			# Reload dietpi-globals to enable ncc command shortcut:
			. /DietPi/dietpi/func/dietpi-globals

			# Adjusting config file:
			local config_php='/var/www/nextcloud/config/config.php'

			local datadir="$(grep -m1 '^[[:blank:]]*SOFTWARE_NEXTCLOUD_DATADIR=' /DietPi/dietpi.txt | sed 's/^.*=//')"
			[ -n "$datadir" ] || datadir="$G_FP_DIETPI_USERDATA/nextcloud_data"
			mkdir -p "$datadir"
			Install_Apply_Permissions &> /dev/null

			if [ -d "$G_FP_DIETPI_USERDATA"/mysql/nextcloud ]; then

				G_DIETPI-NOTIFY 2 'Nextcloud database found, will NOT overwrite.'

			else

				if [ -f "$datadir"/dietpi-nextcloud-database-backup.sql ]; then

					G_DIETPI-NOTIFY 2 'Nextcloud database backup found, starting recovery...'
					local dbuser=$(grep -m1 "^[[:blank:]]*'dbuser'" $config_php | awk '{print $3}' | sed "s/[',]//g")
					local dbpass=$(grep -m1 "^[[:blank:]]*'dbpassword'" $config_php | awk '{print $3}' | sed "s/[',]//g")
					/DietPi/dietpi/func/create_mysql_db nextcloud "$dbuser" "$dbpass"
					mysql -uroot nextcloud < "$datadir"/dietpi-nextcloud-database-backup.sql

				else

					local username="$(grep -m1 '^[[:blank:]]*SOFTWARE_OWNCLOUD_NEXTCLOUD_USERNAME=' /DietPi/dietpi.txt | sed 's/^.*=//')"
					[ -n "$username" ] || username='admin'

					# For MariaDB, temporary database admin user needs to be created, as 'root' uses unix_socket login, which cannot be accessed by sudo -u www-data.
					mysql -e "grant all privileges on *.* to 'tmp_root'@'localhost' identified by '$GLOBAL_PW' with grant option"
					grep -q "'installed' => true," $config_php 2>/dev/null || ncc maintenance:install --no-interaction --database "mysql" --database-name "nextcloud" --database-user "tmp_root" --database-pass "$GLOBAL_PW" --admin-user "$username" --admin-pass "$GLOBAL_PW" --data-dir "$datadir"
					mysql -e "drop user 'tmp_root'@'localhost'"

				fi

			fi

			# Enable Nextcloud to use 4-byte database
			grep -q "^[[:blank:]]*'mysql.utf8mb4'" $config_php || sed -i "/^[[:blank:]]*'dbpassword'/a \ \ 'mysql.utf8mb4' => true," $config_php

			# Disable trusted_domains.
			if (( ! $(cat $config_php | grep -ci -m1 "1 => '*'") )); then

				sed -i "/0 => 'localhost'/a     1 => '*'," $config_php

			fi

			# Set CLI URL to Nextcloud sub directory:
			sed -i "s|'http://localhost'|'http://localhost/nextcloud'|g" $config_php

			# Set pretty URLs (without /index.php/) on Apache:
			if (( ${aSOFTWARE_INSTALL_STATE[83]} >= 1 )); then

				grep -q "^[[:blank:]]*'htaccess.RewriteBase'" $config_php || sed -i "/^[[:blank:]]*'overwrite.cli.url'/a \ \ 'htaccess.RewriteBase' => '/nextcloud'," $config_php
				ncc maintenance:update:htaccess

			fi

			# APCu Memcache
			grep -q "^[[:blank:]]*'memcache.local'" $config_php || sed -i "/^[[:blank:]]*'version'/a \ \ 'memcache.local' => '\\\OC\\\Memcache\\\APCu'," $config_php

			# Redis for transactional file locking:
			# https://docs.nextcloud.com/server/12/admin_manual/configuration_files/files_locking_transactional.html
			# - Enable Redis socket and grant www-data access to it:
			local redis_conf="/etc/redis/redis*.conf"
			grep -q "^[[:blank:]]*unixsocket /" $redis_conf || grep -q '^[[:blank:]]*#unixsocket /' $redis_conf && sed -i 's|^[[:blank:]]*#unixsocket /|unixsocket /|' $redis_conf || echo 'unixsocket /var/run/redis/redis.sock' >> $redis_conf
			grep -q "^[[:blank:]]*#?unixsocketperm " $redis_conf && sed -i "/^[[:blank:]]*#?unixsocketperm /c\unixsocketperm 770" $redis_conf || echo 'unixsocketperm 770' >> $redis_conf
			local redis_sock=$(grep "^[[:blank:]]*unixsocket /" $redis_conf | sed "s/^[[:blank:]]*unixsocket //")
			usermod -a -G redis www-data
			# - Enable Nextloud to use Redis socket:
			if (( ! $(cat $config_php | grep -ci -m1 "'memcache.locking'") )); then

				sed -i "\#'memcache.local'#a \ \ 'filelocking.enabled' => true,\n\
  'memcache.locking' => '\\\OC\\\Memcache\\\Redis',\n\
  'redis' => array(\n\
    'host' => '$redis_sock',\n\
    'port' => 0,\n\
    )," $config_php

			fi

			# Enable Nextcloud background cron job:
			crontab -u www-data -l 2>/dev/null | grep -q '/var/www/nextcloud/cron.php' || ( crontab -u www-data -l 2>/dev/null ; echo "*/15 * * * * php /var/www/nextcloud/cron.php" ) | crontab -u www-data -
			ncc background:cron

			# Enable maintenance mode to allow handling by dietpi-services:
			grep -q "^[[:blank:]]*'maintenance' => true," $config_php || ncc maintenance:mode --on

		fi

		# Transmission
		INSTALLING_INDEX=44
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Jessie, Transmission uses my systemd service: https://github.com/Fourdee/DietPi/issues/350#issuecomment-220828884
			rm /etc/init.d/transmission-daemon
			rm /etc/systemd/system/transmission-daemon.service
			cat << _EOF_ > /etc/systemd/system/transmission-daemon.service
[Unit]
Description=Barebones transmission-daemon service
DefaultDependencies=no

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/transmission-daemon --config-dir /var/lib/transmission-daemon/info
ExecStop=/usr/bin/killall -w transmission-daemon
StandardOutput=tty

[Install]
WantedBy=multi-user.target
_EOF_

			cat << _EOF_ > /etc/transmission-daemon/settings.json
{
    "alt-speed-down": 50,
    "alt-speed-enabled": false,
    "alt-speed-time-begin": 540,
    "alt-speed-time-day": 127,
    "alt-speed-time-enabled": false,
    "alt-speed-time-end": 1020,
    "alt-speed-up": 50,
    "bind-address-ipv4": "0.0.0.0",
    "bind-address-ipv6": "::",
    "blocklist-enabled": false,
    "blocklist-url": "http://www.example.com/blocklist",
    "cache-size-mb": 48,
    "dht-enabled": true,
    "download-dir": "$G_FP_DIETPI_USERDATA/downloads",
    "download-limit": 100,
    "download-limit-enabled": false,
    "download-queue-enabled": true,
    "download-queue-size": 2,
    "encryption": 2,
    "idle-seeding-limit": 1,
    "idle-seeding-limit-enabled": true,
    "incomplete-dir": "$G_FP_DIETPI_USERDATA/bt-inprogress",
    "incomplete-dir-enabled": false,
    "lpd-enabled": false,
    "max-peers-global": 8,
    "message-level": 0,
    "peer-congestion-algorithm": "",
    "peer-limit-global": 8,
    "peer-limit-per-torrent": 5,
    "peer-port": 51413,
    "peer-port-random-high": 65535,
    "peer-port-random-low": 49152,
    "peer-port-random-on-start": false,
    "peer-socket-tos": "default",
    "pex-enabled": true,
    "port-forwarding-enabled": true,
    "preallocation": 1,
    "prefetch-enabled": 1,
    "queue-stalled-enabled": true,
    "queue-stalled-minutes": 30,
    "ratio-limit": 1.1,
    "ratio-limit-enabled": true,
    "rename-partial-files": true,
    "rpc-authentication-required": true,
    "rpc-bind-address": "0.0.0.0",
    "rpc-enabled": true,
    "rpc-password": "$GLOBAL_PW",
    "rpc-port": 9091,
    "rpc-url": "/transmission/",
    "rpc-username": "root",
    "rpc-whitelist": "192.*.*.*",
    "rpc-whitelist-enabled": false,
    "scrape-paused-torrents-enabled": true,
    "script-torrent-done-enabled": false,
    "script-torrent-done-filename": "",
    "seed-queue-enabled": false,
    "seed-queue-size": 10,
    "speed-limit-down": 100,
    "speed-limit-down-enabled": false,
    "speed-limit-up": 100,
    "speed-limit-up-enabled": false,
    "start-added-torrents": true,
    "trash-original-torrent-files": true,
    "umask": 18,
    "upload-limit": 100,
    "upload-limit-enabled": false,
    "upload-slots-per-torrent": 2,
    "utp-enabled": true
}
_EOF_

			#Apply optimized settings
			sed -i '/cache-size-mb/c\    "cache-size-mb": '$(Optimize_BitTorrent 0)',' /etc/transmission-daemon/settings.json
			sed -i '/download-queue-size/c\    "download-queue-size": '$(Optimize_BitTorrent 1)',' /etc/transmission-daemon/settings.json
			sed -i '/peer-limit-global/c\    "peer-limit-global": '$(Optimize_BitTorrent 2)',' /etc/transmission-daemon/settings.json
			sed -i '/max-peers-global/c\    "max-peers-global": '$(Optimize_BitTorrent 2)',' /etc/transmission-daemon/settings.json
			sed -i '/peer-limit-per-torrent/c\    "peer-limit-per-torrent": '$(Optimize_BitTorrent 2)',' /etc/transmission-daemon/settings.json
			sed -i '/upload-slots-per-torrent/c\    "upload-slots-per-torrent": '$(Optimize_BitTorrent 3)',' /etc/transmission-daemon/settings.json

		fi

		#PHPBB
		INSTALLING_INDEX=54
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			/DietPi/dietpi/func/create_mysql_db phpbb3 phpbb3 "$GLOBAL_PW"

		fi

		#MPD
		INSTALLING_INDEX=128
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Create MPD env (based on moOde)
			#useradd mpd
			useradd -r -M mpd -G audio -s /usr/bin/nologin
			mkdir -p /var/lib/mpd
			mkdir -p /var/run/mpd
			mkdir -p /var/lib/mpd/music
			mkdir -p /var/lib/mpd/playlists
			touch /var/lib/mpd/state

			#	Link /mnt to MPD defaults: https://github.com/Fourdee/DietPi/issues/1223#issuecomment-346955040
			rm /var/lib/mpd/music/MNT &> /dev/null # Always recreate (reinstalls), else,  mnt -> /mnt
			ln -sf /mnt /var/lib/mpd/music/MNT

			chown -R mpd:audio /var/lib/mpd
			mkdir -p /var/log/mpd
			touch /var/log/mpd/mpd.log
			chmod 644 /var/log/mpd/mpd.log
			chown -R mpd:audio /var/log/mpd

			#	cache
			mkdir -p "$G_FP_DIETPI_USERDATA"/.mpd_cache

			#MPD service/confs
			cat << _EOF_ > /etc/default/mpd
#Even though we declare the conf location in our service, MPD will fail to start if this file does not exist.
## The configuration file location for mpd:
MPDCONF=/etc/mpd.conf
_EOF_

			cat << _EOF_ > /lib/systemd/system/mpd.service
[Unit]
Description=Music Player Daemon
After=network.target sound.target

[Service]
User=root
EnvironmentFile=/etc/default/mpd
ExecStartPre=/bin/mkdir -p /var/run/mpd
ExecStartPre=/bin/chown -R mpd:audio /var/run/mpd
ExecStart=$(which mpd) --no-daemon /etc/mpd.conf

[Install]
WantedBy=multi-user.target

_EOF_

			#Copy default config
			cp /DietPi/dietpi/conf/mpd.conf /etc/mpd.conf

			chown mpd:audio /etc/mpd.conf
			chmod 0666 /etc/mpd.conf

			#JustBoom specials
			if (( $(cat /DietPi/dietpi.txt | grep -ci -m1 '^CONFIG_SOUNDCARD=justboom') )); then

				# - Name displayed in YMPD sound button
				local justboom_soundcard_desc='JustBoom DietPi'
				sed -i "/^name \"/c\name \"$justboom_soundcard_desc\"" /etc/mpd.conf
				sed -i "/^zeroconf_name \"/c\zeroconf_name \"$justboom_soundcard_desc\"" /etc/mpd.conf

				# - Output (192khz 32bit)
				local target_bitdepth=32
				local target_rate=192000
				sed -i '/^format "/c\format "'$target_rate':'$target_bitdepth':2"' /etc/mpd.conf
				sed -i '/audio_output_format "/c\audio_output_format "'$target_rate':'$target_bitdepth':2"' /etc/mpd.conf

				# - Set SOXR quality
				#	All RPi's can handle SOXR VH @ 192khz 32bit: https://github.com/Fourdee/DietPi/issues/581#issuecomment-256643079
				sed -i '/samplerate_converter "/c\samplerate_converter "soxr very high"' /etc/mpd.conf #highest

			fi

			#Grab our test music for the user.
			Download_Test_Media

		fi

		# Proftpd
		INSTALLING_INDEX=94
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			sed -i "/root/c\#root" /etc/ftpusers
			cp /DietPi/dietpi/conf/proftpd.conf /etc/proftpd/proftpd.conf
			sed -i "/DefaultRoot /c\DefaultRoot $G_FP_DIETPI_USERDATA" /etc/proftpd/proftpd.conf

		fi

		#Samba Server
		INSTALLING_INDEX=96
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			echo -e "dietpi\ndietpi" | smbpasswd -s -a root
			cp /DietPi/dietpi/conf/smb.conf /etc/samba/smb.conf

			sed -i "/path = /c\path = $G_FP_DIETPI_USERDATA" /etc/samba/smb.conf

		fi

		#vsFTPD
		INSTALLING_INDEX=95
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			sed -i '/root/c\#root' /etc/ftpusers

			cp /DietPi/dietpi/conf/vsftpd.conf /etc/vsftpd.conf
			sed -i "/^local_root=/c\local_root=$G_FP_DIETPI_USERDATA" /etc/vsftpd.conf

		fi

		#NFS_SERVER
		INSTALLING_INDEX=109
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			cat << _EOF_ > /etc/exports
$G_FP_DIETPI_USERDATA *(rw,async,no_root_squash,fsid=0,crossmnt,no_subtree_check)
_EOF_

		fi

		#YMPD
		INSTALLING_INDEX=32
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#YMPD service
			cat << _EOF_ > /etc/systemd/system/ympd.service
[Unit]
Description=YMPD
After=mpd.service

[Service]
Type=simple
User=root
ExecStart=/usr/bin/ympd --user root --webport 1337

[Install]
WantedBy=multi-user.target
_EOF_

		fi

		#Roon Bridge
		INSTALLING_INDEX=121
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			mkdir -p "$G_FP_DIETPI_USERDATA"/roon

			cp /DietPi/dietpi/conf/roonbridge.service /etc/systemd/system/roonbridge.service

			# - Move logfiles to /var/log/ (dietpi-ramlog)
			#	Remove any previous folders to clear for symlink
			rm -R "$G_FP_DIETPI_USERDATA"/roon/RoonBridge/Logs &> /dev/null
			rm -R "$G_FP_DIETPI_USERDATA"/roon/RAATServer/Logs &> /dev/null

			mkdir -p "$G_FP_DIETPI_USERDATA"/roon/RoonBridge
			mkdir -p "$G_FP_DIETPI_USERDATA"/roon/RAATServer

			ln -sf /var/log "$G_FP_DIETPI_USERDATA"/roon/RoonBridge/Logs
			ln -sf /var/log "$G_FP_DIETPI_USERDATA"/roon/RAATServer/Logs

		fi

		#NodeRed
		INSTALLING_INDEX=122
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			mkdir -p "$G_FP_DIETPI_USERDATA"/node-red

			adduser nodered --system --group --no-create-home --shell=/bin/nologin

			cat << _EOF_ > /etc/systemd/system/node-red.service
[Unit]
Description=Node-Red

[Service]
Type=simple
User=nodered
ExecStart=/usr/local/bin/node-red -u $G_FP_DIETPI_USERDATA/node-red

[Install]
WantedBy=multi-user.target
_EOF_

			#Symlink to home dir: https://github.com/Fourdee/DietPi/issues/1256
			ln -sf "$G_FP_DIETPI_USERDATA"/node-red "$HOME"/.node-red

		fi

		#Tomcat8
		INSTALLING_INDEX=125
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			sed -i "/JAVA_HOME=/c\JAVA_HOME=$(find \/usr\/lib\/jvm\/ -name java-8-openjdk*)" /etc/default/tomcat8

		fi

		#CAVA
		INSTALLING_INDEX=119
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# - Cava conf
			mkdir -p "$HOME"/.config/cava
			cp /DietPi/dietpi/conf/cava.conf "$HOME"/.config/cava/config

			# - lower MPD buffer size to reduce latency of spectrum:
			sed -i '/audio_buffer_size /c\audio_buffer_size "384"' /etc/mpd.conf

			# - fifo stream for mpd
			if (( ! $(cat /etc/mpd.conf | grep -ci -m1 '/tmp/mpd.fifo') )); then

				cat << _EOF_ >> /etc/mpd.conf

#Cava fifo stream
audio_output {

    type "fifo"
    enabled "yes"
    name "CAVA"
    path "/tmp/mpd.fifo"
    format "44100:16:2"

}
_EOF_

			fi

		fi

		#Mopidy
		INSTALLING_INDEX=118
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			sed -i "/User=/c\User=root" /lib/systemd/system/mopidy.service

			# - conf
			mkdir -p "$G_FP_DIETPI_USERDATA"/mopidy/cache
			mkdir -p "$G_FP_DIETPI_USERDATA"/mopidy/data
			mkdir -p ~/.config/mopidy

			cat << _EOF_ > ~/.config/mopidy/mopidy.conf
[core]
cache_dir = $G_FP_DIETPI_USERDATA/mopidy/cache
config_dir = /etc/mopidy
data_dir = $G_FP_DIETPI_USERDATA/mopidy/data

[logging]
config_file = /etc/mopidy/logging.conf
debug_file = /var/log/mopidy.log

[local]
library = images
media_dir = /mnt
enabled = true
scan_timeout = 1000
scan_flush_threshold = 100
scan_follow_symlinks = false
excluded_file_extensions =
  .directory
  .html
  .jpeg
  .jpg
  .log
  .nfo
  .png
  .txt

[file]
enabled = true
media_dirs = /mnt

[m3u]
playlists_dir = /mnt

[http]
enabled = true
hostname = ::
port = 6680
static_dir =
zeroconf = Mopidy HTTP server on $hostname

_EOF_

			#	NB: mopidy uses both config locations, so lets make sure we match them
			cp ~/.config/mopidy/mopidy.conf /etc/mopidy/mopidy.conf

			Download_Test_Media

		fi

		#Kodi
		INSTALLING_INDEX=31
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Remove Kodi user (Whilst waving)
			userdel -r kodi &> /dev/null

			#Run Kodi as root
			sed -i '/USER=/c\USER=root' /etc/default/kodi &> /dev/null

			#Copy udev rules, probably not needed for root, but we'll do it anyway
			cp /DietPi/dietpi/conf/kodi_udev /etc/udev/rules.d/99-input.rules
			chmod +x /etc/udev/rules.d/99-input.rules

			#Create .desktop SymLinks
			mkdir -p "$HOME"/Desktop
			rm /usr/share/applications/kodi.desktop &> /dev/null
			wget http://dietpi.com/downloads/conf/desktop/kodi.desktop -O /usr/share/applications/kodi.desktop
			ln -sf /usr/share/applications/kodi.desktop "$HOME"/Desktop/kodi.desktop

		fi

		#MINIDLNA
		INSTALLING_INDEX=39
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Run as root
			sed -i '/USER=m/c\USER=root' /etc/init.d/minidlna
			# + SystemD
			sed -i '/User=m/c\User=root' /lib/systemd/system/minidlna.service &> /dev/null
			sed -i '/Group=m/c\Group=root' /lib/systemd/system/minidlna.service &> /dev/null

			#Copy Config
			cp /DietPi/dietpi/conf/minidlna.conf /etc/minidlna.conf

			#Setup data directories
			mkdir -p "$G_FP_DIETPI_USERDATA"/.MiniDLNA_Cache

		fi


		#NoIp
		INSTALLING_INDEX=67
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#noip2 service file
			cat << _EOF_ > /etc/systemd/system/noip2.service
[Unit]
Description=noip2
After=network.target network-online.target rsyslog.service

[Service]
Type=forking
RemainAfterExit=yes

ExecStart=/usr/local/bin/noip2
ExecStop=/usr/bin/killall -w noip2

[Install]
WantedBy=multi-user.target
_EOF_

		fi

		#amiberry
		INSTALLING_INDEX=108
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Allow binary execution
			chmod -R +x /etc/amiberry

			#Create userdata/rom directories and symlink from /etc/amiberry/
			mkdir -p "$G_FP_DIETPI_USERDATA"/amiberry

			#Copy default configs, then setup symlinks from Uae4ARM folders to userdata.
			# - Conf
			cp -R /etc/amiberry/conf "$G_FP_DIETPI_USERDATA"/amiberry/
			rm -R /etc/amiberry/conf &> /dev/null
			ln -sf "$G_FP_DIETPI_USERDATA"/amiberry/conf /etc/amiberry/conf

			# - Disks
			rm -R /etc/amiberry/disks &> /dev/null
			mkdir -p "$G_FP_DIETPI_USERDATA"/amiberry/disks
			ln -sf "$G_FP_DIETPI_USERDATA"/amiberry/disks /etc/amiberry/disks

			# - floppy_images
			rm -R /etc/amiberry/floppy_images &> /dev/null
			mkdir -p "$G_FP_DIETPI_USERDATA"/amiberry/floppy_images
			ln -sf "$G_FP_DIETPI_USERDATA"/amiberry/floppy_images /etc/amiberry/floppy_images
			cat << _EOF_ > "$G_FP_DIETPI_USERDATA"/amiberry/floppy_images/dir.txt
Put your Amiga floopy images (*.adf) in this directory.
_EOF_

			# - HDF
			rm -R /etc/amiberry/hdf &> /dev/null
			mkdir -p "$G_FP_DIETPI_USERDATA"/amiberry/hdf
			ln -sf "$G_FP_DIETPI_USERDATA"/amiberry/hdf /etc/amiberry/hdf

			# - Kickstarts
			rm -R /etc/amiberry/kickstarts &> /dev/null
			mkdir -p "$G_FP_DIETPI_USERDATA"/amiberry/kickstarts
			ln -sf "$G_FP_DIETPI_USERDATA"/amiberry/kickstarts /etc/amiberry/kickstarts
			cat << _EOF_ > "$G_FP_DIETPI_USERDATA"/amiberry/kickstarts/dir.txt
Put your Kickstart Roms (*.rom) in this directory.
They should be named accordingly depending on version: kick12.rom , kick13.rom , kick20.rom, kick31.rom
_EOF_

			# - Savestates
			rm -R /etc/amiberry/savestates &> /dev/null
			mkdir -p "$G_FP_DIETPI_USERDATA"/amiberry/savestates
			ln -sf "$G_FP_DIETPI_USERDATA"/amiberry/savestates /etc/amiberry/savestates
			cat << _EOF_ > "$G_FP_DIETPI_USERDATA"/amiberry/savestates/dir.txt
Saved states will be stored here.
_EOF_

			# - Screenshots
			rm -R /etc/amiberry/screenshots &> /dev/null
			mkdir -p "$G_FP_DIETPI_USERDATA"/amiberry/screenshots
			ln -sf "$G_FP_DIETPI_USERDATA"/amiberry/screenshots /etc/amiberry/screenshots
			cat << _EOF_ > "$G_FP_DIETPI_USERDATA"/amiberry/screenshots/dir.txt
Screenshots will be stored here.
_EOF_


			#Uae4arm does not support browsing symlinks (https://github.com/Fourdee/DietPi/issues/474#issuecomment-242973839)
			#	So we need to change config file default paths to actual userdata location:
			local fp_userdata_actual=$(readlink "$G_FP_DIETPI_USERDATA") # Only returns a value if symlink exists (eg: off SDcard)
			if [ -n "$fp_userdata_actual" ]; then

				sed -i "s:$G_FP_DIETPI_USERDATA:$fp_userdata_actual:g" "$G_FP_DIETPI_USERDATA"/amiberry/conf/adfdir.conf
				sed -i "s:$G_FP_DIETPI_USERDATA:$fp_userdata_actual:g" "$G_FP_DIETPI_USERDATA"/amiberry/conf/autostart.uae

			fi

			#Symlink HW specific binary for this system to /etc/amiberry/amiberry
			local amiberry_filename='amiberry-rpi'

			# - RPi 3
			if (( $G_HW_MODEL == 3 )); then

				amiberry_filename+='3'

			# - RPi 2
			elif (( $G_HW_MODEL == 2 )); then

				amiberry_filename+='2'

			# - Assume RPi 1 (ARMv6)
			else

				amiberry_filename+='1'

			fi

			ln -sf /etc/amiberry/"$amiberry_filename" /etc/amiberry/amiberry

			# + SDL2
			amiberry_filename+='-sdl2'
			ln -sf /etc/amiberry/"$amiberry_filename" /etc/amiberry/amiberry-sdl2

			#service SDL1
			cat << _EOF_ > /etc/systemd/system/amiberry.service
[Unit]
Description=AmiBerry Amiga Emulator
DefaultDependencies=no

[Service]
Type=simple
User=root
WorkingDirectory=/etc/amiberry
ExecStart=/bin/bash -c ./amiberry_run.sh

[Install]
WantedBy=local-fs.target
_EOF_
			systemctl daemon-reload

			cat << _EOF_ > /etc/amiberry/amiberry_run.sh
#!/bin/bash
if (( \$(ps aux | grep -ci -m1 '[X]11') )); then

./amiberry -f conf/autostart.uae

else

xinit ./amiberry -f conf/autostart.uae

fi
_EOF_

			chmod +x /etc/amiberry/amiberry_run.sh

			#service SDL2
			cat << _EOF_ > /etc/systemd/system/amiberry-sdl2.service
[Unit]
Description=AmiBerry Amiga Emulator

[Service]
Type=simple
User=root
WorkingDirectory=/etc/amiberry
ExecStart=/bin/bash -c ./amiberry_run_sdl2.sh

[Install]
WantedBy=local-fs.target
_EOF_
			systemctl daemon-reload

			#DEBUG
			#systemctl restart amiberry-sdl2

			cat << _EOF_ > /etc/amiberry/amiberry_run_sdl2.sh
#!/bin/bash
xinit ./amiberry-sdl2 -f conf/autostart.uae
_EOF_

			chmod +x /etc/amiberry/amiberry_run_sdl2.sh

		fi

		#dxx-rebirth
		INSTALLING_INDEX=112
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Symlink savegames to root
			# - Remove existing syslinks
			rm -R "$HOME"/.d1x-rebirth &> /dev/null
			rm -R "$HOME"/.d2x-rebirth &> /dev/null

			ln -sf "$G_FP_DIETPI_USERDATA"/dxx-rebirth/descent_1_profiles "$HOME"/.d1x-rebirth
			ln -sf "$G_FP_DIETPI_USERDATA"/dxx-rebirth/descent_2_profiles "$HOME"/.d2x-rebirth

			#+exe
			chmod +x -R "$G_FP_DIETPI_USERDATA"/dxx-rebirth/*

			#Create .Desktop SymLinks
			mkdir -p "$HOME"/Desktop
			mkdir -p /usr/share/applications

			ln -s "$G_FP_DIETPI_USERDATA"/dxx-rebirth/dxx-rebirth.desktop "$HOME"/Desktop/dxx-rebirth.desktop
			ln -s "$G_FP_DIETPI_USERDATA"/dxx-rebirth/dxx-rebirth.desktop  /usr/share/applications/dxx-rebirth.desktop

		fi

		#OpenTyrian
		INSTALLING_INDEX=51
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Copy the DietPi run file for OpenTyrian
			cp /DietPi/dietpi/conf/opentyrian_run /usr/local/games/opentyrian/run
			chmod +x /usr/local/games/opentyrian/run

			#Create .Desktop SymLinks
			mkdir -p "$HOME"/Desktop
			rm /usr/share/applications/opentyrian.desktop &> /dev/null
			wget http://dietpi.com/downloads/conf/desktop/pcmanfm.conf -O /usr/share/applications/opentyrian.desktop
			ln -s /usr/share/applications/opentyrian.desktop "$HOME"/Desktop/opentyrian.desktop

		fi

		#DIETPICAM
		INSTALLING_INDEX=59
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# - raspimjpeg conf
			chmod +x /etc/raspimjpeg
			ln -s /etc/raspimjpeg /var/www/dietpicam/raspimjpeg

			# - Motion conf
			chgrp www-data /etc/motion/motion.conf
			chmod 777 /etc/motion/motion.conf
			usermod -a -G video www-data

			# - raspimjpeg/php schedule startup and control script
			cp /DietPi/dietpi/conf/raspimjpeg.service /var/lib/dietpi/dietpi-software/services/raspimjpeg.service

			# - Setup Data directory
			local dietpicam_media_directory=$G_FP_DIETPI_USERDATA

			mkdir -p "$dietpicam_media_directory"/dietpicam
			rm -R /var/www/dietpicam/media
			ln -s "$dietpicam_media_directory"/dietpicam /var/www/dietpicam/media

			# - Enable RPi camera
			/DietPi/dietpi/func/dietpi-set_hardware rpi-camera enable

		fi

		#Deluge
		INSTALLING_INDEX=45
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#copy init
			cp /DietPi/dietpi/conf/deluge.service /var/lib/dietpi/dietpi-software/services/deluge.service

			#Generate deluge default config
			deluged
			killall -w deluged

			#Copy DietPi configs
			cp /DietPi/dietpi/conf/deluge.conf "$HOME"/.config/deluge/core.conf
			cp /DietPi/dietpi/conf/deluge_web.conf "$HOME"/.config/deluge/web.conf

			#Set remote access login details
			cat << _EOF_ > "$HOME"/.config/deluge/auth
root:$GLOBAL_PW:10
_EOF_

			#Apply Optimized settings
			# - Cache size is in steps of 16 KiB. (Cachesize * 16 = total KiB)
			local deluge_cache_size=$(( $(echo -e "scale=0; $(Optimize_BitTorrent 0) * 1024 / 16" | bc -l ) ))
			sed -i '/"cache_size": /c\ "cache_size": '"$deluge_cache_size"',' "$HOME"/.config/deluge/core.conf

			sed -i '/"max_active_limit": /c\ "max_active_limit": '"$(Optimize_BitTorrent 1)"',' "$HOME"/.config/deluge/core.conf
			sed -i '/"max_active_downloading": /c\ "max_active_downloading": '"$(Optimize_BitTorrent 1)"',' "$HOME"/.config/deluge/core.conf
			sed -i '/"max_connections_global": /c\ "max_connections_global": '"$(Optimize_BitTorrent 2)"',' "$HOME"/.config/deluge/core.conf
			sed -i '/"max_upload_slots_global": /c\ "max_upload_slots_global": '"$(Optimize_BitTorrent 3)"',' "$HOME"/.config/deluge/core.conf

		fi

		#RaspControl
		INSTALLING_INDEX=106
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Setup login file
			mkdir -p /etc/raspcontrol

			cat << _EOF_ > /etc/raspcontrol/database.aptmnt
{
    "user": "root",
    "password": "$GLOBAL_PW"
}
_EOF_

			chown -R www-data:www-data /etc/raspcontrol
			chmod -R 750 /etc/raspcontrol

		fi

		#PIHOLE
		INSTALLING_INDEX=93
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# - Create a symlink so users can use http://ip/pihole
			ln -sf /var/www/html/admin /var/www/pihole

			# - Create a symlink so users can use http://ip/admin
			ln -sf /var/www/html/admin /var/www/admin

			# - Generate index page that replaces adverts and prevents popups
			cat << _EOF_ > /var/www/index.html
<html>
Blocked by Pi-hole.
<script>window.close();</script>
</html>
_EOF_

			# - Generate pihole.log , set permissions to www-data
			echo -e "" > /var/log/pihole.log
			chown www-data:www-data /var/log/pihole.log
			chmod 775 /var/log/pihole.log

			# - Generate web interface PW: https://github.com/Fourdee/DietPi/issues/662
			pihole -a -p "$GLOBAL_PW"

			# - PiHole now generates a password, inform user of the correct one:
			whiptail --title "PiHole: Web interface" --msgbox "DietPi has changed the PiHole web interface password to:\n- $GLOBAL_PW\n\nPlease use this password when logging into the web interface:\n - http://ip/pihole\n\nThis password can be changed, please see pihole binary for info:\n - pihole --help" --backtitle "$WHIP_BACKTITLE" 16 70


		fi

		#SUBSONIC 5/6
		INSTALLING_INDEX=34
		if (( ${aSOFTWARE_INSTALL_STATE[33]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[34]} == 1 )); then

			Banner_Configuration

			#Optimize memory limit
			local subsonic_memory_max=$(( $RAM_TOTAL / 5 ))
			#Minimum cap 150mb
			if (( $subsonic_memory_max < 150 )); then

				subsonic_memory_max=150

			fi

			cat << _EOF_ > /etc/default/subsonic
SUBSONIC_USER=root
SUBSONIC_ARGS="--quiet --pidfile=/run/subsonic.pid --max-memory=$subsonic_memory_max --default-music-folder=$G_FP_DIETPI_USERDATA/$FOLDER_MUSIC --default-podcast-folder=$G_FP_DIETPI_USERDATA/$FOLDER_MUSIC --default-playlist-folder=$G_FP_DIETPI_USERDATA/$FOLDER_MUSIC"
_EOF_

			#Grab our test media for user
			Download_Test_Media

			#Symlink ffmpeg to subsonic transcoder
			#rpi armv6 jessie (using compiled ffmpeg)
			if (( $G_HW_MODEL < 2 )); then

				ln -fs /usr/local/bin/ffmpeg /var/subsonic/transcode

			#ARMv7
			else

				ln -fs /usr/bin/ffmpeg /var/subsonic/transcode

			fi

		fi

		#WEBIOPI
		INSTALLING_INDEX=71
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#auto start
			update-rc.d webiopi defaults

			WEBIOPI=2
		fi

		#DIETPICLOUDSHELL
		INSTALLING_INDEX=62
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Enable DietPi-Cloudshell autostart
			/DietPi/dietpi/dietpi-autostart 5

			#Service
			cat << _EOF_ > /etc/systemd/system/dietpi-cloudshell.service
[Unit]
Description=dietpi-cloudshell on main screen

[Service]
Type=simple
StandardOutput=tty
TTYPath=/dev/tty1

ExecStartPre=/usr/bin/setterm --term linux --blank 0 --powersave off --cursor off

ExecStart=/bin/bash -c '/DietPi/dietpi/dietpi-cloudshell 1'

ExecStop=/usr/bin/setterm --reset
ExecStop=/bin/bash -c 'G_DIETPI-NOTIFY 0 DietPi-Cloudshell terminated, have a nice day!'

[Install]
WantedBy=multi-user.target
_EOF_
			systemctl daemon-reload

		fi

		#HAPROXY
		INSTALLING_INDEX=98
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Create jail directory
			mkdir -p /var/lib/haproxy

			cat << _EOF_ > /etc/haproxy/haproxy.cfg
global

	#rsyslog is required for logging
	#log /var/log    local0
	#log /var/log    local1 notice
	maxconn 64
	#Jail directory
	chroot /var/lib/haproxy
	stats socket /run/haproxy.sock mode 660 level admin
	stats timeout 30s
	user root
	group root
	daemon

	# Default SSL material locations
	ca-base /etc/ssl/certs
	crt-base /etc/ssl/private

	# Default ciphers to use on SSL-enabled listening sockets.
	# For more information, see ciphers(1SSL).
	ssl-default-bind-ciphers kEECDH+aRSA+AES:kRSA+AES:+AES256:RC4-SHA:!kEDH:!LOW:!EXP:!MD5:!aNULL:!eNULL

defaults

	log     global
	mode    http
	option  httplog
	option  dontlognull
	timeout connect 5000
	timeout client  50000
	timeout server  50000
	errorfile 400 /etc/haproxy/errors/400.http
	errorfile 403 /etc/haproxy/errors/403.http
	errorfile 408 /etc/haproxy/errors/408.http
	errorfile 500 /etc/haproxy/errors/500.http
	errorfile 502 /etc/haproxy/errors/502.http
	errorfile 503 /etc/haproxy/errors/503.http
	errorfile 504 /etc/haproxy/errors/504.http

frontend localnodes

	bind *:80
	mode http
	default_backend nodes

backend nodes

	mode http
	balance roundrobin
	option forwardfor
	http-request set-header X-Forwarded-Port %[dst_port]
	http-request add-header X-Forwarded-Proto https if { ssl_fc }
	option httpchk HEAD / HTTP/1.1\r\nHost:localhost
	server web01 127.0.0.1:9000 check
	server web02 127.0.0.1:9001 check
	server web03 127.0.0.1:9002 check

#Admin web page

	listen stats
	bind *:1338
	stats enable
	stats uri /
	stats hide-version
	stats auth admin:dietpi
_EOF_

			#Add html error pages
			mkdir -p /etc/haproxy/errors
			local errorcode=0

			errorcode=400; echo -e "[html]$errorcode[/html]" > /etc/haproxy/errors/"$errorcode".http
			errorcode=403; echo -e "[html]$errorcode[/html]" > /etc/haproxy/errors/"$errorcode".http
			errorcode=408; echo -e "[html]$errorcode[/html]" > /etc/haproxy/errors/"$errorcode".http
			errorcode=500; echo -e "[html]$errorcode[/html]" > /etc/haproxy/errors/"$errorcode".http
			errorcode=502; echo -e "[html]$errorcode[/html]" > /etc/haproxy/errors/"$errorcode".http
			errorcode=503; echo -e "[html]$errorcode[/html]" > /etc/haproxy/errors/"$errorcode".http
			errorcode=504; echo -e "[html]$errorcode[/html]" > /etc/haproxy/errors/"$errorcode".http

		fi

		#SQUEEZEBOXSERVER
		INSTALLING_INDEX=35
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Remove service
			update-rc.d logitechmediaserver remove
			rm /etc/init.d/logitechmediaserver

			#DietPi-Services init
			cp /DietPi/dietpi/conf/squeezeboxserver.service /var/lib/dietpi/dietpi-software/services/squeezeboxserver.service

			#Grab our test media for user
			Download_Test_Media

		fi

		#WORDPRESS
		INSTALLING_INDEX=55
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Create mysql DB
			/DietPi/dietpi/func/create_mysql_db wordpress wordpress "$GLOBAL_PW"

		fi

		#TIGHTVNCSERVER / VNC4SERVER / RealVNC - Shared setup
		#INSTALLING_INDEX=27/28/120
		if (( ${aSOFTWARE_INSTALL_STATE[27]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[28]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[120]} == 1 )); then

			#Banner_Configuration

			#User, enter PW
			if (( $G_USER_INPUTS )); then

				local entering_pw=1
				local loop_count=0

				# - RealVNC uses Unix account
				if (( ${aSOFTWARE_INSTALL_STATE[120]} == 1 )); then

					entering_pw=0

				else

					WHIP_QUESTION='A password is required for your VNC Server.\n\nThe next screen will allow you to set your password, this password will be used when connecting from a VNC client/viewer.\n\nPress Ok/Enter when ready.'
					whiptail --title "VNC Server Password" --msgbox "$WHIP_QUESTION" --backtitle "$WHIP_BACKTITLE" 13 70

				fi

				while (( $entering_pw == 1 )); do

					vncpasswd
					((loop_count++))

					# - Password file created
					if [ -f "$HOME"/.vnc/passwd ]; then

						entering_pw=0

					# - Endless loop
					elif (( $loop_count >= 30 )); then

						entering_pw=0

					fi

				done

			fi

			cat << _EOF_ > /etc/systemd/system/vncserver.service
[Unit]
Description=Manage VNC Server
After=dietpi-service.service
After=rc.local.service

[Service]
Type=idle
RemainAfterExit=yes
ExecStart=/bin/bash /usr/local/bin/vncserver start
ExecStop=/bin/bash /usr/local/bin/vncserver stop
User=root

[Install]
WantedBy=multi-user.target
_EOF_

			systemctl enable vncserver.service
			systemctl daemon-reload

			cat << _EOF_ > /usr/local/bin/vncserver
#!/bin/bash

#Globals
VNC_INSTALLED=0
BINARY_FP=0
SHARED_MODE=0

WIDTH=\$(cat /DietPi/dietpi.txt | grep -m1 '^SOFTWARE_VNCSERVER_WIDTH=' | sed 's/.*=//')
HEIGHT=\$(cat /DietPi/dietpi.txt | grep -m1 '^SOFTWARE_VNCSERVER_HEIGHT=' | sed 's/.*=//')
DEPTH=\$(cat /DietPi/dietpi.txt | grep -m1 '^SOFTWARE_VNCSERVER_DEPTH=' | sed 's/.*=//')
DISPLAY=\$(cat /DietPi/dietpi.txt | grep -m1 '^SOFTWARE_VNCSERVER_DISPLAY_INDEX=' | sed 's/.*=//')
SHARED_MODE=\$(cat /DietPi/dietpi.txt | grep -m1 '^SOFTWARE_VNCSERVER_SHARE_DESKTOP=' | sed 's/.*=//')

#RealVNC | Slightly different launch method to VNC4server
REALVNC=0
if (( \$(dpkg --get-selections | grep -ci -m1 '^realvnc-vnc-server') )); then

	REALVNC=1

	#Set shared desktop mode if autostart is enabled for desktops. This prevents another VNC server being launched on :1.
	if (( \$(cat /DietPi/dietpi/.dietpi-autostart_index) == 2 )); then

		SHARED_MODE=1

	fi

fi

#Find binary FP to use
if [ -f /usr/bin/tigervncserver ]; then
    BINARY_FP='/usr/bin/tigervncserver'
    VNC_INSTALLED=1
elif [ -f /usr/bin/vnc4server ]; then
    BINARY_FP='/usr/bin/vnc4server'
    VNC_INSTALLED=1
elif [ -f /usr/bin/vncserver ]; then
    BINARY_FP='/usr/bin/vncserver'
    VNC_INSTALLED=1
fi

#Exit if no VNC binary found
if (( ! \$VNC_INSTALLED )); then
    exit 1
fi

case "\$1" in
    start)
        if (( \$SHARED_MODE )); then

			# - excluding RealVNC as it has its own services
			if (( ! \$REALVNC )); then

				#wait for X to start
				while (( ! \$(ps aux | grep -ci -m1 '[/]usr/bin/X') ))
				do

					sleep 3

				done

				xset dpms force on #disable screen blanking
				x11vnc -display :0 -usepw -forever &

			fi

        else

            \$BINARY_FP :\$DISPLAY -geometry \$WIDTH'x'\$HEIGHT -depth \$DEPTH

        fi
    ;;

    stop)
        \$BINARY_FP -kill :\$DISPLAY &> /dev/null
        killall -w x11vnc &> /dev/null
		killall -w Xtigervnc &> /dev/null
    ;;

esac

exit 0
_EOF_
			chmod +x /usr/local/bin/vncserver

			# + RealVNC | enable services
			if (( ${aSOFTWARE_INSTALL_STATE[120]} == 1 )); then

				systemctl enable vncserver-x11-serviced.service
				systemctl enable vncserver-virtuald.service

			fi

			# - Stretch + TigerVNC: Disable Localhost only by default
			if (( $G_DISTRO >= 4 )); then

				echo -e '$localhost = "no";' >> /etc/vnc.conf

			fi

		fi

		#VNC4SERVER / RealVNC
		INSTALLING_INDEX=28
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} >= 1 ||
			${aSOFTWARE_INSTALL_STATE[120]} >= 1 )); then

			Banner_Configuration

			local cmd_launch_desktop=''
			#DESKTOP_LXDE
			if (( ${aSOFTWARE_INSTALL_STATE[23]} >= 1 )); then

				cmd_launch_desktop='/usr/bin/lxsession -s LXDE &'

			#DESKTOP_MATE
			elif (( ${aSOFTWARE_INSTALL_STATE[24]} >= 1 )); then

				cmd_launch_desktop='x-window-manager &'

			#DESKTOP_GNUSTEP
			elif (( ${aSOFTWARE_INSTALL_STATE[26]} >= 1 )); then

				cmd_launch_desktop='x-window-manager &'

			#DESKTOP_XFCE
			elif (( ${aSOFTWARE_INSTALL_STATE[25]} >= 1 )); then

				cmd_launch_desktop='/usr/bin/xfce4-session &'

			fi

			mkdir -p "$HOME"/.vnc
			cat << _EOF_ > "$HOME"/.vnc/xstartup
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r /root/.Xresources ] && xrdb /root/.Xresources
xsetroot -solid grey
vncconfig -iconic &
$cmd_launch_desktop
_EOF_

			chmod +x "$HOME"/.vnc/xstartup

		fi


		#FAIL2BAN
		INSTALLING_INDEX=73
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#	Generate log
			echo 0 > /var/log/auth.log

			cat << _EOF_ > /etc/fail2ban/fail2ban.conf
[Definition]
# loglevel #1=error #2=warn #3=info
loglevel = 3
logtarget = /var/log/fail2ban.log
socket = /var/run/fail2ban/fail2ban.sock
pidfile = /var/run/fail2ban/fail2ban.pid
_EOF_

			cat << _EOF_ > /etc/fail2ban/jail.conf
[DEFAULT]

enabled = true
ignoreip = 127.0.0.1/8
ignorecommand =
backend = auto
bantime = 600
findtime = 600
maxretry = 3
banaction = route
action_ = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s"]
action = %(action_)s

[sshd]

enabled  = true
port     = ssh
filter   = sshd
logpath  = /var/log/auth.log
maxretry = 6

[dropbear]

enabled  = true
port     = ssh
filter   = dropbear
logpath  = /var/log/auth.log
maxretry = 6
_EOF_

		fi

		#PHPSYSINFO
		INSTALLING_INDEX=64
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#conf
			cp /DietPi/dietpi/conf/phpsysinfo.ini /var/www/phpsysinfo/phpsysinfo.ini

		fi

		#PHPIMAGEGALLERY
		INSTALLING_INDEX=56
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Get test images
			mkdir -p /var/www/gallery/DietPi
			wget http://dietpi.com/images/dietpi-logo_256.png -O /var/www/gallery/DietPi/logo_256.png

			mkdir -p /var/www/gallery/Tr-Zero
			wget http://media.indiedb.com/images/games/1/25/24673/SS_0.jpg -O /var/www/gallery/Tr-Zero/SS_0.jpg
			wget http://media.indiedb.com/images/games/1/25/24673/SS_44.jpg -O /var/www/gallery/Tr-Zero/SS_1.jpg
			wget http://media.indiedb.com/images/games/1/25/24673/3.png -O /var/www/gallery/Tr-Zero/SS_2.jpg

			#permissions for cache/thumbnail/database
			mkdir -p /var/www/gallery/_sfpg_data

			#enable (Some type of security trigger)
			sed -i "/define('SECURITY_PHRASE'/c\define('SECURITY_PHRASE', 'true');" /var/www/gallery/index.php

		fi

		#AMPACHE
		INSTALLING_INDEX=40
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			Download_Test_Media

			#create/insert our pre-made ampache sql db
			G_RUN_CMD wget http://dietpi.com/downloads/mysql_databases/ampache_mysql_3.8.2-v6.0.zip -O sql.zip
			unzip -o sql.zip
			rm sql.zip

			/DietPi/dietpi/func/create_mysql_db ampache ampache "$GLOBAL_PW"
			mysql ampache < ampache.sql
			rm ampache.sql

			#Grab config
			G_RUN_CMD wget http://dietpi.com/downloads/conf/ampache.cfg.php_3.8.2-v6.0 -O /var/www/ampache/config/ampache.cfg.php

		fi

		#OPENVPNSERVER
		INSTALLING_INDEX=97
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			local key_size=1024

			#Start Cert/Key generation.
			cp -R /usr/share/easy-rsa/ /etc/openvpn
			mkdir -p /etc/openvpn/easy-rsa/keys
			cat << _EOF_ >> /etc/openvpn/easy-rsa/vars
export KEY_SIZE=$key_size
export KEY_COUNTRY="UK"
export KEY_PROVINCE="DietPi"
export KEY_CITY="DietPi"
export KEY_ORG="DietPi"
export KEY_EMAIL="noreply@DietPi.com"
export KEY_OU="DietPi"
export KEY_NAME="DietPi_OpenVPN_Server"
_EOF_

			#Create Server Cert Auth
			G_DIETPI-NOTIFY 2 "Generating unique OpenVPN certificates and keys. Please wait...\n"
			openssl dhparam -out /etc/openvpn/dh"$key_size".pem "$key_size"

			#Build Server certs/keys
			chmod -R +x /etc/openvpn/easy-rsa
			cd /etc/openvpn/easy-rsa
			. ./vars
			./clean-all
			./build-ca --batch DietPi_OpenVPN_Server
			./build-key-server --batch DietPi_OpenVPN_Server

			#Copy Server cert/keys
			cp /etc/openvpn/easy-rsa/keys/{DietPi_OpenVPN_Server.crt,DietPi_OpenVPN_Server.key,ca.crt} /etc/openvpn/

			#Build client cert/keys
			./build-key --batch DietPi_OpenVPN_Client

			cd ..
			#End Cert/Key generation.

			#Server config
			cat << _EOF_ > /etc/openvpn/server.conf
port 1194
proto udp
dev tun

ca ca.crt
cert DietPi_OpenVPN_Server.crt
key DietPi_OpenVPN_Server.key
dh dh$key_size.pem

server 10.8.0.0 255.255.255.0

client-to-client
keepalive 10 60
comp-lzo
max-clients 10

user nobody
group nogroup

persist-key
persist-tun
verb 3

#Web Forwarding (uncomment to enable)
#push "redirect-gateway"
#push "dhcp-option DNS 10.8.0.1"

_EOF_

			#Client config
			cat << _EOF_ > /etc/openvpn/easy-rsa/keys/DietPi_OpenVPN_Client.ovpn
client
proto udp
dev tun

#Ip/Domain name of DietPi system, running OpenVPN server.
remote mywebsite.com 1194

resolv-retry infinite
nobind

user nobody
group nogroup

persist-key
persist-tun

ns-cert-type server
comp-lzo
verb 3

_EOF_

			#Unified client file. Add DietPi generated certs/keys.
			# - Add Server Cert auth
			echo '<ca>' >> /etc/openvpn/easy-rsa/keys/DietPi_OpenVPN_Client.ovpn
			cat /etc/openvpn/ca.crt >> /etc/openvpn/easy-rsa/keys/DietPi_OpenVPN_Client.ovpn
			echo '</ca>' >> /etc/openvpn/easy-rsa/keys/DietPi_OpenVPN_Client.ovpn
			# - Add Client Cert
			echo '<cert>' >> /etc/openvpn/easy-rsa/keys/DietPi_OpenVPN_Client.ovpn
			cat /etc/openvpn/easy-rsa/keys/DietPi_OpenVPN_Client.crt >> /etc/openvpn/easy-rsa/keys/DietPi_OpenVPN_Client.ovpn
			echo '</cert>' >> /etc/openvpn/easy-rsa/keys/DietPi_OpenVPN_Client.ovpn
			# - Add Client Key
			echo '<key>' >> /etc/openvpn/easy-rsa/keys/DietPi_OpenVPN_Client.ovpn
			cat /etc/openvpn/easy-rsa/keys/DietPi_OpenVPN_Client.key >> /etc/openvpn/easy-rsa/keys/DietPi_OpenVPN_Client.ovpn
			echo '</key>' >> /etc/openvpn/easy-rsa/keys/DietPi_OpenVPN_Client.ovpn

			#Copy client file to userdata location
			cp /etc/openvpn/easy-rsa/keys/DietPi_OpenVPN_Client.ovpn "$G_FP_DIETPI_USERDATA"/
			# - and /boot partition
			cp /etc/openvpn/easy-rsa/keys/DietPi_OpenVPN_Client.ovpn /boot/

			#enable ipv4 forwarding
			sed -i '/net.ipv4.ip_forward=/c\net.ipv4.ip_forward=1' /etc/sysctl.conf

			#Web Fowarding (Setup IPtables, must also be run during boot)
			#iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o "$(sed -n 3p /DietPi/dietpi/.network)" -j MASQUERADE

		fi

		#WIFIHOTSPOT
		INSTALLING_INDEX=60
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			local eth_index=$(sed -n 1p /DietPi/dietpi/.network)
			local wifi_index=$(sed -n 2p /DietPi/dietpi/.network)

			# - DHCPD Config
			cat << _EOF_ > /etc/dhcp/dhcpd.conf
ddns-update-style none;
default-lease-time 600;
max-lease-time 7200;
authoritative;
log-facility local7;

subnet 192.168.42.0 netmask 255.255.255.0 {
        range 192.168.42.10 192.168.42.50;
        option broadcast-address 192.168.42.255;
        option routers 192.168.42.1;
        option domain-name "local";
        option domain-name-servers 8.8.8.8, 8.8.4.4;
}
_EOF_

			# - Assign wlan as interface for dhcp server.
			cat << _EOF_ > /etc/default/isc-dhcp-server
INTERFACES="wlan$wifi_index"
_EOF_

			# - Remove all entries below wlan, so we can recreate them.
			sed -i '/allow-hotplug wlan/q0' /etc/network/interfaces

			# - enable up wlan
			sed -i "/allow-hotplug wlan/c\allow-hotplug wlan$wifi_index" /etc/network/interfaces

			# - Add wifi settings to network interfaces config
			cat << _EOF_ >> /etc/network/interfaces
iface wlan$wifi_index inet static
address 192.168.42.1
netmask 255.255.255.0
#gateway 192.168.0.1
wireless-power off
#dns-nameservers 8.8.8.8 8.8.4.4

# IP tables
up iptables-restore < /etc/iptables.ipv4.nat
_EOF_

			# - Assign static IP for wlan now
			ifconfig wlan$wifi_index 192.168.42.1

			# - Create access point config
			cat << _EOF_ > /etc/hostapd/hostapd.conf
interface=wlan$wifi_index
driver=nl80211
ssid=$(cat /DietPi/dietpi.txt | grep -m1 '^SOFTWARE_WIFI_HOTSPOT_SSID=' | sed 's/.*=//')
hw_mode=g
channel=$(cat /DietPi/dietpi.txt | grep -m1 '^SOFTWARE_WIFI_HOTSPOT_CHANNEL=' | sed 's/.*=//')
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=$(cat /DietPi/dietpi.txt | grep -m1 '^SOFTWARE_WIFI_HOTSPOT_KEY=' | sed 's/.*=//')
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
_EOF_

			# - Check for RTL8188C* device, use the patched driver with compiled binary: https://github.com/pritambaral/hostapd-rtl871xdrv#why
			if (( $WIFIHOTSPOT_RTL8188C_DEVICE )); then

				sed -i "/^driver=/c\driver=rtl871xdrv" /etc/hostapd/hostapd.conf

			fi

			# - Enable access point config
			cat << _EOF_ > /etc/default/hostapd
DAEMON_CONF="/etc/hostapd/hostapd.conf"
_EOF_

			# - Enable IPv4 forwarding
			sed -i "/net.ipv4.ip_forward=/c\net.ipv4.ip_forward=1" /etc/sysctl.conf
			echo 1 > /proc/sys/net/ipv4/ip_forward

			# - Apply iptables
			iptables -t nat -A POSTROUTING -o eth$eth_index -j MASQUERADE
			iptables -A FORWARD -i eth$eth_index -o wlan$wifi_index -m state --state RELATED,ESTABLISHED -j ACCEPT
			iptables -A FORWARD -i wlan$wifi_index -o eth$eth_index -j ACCEPT

			# - Save IP tables, applied during ifup in /etc/network/interfaces.
			iptables-save > /etc/iptables.ipv4.nat

			# - RPi 3 - onboard wifi, enable N
			if (( $G_HW_MODEL == 3 && ! $WIFIHOTSPOT_RTL8188C_DEVICE )); then

				# - Add Wireless N support
				echo -e "ieee80211n=1" >> /etc/hostapd/hostapd.conf

			fi

		fi

		#TORHOTSPOT
		INSTALLING_INDEX=61
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# - Tor config
			cat << _EOF_ > /etc/tor/torrc
Log notice file /var/log/tor/notices.log
VirtualAddrNetwork 10.192.0.0/10
AutomapHostsSuffixes .onion,.exit
AutomapHostsOnResolve 1
TransPort 9040
TransListenAddress 192.168.42.1
DNSPort 53
DNSListenAddress 192.168.42.1
_EOF_

			# - Flush IP tables
			iptables -F
			iptables -t nat -F

			# - Generate tor prerouting tables
			local wifi_index=$(sed -n 2p /DietPi/dietpi/.network)
			iptables -t nat -A PREROUTING -i wlan$wifi_index -p tcp --dport 22 -j REDIRECT --to-ports 22
			iptables -t nat -A PREROUTING -i wlan$wifi_index -p udp --dport 53 -j REDIRECT --to-ports 53
			iptables -t nat -A PREROUTING -i wlan$wifi_index -p tcp --syn -j REDIRECT --to-ports 9040

			# - Save
			iptables-save > /etc/iptables.ipv4.nat

			# - Generate Logfile
			mkdir -p /var/log/tor
			echo 0 > /var/log/tor/notices.log
			chown -R debian-tor:nogroup /var/log/tor/notices.log

			# - User: Test tor is functional.
			#https://check.torproject.org

		fi

		#SHAIRPORTSYNC
		INSTALLING_INDEX=37
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Enable SOXR by default:
			cat << _EOF_ >  /usr/local/etc/shairport-sync.conf
general =
{
  name = "%H";
  interpolation = "soxr";
};

metadata =
{
	enabled = "yes";
	include_cover_art = "no";
	pipe_name = "/tmp/shairport-sync-metadata";
	pipe_timeout = 5000;
	socket_address = "226.0.0.1";
	socket_port = 5555;
	socket_msglength = 65000;
};


alsa =
{
//  mixer_control_name = "PCM";
//  output_rate = 44100; // can be 44100, 88200, 176400 or 352800
//  output_format = "S16"; // can be "U8", "S8", "S16", "S24", "S24_3LE", "S24_3BE" or "S32"
};
_EOF_

			#Create shairport user
			groupadd -r shairport-sync &> /dev/null
			useradd -r -M -g shairport-sync -s /usr/bin/nologin -G audio shairport-sync &> /dev/null

			chmod +x /usr/local/bin/shairport-sync

		fi

		#BRUTEFIR
		INSTALLING_INDEX=38
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Copy configs and services
			cp /DietPi/dietpi/conf/brutefir_config /etc/BruteFIR/
			cp /DietPi/dietpi/conf/brutefir.service /var/lib/dietpi/dietpi-software/services/brutefir.service

			#Modules
			echo -e "snd-aloop" > /etc/modules-load.d/brutefir-alsa-loopback.conf
			echo -e "options snd-aloop id=BruteFIR enable=1 pcm_substreams=1 pcm_notify=1"	> /etc/modprobe.d/brutefir-alsa-loopback.conf

			#Asound.conf RPI
			cat << _EOF_ > /etc/asound.conf
pcm.!default {

	type plug

	slave {
		pcm {

			type hw
			card "BruteFIR"
			device 0
			channels 2
			format "S16_LE"
			rate 44100
		}
	}
}

ctl.!default {

	type hw
	card "BruteFIR"
}
_EOF_

		fi


		#PYDIO
		INSTALLING_INDEX=48
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Configure apache2
			# - Disable php output_buffering =
			sed -i '/output_buffering = /c\output_buffering = Off/' "$FP_PHP_BASE_DIR"/apache2/php.ini
			# - Allow overrides and redirects
			sed -i "/AllowOverride /c\    AllowOverride All" /etc/apache2/sites-enabled/000-default*
			# - +Jessie
			sed -i "/AllowOverride /c\    AllowOverride All" /etc/apache2/apache2.conf

			# - Enable apache2 rewrite engine
			a2enmod rewrite

			#Create Mysql DB
			/DietPi/dietpi/func/create_mysql_db pydio pydio "$GLOBAL_PW"

			#Setup Data directory
			local target_data_dir="$G_FP_DIETPI_USERDATA/pydio_data"

			# - Generate user data dir
			mkdir -p "$target_data_dir"

			# - move data structure
			mv /var/www/pydio/data/* "$target_data_dir"/
			rm -R /var/www/pydio/data
			ln -sf "$target_data_dir" /var/www/pydio/data

		fi


		#SQUEEZELITE
		INSTALLING_INDEX=36
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# - Replace Sysinit service with SystemD
			echo -e "#This file is no longer used as service has been upgraded to SystemD.\n#Please see /etc/systemd/system/squeezelite.service to set start options" > /etc/default/squeezelite
			rm /etc/init.d/squeezelite
			cp /DietPi/dietpi/conf/squeezelite.service /etc/systemd/system/squeezelite.service

			Download_Test_Media

		fi

		#EMONHUB
		INSTALLING_INDEX=99
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# - Copy configs
			cp /etc/emonhub/conf/default/emonhub /etc/default/emonhub

			# - Setup service
			cp /etc/emonhub/service/emonhub /etc/init.d/emonhub
			chmod +x /etc/init.d/emonhub
			update-rc.d emonhub defaults

			chmod +x -R /etc/emonhub

			#RPI 3 - Must disable BCM BT to recover UART 0
			if (( $G_HW_MODEL == 3 )); then

				# - Add DToverlay to disable bluetooth
				if (( $(cat /DietPi/config.txt | grep -ci -m1 '=pi3-disable-bt') == 0 )); then

					echo -e "\ndtoverlay=pi3-disable-bt" >> /DietPi/config.txt

				# - Enable
				else

					sed -i '/pi3-disable-bt/c\dtoverlay=pi3-disable-bt' /DietPi/config.txt

				fi

				# - Disable bluetooth service
				systemctl stop hciuart
				systemctl disable hciuart

			fi

			#RPi - Disable serial tty that emonPi uses.
			/DietPi/dietpi/func/dietpi-set_hardware serialconsole disable

			# - Apply user API KEY
			USER_EMONHUB_APIKEY_CURRENT=$(cat /DietPi/dietpi.txt | grep -m1 '^SOFTWARE_EMONHUB_APIKEY=' | sed 's/.*=//')
			sed -i "/apikey/c\        apikey = $USER_EMONHUB_APIKEY_CURRENT" /etc/emonhub/conf/emonhub.conf

		fi

		#RPIMONITOR
		INSTALLING_INDEX=66
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# - Update apt package stats
			/usr/share/rpimonitor/scripts/updatePackagesStatus.pl

			# - USBdrive stats implimentation by Rich
			if (( $USBDRIVE )); then

				sed -i '\/include=\/etc\/rpimonitor\/template\/sdcard.conf/a include=\/etc\/rpimonitor\/template\/usb_hdd.conf' /etc/rpimonitor/data.conf

				cat << _EOF_ > /etc/rpimonitor/template/usb_hdd.conf
########################################################################
# Extract USB HDD (sda1) information
#  Page: 1
#  Information               Status     Statistics
#  - USBHDD1 total          - yes      - yes
#  - USBHDD1 used           - yes      - yes
########################################################################
static.10.name=usbhdd_total
static.10.source=df -t ext4
static.10.regexp=sda1\s+(\d+)
static.10.postprocess=\$1/1024

dynamic.14.name=usbhdd_used
dynamic.14.source=df -t ext4
dynamic.14.regexp=sda1\s+\d+\s+(\d+)
dynamic.14.postprocess=\$1/1024
dynamic.14.rrd=GAUGE

web.status.1.content.9.name=USB HDD
web.status.1.content.9.icon=usb_hdd.png
web.status.1.content.9.line.1="<b>/sda1</b> Used: <b>"+KMG(data.usbhdd_used,'M')+"</b> (<b>"+Percent(data.udbhdd_used,data.usbhdd_total,'M')+"</b>) Free: <b>"+KMG(data.usbhdd_total-data.usbhdd_used,'M')+ "</b> Total: <b>"+ KMG(data.usbhdd_total,'M') +"</b>"
web.status.1.content.9.line.2=ProgressBar(data.usbhdd_used,data.usbhdd_total)

web.statistics.1.content.9.name=USB HDD
web.statistics.1.content.9.graph.1=usbhdd_total
web.statistics.1.content.9.graph.2=usbhdd_used
web.statistics.1.content.9.ds_graph_options.usbhdd_total.label=USB HDD total space (MB)
web.statistics.1.content.9.ds_graph_options.usbhdd_total.color="#FF7777"
web.statistics.1.content.9.ds_graph_options.usbhdd_used.label=USB HDD used space (MB)
web.statistics.1.content.9.ds_graph_options.usbhdd_used.lines={ fill: true }
web.statistics.1.content.9.ds_graph_options.usbhdd_used.color="#7777FF"
_EOF_

			fi

		fi

		#NETDATA
		INSTALLING_INDEX=65
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# - service
			cp /DietPi/dietpi/conf/netdata.service /etc/systemd/system/netdata.service

			systemctl daemon-reload

			# - Create netdata user/group
			getent group netdata > /dev/null || groupadd -r netdata
			getent passwd netdata > /dev/null || useradd -r -g netdata -c netdata -s /sbin/nologin -d / netdata

			for x in /var/cache/netdata /usr/share/netdata/web /etc/netdata /var/log/netdata /var/lib/netdata; do

				chown -R netdata.netdata $x
				chmod 0775 -R $x

			done

		fi

		#BAIKAL
		INSTALLING_INDEX=57
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			Install_Apply_Permissions &> /dev/null

			# - install/run composer | Also run for ampache. Move this to a global function....
			php -r "readfile('https://getcomposer.org/installer');" > composer-setup.php
			php composer-setup.php
			php -r "unlink('composer-setup.php');"

			mv composer.phar /usr/local/bin/composer

			cd /var/www/baikal
			composer install --no-interaction
			cd ~/

			# - Mysql DB
			/DietPi/dietpi/func/create_mysql_db baikal baikal "$GLOBAL_PW"

		fi

		#MUMBLESERVER
		INSTALLING_INDEX=43
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Cap total connections
			local max_users=$(( $G_HW_CPU_CORES * 8 ))
			sed -i "/users=/c\users=$max_users" /etc/mumble-server.ini

			#Name the root channel
			sed -i '/registerName=/c\registerName=DietPi Mumble Server' /etc/mumble-server.ini

			#Disable DB logging
			sed -i '/logdays=/c\logdays=-1' /etc/mumble-server.ini

			#Set Superuser passwd: http://dietpi.com/phpbb/viewtopic.php?f=11&t=2024#p8084
			murmurd -ini /etc/mumble-server.ini -supw "$GLOBAL_PW"

		fi

		#EMBYSERVER
		INSTALLING_INDEX=41
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			Download_Test_Media

		fi

		#PLEXMEDIASERVER
		INSTALLING_INDEX=42
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			Download_Test_Media

			#For all ARM devices:
			# - en_US.UTF8 must be installed and the default locale on system. This is for SBC installs using dev2day repo: https://github.com/Fourdee/DietPi/issues/116#issuecomment-222195911
			if (( $G_USER_INPUTS &&
				$G_HW_ARCH < 10 && ! $(locale | grep -ci -m1 'en_US.UTF-8') )); then

				sed -i '/en_US.UTF-8 UTF-8/c\en_US.UTF-8 UTF-8' /etc/locale.gen
				locale-gen

				WHIP_QUESTION='Plex Media Server requires en_US.UTF8 locale to be installed and set to default, else, Plex will not start.\n\nOn the next screen:\n - Press enter (Do not make any changes to the selections, we have already selected en_US.UTF8 for you).\n\nOn the screen after:\n - Select en_US.UTF8 and press enter.'
				whiptail --title "Plex en_US.UTF8" --msgbox "$WHIP_QUESTION" --backtitle "$WHIP_BACKTITLE" 16 70

				dpkg-reconfigure locales

			fi

		fi

		#CUBERITE
		INSTALLING_INDEX=52
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			cat << _EOF_ > /etc/systemd/system/cuberite.service
[Unit]
Description=Cuberite Server

[Service]
Type=oneshot
WorkingDirectory=/etc/cubrite
ExecStart=/etc/cubrite/Cuberite --service
ExecStop=/usr/bin/killall -w Cuberite
RemainAfterExit=yes
User=root

[Install]
WantedBy=multi-user.target
_EOF_
systemctl enable cuberite.service
systemctl daemon-reload

			#WebUI settings
			cat << _EOF_ > /etc/cubrite/webadmin.ini
[User:root]
Password=$GLOBAL_PW

[WebAdmin]
Ports=1339
Enabled=1
_EOF_

		fi

		#MINEOS
		INSTALLING_INDEX=53
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Stop mineos from running while we config it. When we didnt do this, the program would constantly overwrite our symlink from (/var/games/minecraft).
			/DietPi/dietpi/dietpi-services stop
			killall -w supervisord &> /dev/null
			killall -w node &> /dev/null
			killall -w nodejs &> /dev/null

			ln -sf "$G_FP_DIETPI_USERDATA"/mineos/minecraft/mineos_console.js /usr/local/bin/mineos

			cp "$G_FP_DIETPI_USERDATA"/mineos/minecraft/mineos.conf /etc/mineos.conf

			# - setup SSL cert
			cd "$G_FP_DIETPI_USERDATA"/mineos/minecraft
			./generate-sslcert.sh

			# - Supervisor service
			cp "$G_FP_DIETPI_USERDATA"/mineos/minecraft/init/supervisor_conf /etc/supervisor/conf.d/mineos.conf

			cd "$HOME"

			# - Add underprivilged user for web access
			useradd mineos
			echo -e "dietpi\ndietpi\n" | passwd mineos

			# - Move server data storage to userdata dir (High disk writes)
			mkdir -p "$G_FP_DIETPI_USERDATA"/mineos/serverdata
			mkdir -p /var/games #sometimes this is not created by mineos after installation... Ensures symlink creation does not fail.
			cp -R /var/games/minecraft/* "$G_FP_DIETPI_USERDATA"/mineos/serverdata/ #Folder does not exist during installation, as of 18/09/16
			rm -R /var/games/minecraft

			ln -sf "$G_FP_DIETPI_USERDATA"/mineos/serverdata /var/games/minecraft

			chown -R mineos:mineos /var/games/minecraft

			# - correct the node filepath for supervisor mineos
			sed -i '/^command=/c\command=/usr/local/bin/node webui.js' /etc/supervisor/conf.d/mineos.conf

			# - Set directory to G_FP_DIETPI_USERDATA
			sed -i "/^directory=/c\directory=$G_FP_DIETPI_USERDATA/mineos/minecraft" /etc/supervisor/conf.d/mineos.conf

			supervisorctl reload

		fi

		#GOGS
		INSTALLING_INDEX=49
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# - Data storage / user data
			mkdir -p "$G_FP_DIETPI_USERDATA"/gogs-repo

			# - sqldb
			/DietPi/dietpi/func/create_mysql_db gogs gogs "$GLOBAL_PW"

			# - service (couldnt get this to run as a new thread with systemD (&). so bash script ftw.
			cat << _EOF_ > /etc/gogs/start.sh
#!/bin/bash
#Simple script to start gogs for DietPi systems
/etc/gogs/gogs web &> /var/log/gogs_daemon.log &
exit
_EOF_

			chmod +x /etc/gogs/start.sh

			cat << _EOF_ > /etc/systemd/system/gogs.service
[Unit]
Description=DietPi Gogs service
DefaultDependencies=no

[Service]
Type=oneshot
RemainAfterExit=yes
User=root
ExecStart=/bin/bash /etc/gogs/start.sh
ExecStop=/usr/bin/killall -w gogs
StandardOutput=tty

[Install]
WantedBy=multi-user.target
_EOF_

		fi

		#QBITTORRENT
		INSTALLING_INDEX=46
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# - conf.
			mkdir -p "$HOME"/.config/qBittorrent
			cat << _EOF_ > "$HOME"/.config/qBittorrent/qBittorrent.conf
[General]
ported_to_new_savepath_system=true

[Preferences]
Downloads\DiskWriteCacheSize=$(Optimize_BitTorrent 0)
Downloads\DiskWriteCacheTTL=60
Queueing\MaxActiveDownloads=$(Optimize_BitTorrent 1)
Queueing\MaxActiveTorrents=$(Optimize_BitTorrent 1)
Queueing\MaxActiveUploads=1
Queueing\IgnoreSlowTorrents=false
Bittorrent\MaxConnecs=$(Optimize_BitTorrent 2)
Bittorrent\MaxConnecsPerTorrent=$(Optimize_BitTorrent 2)
Bittorrent\MaxUploads=$(Optimize_BitTorrent 3)
Bittorrent\MaxUploadsPerTorrent=$(Optimize_BitTorrent 3)
WebUI\Port=1340
WebUI\Enabled=true
General\Locale=en_GB
Downloads\SavePath=$G_FP_DIETPI_USERDATA/downloads
Downloads\TempPathEnabled=false
Downloads\TempPath=$G_FP_DIETPI_USERDATA/downloads
Downloads\ScanDirs=@Invalid()
Downloads\DownloadInScanDirs=@Invalid()
Downloads\TorrentExportDir=
MailNotification\enabled=false
MailNotification\email=
MailNotification\smtp_server=smtp.changeme.com
MailNotification\req_ssl=false
MailNotification\req_auth=false
MailNotification\username=
MailNotification\password=
Downloads\PreAllocation=false
Queueing\QueueingEnabled=false
Downloads\UseIncompleteExtension=false
Connection\PortRangeMin=6881
Connection\UPnP=true
Connection\GlobalDLLimit=-1
Connection\GlobalUPLimit=-1
Bittorrent\uTP=true
Bittorrent\uTP_rate_limited=false
Advanced\IncludeOverhead=false
Connection\GlobalDLLimitAlt=10
Connection\GlobalUPLimitAlt=10
Scheduler\Enabled=false
Bittorrent\DHT=true
Bittorrent\sameDHTPortAsBT=true
Bittorrent\DHTPort=6881
Bittorrent\PeX=true
Bittorrent\LSD=true
Bittorrent\Encryption=1
Advanced\AnonymousMode=false
Connection\ProxyType=-1
Connection\Proxy\IP=0.0.0.0
Connection\Proxy\Port=8080
Connection\ProxyPeerConnections=false
Connection\Proxy\Authentication=false
Connection\Proxy\Username=
Connection\Proxy\Password=
IPFilter\Enabled=false
IPFilter\File=
WebUI\Username=root
WebUI\LocalHostAuth=true
WebUI\HTTPS\Enabled=false
DynDNS\Enabled=false
DynDNS\Service=0
DynDNS\Username=
DynDNS\Password=
DynDNS\DomainName=changeme.dyndns.org
WebUI\Password_ha1=@ByteArray($(echo -ne "$GLOBAL_PW" | md5sum | awk '{print $1}'))


[LegalNotice]
Accepted=true

[AutoRun]
enabled=false
program=
_EOF_

			# - service
			cat << _EOF_ > /etc/systemd/system/qbittorrent.service
[Unit]
Description=qBittorrent Daemon Service
After=network.target

[Service]
Type=oneshot
User=root
RemainAfterExit=yes
ExecStart=/usr/bin/qbittorrent-nox -d --webui-port=1340
ExecStop=/usr/bin/killall -w qbittorrent-nox

[Install]
WantedBy=multi-user.target
_EOF_

			systemctl daemon-reload

		fi

		#RTORRENT
		INSTALLING_INDEX=107
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Create username/password for rutorrent based on webserver type.
			# - Apache2
			if (( ${aSOFTWARE_INSTALL_STATE[83]} >= 1 )); then

				# - Allow overrides redirects and .htaccess
				sed -i "/AllowOverride /c\    AllowOverride All" /etc/apache2/sites-enabled/000-default*
				sed -i "/AllowOverride /c\    AllowOverride All" /etc/apache2/apache2.conf

				a2enmod rewrite

				#install scgi module
				G_AGI libapache2-mod-scgi

				htpasswd -cb /etc/.rutorrent-htaccess root "$GLOBAL_PW"
				cat << _EOF_ > /var/www/rutorrent/.htaccess
AuthUserFile /etc/.rutorrent-htaccess
AuthName "ruTorrent_login"
AuthType Basic
require user root
_EOF_

				cat << _EOF_ > /etc/apache2/sites-available/rutorrent.conf
SCGIMount /RPC2 127.0.0.1:5000
<location /RPC2>
AuthName "rTorrent secure access"
AuthType Basic
AuthBasicProvider file
AuthUserFile /etc/.rutorrent-htaccess
Require user root
</location>
_EOF_
				ln -s /etc/apache2/sites-available/rutorrent.conf /etc/apache2/sites-enabled/rutorrent.conf

			# - Lighttpd
			elif (( ${aSOFTWARE_INSTALL_STATE[84]} >= 1 )); then

				echo -e "root:rtorrent:$(echo -n "root:rtorrent:dietpi" | md5sum | cut -b -32)" > /etc/.rutorrent-htaccess

				# - add to /etc/lighttpd/lighttpd.conf
				if (( ! $(cat /etc/lighttpd/lighttpd.conf | grep -ci -m1 '^#RUTORRENT_DIETPI') )); then

					cat << _EOF_ >> /etc/lighttpd/lighttpd.conf
#RUTORRENT_DIETPI
server.modules += ( "mod_fastcgi" )
server.modules += ( "mod_scgi" )
server.modules += ( "mod_auth" )
auth.debug = 0
auth.backend = "htdigest"
auth.backend.htdigest.userfile = "/etc/.rutorrent-htaccess"

auth.require = ( "/rutorrent/" => (
                    "method"  => "digest",
                    "realm"   => "rtorrent",
                    "require" => "valid-user"
               ))

scgi.server = ( "/RPC2" =>
    ( "127.0.0.1" =>
        (
            "host" => "127.0.0.1",
            "port" => 5000,
            "check-local" => "disable"
        )
    )
)
#RUTORRENT_DIETPI
_EOF_

				fi

			# - Nginx
			elif (( ${aSOFTWARE_INSTALL_STATE[85]} >= 1 )); then

				echo "root:$(openssl passwd -crypt dietpi)" > /etc/.rutorrent-htaccess

				cat << _EOF_ > /etc/nginx/sites-dietpi/rutorrent.config
location /rutorrent {
    auth_basic "Restricted Content";
    auth_basic_user_file /etc/.rutorrent-htaccess;
}

location /RPC2 {
    include scgi_params;
    scgi_pass 127.0.0.1:5000;
}
_EOF_

			fi

			# - Define curl location in config.php (for lighttpd and nginx)
			sed -i '/"curl"[[:space:]]/c\        "curl" => "/usr/bin/curl",' /var/www/rutorrent/conf/config.php

			chown www-data:www-data /etc/.rutorrent-htaccess
			chmod 400 /etc/.rutorrent-htaccess

			# - Session folder
			mkdir -p "$G_FP_DIETPI_USERDATA"/downloads/.session

			# - Service using screen | '/usr/bin/rtorrent &> /var/log/rtorrent.log &' doesnt work, hangs program after 5 seconds
			cat << _EOF_ > /etc/systemd/system/rtorrent.service
[Unit]
Description=rTorrent
After=network.target

[Service]
User=root
Type=forking
KillMode=none
ExecStart=/usr/bin/screen -d -m -fa -S rtorrent /usr/bin/rtorrent
ExecStop=/usr/bin/killall -w -s 2 /usr/bin/rtorrent
WorkingDirectory=%h

[Install]
WantedBy=multi-user.target
_EOF_
			systemctl daemon-reload

			#Default conf
			cat << _EOF_ > "$HOME"/.rtorrent.rc
#Attempt to reduce disk throttling/abuse | 0.9.2 command does not exist
#max_open_files = 50

#Max queue
scheduler.max_active.set = 3

#byte value
max_memory_usage = $(( $(Optimize_BitTorrent 0) * 1024 * 1024 ))

# Maximum and minimum number of peers to connect to per torrent.
min_peers = 1
max_peers = $(( $(Optimize_BitTorrent 2) / 2 + 1 ))

# Same as above but for seeding completed torrents (-1 = same as downloading)
min_peers_seed = -1
max_peers_seed = -1

# Maximum number of simultaneous downloads
max_downloads_global = $(Optimize_BitTorrent 2)
# Maximum number of simultaneous uploads
max_uploads_global = $(Optimize_BitTorrent 3)

# Global upload and download rate in KiB. "0" for unlimited.
download_rate = 0
upload_rate = 0

# Default directory to save the downloaded torrents.
directory = $G_FP_DIETPI_USERDATA/downloads

# Default session directory. Make sure you don't run multiple instance
# of rtorrent using the same session directory. Perhaps using a
# relative path?
session = $G_FP_DIETPI_USERDATA/downloads/.session

# Close torrents when diskspace is low.
schedule = low_diskspace,5,60,close_low_diskspace=1000M

# Periodically save session data
schedule = session_save,240,300,session_save=

# Enable the default ratio group.
ratio.enable=yes
# Change the limits, the defaults should be sufficient.
# Upload to a minimum ratio of 1.01
ratio.min.set=101
# Upload to a maximum ratio of 1.25
ratio.max.set=125
# Upload a minimum of x MB
ratio.upload.set=1M

# When seeding ratio is reached close the torrent
system.method.set = group.seeding.ratio.command, d.close=

# Move files to ./unsorted when download completes
system.method.set_key = event.download.finished,move_complete,"execute=mv,-n,$d.get_base_path=,./unsorted/;d.set_directory=./unsorted/"

# Port range to use for listening.
port_range = 33101-33199

# Start opening ports at a random position within the port range.
port_random = yes

# Encryption options, set to none (default) or any combination of the following:
# allow_incoming, try_outgoing, require, require_RC4, enable_retry, prefer_plaintext
#
# The example value allows incoming encrypted connections, starts unencrypted
# outgoing connections but retries with encryption if they fail, preferring
# plaintext to RC4 encryption after the encrypted handshake
#
encryption = require

# Sort the main view by ratio
view.sort_current = main,greater=d.get_ratio=
view.sort_new = main,less=d.get_ratio=
view.sort = main

# Sort the seeding view by the upload rate and only show torrents with peers
view.sort_current = seeding,greater=d.get_up_rate=
view.filter = seeding,"and=d.get_complete=,d.get_peers_connected="
view.sort_new = seeding,less=d.get_up_rate=
view.sort = seeding

# Sort the leeching view by name
view.sort_current = leeching,greater=d.get_name=
view.sort_new = leeching,greater=d.get_name=
view.sort = leeching

# Filter the active view by connected peers
view.sort_current = active,less=d.get_name=
view.sort_new = leeching,less=d.get_name=
view.filter = active,d.get_peers_connected=
view.sort = active

schedule = sort_main,11,5,view.sort=main
schedule = sort_seeding,12,5,view.sort=seeding
schedule = sort_leeching,13,5,view.sort=leeching
schedule = sort_active,14,5,view.sort=active

# Enable DHT support for trackerless torrents or when all trackers are down.
# May be set to "disable" (completely disable DHT), "off" (do not start DHT),
# "auto" (start and stop DHT as needed), or "on" (start DHT immediately).
# The default is "off". For DHT to work, a session directory must be defined.
#
dht = auto

# UDP port to use for DHT.
#
#dht_port = 6881

# Enable peer exchange (for torrents not marked private)
#
peer_exchange = yes

#Enable remote access (eg: webui)
scgi_port = localhost:5000

_EOF_


		fi

		#Aria2
		INSTALLING_INDEX=132
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			cat << _EOF_ > /etc/systemd/system/aria2.service
[Unit]
Description=DietPi Aria2

[Service]
Type=simple
ExecStart=$(which aria2c) --enable-rpc --rpc-listen-all --rpc-secret=$GLOBAL_PW --dir=$G_FP_DIETPI_USERDATA/$FOLDER_DOWNLOADS

[Install]
WantedBy=multi-user.target
_EOF_

		fi

		#SYNCTHING
		INSTALLING_INDEX=50
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# - Generate dir's
			mkdir -p "$G_FP_DIETPI_USERDATA"/syncthing
			mkdir -p "$G_FP_DIETPI_USERDATA"/syncthing_data

			#	Logs/Binary
			mkdir -p /var/log/syncthing
   			echo '' > /var/log/syncthing/syncthing.log
   			chown -R dietpi:dietpi /var/log/syncthing
   			chown -R dietpi:dietpi /etc/syncthing

			# - run syncthing to create cert/config and exit
			/etc/syncthing/syncthing -generate="$G_FP_DIETPI_USERDATA"/syncthing

			# - Disable automatic upgrades
			sed -i '/<\/autoUpgradeIntervalH>/c\        <autoUpgradeIntervalH>0<\/autoUpgradeIntervalH>' "$G_FP_DIETPI_USERDATA"/syncthing/config.xml

			# - Allow external access (LAN).
			sed -i '/:8384<\/address>/c\        <address>0.0.0.0:8384<\/address>' "$G_FP_DIETPI_USERDATA"/syncthing/config.xml

			# - Set default folder
			sed -i '/label=\"Default Folder/c\    <folder id=\"0000-0000\" label=\"Syncthing Data\" path=\"'"$G_FP_DIETPI_USERDATA/syncthing_data"'\" type=\"readwrite\" rescanIntervalS=\"60\" ignorePerms=\"false\" autoNormalize=\"true\">' "$G_FP_DIETPI_USERDATA"/syncthing/config.xml

			# - Disable browser starting
			sed -i '/<\/startBrowser>/c\        <startBrowser>false<\/startBrowser>' "$G_FP_DIETPI_USERDATA"/syncthing/config.xml

			# - Enable filesystem watcher (previously inotify)
			sed -i 's/fsWatcherEnabled=\"false\"/fsWatcherEnabled=\"true\"/g' "$G_FP_DIETPI_USERDATA"/syncthing/config.xml

			#services
			cat << _EOF_ > /etc/systemd/system/syncthing.service
[Unit]
Description=Syncthing
After=network.target

[Service]
Type=simple
ExecStart=/etc/syncthing/syncthing -logfile=/var/log/syncthing/syncthing.log -logflags=3 -home=$G_FP_DIETPI_USERDATA/syncthing
User=dietpi

[Install]
WantedBy=multi-user.target
_EOF_

			# - Increase open file limit:
			echo -e "fs.inotify.max_user_watches=204800" | tee -a /etc/sysctl.conf

		fi

		#Urbackup server
		INSTALLING_INDEX=111
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			mkdir -p "$G_FP_DIETPI_USERDATA"/urbackup/urbackup_tmp_files

			#As we have /tmp mounted to RAM, change tmp locations
			sed -i '/DAEMON_TMPDIR=/c\DAEMON_TMPDIR="/var/tmp"' /etc/default/urbackupsrv

			#https://github.com/Fourdee/DietPi/issues/545#issuecomment-252419739
			#sqlite3 /usr/local/var/urbackup/backup_server_settings.db "UPDATE settings SET value = '/mnt/dietpi_userdata/urbackup/' WHERE key = 'backupfolder'"

		fi

		#SICKRAGE
		INSTALLING_INDEX=116
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			mkdir -p "$G_FP_DIETPI_USERDATA"/sickrage

			cat << _EOF_ > /etc/systemd/system/sickrage.service
[Unit]
Description=SickRage
After=dietpi-service.service

[Service]
User=root
Group=root
Type=forking
GuessMainPID=no
ExecStart=/usr/bin/python /etc/sickrage/SickBeard.py -q --daemon --nolaunch --datadir=$G_FP_DIETPI_USERDATA/sickrage
#ExecStop=/usr/bin/killall -w SickBeard.py

[Install]
WantedBy=multi-user.target
_EOF_

			#Grab our premade config:
			#	SickRage must be run at least once, or it will simply overwrite our config
			G_DIETPI-NOTIFY 2 "Configuring SickRage, please wait..."
			systemctl start sickrage

			#	Wait for SickRage to generate its default config.ini, else, it will just overwrite our config.ini.
			local max_loops=10
			local current_loop=0
			while [ ! -f "$G_FP_DIETPI_USERDATA/sickrage/config.ini" ]
			do

				G_DIETPI-NOTIFY 2 "Waiting for SickRage to finish 1st run prep, please wait..."
				sleep 1

				((current_loop++))

				if (( $current_loop >= $max_loops )); then

					G_DIETPI-NOTIFY 1 "Timed-out waiting for SickRage to generate config.ini"
					break

				fi

			done

			systemctl stop sickrage

			cp "$G_FP_DIETPI_USERDATA"/sickrage/config.ini "$G_FP_DIETPI_USERDATA"/sickrage/config.ini.default
			wget http://dietpi.com/downloads/conf/sickrage_dietpi_config.ini -O "$G_FP_DIETPI_USERDATA"/sickrage/config.ini

		fi

		#TONIDO
		INSTALLING_INDEX=134
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#service
			cat << _EOF_ > /etc/systemd/system/tonido.service
[Unit]
Description=Tonido - DietPi

[Service]
Type=simple
User=root
WorkingDirectory=/etc/tonido
ExecStart=/bin/bash -c 'export LD_LIBRARY_PATH=/etc/tonido; export TONIDODIR=/etc/tonido; ./tonidoconsole'

[Install]
WantedBy=multi-user.target
_EOF_

			# - userdirs
			mkdir -p "$G_FP_DIETPI_USERDATA"/tonido/sync
			mkdir -p "$G_FP_DIETPI_USERDATA"/tonido/syncdata

			#	symlink
			cp -R "$HOME"/tonido "$G_FP_DIETPI_USERDATA"/ &> /dev/null
			rm -R "$HOME"/tonido &> /dev/null
			ln -sf "$G_FP_DIETPI_USERDATA"/tonido "$HOME"/tonido
			ln -sf "$G_FP_DIETPI_USERDATA"/tonido/sync "$HOME"/TonidoSync
			ln -sf "$G_FP_DIETPI_USERDATA"/tonido/syncdata "$HOME"/TonidoSyncData

			# - armv7 switch
			if (( $G_HW_ARCH == 2 )); then

				sed -i 's/armv6l/armv7l/' /etc/tonido/manifest.xml
				sed -i 's/armv6l/armv7l/' /etc/tonido/plugins/*/manifest.xml

			fi

		fi

		#Chromium
		INSTALLING_INDEX=113
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Allow root, start maximized and disable sandbox under root (blank screen without)
			local export_options="export CHROMIUM_FLAGS=\"\$CHROMIUM_FLAGS --no-sandbox --temp-profile --start-maximized --user-data-dir "

			#RPi
			if (( $G_HW_MODEL < 10 )); then

				#	OpenGL
				if (( $G_HW_MODEL >= 2 )); then

					#Hangs xinit: https://github.com/Fourdee/DietPi/issues/834
					#/DietPi/dietpi/func/dietpi-set_hardware rpi-opengl enable
					echo 0

				fi

			#OpenGL
			elif (( $G_HW_MODEL == 21 )); then

				echo 0 &> /dev/null

			#GLES
			else

				export_options+='--use-gl=egl'

			fi

			export_options+="\""

			mkdir -p /etc/chromium.d
			cat << _EOF_ > /etc/chromium.d/custom_flags
$export_options
_EOF_

			#	Chromium 60+
			cp /etc/chromium.d/custom_flags "$HOME"/.chromium-browser.init

			#Symlink to desktop
			#	* for RPi Stretch due to chromium-browser.desktop
			ln -sf /usr/share/applications/chromium*.desktop "$HOME"/Desktop/chromium.desktop

		fi

		#OMV
		INSTALLING_INDEX=126
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			omv-initsystem

		fi

		#O!MPD
		INSTALLING_INDEX=129
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			sed -i "/'mysqli_user'/c \$cfg[\'mysqli_user\']                 = \'ompd\';" /var/www/ompd/include/config.inc.php
			sed -i "/'mysqli_password'/c \$cfg[\'mysqli_password\']                 = \'$GLOBAL_PW\';" /var/www/ompd/include/config.inc.php
			sed -i "/'media_dir'/c \$cfg[\'media_dir\']                 = \'/var/lib/mpd/music/\';" /var/www/ompd/include/config.inc.php
			sed -i "/'ignore_media_dir_access_error'/c \$cfg[\'ignore_media_dir_access_error\']                 = \'true';" /var/www/ompd/include/config.inc.php

			/DietPi/dietpi/func/create_mysql_db ompd ompd "$GLOBAL_PW"

		fi

		#IceCast + DarkIce
		INSTALLING_INDEX=135
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#icecast set passwords:
			sed -i '/\<source-password\>/c\\<source-password\>dietpi\<\/source-password\>' /etc/icecast2/icecast.xml
			sed -i '/\<relay-password\>/c\\<relay-password\>dietpi\<\/relay-password\>' /etc/icecast2/icecast.xml

			#	Create random password
			local admin_password=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w10 | head -n1)
			sed -i "/\<admin-password\>/c\\<admin-password\>$admin_password\<\/admin-password\>" /etc/icecast2/icecast.xml

			sed -i '/ENABLE=/c\ENABLE=true' /etc/default/icecast2

			#Configure for ALSA loopback?
			# echo -e "options snd_aloop pcm_substreams=2 #index=10# breaks module loading..." > /etc/modprobe.d/snd_aloop_index.conf
			# modprobe snd-aloop
			# if (( ! $(cat /etc/modules | grep -ci -m1 '^snd-aloop') )); then

				# echo -e "snd-aloop" >> /etc/modules

			# fi

			#Darkice
			local input_device_index=$(arecord -l | grep -m1 'card' | awk '{print $2}' | sed 's/://')

			cat << _EOF_ > /etc/darkice.cfg
[general]
duration      = 0
bufferSecs    = 3
reconnect     = yes

[input]
device        = hw:$input_device_index,0
sampleRate    = 44100
bitsPerSample = 16
channel       = 1

[icecast2-0]
bitrateMode   = vbr
format        = vorbis
quality       = 0.8
server        = dietpi
port          = 8000
password      = dietpi
mountPoint    = DietPi
name          = DietPi
description   = DarkIce on DietPi
url           = http://localhost
genre         = none
public        = no
#localDumpFile = $G_FP_DIETPI_USERDATA/darkice_recording.ogg
_EOF_

			#SystemD service for Darkice
			rm /etc/init.d/darkice
			cat << _EOF_ > /etc/systemd/system/darkice.service
[Unit]
Description=DarkIce - DietPi
After=icecast2.service
Requires=icecast2.service

[Service]
Type=simple
ExecStart=$(which darkice)

[Install]
WantedBy=multi-user.target
_EOF_

		fi

		#Blynk
		INSTALLING_INDEX=131
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# - service
			local fp_java_binary=$(which java)

			mkdir -p "$G_FP_DIETPI_USERDATA"/blynk
			CONFIG_FILE_URL_ADDRESS='https://raw.githubusercontent.com/blynkkk/blynk-server/master/server/core/src/main/resources/server.properties'
			wget "$CONFIG_FILE_URL_ADDRESS" -O "$G_FP_DIETPI_USERDATA"/blynk/server.properties
			sed -i "/data.folder=/c\data.folder=$G_FP_DIETPI_USERDATA/blynk" "$G_FP_DIETPI_USERDATA"/blynk/server.properties

			cat << _EOF_ > /etc/systemd/system/blynkserver.service
[Unit]
Description=Blynk Server
After=network.target

[Service]
Type=simple
ExecStart=$fp_java_binary -jar /etc/blynkserver/server.jar -serverConfig $G_FP_DIETPI_USERDATA/blynk/server.properties

[Install]
WantedBy=multi-user.target
_EOF_

		fi

		#MotionEye
		INSTALLING_INDEX=136
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Enable RPi cam
			if (( $G_HW_MODEL < 10 )); then

				/DietPi/dietpi/func/dietpi-set_hardware rpi-camera enable

			fi

			mkdir -p /etc/motioneye
			cp /usr/local/share/motioneye/extra/motioneye.conf.sample /etc/motioneye/motioneye.conf

			mkdir -p "$G_FP_DIETPI_USERDATA"/motioneye
			sed -i "/^media_path/c\media_path $G_FP_DIETPI_USERDATA/motioneye" /etc/motioneye/motioneye.conf

			#	service
			cp /usr/local/share/motioneye/extra/motioneye.systemd-unit-local /etc/systemd/system/motioneye.service

		fi

		#CloudPrint
		INSTALLING_INDEX=137
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# - Enable web admin
			cupsctl --remote-admin
			usermod -a -G lpadmin root

		fi

		#VirtualHere
		INSTALLING_INDEX=138
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			cat << _EOF_ > /etc/systemd/system/virtualhere.service
[Unit]
Description=VirtualHere DietPi service
After=local-fs.target

[Service]
Type=simple

ExecStart=/etc/vhusbd/vhusbd -r /var/log/virtualhere.log

[Install]
WantedBy=multi-user.target
_EOF_
			systemctl daemon-reload

			echo -e "ServerName='DietPi'" > /etc/vhusbd/config.ini

		fi

		#SABnzbd
		INSTALLING_INDEX=139
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			cat << _EOF_ > /etc/systemd/system/sabnzbd.service
[Unit]
Description=sabnzbd DietPi

[Service]
Type=simple
ExecStart=/usr/bin/python /etc/sabnzbd/SABnzbd.py -f /etc/sabnzbd/sabnzbd.ini

[Install]
WantedBy=multi-user.target
_EOF_
			systemctl daemon-reload

			#Create config:
			#	API keys and intial config are only generated during 1st run of sabnzbd
			#	We need to launch program, then apply our config tweaks, else, wizard setup in web interface simply loops without API keys.
			rm /etc/sabnzbd/sabnzbd.ini &> /dev/null

			systemctl start sabnzbd
			G_DIETPI-NOTIFY 2 "Generating initial config, please wait..."
			while [ ! -f /etc/sabnzbd/sabnzbd.ini ]
			do

				sleep 1

			done

			sleep 2

			systemctl stop sabnzbd

			sleep 2 #additional wait, config being overwritten after below changes: http://dietpi.com/phpbb/viewtopic.php?f=11&t=1848&p=7085#p7082

			sed -i "/^download_dir =/c\download_dir = $G_FP_DIETPI_USERDATA/downloads/incomplete" /etc/sabnzbd/sabnzbd.ini
			sed -i "/^complete_dir =/c\complete_dir = $G_FP_DIETPI_USERDATA/downloads/complete" /etc/sabnzbd/sabnzbd.ini
			sed -i "/^nzb_backup_dir =/c\nzb_backup_dir = $G_FP_DIETPI_USERDATA/downloads/sabnzbd_nzb_backup" /etc/sabnzbd/sabnzbd.ini
			sed -i "/^admin_dir =/c\admin_dir = $G_FP_DIETPI_USERDATA/downloads/sabnzbd_admin" /etc/sabnzbd/sabnzbd.ini
			sed -i "/^log_dir =/c\log_dir = /var/log" /etc/sabnzbd/sabnzbd.ini
			sed -i "/^log_level =/c\log_level = 0" /etc/sabnzbd/sabnzbd.ini #err only
			sed -i "/^refresh_rate =/c\refresh_rate = 2" /etc/sabnzbd/sabnzbd.ini
			sed -i "/^host =/c\host = 0.0.0.0" /etc/sabnzbd/sabnzbd.ini

		fi

		#spotifyconnectweb
		INSTALLING_INDEX=141
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			cat << _EOF_ > /etc/systemd/system/spotify-connect-web.service
[Unit]
Description=spotify-connect-web
After=sound.target

[Service]
Type=simple
WorkingDirectory=$G_FP_DIETPI_USERDATA/spotify-connect-web
ExecStart=$G_FP_DIETPI_USERDATA/spotify-connect-web/spotify-connect-web

[Install]
WantedBy=multi-user.target
_EOF_

		fi

		#couchpotato
		INSTALLING_INDEX=142
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			cp /etc/couchpotato/init/ubuntu.default /etc/default/couchpotato
			sed -i "/CP_USER=/c\CP_USER=root" /etc/default/couchpotato
			sed -i "/CP_HOME=/c\CP_HOME=/etc/couchpotato" /etc/default/couchpotato
			sed -i "/CP_DATA=/c\CP_DATA=$G_FP_DIETPI_USERDATA/couchpotato" /etc/default/couchpotato

			mkdir -p "$G_FP_DIETPI_USERDATA"/couchpotato
			#useradd -d "$G_FP_DIETPI_USERDATA"/couchpotato couchpotato

			cp /etc/couchpotato/init/ubuntu /etc/init.d/couchpotato

		fi

		#Koel
		INSTALLING_INDEX=143
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			Download_Test_Media

			/DietPi/dietpi/func/create_mysql_db koel koel "$GLOBAL_PW"

			cd /var/www/koel

			sed -i '/DB_CONNECTION=/c\DB_CONNECTION=mysql' .env
			sed -i '/DB_HOST=/c\DB_HOST=127.0.0.1' .env
			sed -i '/DB_DATABASE=/c\DB_DATABASE=koel' .env
			sed -i '/DB_USERNAME=/c\DB_USERNAME=koel' .env
			sed -i "/DB_PASSWORD=/c\DB_PASSWORD=$GLOBAL_PW" .env

			sed -i '/ADMIN_EMAIL=/c\ADMIN_EMAIL=dietpi@dietpi.com' .env
			sed -i '/ADMIN_NAME=/c\ADMIN_NAME=admin' .env
			sed -i "/ADMIN_PASSWORD=/c\ADMIN_PASSWORD=$GLOBAL_PW" .env

			sed -i "/FFMPEG_PATH=/c\FFMPEG_PATH=$(which ffmpeg)" .env

			php artisan koel:init
			#php artisan db:seed --force

			cd "$HOME"

			cat << _EOF_ > /etc/systemd/system/koel.service
[Unit]
Description=Koel

[Service]
Type=simple
User=root
WorkingDirectory=/var/www/koel
ExecStart=$(which php) /var/www/koel/artisan serve --host 0.0.0.0

[Install]
WantedBy=multi-user.target
_EOF_

		fi

		#Sonarr
		INSTALLING_INDEX=144
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			cat << _EOF_ > /etc/systemd/system/sonarr.service
[Unit]
Description=Sonarr (NzbDrone) Daemon
After=network.target

[Service]
User=root
Restart=on-failure
RestartSec=5
Type=simple
ExecStart=/usr/bin/mono --debug /opt/NzbDrone/NzbDrone.exe -nobrowser
TimeoutStopSec=20

[Install]
WantedBy=multi-user.target
_EOF_

		fi

		#Radarr
		INSTALLING_INDEX=145
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			cat << _EOF_ > /etc/systemd/system/radarr.service
[Unit]
Description=Radarr Daemon
After=network.target

[Service]
User=root
Restart=on-failure
RestartSec=5
Type=simple
ExecStart=/usr/bin/mono --debug /opt/Radarr/Radarr.exe -nobrowser
TimeoutStopSec=20

[Install]
WantedBy=multi-user.target
_EOF_

		fi

		#PlexPy
		INSTALLING_INDEX=146
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			mkdir -p "$G_FP_DIETPI_USERDATA"/plexpy

			cat << _EOF_ > /etc/systemd/system/plexpy.service
[Unit]
Description=PlexPy - Stats for Plex Media Server usage

[Service]
ExecStart=/opt/plexpy/PlexPy.py --quiet --daemon --nolaunch --config /opt/plexpy/config.ini --datadir $G_FP_DIETPI_USERDATA/plexpy
GuessMainPID=no
Type=forking
User=root
Group=root

[Install]
WantedBy=multi-user.target
_EOF_

		fi

		#Jackett
		INSTALLING_INDEX=147
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			cat << _EOF_ > /etc/systemd/system/jackett.service
[Unit]
Description=Jackett Daemon
After=network.target

[Service]
User=root
Restart=always
RestartSec=5
Type=simple
ExecStart=/usr/bin/mono --debug /opt/jackett/JackettConsole.exe
TimeoutStopSec=20

[Install]
WantedBy=multi-user.target
_EOF_

		fi

		#NZBget
		INSTALLING_INDEX=149
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			sed -i "/MainDir=/c\MainDir=$G_FP_DIETPI_USERDATA/downloads" "$G_FP_DIETPI_USERDATA"/nzbget/nzbget.conf
			sed -i "/DestDir=/c\DestDir=$G_FP_DIETPI_USERDATA/downloads/complete" "$G_FP_DIETPI_USERDATA"/nzbget/nzbget.conf

			sed -i "/LogFile=/c\LogFile=/var/log/nzbget.log" "$G_FP_DIETPI_USERDATA"/nzbget/nzbget.conf

			sed -i "/ControlUsername=/c\ControlUsername=root" "$G_FP_DIETPI_USERDATA"/nzbget/nzbget.conf
			sed -i "/ControlPassword=/c\ControlPassword=$GLOBAL_PW" "$G_FP_DIETPI_USERDATA"/nzbget/nzbget.conf

			#	Optimizations
			sed -i "/Server1.Cipher=/c\Server1.Cipher=RC4-MD5" "$G_FP_DIETPI_USERDATA"/nzbget/nzbget.conf
			sed -i "/CrcCheck=/c\CrcCheck=no" "$G_FP_DIETPI_USERDATA"/nzbget/nzbget.conf
			sed -i "/ParScan=/c\ParScan=limited" "$G_FP_DIETPI_USERDATA"/nzbget/nzbget.conf
			sed -i "/ParThreads=/c\ParThreads=$G_HW_CPU_CORES" "$G_FP_DIETPI_USERDATA"/nzbget/nzbget.conf

			sed -i "/DebugTarget=/c\DebugTarget=none" "$G_FP_DIETPI_USERDATA"/nzbget/nzbget.conf
			sed -i "/CrashTrace=/c\CrashTrace=no" "$G_FP_DIETPI_USERDATA"/nzbget/nzbget.conf
			sed -i "/DetailTarget=/c\DetailTarget=none" "$G_FP_DIETPI_USERDATA"/nzbget/nzbget.conf

			sed -i "/ParBuffer=/c\ParBuffer=$(Optimize_BitTorrent 0)" "$G_FP_DIETPI_USERDATA"/nzbget/nzbget.conf
			sed -i "/ArticleCache=/c\ArticleCache=$(Optimize_BitTorrent 0)" "$G_FP_DIETPI_USERDATA"/nzbget/nzbget.conf
			sed -i "/WriteBuffer=/c\WriteBuffer=$(Optimize_BitTorrent 0)" "$G_FP_DIETPI_USERDATA"/nzbget/nzbget.conf

			cat << _EOF_ > /etc/systemd/system/nzbget.service
[Unit]
Description=NZBget

[Service]
Type=forking
User=root
WorkingDirectory=$G_FP_DIETPI_USERDATA/nzbget
ExecStart=$G_FP_DIETPI_USERDATA/nzbget/nzbget -D

[Install]
WantedBy=multi-user.target
_EOF_

		fi

		#HTPC Manager
		INSTALLING_INDEX=155
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			cat << _EOF_ > /etc/systemd/system/htpc-manager.service
[Unit]
Description=HTPC Manager
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/python $G_FP_DIETPI_USERDATA/htpc-manager/Htpc.py

[Install]
WantedBy=multi-user.target
_EOF_

		fi

		#OctoPrint
		INSTALLING_INDEX=153
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			cat << _EOF_ > /etc/systemd/system/octoprint.service
[Unit]
Description=OctoPrint

[Service]
Type=simple
User=root
ExecStart=$(which octoprint) serve --iknowwhatimdoing

[Install]
WantedBy=multi-user.target
_EOF_

		fi

		#RoonServer
		INSTALLING_INDEX=154
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			cat << _EOF_ > /etc/systemd/system/roonserver.service
[Unit]
Description=Roon Server
After=network.target

[Service]
Type=simple
User=root
Environment=ROON_DATAROOT=$G_FP_DIETPI_USERDATA/roonserver
ExecStart=$G_FP_DIETPI_USERDATA/roonserver/start.sh

[Install]
WantedBy=multi-user.target
_EOF_

		fi

		#Steam
		INSTALLING_INDEX=156
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			mkdir -p "$G_FP_DIETPI_USERDATA"/steam
			mv "$HOME"/.steam/* "$G_FP_DIETPI_USERDATA"/steam/
			rm -R "$HOME"/.steam

			ln -sf "$G_FP_DIETPI_USERDATA"/steam "$HOME"/.steam

		fi

		#------------------ Home Automation: Home Assistant ------------------
		INSTALLING_INDEX=157
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

            cat << _EOF_ > /etc/systemd/system/home-assistant.service
[Unit]
Description=Home Assistant
After=network.target

[Service]
Type=simple
User=homeassistant
ExecStart=/srv/homeassistant/homeassistant-start.sh

[Install]
WantedBy=multi-user.target

_EOF_

			# Link to the default ha location for the homeassistant user, this makes
			# the configuration avaliable for the user to edit. Configuration generated
			# when service is started at /home/homeassistant/.homeassistant
			mkdir "$G_FP_DIETPI_USERDATA"/homeassistant
			ln -sf "$G_FP_DIETPI_USERDATA"/homeassistant /home/homeassistant/.homeassistant

		fi
		#-------------------------------------------------------------------

		#Minio Config
		INSTALLING_INDEX=158
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# Create simple mandatory default configuration file
			cat << _EOF_ >> /etc/default/minio
# Default file path
MINIO_VOLUMES="$G_FP_DIETPI_USERDATA/minio-data"
# Use if you want to run Minio on a custom port.
# MINIO_OPTS="--address :9199"
# Access Key of the server.
# MINIO_ACCESS_KEY=Server-Access-Key
# Secret key of the server.
# MINIO_SECRET_KEY=Server-Secret-Key
_EOF_

			# Enable startup on boot by default
			systemctl enable minio.service

		fi

		#Docker Config
		INSTALLING_INDEX=162
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# Create directory for docker containers
			mkdir "$G_FP_DIETPI_USERDATA"/docker-data

			# stop service
			systemctl stop docker.service

			# Set container(s) locations in /lib/systemd/system/docker.service
			sed -i "/ExecStart=\/usr\/bin\/dockerd/c\ExecStart=\/usr\/bin\/dockerd -g $G_FP_DIETPI_USERDATA\/docker-data -H fd:\/\/" /lib/systemd/system/docker.service

		fi

		#-------------------------------------------------------------------
		#FuguHub Config
		INSTALLING_INDEX=161
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# Setup Filestore DietPi appropriate
			# IF already present just create symlink
			if [ ! -f "$G_FP_DIETPI_USERDATA"/fuguhub-data/ ]; then
				# Move installed filestore to dietpi folder
				mkdir "$G_FP_DIETPI_USERDATA"/fuguhub-data/
				mv /home/bd/disk/*  "$G_FP_DIETPI_USERDATA"/fuguhub-data/
				# Removed 'actual' folder to make way for symlink
				rm -r /home/bd/disk
				# Create symlink
				ln -s "$G_FP_DIETPI_USERDATA"/fuguhub-data /home/bd/disk
				# Set permissions
				# setfacl -R -m u:bd:rwx "$G_FP_DIETPI_USERDATA"/fuguhub-data/
			else
				# Removed 'actual' folder to make way for symlink
				rm -r /home/bd/disk
				# Create symlink
				ln -s "$G_FP_DIETPI_USERDATA"/fuguhub-data /home/bd/disk
			fi

		fi

		#-------------------------------------------------------------------
		#Nukkit Config
		INSTALLING_INDEX=164
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# Conig file to autostart -- english default
			wget -O /usr/local/bin/nukkit/nukkit.yml https://github.com/Nukkit/Languages/raw/master/eng/nukkit.yml
			# create systemd file
			cat << _EOF_ > /etc/systemd/system/nukkit.service
[Unit]
Description=nukkit

[Service]
WorkingDirectory=/usr/local/bin/nukkit
ExecStart=/bin/bash -c 'java -jar /usr/local/bin/nukkit/nukkit.jar'

[Install]
WantedBy=multi-user.target
_EOF_

		fi

		#GITEA Config
		INSTALLING_INDEX=165
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# - service
			cat << _EOF_ > /etc/systemd/system/gitea.service

[Unit]
Description=Gitea (Git with a cup of tea)

[Service]
Type=simple
User=dietpi
WorkingDirectory=$G_FP_DIETPI_USERDATA/gitea/gitea-repositories
ExecStart=$G_FP_DIETPI_USERDATA/gitea/gitea web
Environment=USER=dietpi HOME=$G_FP_DIETPI_USERDATA/gitea

[Install]
WantedBy=multi-user.target
_EOF_

			# - Logs
			mkdir -p /var/log/gitea
			chown -R dietpi:dietpi /var/log/gitea

			# - sqldb
			/DietPi/dietpi/func/create_mysql_db gitea gitea "$GLOBAL_PW"

		fi


		#Allo Config
		INSTALLING_INDEX=159 #160 for quick reinstall/update
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[160]} == 1 )); then

			Banner_Configuration

			/DietPi/dietpi/func/create_mysql_db allo_db allo_db "$GLOBAL_PW"
			mysql allo_db < /var/www/allo_db.sql
			rm /var/www/allo_db.sql

			# - Redirect to web interface by default:
			rm /var/www/index.htm*
			cat << _EOF_ > /var/www/index.php
<?php
/* Redirect to allo web interface */
\$host  = \$_SERVER['HTTP_HOST'];
\$uri   = rtrim(dirname(\$_SERVER['PHP_SELF']), '/\\\\');
\$extra = 'index.php';
header("Location: http://\$host\$uri/allo/public/\$extra");
exit;
?>
_EOF_

			#HW specific changes
			# - SPARKY ONLY - Auto detect eth adapter
			if (( $G_HW_MODEL == 70 )); then

				# - Disable onboard ETH if adapter found
				cat << _EOF_ > /etc/systemd/system/sparky_eth_controller.service
[Unit]
Description=Sparky auto detect and set onboard ETH/USB ETH
After=network.target networking.service

[Service]
Type=simple
RemainAfterExit=yes
ExecStart=/bin/bash -c '/usr/local/bin/sparky_eth_controller.sh'

[Install]
WantedBy=multi-user.target
_EOF_
				systemctl daemon-reload
				systemctl enable sparky_eth_controller.service

				cat << _EOF_ > /usr/local/bin/sparky_eth_controller.sh
#!/bin/bash
#We need to wait until USB eth is established on USB bus. This takes much longer than onboard init and network.target network-pre.target
sleep 20
# - Set USB ETH if found
if (( \$(ifconfig -a | grep -ci -m1 'eth1') )); then

	echo -e "blacklist ethernet" > /etc/modprobe.d/disable_sparkysbc_ethernet.conf
	rm /etc/udev/rules.d/70-persistent-net.rules &> /dev/null
	rm /etc/udev/rules.d/70-persistant-net.rules &> /dev/null
	reboot

# - Enable onboard ETH if no adapter found
elif (( ! \$(ifconfig -a | grep -ci -m1 'eth0') )); then

	rm /etc/modprobe.d/disable_sparkysbc_ethernet.conf &> /dev/null
	rm /etc/udev/rules.d/70-persistent-net.rules &> /dev/null
	rm /etc/udev/rules.d/70-persistant-net.rules &> /dev/null
	reboot

fi
_EOF_

				chmod +x /usr/local/bin/sparky_eth_controller.sh

			fi

			# - Allow for quick updates with 160 reinstall
			aSOFTWARE_INSTALL_STATE[160]=2

		fi

		#Gmediarender
		INSTALLING_INDEX=163
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			cp /DietPi/dietpi/conf/gmrender.service /etc/systemd/system/gmrender.service

		fi

		#AudioPhonics Pi-SPC
		INSTALLING_INDEX=166
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			mkdir -p /var/lib/dietpi/dietpi-software/installed/pi-spc

			cat << _EOF_ > /var/lib/dietpi/dietpi-software/installed/pi-spc/sds.sh
#!/bin/bash
#DietPi version
PATH=/usr/bin:/home/pi/wiringPi/gpio:/usr/local/bin

TICKRATE=0.25

echo -e "Audiophonics Shutdown script starting..."
echo -e "Asserting pins : "
echo -e "ShutDown : GPIO17=in, Low"
echo -e "BootOK   : GPIO22=out, High"
echo -e "SoftSD   : GPIO04=out, Low"

gpio -g mode 04 out
gpio -g write 04 0
gpio -g mode 17 in
gpio -g write 17 0
gpio -g mode 22 out
gpio -g write 22 1

while true
do

	if (( \$(gpio -g read 17) == 1 )); then

		G_DIETPI-NOTIFY 0 "AudioPhonics Pi-SPC: Power off requested. Shutting down system."
		sudo poweroff
		#sudo shutdown -h -P now
		break

	fi

	sleep \$TICKRATE

done

exit 0
_EOF_

			chmod +x /var/lib/dietpi/dietpi-software/installed/pi-spc/sds.sh

			cat << _EOF_ > /etc/systemd/system/pi-spc.service
[Unit]
Description=AudioPhonics Pi-SPC

[Service]
Type=simple
StandardOutput=tty
User=root

ExecStart=/bin/bash -c '/var/lib/dietpi/dietpi-software/installed/pi-spc/sds.sh'

[Install]
WantedBy=multi-user.target
_EOF_

		fi

		#moOde Configuration
		INSTALLING_INDEX=168
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			#Create moOde runtime environment ---------------------------------------------------------
			#	Create Pi user, does not exist on DietPi systems.
			#	- Required for some moOde bash scripts which live in /home/pi
			/DietPi/dietpi/func/dietpi-set_software useradd pi

			#	Priv
			#echo -e 'pi\tALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers # Completed with /DietPi/dietpi/func/dietpi-set_software useradd pi
			echo -e 'www-data\tALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers

			#	Dirs
			mkdir -p /var/local/www/commandw
			mkdir -p /var/local/www/cssw
			mkdir -p /var/local/www/jsw
			mkdir -p /var/local/www/imagesw
			mkdir -p /var/local/www/imagesw/toggle
			mkdir -p /var/local/www/db
			mkdir -p /var/local/www/templatesw
			chmod -R 0755 /var/local/www

			mkdir -p /var/lib/mpd/music/RADIO
			mkdir -p /mnt/NAS
			mkdir -p /mnt/SDCARD
			mkdir -p /mnt/UPNP
			mkdir /media

			#	Symlinks
			ln -s /mnt/NAS /var/lib/mpd/music/NAS
			ln -s /mnt/SDCARD /var/lib/mpd/music/SDCARD
			ln -s /media /var/lib/mpd/music/USB
			ln -s /var/lib/mpd/music /var/www/mpdmusic

			#	Logs
			touch /var/log/moode.log
			chmod 0666 /var/log/moode.log
			touch /var/log/php_errors.log
			chmod 0666 /var/log/php_errors.log

			#	Files
			cp ./rel-stretch/mpd/sticker.sql /var/lib/mpd
			cp -r "./rel-stretch/other/sdcard/Stereo Test/" /var/lib/mpd/music/SDCARD
			#cp ./rel-stretch/network/interfaces.default /etc/network/interfaces #Disabled as overwrites DietPi network conf. As DietPi does not use/set /etc/dhcpcd.conf, this will render no connection after reboot.
			cp ./rel-stretch/network/wpa_supplicant.conf.default /etc/wpa_supplicant/wpa_supplicant.conf
			cp ./rel-stretch/network/dhcpcd.conf.default /etc/dhcpcd.conf
			cp ./rel-stretch/network/hostapd.conf.default /etc/hostapd/hostapd.conf
			cp ./rel-stretch/var/local/www/db/moode-sqlite3.db.default /var/local/www/db/moode-sqlite3.db

			#	Permissions
			chmod 0777 /var/lib/mpd/music/RADIO
			chmod -R 0777 /var/local/www/db

			#	Deletes
			rm /etc/update-motd.d/10-uname

			#Install moOde sources and configs ---------------------------------------------------------
			#	Application sources and configs
			rm /var/lib/mpd/music/RADIO/*
			rm /var/www/images/radio-logos/*

			cp ./rel-stretch/mpd/RADIO/* /var/lib/mpd/music/RADIO
			cp ./rel-stretch/mpd/playlists/* /var/lib/mpd/playlists
			cp -r ./rel-stretch/etc/* /etc/
			cp -r ./rel-stretch/home/* /home/pi/
			cp -r ./rel-stretch/home/.dircolors /home/pi/
			cp -r ./rel-stretch/lib/* /lib/
			cp -r ./rel-stretch/usr/* /usr/
			cp -r ./rel-stretch/var/* /var/
			cp -r ./rel-stretch/www/* /var/www/

			#	Prep SQL DB
			chmod 0755 /var/www/command/*
			/var/www/command/util.sh "emerald" "2ecc71" "27ae60"
			sqlite3 /var/local/www/db/moode-sqlite3.db "update cfg_system set value='Emerald' where param='themecolor'"

			#	Enabled moOde features
			# sqlite3 /var/local/www/db/moode-sqlite3.db "update cfg_system set value='254' where param='feat_bitmask'"
			# // features availability bitmask settings
			# const FEAT_ADVKERNELS = 0b00000001; // 1
			# const FEAT_AIRPLAY = 0b00000010; // 2
			# const FEAT_MINIDLNA = 0b00000100; // 4
			# const FEAT_MPDAS = 0b00001000; // 8
			# const FEAT_SQUEEZELITE = 0b00010000; // 16
			# const FEAT_UPMPDCLI = 0b00100000; // 32
			# const FEAT_SQSHCHK = 0b01000000; // 64
			# const FEAT_GMUSICAPI = 0b10000000; // 128

			#	Permissions for service files
			#	- MPD
			chmod 0755 /etc/init.d/mpd
			chmod 0644 /lib/systemd/system/mpd.service
			chmod 0644 /lib/systemd/system/mpd.socket

			#	- Bluetooth
			chmod 0666 /etc/bluealsaaplay.conf
			chmod 0644 /etc/systemd/system/bluealsa-aplay@.service
			chmod 0644 /etc/systemd/system/bluealsa.service
			chmod 0644 /lib/systemd/system/bluetooth.service
			chmod 0755 /usr/local/bin/a2dp-autoconnect

			#	- Rotenc
			chmod 0644 /lib/systemd/system/rotenc.service

			#	- Udev
			chmod 0644 /etc/udev/rules.d/*

			#	Services are started by moOde Worker so lets disable them here.
			systemctl daemon-reload
			#systemctl disable mpd.service #dietpi-services
			systemctl disable mpd.socket
			systemctl disable rotenc.service

			#	Following binaries will not have been installed yet, but let's disable the services here
			chmod 0644 /lib/systemd/system/squeezelite-armv6l.service
			chmod 0644 /lib/systemd/system/squeezelite-armv7l.service
			systemctl disable squeezelite-armv6l
			systemctl disable squeezelite-armv7l
			chmod 0644 /lib/systemd/system/upmpdcli.service
			systemctl disable upmpdcli.service

			#	Initial permissions for certain files. These also get set during moOde Worker startup.
			chmod 0777 /var/local/www/playhistory.log
			chmod 0777 /var/local/www/currentsong.txt
			touch /var/local/www/libcache.json
			chmod 0777 /var/local/www/libcache.json

			#ALSAEQ ------------------------------------------------------------------------------------
			#alsamixer -D alsaequal # Disabled, need to automate alsaequal.bin generation.
			chmod 0755 /usr/local/bin/alsaequal.bin
			chown mpd:audio /usr/local/bin/alsaequal.bin
			rm /usr/share/alsa/alsa.conf.d/equal.conf

			mpc enable only 1

			#DietPi - Post steps START -----------------------------------------------------------------
			#	PHP-FPM set to v5 if Jessie
			#	/etc/nginx/nginx.conf
			#	fastcgi_pass unix:/run/php5-fpm.sock;

			#	??? Support for all webserver types with global site conf? (eg: lighttpd/nginx/apache2)
			#	Need to also look at fastcgi_parms in /etc/nginx
			# ln -sf /var/local/www/cssw /var/www/cssw
			# ln -sf /var/local/www/imagesw /var/www/imagesw
			# ln -sf /var/local/www/jsw /var/www/jsw
			# ln -sf /var/local/www/templatesw /var/www/templatesw
			# chown -R www-data:www-data /var/local/www

			#Remove default .html site
			rm /var/www/index.h*

			#	Combined /etc/rc.local
			cat << _EOF_ > /etc/rc.local
#!/bin/bash
#Precaution: Wait for DietPi Ramdisk to finish
while [ ! -f /DietPi/.ramdisk ]
do

    G_DIETPI-NOTIFY 2 "Waiting for DietPi-RAMDISK to finish mounting DietPi to RAM..."
    sleep 1

done

echo -e "\$(cat /proc/uptime | awk '{print \$1}') Seconds" > /var/log/boottime
if (( \$(cat /DietPi/dietpi/.install_stage) == 1 )); then

    /DietPi/dietpi/dietpi-services start

fi
/DietPi/dietpi/dietpi-banner 0
echo -e " Default Login:\n Username = root\n Password = dietpi\n"

#moOde additions
SQLDB=/var/local/www/db/moode-sqlite3.db

# set cpu govenor
RESULT=\$(sqlite3 \$SQLDB "select value from cfg_system where param='cpugov'")
echo "\$RESULT" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

/usr/bin/udisks-glue > /dev/null 2>&1
/var/www/command/worker.php > /dev/null 2>&1

exit 0
_EOF_

			#	moOde worker service
			#	??? Hangs on /bin/systemd-tty-ask-password-agent --watch
			# cat << _EOF_ > /etc/systemd/system/moode-worker.service
# [Unit]
# Description=moOde worker.php service
# After=php7.0-fpm.service php5-fpm.service apache2.service lighttpd.service nginx.service

# [Service]
# Type=forking
# StandardOutput=tty
# StandardInput=tty
# User=root
# ExecStart=/bin/bash -c '/var/www/command/worker.php'

# [Install]
# WantedBy=multi-user.target
# _EOF_

			sqlite3 /var/local/www/db/moode-sqlite3.db "update cfg_system set value='/DietPi/config.txt' where param='res_boot_config_txt'"

			Download_Test_Media

			#DietPi - Post steps END -------------------------------------------------------------------

		fi

		#Google AIY
		INSTALLING_INDEX=169
		if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

			Banner_Configuration

			# - Symlink userdata location for assistant.json
			ln -sf "$G_FP_DIETPI_USERDATA"/voice-recognizer-raspi/assistant.json /home/dietpi/assistant.json

			# - Generate cache dir
			mkdir -p /home/dietpi/.cache/voice-recognizer

			#Setup soundcard
			/DietPi/dietpi/func/dietpi-set_hardware soundcard googlevoicehat-soundcard

		fi

	}

	Install_Apply_GPU_Settings(){

		local gpu_enabled=0
		local gpu_memory=0

		#Define Memory Split Modes with installed software
		#Mode 4 RPI ONLY (Descent HIGH GPU RAM / 192MB)
		if (( ${aSOFTWARE_INSTALL_STATE[112]} == 2 )); then

			gpu_enabled=1
			gpu_memory=192

		#Define Memory Split Modes with installed software
		#Mode 3 (KODI / DIETPICAM / UAE4ARM / JRiver / MED GPU RAM / 128MB)
		elif (( ${aSOFTWARE_INSTALL_STATE[31]} == 2 ||
			${aSOFTWARE_INSTALL_STATE[59]} == 2 ||
			${aSOFTWARE_INSTALL_STATE[108]} == 2 ||
			${aSOFTWARE_INSTALL_STATE[148]} == 2 )); then

			gpu_enabled=1
			gpu_memory=128

		#Mode 2 (Desktop / LOW GPU RAM)
		#All DESKTOP_* and OPENTYRIAN
		elif (( ${aSOFTWARE_INSTALL_STATE[23]} == 2 ||
			${aSOFTWARE_INSTALL_STATE[24]} == 2 ||
			${aSOFTWARE_INSTALL_STATE[25]} == 2 ||
			${aSOFTWARE_INSTALL_STATE[26]} == 2 ||
			${aSOFTWARE_INSTALL_STATE[51]} == 2 )); then

			gpu_enabled=1
			gpu_memory=64

		#Mode 1 - DIETPICLOUDSHELL (forces display output)
		elif (( ${aSOFTWARE_INSTALL_STATE[62]} == 2 )); then

			gpu_enabled=1

		fi

		#Apply
		if (( $gpu_memory > 0 )); then

			#RPi
			if (( $G_HW_MODEL < 10 )); then

				/DietPi/dietpi/func/dietpi-set_hardware gpumemsplit $gpu_memory

			fi

		fi

		if (( $gpu_enabled )); then

			#RPi
			if (( $G_HW_MODEL < 10 )); then

				sed -i "/CONFIG_HDMI_OUTPUT=/c\CONFIG_HDMI_OUTPUT=1" /DietPi/dietpi.txt

			#odroid C1
			elif (( $G_HW_MODEL == 10 )); then

				sed -i '/setenv hdmioutput /c\setenv hdmioutput "1"' /DietPi/boot.ini
				sed -i '/setenv vpu /c\setenv vpu "1"' /DietPi/boot.ini
				sed -i '/setenv m_bpp /c\setenv m_bpp "32"' /DietPi/boot.ini

			#Odroid C2
			elif (( $G_HW_MODEL == 12 )); then

				sed -i '/setenv nographics /c\setenv nographics "0"' /DietPi/boot.ini

			fi

		fi

	}

	Check_USB_Drive_Installed(){

		USBDRIVE=0

		FP_DIETPI_DEDICATED_USBDRIVE=$(df -P | grep -m1 '^/dev/sda1' | awk '{print $6}')

		#Only enable if mounted
		if [ -n "$FP_DIETPI_DEDICATED_USBDRIVE" ] &&
			(( $(df -P | grep -ci -m1 "$FP_DIETPI_DEDICATED_USBDRIVE") )); then

			USBDRIVE=1

		fi

	}

	Uninstall_Software(){

		#NB: systemctl daemon-reload is executed after this func in Uninstall_Software_Finalize()

		local index=$1

		#----------------------------------------------------------------------
		#Inform User
		G_DIETPI-NOTIFY 3 DietPi-Software "Uninstall"

		echo -e ""
		G_DIETPI-NOTIFY 0 "Uninstalling ${aSOFTWARE_WHIP_NAME[$index]}: ${aSOFTWARE_WHIP_DESC[$index]}\n"

		#Was a uninstall event trigged?
		local valid_input=1

		#----------------------------------------------------------------------
		#DIETPI SOFTWARE
		if (( $index == 100 )); then

			grasshopper_directory='/var/www'
			rm -R "$grasshopper_directory"/documentation
			rm -R "$grasshopper_directory"/css
			rm -R "$grasshopper_directory"/db
			rm -R "$grasshopper_directory"/exec
			rm -R "$grasshopper_directory"/includes
			rm -R "$grasshopper_directory"/install
			rm -R "$grasshopper_directory"/phpliteadmin
			rm -R "$grasshopper_directory"/js
			rm -R "$grasshopper_directory"/setup
			rm -R "$grasshopper_directory"/pics
			rm -R "$grasshopper_directory"/themes
			rm "$grasshopper_directory"/favicon.ico
			rm "$grasshopper_directory"/index.php
			#PDF documentation
			rm "$grasshopper_directory"/Grasshopper*

			update-rc.d grasshopper remove
			rm /etc/init.d/grasshopper

		elif (( $index == 23 )); then

			G_AGP lxde lxde-* upower policykit-1 iceweasel p7zip-full

		elif (( $index == 24 )); then

			G_AGP mate-desktop-environment-extras upower policykit-1 iceweasel p7zip-full

		elif (( $index == 26 )); then

			G_AGP x-window-system-core wmaker gnustep gnustep-devel gnustep-games upower policykit-1 iceweasel p7zip-full

		elif (( $index == 25 )); then

			G_AGP xfce4 gnome-icon-theme tango-icon-theme iceweasel p7zip-full

		elif (( $index == 22 )); then

			G_AGP quiterss

		elif (( $index == 30 )); then

			G_RUN_CMD dpkg -P nomachine

		elif (( $index == 29 )); then

			G_AGP xrdp

		elif (( $index == 44 )); then

			G_AGP transmission-daemon
			rm /etc/init.d/transmission-daemon &> /dev/null
			rm /etc/systemd/system/transmission-daemon.service &> /dev/null

		elif (( $index == 47 )); then
			#ownCloud
			# Remove background cron job
			crontab -u www-data -l | grep -v '/var/www/owncloud/cron.php'  | crontab -u www-data -
			# Disable and remove webserver configs
			a2dissite owncloud 2>/dev/null
			rm /etc/apache2/sites-available/owncloud.conf 2>/dev/null
			rm /etc/nginx/sites-dietpi/owncloud.config 2>/dev/null
			# Find datadir for backups
			G_DIETPI-NOTIFY 2 "DietPi will perform an automated backup of your ownCloud database and installation directory, which will be stored inside your ownCloud data directory.\nThe data directory won't be removed. So you can at any time recover your whole ownCloud instance.\nRemove the data directory manually, if you don't need it anymore."
			local datadir=$(grep -m1 "'datadirectory'" /var/www/owncloud/config/config.php | awk '{print $3}' | sed "s/[',]//g")
			[ -n "$datadir" ] || datadir="$G_FP_DIETPI_USERDATA/owncloud_data"
			# Drop MariaDB user and database
			systemctl start mysql
			mysql -e "drop user $(grep -m1 "'dbuser'" /var/www/owncloud/config/config.php | awk '{print $3}' | sed "s/,//")@$(grep -m1 "'dbhost'" /var/www/owncloud/config/config.php | awk '{print $3}' | sed "s/,//")"
			mysql -e "drop user $(grep -m1 "'dbuser'" /var/www/owncloud/config/config.php | awk '{print $3}' | sed "s/,//")" 2> /dev/null
			[ -d "$G_FP_DIETPI_USERDATA"/mysql/owncloud ] && mysqldump owncloud > "$datadir"/dietpi-owncloud-database-backup.sql
			mysqladmin drop owncloud -f
			# Backup ownCloud installation folder
			cp -a /var/www/owncloud/. "$datadir"/dietpi-owncloud-installation-backup
			# Remove ownCloud installation folder
			rm -R /var/www/owncloud

		elif (( $index == 114 )); then
			#Nextcloud
			crontab -u www-data -l | grep -v '/var/www/nextcloud/cron.php'  | crontab -u www-data -
			# Disable and remove webserver configs
			a2dissite nextcloud 2>/dev/null
			rm /etc/apache2/sites-available/nextcloud.conf 2>/dev/null
			rm /etc/nginx/sites-dietpi/nextcloud.config 2>/dev/null
			lighttpd-disable-mod dietpi-nextcloud 2>/dev/null
			rm /etc/lighttpd/conf-available/99-dietpi-nextcloud.conf 2>/dev/null
			# Find datadir for backups
			G_DIETPI-NOTIFY 2 "DietPi will perform an automated backup of your Nextcloud database and installation directory, which will be stored inside your Nextcloud data directory.\nThe data directory won't be removed. So you can at any time recover your whole Nextcloud instance.\nRemove the data directory manually, if you don't need it anymore."
			local datadir=$(grep -m1 "'datadirectory'" /var/www/nextcloud/config/config.php | awk '{print $3}' | sed "s/[',]//g")
			[ -n "$datadir" ] || datadir="$G_FP_DIETPI_USERDATA/nextcloud_data"
			# Drop MariaDB user and database
			systemctl start mysql
			mysql -e "drop user $(grep -m1 "'dbuser'" /var/www/nextcloud/config/config.php | awk '{print $3}' | sed "s/,//")@$(grep -m1 "'dbhost'" /var/www/nextcloud/config/config.php | awk '{print $3}' | sed "s/,//")"
			mysql -e "drop user $(grep -m1 "'dbuser'" /var/www/nextcloud/config/config.php | awk '{print $3}' | sed "s/,//")" 2> /dev/null
			[ -d "$G_FP_DIETPI_USERDATA"/mysql/nextcloud ] && mysqldump nextcloud > "$datadir"/dietpi-nextcloud-database-backup.sql
			mysqladmin drop nextcloud -f
			# Backup Nextcloud installation folder
			cp -a /var/www/nextcloud/. "$datadir"/dietpi-nextcloud-installation-backup
			# Remove Nextcloud installation folder
			rm -R /var/www/nextcloud

		elif (( $index == 83 )); then

			G_AGP apache2

		elif (( $index == 85 )); then

			G_AGP nginx

		elif (( $index == 84 )); then

			G_AGP lighttpd

		elif (( $index == 88 )); then

			G_AGP mariadb-server

			### Also for MariaDB?
			# - custom confs
			#rm /etc/mysql/conf.d/reduce_resources.cnf

			# - SQL store
			rm /var/lib/mysql &> /dev/null || rm -R /var/lib/mysql &> /dev/null #in case of symlink or folder
			rm -R "$G_FP_DIETPI_USERDATA"/mysql

		elif (( $index == 87 )); then

			G_AGP sqlite3

		elif (( $index == 91 )); then

			G_AGP "$PHP_APT_PACKAGE_NAME"-redis redis-server redis-tools

		elif (( $index == 89 )); then

			rm "$FP_PHP_BASE_DIR"/fpm/pool.d/www.conf
			rm "$FP_PHP_BASE_DIR"/mods-available/dietpi.ini 2> /dev/null
			G_AGP "$PHP_APT_PACKAGE_NAME"-* libapache2-mod-"$PHP_APT_PACKAGE_NAME"
			rm /var/www/phpinfo.php
			rm /var/www/apc.php
			rm /var/www/opcache.php
			# temp php uploads, if it was created
			rm -R /var/tmp/php_upload_tmp 2> /dev/null

		elif (( $index == 90 )); then

			systemctl start mysql
			mysqladmin drop phpmyadmin -f
			mysql -e "drop user 'phpmyadmin'@'localhost'"
			G_AGP phpmyadmin

		elif (( $index == 54 )); then

			systemctl start mysql
			mysqladmin drop phpbb3 -f
			mysql -e "drop user phpbb3@localhost"
			rm -R /var/www/phpBB3

		elif (( $index == 115 )); then

			G_RUN_CMD dpkg -P webmin

		elif (( $index == 32 )); then

			rm /usr/bin/ympd
			rm /etc/systemd/system/ympd.service

		elif (( $index == 128 )); then

			#apt-mark auto libavformat57 libupnp6 libao-common libao4 libasound2 libasound2-data libasyncns0 libaudiofile1 libavahi-client3 libavahi-common-data libavahi-common3 libavcodec56 libavformat56 libavresample2 libavutil54 libbinio1ldbl libcaca0 libcdio-cdda1 libcdio-paranoia1 libcdio13 libcups2 libcurl3-gnutls libdirectfb-1.2-9 libdnet libfaad2 libflac8 libfluidsynth1 libgme0 libgomp1 libgsm1 libice6 libid3tag0 libiso9660-8 libjack-jackd2-0 libjson-c2 libldb1 libmad0 libmikmod3 libmms0 libmodplug1 libmp3lame0 libmpcdec6 libmpg123-0 libnfs4 libntdb1 libogg0 libopenal-data libopenal1 libopenjpeg5 libopus0 liborc-0.4-0 libpulse0 libresid-builder0c2a libroar2 libsamplerate0 libschroedinger-1.0-0 libsdl1.2debian libshout3 libsidplay2 libsidutils0 libslp1 libsm6 libsmbclient libsndfile1 libsoxr0 libspeex1 libspeexdsp1 libsqlite3-0 libtalloc2 libtdb1 libtevent0 libtheora0 libupnp6 libva1 libvorbis0a libvorbisenc2 libvorbisfile3 libvpx1 libwavpack1 libwbclient0 libwildmidi-config libwildmidi1 libx11-6 libx11-data libx11-xcb1 libx264-142 libxau6 libxcb1 libxdmcp6 libxext6 libxi6 libxtst6 libxvidcore4 libyajl2 libzzip-0-13 mime-support python python-talloc python2.7 samba-libs x11-common file &> /dev/null
			apt-mark unhold mpd 1> /dev/null
			(( $G_DISTRO == 3 && $G_HW_ARCH != 3 )) && G_AGP mpd libmpdclient2 || G_RUN_CMD dpkg -P mpd libmpdclient2
			userdel -f mpd &> /dev/null
			rm /lib/systemd/system/mpd.service
			rm -R "$G_FP_DIETPI_USERDATA"/.mpd_cache

		elif (( $index == 121 )); then

			rm /etc/systemd/system/roonbridge.service
			rm -R /etc/roonbridge

		elif (( $index == 122 )); then

			rm /etc/systemd/system/node-red.service
			rm "$HOME"/.node-red
			rm -R "$G_FP_DIETPI_USERDATA"/node-red

			userdel -f nodered

		elif (( $index == 123 )); then

			if (( $G_DISTRO > 4 )); then

				G_AGP mosquitto

			else

				#apt-mark auto libssl1.0.0
				dpkg -P mosquitto

			fi

		elif (( $index == 124 )); then

			#apt-mark auto gcc-6-base libstdc++6 &> /dev/null
			G_RUN_CMD dpkg -P networkaudiod

		elif (( $index == 125 )); then

			G_AGP tomcat8

		elif (( $index == 126 )); then

			G_AGP openmediavault
			rm /etc/apt/sources.list.d/openmediavault.list

		elif (( $index == 129 )); then

			rm -R /var/www/ompd
			systemctl start mysql
			mysqladmin drop ompd -f
			mysql -e "drop user ompd@localhost"

		elif (( $index == 130 )); then

			G_AGP python-pip python3-pip

		elif (( $index == 131 )); then

			rm /etc/systemd/system/blynkserver.service

			rm -R /etc/blynkserver

		elif (( $index == 132 )); then

			rm /etc/systemd/system/aria2.service
			rm /usr/local/bin/aria2c
			rm -R /var/www/aria2

			G_AGP aria2

		elif (( $index == 133 )); then

			rm /etc/systemd/system/yacy.service


			rm -R /etc/yacy

		elif (( $index == 134 )); then

			#apt-mark auto libjpeg8 libpng12-0 libfontconfig1 libssl1.0.0 &> /dev/null

			rm /etc/systemd/system/tonido.service

			rm -R /etc/tonido

			rm "$HOME"/tonido
			rm "$HOME"/TonidoSync
			rm "$HOME"/TonidoSyncData

		elif (( $index == 135 )); then

			G_AGP darkice icecast2
			rm /etc/systemd/system/darkice.service


		elif (( $index == 136 )); then

			#apt-mark auto v4l-utils python python-dev libssl-dev libcurl4-openssl-dev libjpeg-dev zlib1g-dev libx264-142 libavcodec56 libavformat56 libmysqlclient18 libswscale3 libpq5 &> /dev/null
			(( $G_DISTRO > 3 )) && G_AGP motion || G_RUN_CMD dpkg -P motion

			rm -R /etc/motioneye

			rm /etc/systemd/system/motioneye.service

			pip uninstall -y motioneye

		elif (( $index == 137 )); then

			G_AGP cloudprint-service
			if (( $G_DISTRO == 3 )); then

				rm /etc/apt/sources.list.d/cloudprint.list
				G_AGUP

			fi

		elif (( $index == 138 )); then

			rm -R /etc/vhusbd

			rm /etc/systemd/system/virtualhere.service

		elif (( $index == 139 )); then

			rm -R /etc/sabnzbd

			rm /etc/systemd/system/sabnzbd.service

		elif (( $index == 140 )); then

			G_RUN_CMD dpkg -P libsdl2 libsdl2-image libsdl2-mixer libsdl2-net libsdl2-ttf libsmpeg2

		elif (( $index == 141 )); then

			rm -R "$G_FP_DIETPI_USERDATA"/spotify-connect-web
			rm /etc/systemd/system/spotify-connect-web.service

		elif (( $index == 142 )); then

			rm -R /etc/couchpotato
			rm -R "$G_FP_DIETPI_USERDATA"/couchpotato
			rm /etc/init.d/couchpotato

			#userdel -f couchpotato

		elif (( $index == 143 )); then

			systemctl start mysql
			mysqladmin drop koel -f
			mysql -e "drop user koel@localhost"

			rm -R /var/www/koel

			rm /etc/systemd/system/koel.service

		elif (( $index == 144 )); then

			G_AGP nzbdrone
			rm /etc/systemd/system/sonarr.service
			rm /etc/apt/sources.list.d/sonarr.list
			G_AGUP

		elif (( $index == 145 )); then

			rm -R /opt/Radarr
			rm /etc/systemd/system/radarr.service

		elif (( $index == 146 )); then

			rm -R /opt/plexpy
			rm -R "$G_FP_DIETPI_USERDATA"/plexpy
			rm /etc/systemd/system/plexpy.service

		elif (( $index == 147 )); then

			rm -R /opt/jackett
			rm /etc/systemd/system/jackett.service

		elif (( $index == 148 )); then

			G_AGP mediacenter22

		elif (( $index == 149 )); then

			rm -R "$G_FP_DIETPI_USERDATA"/nzbget
			rm /etc/systemd/system/nzbget.service

		elif (( $index == 155 )); then

			rm -R "$G_FP_DIETPI_USERDATA"/htpc-manager
			rm /etc/systemd/system/htpc-manager.service

		elif (( $index == 150 )); then

			#G_AGP mono-runtime #shared lib

			rm /etc/apt/sources.list.d/mono-xamarin.list
			G_AGUP

		elif (( $index == 151 )); then

			G_AGP nvidia-driver nvidia-xconfig libgl1-nvidia-glx:i386

		elif (( $index == 152 )); then

			G_AGP avahi-daemon

		elif (( $index == 153 )); then

			rm -R "$G_FP_DIETPI_USERDATA"/octoprint
			rm $(which octoprint)
			rm -R "$HOME"/.octoprint
			rm /etc/systemd/system/octoprint.service

		elif (( $index == 154 )); then

			rm -R "$G_FP_DIETPI_USERDATA"/roonserver
			rm /etc/systemd/system/roonserver.service

		elif (( $index == 156 )); then

			G_AGP steam
			rm -R "$HOME"/.steam
			rm -R "$G_FP_DIETPI_USERDATA"/steam

		elif (( $index == 119 )); then

			G_AGP cava
			rm "$HOME/.config/cava/config"
			rm "$HOME/cava.psf"

		elif (( $index == 118 )); then

			G_AGP mopidy
			rm /etc/apt/sources.list.d/mopidy.list

			pip uninstall -y Mopidy-MusicBox-Webclient Mopidy-Local-Images

		elif (( $index == 31 )); then

			G_AGP kodi
			#+Odroids
			G_AGP kodi-odroid
			rm /usr/share/applications/kodi.desktop
			rm ~/Desktop/kodi.desktop

		elif (( $index == 39 )); then

			G_AGP minidlna

		elif (( $index == 51 )); then

			G_AGP ibsdl1.2debian libsdl-net1.2
			rm -R /usr/local/games/opentyrian
			rm /usr/share/applications/opentyrian.desktop
			rm ~/Desktop/opentyrian.desktop

		elif (( $index == 59 )); then

			G_AGP gpac
			rm -R /var/www/dietpicam
			rm /opt/vc/bin/raspimjpeg
			rm /usr/bin/raspimjpeg
			rm /var/lib/dietpi/dietpi-software/services/raspimjpeg.service
			rm /etc/raspimjpeg

		elif (( $index == 45 )); then

			G_AGP deluged deluge-web deluge-webui deluge-console
			rm /var/lib/dietpi/dietpi-software/services/deluge.service
			rm -R ~/.config/deluge

		elif (( $index == 94 )); then

			G_AGP proftpd-basic

		elif (( $index == 96 )); then

			G_AGP samba samba-common-bin

		elif (( $index == 95 )); then

			G_AGP vsftpd

		elif (( $index == 109 )); then

			G_AGP nfs-kernel-server

		elif (( $index == 67 )); then

			rm /usr/local/bin/noip2
			rm /etc/systemd/system/noip2.service

		elif (( $index == 106 )); then

			rm -R /var/www/raspcontrol
			rm -R /etc/raspcontrol

		elif (( $index == 63 )); then

			rm -R /var/www/linuxdash

		elif (( $index == 93 )); then

			G_AGP dnsmasq
			pihole uninstall

			#https://github.com/Fourdee/DietPi/issues/753
			chmod 774 /etc/lighttpd/lighttpd.conf &> /dev/null

			rm -R /etc/pihole
			rm -R /etc/.pihole
			rm -R /var/www/html/admin

			# - symlinks
			rm /var/www/pihole
			rm /var/www/admin

		elif (( $index == 33 || $index == 34 )); then

			G_RUN_CMD dpkg -P subsonic
			rm -R /var/subsonic

		elif (( $index == 71 )); then

			update-rc.d webiopi remove
			rm -R /etc/webiopi
			rm -R /usr/share/webiopi
			rm /usr/bin/webiopi
			rm /etc/init.d/webiopi

		elif (( $index == 68 )); then

			# <= v150 (weaved)
			rm -R /etc/weaved
			rm -R "$HOME"/weaved_software
			rm "$HOME"/weaved_setup.bin

			# Remot3.it
			G_RUN_CMD dpkg -P weavedconnectd

		elif (( $index == 62 )); then

			#Kill
			systemctl stop dietpi-cloudshell
			rm /etc/systemd/system/dietpi-cloudshell.service

			# - For old version of dietpi-cloudshell, without service.
			killall -w dietpi-cloudshell

			#Disable auto login, revert boot index to console
			/DietPi/dietpi/dietpi-autostart 0

		elif (( $index == 98 )); then

			update-rc.d haproxy remove
			rm /etc/init.d/haproxy

			rm -r /etc/haproxy

			#Shared dev libraries. Leave these installed
			#G_AGP libpcre3-dev libssl-dev

		elif (( $index == 35 )); then

			#apt-mark auto libxml-parser-perl zlib1g-dev libjpeg-dev libpng-dev libjpeg62-turbo-dev &> /dev/null
			G_RUN_CMD dpkg -P logitechmediaserver
			rm /var/lib/dietpi/dietpi-software/services/squeezeboxserver.service
			rm -R /var/lib/squeezeboxserver
			rm -R /usr/share/squeezeboxserver

		elif (( $index == 55 )); then

			systemctl start mysql
			mysqladmin drop wordpress -f
			mysql -e "drop user wordpress@localhost"

			rm -R /var/www/wordpress

		elif (( $index == 27 || $index == 28 || $index == 120 )); then

			G_AGP tightvncserver
			G_AGP vnc4server
			G_AGP x11vnc
			G_AGP realvnc-vnc-server
			G_AGP tigervnc-*

			rm /etc/systemd/system/vncserver.service
			rm /etc/init.d/vncserver

			rm /usr/local/bin/vncserver

			rm -R "$HOME"/.vnc

			# + RealVNC services
			systemctl disable vncserver-x11-serviced.service
			systemctl disable vncserver-virtuald.service

		elif (( $index == 73 )); then

			G_AGP fail2ban

		elif (( $index == 64 )); then

			rm -R /var/www/phpsysinfo

		elif (( $index == 56 )); then

			rm /var/www/gallery/index.php
			rm -R /var/www/gallery/_sfpg_data

		elif (( $index == 40 )); then

			rm -R /var/www/ampache

			#drop database
			systemctl start mysql
			mysqladmin drop ampache -f
			mysql -e "drop user ampache@localhost"

		elif (( $index == 117 )); then

			rm /etc/apt/sources.list.d/swupdate.openvpn.net.list
			pivpn -u
			userdel -f pivpn

		elif (( $index == 97 )); then

			G_AGP openvpn
			rm -R /etc/openvpn &> /dev/null

		elif (( $index == 92 )); then

			if (( $G_DISTRO >= 4 )); then

				G_AGP python-certbot-apache python-certbot-nginx certbot

			fi

			rm -R /etc/letsencrypt_scripts &>/dev/null
			rm -R /etc/certbot_scripts &>/dev/null

		elif (( $index == 69 )); then

			G_AGP python-rpi.gpio python3-rpi.gpio

		elif (( $index == 72 )); then

			G_AGP i2c-tools
			#Disable
			/DietPi/dietpi/func/dietpi-set_hardware i2c disable

		elif (( $index == 70 )); then

			rm -R /root/wiringPi* &> /dev/null

		elif (( $index == 60 )); then

			#apt-mark auto libssl1.0.0 &> /dev/null
			G_AGP hostapd isc-dhcp-server

			rm /etc/dhcp/dhcpd.conf &> /dev/null
			rm /etc/hostapd/hostapd.conf &> /dev/null
			rm /etc/default/isc-dhcp-server &> /dev/null
			rm /etc/default/hostapd &> /dev/null
			rm /etc/iptables.ipv4.nat &> /dev/null
			# - remove binary (used a -f trigger to detect wifi hotspot mode in dietpi-config).
			rm /usr/sbin/hostapd &> /dev/null
			rm /usr/sbin/hostapd_cli &> /dev/null

			#Set Wlan back to inactive and ready for use with dietpi-config.
			local wifi_index=$(sed -n 2p /DietPi/dietpi/.network)

			# - Remove all entries below wlan, so we can recreate them.
			sed -i '/allow-hotplug wlan/q0' /etc/network/interfaces

			# - Disable wlan
			sed -i "/allow-hotplug wlan/c\#allow-hotplug wlan$wifi_index" /etc/network/interfaces

			# - Add default wifi settings to network interfaces config
			cat << _EOF_ >> /etc/network/interfaces
iface wlan$wifi_index inet dhcp
address 192.168.0.101
netmask 255.255.255.0
gateway 192.168.0.1
wireless-power off
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
#dns-nameservers 8.8.8.8 8.8.4.4
_EOF_

			# - Flush IP tables
			iptables -F
			iptables -t nat -F
			iptables-save > /etc/iptables.ipv4.nat

		elif (( $index == 61 )); then

			G_AGP tor

			# - uninstall WIFIHOTSPOT ALSO. Due to IPtables needing reset.
			Uninstall_Software 60

		elif (( $index == 37 )); then

			#apt-mark auto libssl1.0.0 openssl libsoxr0 libavahi-client3 libtool libconfig9 libpopt0 libdaemon0 &> /dev/null
			#No package is installed anymore, files are directly extracted into places, need to remove them manually?
			#https://github.com/Fourdee/DietPi/blob/testing/dietpi/dietpi-software#L5968
			#G_RUN_CMD dpkg -P shairport-sync
			rm /lib/systemd/system/shairport-sync.service /usr/local/bin/shairport-sync /usr/local/etc/shairport-sync.conf* /usr/local/share/man/man7/shairport-sync.7.gz &> /dev/null
			userdel -f shairport-sync

		elif (( $index == 38 )); then

			G_AGP brutefir

			rm -R /etc/BruteFIR
			rm /var/lib/dietpi/dietpi-software/services/brutefir.service
			rm /etc/asound.conf

			rm /etc/modules-load.d/brutefir-alsa-loopback.conf
			rm /etc/modprobe.d/brutefir-alsa-loopback.conf

		elif (( $index == 48 )); then

			rm -R /var/www/pydio

			#drop database
			systemctl start mysql
			mysqladmin drop pydio -f
			mysql -e "drop user pydio@localhost"

		elif (( $index == 36 )); then

			G_AGP squeezelite

			rm -R /usr/bin/squeezelite*
			rm /etc/systemd/system/squeezelite.service

		elif (( $index == 99 )); then

			rm -R /etc/emonhub
			rm /etc/init.d/emonhub
			rm /etc/default/emonhub

		elif (( $index == 66 )); then

			G_RUN_CMD dpkg -P rpimonitor

		elif (( $index == 57 )); then

			rm -R /var/www/baikal

			#drop database
			systemctl start mysql
			mysqladmin drop baikal -f
			mysql -e "drop user baikal@localhost"

		elif (( $index == 65 )); then

			#apt-mark auto zlib1g-dev &> /dev/null

			#all
			rm /etc/systemd/system/netdata.service

			userdel -f netdata
			groupdel netdata

			#1.2.0+
			G_RUN_CMD dpkg -P netdata

			#1.0.0
			rm /usr/sbin/netdata

			rm -R /etc/netdata
			rm -R /usr/share/netdata
			rm -R /usr/libexec/netdata
			rm -R /var/cache/netdata
			rm -R /var/log/netdata

		elif (( $index == 43 )); then

			G_AGP mumble-server

		elif (( $index == 41 )); then

			G_AGP emby-server embymagick

			rm /etc/apt/sources.list.d/emby-server.list
			G_AGUP

		elif (( $index == 58 )); then

			rm -R /etc/openbazaar-server
			rm /etc/systemd/system/openbazaar.service

		elif (( $index == 42 )); then

			(( $G_HW_ARCH == 10 )) && G_RUN_CMD dpkg -P plexmediaserver plexmediaserver-installer || G_AGP plexmediaserver*

			rm -R /var/lib/plexmediaserver

			rm /etc/apt/sources.list.d/plex.list &> /dev/null
			G_AGUP

		elif (( $index == 52 )); then

			rm -R /etc/cuberite
			rm /etc/systemd/system/cuberite.service

		elif (( $index == 53 )); then

			rm -R "$USERDATA_DIRECTORY"/mineos
			rm -R /var/games/minecraft

			rm /etc/supervisor/conf.d/mineos.conf
			supervisorctl reload

			rm /usr/local/bin/mineos

			userdel -f mineos

		elif (( $index == 49 )); then

			rm -R /etc/gogs
			rm /etc/systemd/system/gogs.service

			rm /var/log/gogs_daemon.log
			rm /var/log/gogs.log

			systemctl start mysql
			mysqladmin drop gogs -f
			mysql -e "drop user gogs@localhost"

		elif (( $index == 46 )); then

			G_AGP qbittorrent-nox

			rm /etc/systemd/system/qbittorrent.service
			rm -R "$HOME"/.config/qBittorrent

		elif (( $index == 50 )); then

			rm -R /etc/syncthing
			rm /usr/bin/syncthing &> /dev/null # DietPi v158 <=
			rm /etc/systemd/system/syncthing.service
			rm -R "$G_FP_DIETPI_USERDATA"/syncthing

		elif (( $index == 116 )); then

			rm /etc/systemd/system/sickrage.service
			rm -R /etc/sickrage

		elif (( $index == 107 )); then

			G_AGP rtorrent
			rm -R /var/www/rutorrent
			rm "$HOME"/.rtorrent.rc
			rm /etc/systemd/system/rtorrent.service

			# - webserver rutorrent user/pw settings
			rm /etc/.rutorrent-htaccess

			#	lighttpd
			#Remove from
			#RUTORRENT_DIETPI to #RUTORRENT_DIETPI in /etc/lighttpd/lighttpd.conf

			#	nginx
			rm /etc/nginx/sites-dietpi/rutorrent.config

			#	apache2
			rm /etc/apache2/sites-available/rutorrent.conf

		elif (( $index == 108 )); then

			rm -R /etc/amiberry
			rm /etc/systemd/system/amiberry.service
			rm /etc/systemd/system/amiberry-sdl2.service

			#Disable autostart, revert boot index to console
			/DietPi/dietpi/dietpi-autostart 0

		elif (( $index == 112 )); then

			rm "$G_FP_DIETPI_USERDATA"/dxx-rebirth/*
			rm -R "$G_FP_DIETPI_USERDATA"/dxx-rebirth/descent_1_game
			rm -R "$G_FP_DIETPI_USERDATA"/dxx-rebirth/descent_2_game

			#Remove symlinks
			rm "$HOME"/.d1x-rebirth
			rm "$HOME"/.d2x-rebirth
			rm "$HOME"/Desktop/dxx-rebirth.desktop
			rm /usr/share/applications/dxx-rebirth.desktop

		elif (( $index == 113 )); then

			#apt-mark auto libgnome-keyring0 libnspr4 libnss3 libnss3-1d libspeechd2 libxslt1.1 libxss1 xdg-utils libgnome-keyring-common libltdl7 &> /dev/null
			apt-mark unhold chromium chromedriver

			rm /etc/chromium.d/custom_flags
			rm "$HOME"/.chromium-browser.init

			(( $G_DISTRO >=4 )) && G_AGP chromium* || G_RUN_CMD dpkg -P chromium chromedriver

		elif (( $index == 157)); then

            # Remove installationof HA.
            rm -R /srv/homeassistant

            # Remove the user and all files. This removed pyenv for this user as well.
            userdel -r -f homeassistant
            groupdel homeassistant

            # Remove the service.
            rm /etc/systemd/system/home-assistant.service

		elif (( $index == 165 )); then

			# Delete systemd files
			rm /etc/systemd/system/gitea.service

			# Delete data
			rm -R "$G_FP_DIETPI_USERDATA"/gitea
			rm -R /var/log/gitea

			# drop/delete database
			systemctl start mysql
			mysqladmin drop gitea -f
			mysql -e "drop user gitea@localhost"

		elif (( $index == 166 )); then

			rm /etc/systemd/system/pi-spc.service
			rm -R /var/lib/dietpi/dietpi-software/installed/pi-spc

		elif (( $index == 167 )); then

			G_AGP raspotify
			rm /etc/apt/sources.list.d/raspotify.list
			G_AGUP

		elif (( $index == 168 )); then

			echo -e "pending"

		elif (( $index == 169 )); then

			rm -R "$G_FP_DIETPI_USERDATA"/voice-recognizer-raspi
			rm /etc/systemd/system/voice-recognizer.service
			rm /etc/systemd/system/alsa-init.service
			rm -R /home/dietpi/assistant.json

		elif (( $index == 170 )); then

			Reset_NTPD
			G_AGP ntp

		elif (( $index == 158 )); then

			# Remove service
			systemctl stop minio.service
			systemctl disable minio.service

			# Remove files
			rm /usr/local/bin/minio
			rm /etc/systemd/system/minio.service
			rm /etc/default/minio

			# Remove userdel
			userdel -r -f minio-user

		elif (( $index == 161 )); then

			/etc/init.d/bdd stop
			sleep 2
			killall --user bd
			sleep 2
			rm /etc/rc3.d/S99bdd
			rm /etc/rc4.d/S99bdd
			rm /etc/rc2.d/S99bdd
			rm /etc/rc5.d/S99bdd
			rm /etc/init.d/bdd

			userdel -r bd

		elif (( $index == 162 )); then

			if (( $G_HW_ARCH == 10 )); then
				# remove docker and all its unused dependencies - x86_64 package name is different
				G_AGP docker-ce
			else
				# remove docker and all its unused dependencies - ARM package name
				G_AGP docker-engine
			fi

			# delete data files - dietpi
			rm -r "$G_FP_DIETPI_USERDATA"/docker-data
			# remove default unused folder
			rm -r /var/lib/docker

		elif (( $index == 164 )); then

			# Remove Service file
			rm /etc/systemd/system/nukkit.service

			# remove nukkit java file/folder
			rm -r /usr/local/bin/nukkit

		elif (( $index == 163 )); then

			#apt-mark auto libupnp6 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-alsa &> /dev/null
			G_RUN_CMD dpkg -P gmrender
			rm /etc/systemd/system/gmrender.service

		elif (( $index == 159 || $index == 160 )); then

			rm -R /var/www/allo
			systemctl start mysql
			mysqladmin drop allo_db -f
			mysql -e "drop user allo_db@localhost"


		#----------------------------------------------------------------------
		#LINUX SOFTWARE

		elif (( $index == 15 )); then

			G_AGP tcpdump

		elif (( $index == 14 )); then

			G_AGP nload

		elif (( $index == 13 )); then

			G_AGP mtr-tiny

		elif (( $index == 11 )); then

			G_AGP iptraf

		elif (( $index == 10 )); then

			G_AGP iftop

		elif (( $index == 19 )); then

			G_AGP jed

		elif (( $index == 3 )); then

			G_AGP mc

		elif (( $index == 18 )); then

			G_AGP emacs

		elif (( $index == 20 || $i == 21 )); then

			G_AGP vim vim-tiny

		elif (( $index == 127 )); then

			G_AGP neovim

		elif (( $index == 0 )); then

			#This also removes OpenSSH server. So lets check OpenSSH server isnt installed before hand.
			if (( $(dpkg -l | grep -ci -m1 'openssh-server') == 0 )); then

				G_AGP openssh-client

			fi

		elif (( $index == 1 )); then

			umount -f /mnt/samba
			G_AGP smbclient
			#Disable in fstab
			sed -i '/\/mnt\/samba/c\#\/mnt\/samba . Please use dietpi-config and the Networking Options: NAS menu to setup this mount' /etc/fstab
			#Add info file for installation method.
			echo -e "Samba client can be installed and setup by DietPi-Config.\nSimply run: dietpi-config and select the Networking Options: NAS/Misc menu" > /mnt/samba/readme.txt

		elif (( $index == 111 )); then

			G_RUN_CMD dpkg -P urbackup-server

			#+sourcebuild
			rm /etc/systemd/system/urbackupsrv.service
			rm /etc/default/urbackupsrv
			rm /etc/logrotate.d/urbackupsrv
			rm /usr/sbin/urbackupsrv
			rm /usr/bin/urbackup_snapshot_helper
			rm /usr/bin/urbackupsrv
			rm -R /usr/share/urbackup

		elif (( $index == 110 )); then

			umount -f /mnt/nfs_client

			#nfs-kernel-server depends on nfs-common
			if (( ${aSOFTWARE_INSTALL_STATE[109]} == 0 )); then

				G_AGP nfs-common

			fi

			#Disable in fstab
			sed -i '/\/mnt\/nfs_client/c\#\/mnt\/nfs_client . Please use dietpi-config and the Networking Options: NAS menu to setup this mount' /etc/fstab

			#Add info file for installation method.
			echo -e "NFS client can be installed and setup by DietPi-Config.\nSimply run: dietpi-config and select the Networking Options: NAS/Misc menu" > /mnt/nfs_client/readme.txt

		elif (( $index == 16 )); then

			G_AGP build-essential

		elif (( $index == 17 )); then

			G_AGP git

		elif (( $index == 5 )); then

			G_AGP alsa-utils

		elif (( $index == 6 )); then

			#apt-mark auto aml-libs-odroid mali450-odroid xf86-video-mali-odroid libump* xf86-video-fbturbo* firmware-samsung xf86-video-armsoc-odroid malit628-odroid &> /dev/null
			G_AGP xcompmgr xterm xinit xauth xserver-xorg dbus-x11 xfonts-base x11-xserver-utils x11-common x11-utils
			rm /etc/xdg/autostart/xcompmgr.desktop /etc/X11/xorg.conf &> /dev/null

		elif (( $index == 2 )); then

			umount -f /mnt/ftp_client
			G_AGP curlftpfs

			#Disable in fstab
			sed -i '/\/mnt\/ftp_client/c\#\/mnt\/ftp_client . Please use dietpi-config and the Networking Options: NAS menu to setup this mount' /etc/fstab

			#Add info file for installation method.
			echo -e "FTP client mount can be installed and setup by DietPi-Config.\nSimply run: dietpi-config and select the Networking Options: NAS/Misc menu" > /mnt/ftp_client/readme.txt

		elif (( $index == 7 )); then

			G_AGP ffmpeg
			# + RPi, use dpkg -P as packages were installed via dpkg -i and APT can produce error/terminate dietpi-software:
			# https://github.com/Fourdee/DietPi/issues/1352#issuecomment-354552622
			(( $G_HW_MODEL < 10 )) && G_RUN_CMD dpkg -P libx264 libmp3lame libfdk-aac

		elif (( $index == 8 )); then

			G_AGP openjdk-8-jdk
			rm /etc/apt/preferences.d/99-dietpi-openjdk-8-jdk &> /dev/null

		elif (( $index == 104 )); then

			G_AGP dropbear* #stretch | dropbear-initramfs dropbear-run

		elif (( $index == 105 )); then

			G_AGP openssh-*

			# This also clears Openssh-client
			aSOFTWARE_INSTALL_STATE[0]=0

		elif (( $index == 103 )); then

			sed -i '/\/var\/log/c\#\/var\/log DietPi Ramlog Disabled' /etc/fstab

		elif (( $index == 101 )); then

			G_AGP logrotate

		elif (( $index == 102 )); then

			G_AGP rsyslog

		elif (( $index == 9 )); then

			G_AGP nodejs

			# - old install via repo
			if [ -f /etc/apt/sources.list.d/nodesource_nodejs.list ]; then

				rm /etc/apt/sources.list.d/nodesource_nodejs.list
				G_AGUP

			fi

			rm /usr/local/bin/node

		elif (( $index == 4 )); then

			G_AGP vifm

		else

			G_DIETPI-NOTIFY 2 "Software index $index is unknown, or, has no removal code."
			valid_input=0

		fi

		#----------------------------------------------------------------------
		#log to .uninstalled file
		if [ ! -f /DietPi/dietpi/.uninstalled ]; then

			echo -e "DietPi Uninstall Software Log\n----------------------\n" > /DietPi/dietpi/.uninstalled

		fi

		echo -e "$index | $(date)" >> /DietPi/dietpi/.uninstalled

		#Update array installed state
		aSOFTWARE_INSTALL_STATE[$index]=0

		#----------------------------------------------------------------------
		#Reset error handler (eg: for usermsg clear)
		G_ERROR_HANDLER_RESET
		#----------------------------------------------------------------------

	}

	Uninstall_Software_Finalize(){

		#Purge
		G_DIETPI-NOTIFY 3 DietPi-Software "Removing packages that are no longer required"

		apt-get autoremove --purge -y

		#Check if we need to clear DietPi choices
		local fp_temp='/tmp/.dietpi-uninstall_dpkg'
		dpkg --get-selections | awk '{print $1}' > "$fp_temp"
		if (( ! $(grep -ci -m1 '^openssh-server' "$fp_temp") &&
			! $(grep -ci -m1 '^dropbear' "$fp_temp") )); then

			INDEX_SSHSERVER_CURRENT=0
			INDEX_SSHSERVER_TARGET=0

		fi

		if (( ! $(grep -ci -m1 '^samba$' "$fp_temp") &&
			! $(grep -ci -m1 '^proftpd-basic' "$fp_temp") )); then

			INDEX_FILESERVER_CURRENT=0
			INDEX_FILESERVER_TARGET=0

		fi

		if (( $(grep -ci -m1 '#/var/log' /etc/fstab) &&
			! $(grep -ci -m1 '^rsyslog' "$fp_temp") &&
			! $(grep -ci -m1 '^logrotate' "$fp_temp") )); then

			INDEX_LOGGING_CURRENT=0
			INDEX_LOGGING_TARGET=0

		fi

		rm "$fp_temp"

		systemctl daemon-reload

	}

	Run_Installations(){

		#------------------------------------------------------------
		#Abort if time sync is incomplete
		Check_NTPD_Status
		#------------------------------------------------------------
		#Disable powersaving on Main screen during installation
		setterm -blank 0 -powersave off 2> /dev/null
		#------------------------------------------------------------
		# Unmask all services: https://github.com/Fourdee/DietPi/issues/1320
		/DietPi/dietpi/dietpi-services unmask all
		# Stop Services
		/DietPi/dietpi/dietpi-services stop
		#------------------------------------------------------------
		#Generate Swapfile during 1st run (moved from boot: https://github.com/Fourdee/DietPi/issues/1270#issue-278797206)
		if (( $G_DIETPI_INSTALL_STAGE == 0 )); then

			/DietPi/dietpi/func/dietpi-set_dphys-swapfile $(grep -m1 '^AUTO_SETUP_SWAPFILE_SIZE=' /DietPi/dietpi.txt | sed 's/.*=//')

		fi
		#------------------------------------------------------------
		#Generate userdata folders:
		Create_UserContent_Folders
		#------------------------------------------------------------
		#Set current path to home folder
		cd "$HOME"

		#Update Apt
		Banner_Apt_Update

		#Always clean and update apt, before running installs.
		apt-get clean
		G_AGUP

		#Simluated apt installation to check for failures related to apt-cache.
		G_DIETPI-NOTIFY 2 "Running apt simulation to check for errors, please wait..."

		local package_to_test='bash-doc'

		G_AGI $package_to_test -s

		#Upgrade Apt
		Banner_Setup
		Banner_Apt_Update
		G_AGUG

		#Generate dir for dietpi-software installed "non-service" based control scripts
		mkdir -p /var/lib/dietpi/dietpi-software/services
		chmod -R +x /var/lib/dietpi/dietpi-software/services

		#Disable software installation, if user input is required for automated installs
		Install_Disable_Requires_UserInput

		#Apply DietPi choice systems
		Apply_FileServer_Choices
		Apply_SSHServer_Choices
		Apply_Logging_Choices

		#Apply DietPi preference systems
		Apply_Webserver_Preference

		#Update required software that needs to be installed
		Install_Flag_Prereq_Software

		#Install Linux Software
		/DietPi/dietpi/dietpi-services stop
		Install_Linux_Software

		#Install DietPi Optimized Software
		/DietPi/dietpi/dietpi-services stop
		Install_Dietpi_Software

		#Apply Uninstall script created by DietPi choice system
		Uninstall_NonSelected_Choices

		#Apply DietPi configurations and optimizations
		/DietPi/dietpi/dietpi-services stop
		Banner_Configs
		Install_Apply_Configs

		Install_Apply_Permissions &> /dev/null

		#Apply autostart index
		local autostart_current=$(cat /DietPi/dietpi/.dietpi-autostart_index)
		/DietPi/dietpi/dietpi-autostart $autostart_current

		#Disable services so DietPi-services can take control (DietPi will start all services from rc.local)
		/DietPi/dietpi/dietpi-services dietpi_controlled

		#Install finished, set all installed software to state 2 (installed)
		for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
		do

			if (( ${aSOFTWARE_INSTALL_STATE[$i]} == 1 )); then

				aSOFTWARE_INSTALL_STATE[$i]=2

			fi

		done

		#Apply GPU Memory Splits: NB, this only checks for installed state '=2'
		Install_Apply_GPU_Settings

		#Write to .install File
		Write_InstallFileList

		#DietPi-Automation
		if (( $G_DIETPI_INSTALL_STAGE == 0 )); then

			#Apply Timezone
			if [ "$AUTOINSTALL_TIMEZONE" != "Europe/London" ]; then

				echo -e "\nDietPi: Setting Timezone = $AUTOINSTALL_TIMEZONE"
				rm /etc/timezone
				rm /etc/localtime
				ln -fs /usr/share/zoneinfo/$AUTOINSTALL_TIMEZONE /etc/localtime
				dpkg-reconfigure -f noninteractive tzdata

			fi

			#Apply Language (Locale)
			if [ "$AUTOINSTALL_LANGUAGE" != "en_GB.UTF-8" ]; then

				G_DIETPI-NOTIFY 2 "Setting Locale $AUTOINSTALL_LANGUAGE. Please wait"

				#	Sanity, No result, revert back to default
				if [ -z "$AUTOINSTALL_LANGUAGE" ]; then

					AUTOINSTALL_LANGUAGE='en_GB.UTF-8'

				fi

				# - Re-apply locale + auto install en_GB.UTF-8 alongside
				/DietPi/dietpi/func/dietpi-set_software locale "$AUTOINSTALL_LANGUAGE"

			fi

			#Apply Keyboard
			if [ "$AUTOINSTALL_KEYBOARD" != "gb" ]; then

				G_DIETPI-NOTIFY 2 "Setting Keyboard $AUTOINSTALL_KEYBOARD. Please wait...\n"
				sed -i '/XKBLAYOUT=/c XKBLAYOUT="'"$AUTOINSTALL_KEYBOARD"'"' /etc/default/keyboard
				#systemctl restart keyboard-setup

			fi

			#Apply & Mount Network drives if installed
			if (( ${aSOFTWARE_INSTALL_STATE[1]} == 2 )); then

				/DietPi/dietpi/func/dietpi-set_smbclient 1

			fi

			if (( ${aSOFTWARE_INSTALL_STATE[2]} == 2 )); then

				/DietPi/dietpi/func/dietpi-set_curlftpfs 1

			fi

			#Custom 1st run Script (Local file)
			local run_custom_script=0
			if [ -f /boot/Automation_Custom_Script.sh ]; then

				INSTALL_DESCRIPTION='Automation - Local Custom Script'
				Banner_Installing

				cp /boot/Automation_Custom_Script.sh /root/AUTO_CustomScript.sh
				run_custom_script=1

			#Custom 1st run Script (Online file)
			elif [ "$AUTOINSTALL_CUSTOMSCRIPTURL" != "0" ]; then

				INSTALL_DESCRIPTION='Automation - Online Custom Script'
				Banner_Installing


				INSTALL_URL_ADDRESS=$AUTOINSTALL_CUSTOMSCRIPTURL
				G_CHECK_URL "$INSTALL_URL_ADDRESS"

				#Install
				if (( $? == 0 )); then

					#Get script and execute
					wget "$INSTALL_URL_ADDRESS" -O /root/AUTO_CustomScript.sh
					run_custom_script=1

				else

					echo -e "Automated Custom Script URL Error:\n $AUTOINSTALL_CUSTOMSCRIPTURL is offline and/or unreachable" >> "$FP_DIETPIAUTOMATION_LOG"

				fi

			fi

			if (( $run_custom_script )); then

				chmod +x /root/AUTO_CustomScript.sh
				/root/AUTO_CustomScript.sh
				local result=$?
				if (( $result == 0 )); then

					echo -e "Automated custom script executed succesfully:\n - Filepath = /root/AUTO_CustomScript.sh\n - URL = $AUTOINSTALL_CUSTOMSCRIPTURL" >> "$FP_DIETPIAUTOMATION_LOG"

				else

					echo -e "Automated Custom Script Error:\n - Exit code = $result\n - Filepath = /root/AUTO_CustomScript.sh\n - URL = $AUTOINSTALL_CUSTOMSCRIPTURL" >> "$FP_DIETPIAUTOMATION_LOG"

				fi

			fi

			#Apply AutoStart
			/DietPi/dietpi/dietpi-autostart $AUTOINSTALL_AUTOSTARTTARGET

		fi

		#Set Install Stage to Finished
		echo 1 > /DietPi/dietpi/.install_stage

	}

	#/////////////////////////////////////////////////////////////////////////////////////
	# First Run / Automation functions Vars (eg: on a fresh install)
	#/////////////////////////////////////////////////////////////////////////////////////
	AUTOINSTALL_ENABLED=0

	AUTOINSTALL_SSHINDEX=0
	AUTOINSTALL_FILESERVERINDEX=0
	AUTOINSTALL_LOGGINGINDEX=0
	AUTOINSTALL_WEBSERVERINDEX=0

	AUTOINSTALL_AUTOSTARTTARGET=0

	AUTOINSTALL_TIMEZONE=0
	AUTOINSTALL_LANGUAGE=0
	AUTOINSTALL_KEYBOARD=0

	AUTOINSTALL_CUSTOMSCRIPTURL=0

	FirstRun_Automation_Init(){

		#Get settings
		AUTOINSTALL_ENABLED=$(cat /DietPi/dietpi.txt | grep -m1 '^AUTO_SETUP_AUTOMATED=' | sed 's/.*=//')

		AUTOINSTALL_AUTOSTARTTARGET=$(cat /DietPi/dietpi.txt | grep -m1 '^AUTO_SETUP_AUTOSTART_TARGET_INDEX=' | sed 's/.*=//' )

		AUTOINSTALL_SSHINDEX=$(cat /DietPi/dietpi.txt | grep -m1 '^AUTO_SETUP_SSH_SERVER_INDEX=' | sed 's/.*=//')
		AUTOINSTALL_FILESERVERINDEX=$(cat /DietPi/dietpi.txt | grep -m1 '^AUTO_SETUP_FILE_SERVER_INDEX=' | sed 's/.*=//')
		AUTOINSTALL_LOGGINGINDEX=$(cat /DietPi/dietpi.txt | grep -m1 '^AUTO_SETUP_LOGGING_INDEX=' | sed 's/.*=//')
		AUTOINSTALL_WEBSERVERINDEX=$(cat /DietPi/dietpi.txt | grep -m1 '^AUTO_SETUP_WEB_SERVER_INDEX=' | sed 's/.*=//')

		AUTOINSTALL_TIMEZONE=$(cat /DietPi/dietpi.txt | grep -m1 '^AUTO_SETUP_TIMEZONE=' | sed 's/.*=//' )
		AUTOINSTALL_LANGUAGE=$(cat /DietPi/dietpi.txt | grep -m1 '^AUTO_SETUP_LOCALE=' | sed 's/.*=//' )
		AUTOINSTALL_KEYBOARD=$(cat /DietPi/dietpi.txt | grep -m1 '^AUTO_SETUP_KEYBOARD_LAYOUT=' | sed 's/.*=//' )

		AUTOINSTALL_CUSTOMSCRIPTURL=$(cat /DietPi/dietpi.txt | grep -m1 '^AUTO_SETUP_CUSTOM_SCRIPT_EXEC=' | sed 's/AUTO_SETUP_CUSTOM_SCRIPT_EXEC=//')

	}

	FirstRun_Automation_Set(){

		#Automated install
		if (( $AUTOINSTALL_ENABLED >= 1 )); then

			G_DIETPI-NOTIFY 3 DietPi-Software "Running automated installation"

			#Skip dietpi-software menu
			TARGETMENUID=-1

			#Set start install
			GOSTARTINSTALL=1

			#Find all software entires of AUTO_SETUP_INSTALL_SOFTWARE_ID= in dietpi.txt. Then set to state 1 for installation.
			while read -r line
			do

				local index=$( echo -e "$line" | grep '^AUTO_SETUP_INSTALL_SOFTWARE_ID=' | sed 's/[^0-9]*//g' )

				# - Flag for installation
				if [[ $index =~ ^-?[0-9]+$ ]]; then

					aSOFTWARE_INSTALL_STATE[$index]=1

					G_DIETPI-NOTIFY 2 "Automation: ${aSOFTWARE_WHIP_NAME[$index]}. Flagged for installation."

				fi

			done < /DietPi/dietpi.txt

		fi

		#Further Automated options. (Applied regardless of AUTOINSTALL_ENABLED)
		INDEX_SSHSERVER_TARGET=$AUTOINSTALL_SSHINDEX
		INDEX_FILESERVER_TARGET=$AUTOINSTALL_FILESERVERINDEX
		INDEX_LOGGING_TARGET=$AUTOINSTALL_LOGGINGINDEX
		INDEX_WEBSERVER_TARGET=$AUTOINSTALL_WEBSERVERINDEX

		# - IPversion preference: https://github.com/Fourdee/DietPi/issues/472
		/DietPi/dietpi/func/dietpi-set_hardware preferipversion "$(cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_PREFER_IPVERSION=' | sed 's/.*=//')"

	}

	FirstRun_DietPi_Update(){

		#Disable powersaving on main screen
		setterm -blank 0 -powersave off 2> /dev/null

		#-1 = 1st run | 0 = Reboot, updates applied | 1 = Idle, No updates
		#Update .update_stage file to completed
		echo 1 > /DietPi/dietpi/.update_stage

		#Update APT
		G_AGUP

		#Check for updates and apply if needed (1=force apply updates).
		/DietPi/dietpi/dietpi-update 1

		#Check update stage file again (dietpi-update will set to 0 if an update was applied and requires a reboot)
		if (( $(cat /DietPi/dietpi/.update_stage) == 0 )); then

			#Update .update_stage file to completed
			echo 1 > /DietPi/dietpi/.update_stage

			#Prompt user for reboot
			if (( $G_USER_INPUTS )); then

				WHIP_TITLE='DietPi Update Completed'
				whiptail --title "$WHIP_TITLE" --msgbox "DietPi has been updated to the latest version.\nYour system will now reboot. Once completed, simply login to resume DietPi Setup. \n\nPress Enter to Continue." 13 65

			fi

			#Reboot required NOW
			reboot
			Exit_Destroy

		fi

	}

	#/////////////////////////////////////////////////////////////////////////////////////
	# Internet Connection Test Vars
	#/////////////////////////////////////////////////////////////////////////////////////
	#Use /etc/apt/sources.list for connection test
	INTERNET_URL_TEST=$(grep -m1 'deb ' /etc/apt/sources.list | awk '{print $2}')

	Check_Internet_Connection(){

		G_CHECK_URL "$INTERNET_URL_TEST" #will exit on failure here

	}

	#/////////////////////////////////////////////////////////////////////////////////////
	# Globals
	#/////////////////////////////////////////////////////////////////////////////////////
	Input_Modes(){

		# - Skip menu
		TARGETMENUID=-1

		DISABLE_REBOOT=1

		local ainput=("$@")


		#Install software and exit.
		if [ "$1" = "install" ] || [ "$1" = "reinstall" ] || [ "$1" = "uninstall" ] ; then

			G_DIETPI-NOTIFY 3 DietPi-Software "Automated $1"
			sleep 1

			# - Make sure we have at least one entry
			if [ -z "$2" ]; then

				G_DIETPI-NOTIFY 1 "Please enter a software index ID, or, choice system INDEX_*_TARGET=-?"

			else

				# - Uninstall | Stop services prior
				if [ "$1" = "uninstall" ]; then

					# - stop services
					/DietPi/dietpi/dietpi-services stop

				fi

				# - Process inputs
				for i in "${ainput[@]}"
				do

					#Valid int means input is unique ID for software index to be installed
					if [[ $i =~ ^-?[0-9]+$ ]]; then

						if [ "$1" = "uninstall" ]; then

							Uninstall_Software "$i"

						elif [ "$1" = "reinstall" ]; then

							if (( ${aSOFTWARE_INSTALL_STATE[$i]} == 2 )); then

								# - We cant uninstall, may remove additional packages. eg: remove Xserver = Remove every Xserver depandant program like Kodi.
								#Uninstall_Software $i

								# - So lets flag to be installed
								aSOFTWARE_INSTALL_STATE[$i]=1
								GOSTARTINSTALL=1

								G_DIETPI-NOTIFY 0 "Reinstalling ${aSOFTWARE_WHIP_NAME[$i]}: ${aSOFTWARE_WHIP_DESC[$i]}"
								sleep 1

							else

								G_DIETPI-NOTIFY 2 "$i: ${aSOFTWARE_WHIP_NAME[$i]} is not currently installed"
								G_DIETPI-NOTIFY 2 "The program must be installed, before reinstall can be used"
								G_DIETPI-NOTIFY 0 "No changes applied for: ${aSOFTWARE_WHIP_NAME[$i]}"

							fi

						elif [ "$1" = "install" ]; then

							if (( ${aSOFTWARE_INSTALL_STATE[$i]} != 2 )); then

								aSOFTWARE_INSTALL_STATE[$i]=1
								GOSTARTINSTALL=1

								G_DIETPI-NOTIFY 0 "Installing ${aSOFTWARE_WHIP_NAME[$i]}: ${aSOFTWARE_WHIP_DESC[$i]}"
								sleep 0.5

							else

								G_DIETPI-NOTIFY 2 "$i: ${aSOFTWARE_WHIP_NAME[$i]} is already installed"
								G_DIETPI-NOTIFY 0 "No changes applied for: ${aSOFTWARE_WHIP_NAME[$i]}"

							fi

						fi

					fi

				done

				# - Uninstall | Finish up and clear non-required packages
				if [ "$1" = "uninstall" ]; then

					Uninstall_Software_Finalize

					#Save
					Write_InstallFileList

					# - Start services
					/DietPi/dietpi/dietpi-services start

				fi

			fi

		#Apply permissions
		elif [ "$1" = "setpermissions" ]; then

			Install_Apply_Permissions &> /dev/null
			G_DIETPI-NOTIFY 0 "Set permissions completed"

		#List unique software names and ID's
		elif [ "$1" = "list" ]; then

			for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
			do

				local string=''

				if (( ${aSOFTWARE_INSTALL_STATE[$i]} == 2 )); then

					string="\e[32mID $i | "

				else

					string="\e[0mID $i | "

				fi

				string+="=${aSOFTWARE_INSTALL_STATE[$i]} | ${aSOFTWARE_WHIP_NAME[$i]}: \e[90m${aSOFTWARE_WHIP_DESC[$i]}\e[0m |"

				if (( ${aSOFTWARE_REQUIRES_ALSA[$i]} == 1 )); then

					string+=' +ALSA'
				fi

				if (( ${aSOFTWARE_REQUIRES_XSERVERXORG[$i]} == 1 )); then

					string+=' +XSERVER'

				fi

				if (( ${aSOFTWARE_REQUIRES_DESKTOP[$i]} == 1 )); then

					string+=' +DESKTOP'

				fi

				if (( ${aSOFTWARE_REQUIRES_RSYSLOG[$i]} == 1 )); then

					string+=' +RSYSLOG'

				fi

				if (( ${aSOFTWARE_REQUIRES_FFMPEG[$i]} == 1 )); then

					string+=' +FFMPEG'

				fi

				if (( ${aSOFTWARE_REQUIRES_ORACLEJAVA[$i]} == 1 )); then

					string+=' +ORACLEJAVA'

				fi

				if (( ${aSOFTWARE_REQUIRES_NODEJS[$i]} == 1 )); then

					string+=' +NODEJS'

				fi

				if (( ${aSOFTWARE_REQUIRES_BUILDESSENTIAL[$i]} == 1 )); then

					string+=' +BUILDESSENTIAL'

				fi

				if (( ${aSOFTWARE_REQUIRES_GIT[$i]} == 1 )); then

					string+=' +GIT'

				fi

				if (( ${aSOFTWARE_REQUIRES_WEBSERVER[$i]} == 1 )); then

					string+=' +WEBSERVER'

				fi

				if (( ${aSOFTWARE_REQUIRES_MYSQL[$i]} == 1 )); then

					string+=' +MYSQL'

				fi

				if (( ${aSOFTWARE_REQUIRES_SQLITE[$i]} == 1 )); then

					string+=' +SQLITE'

				fi

				# - Available for G_HW_ARCH?
				if (( ! ${aSOFTWARE_AVAIL_G_HW_ARCH[$i,$G_HW_ARCH]} )); then

					string+=" \e[31mDISABLED for G_HW_ARCH\e[0m"

				fi

				# - Available for G_HW_MODEL?
				if (( ! ${aSOFTWARE_AVAIL_G_HW_MODEL[$i,$G_HW_MODEL]} )); then

					string+=" \e[31mDISABLED for G_HW_MODEL\e[0m"

				fi

				# - Online docs
				if [ -n "${aSOFTWARE_ONLINEDOC_URL[$i]}" ]; then

					string+=" | \e[90m$FP_ONLINEDOC_URL${aSOFTWARE_ONLINEDOC_URL[$i]}\e[0m"

				fi

				#Convert string to lowercase (easier to | grep stuff)
				echo -e "${string,,}" #Much faster than echo -e $(echo -e "$string" | tr '[:upper:]' '[:lower:]')

			done

			echo -e "Total Software index HARD limit : $TOTAL_SOFTWARE_INDEXS_HARDLIMIT"
			echo -e "Total Software index Current    : $TOTAL_SOFTWARE_INDEXS"

		#List unique software names and ID's
		elif [ "$1" = "weblist_export" ]; then

			local fp_export_dir='/tmp/dietpi-software/weblist_export'

			rm -R "$fp_export_dir"
			mkdir -p "$fp_export_dir"

			# - Category desc | Remove '─' before saving.
			local fp_target="$fp_export_dir/category_dietpi_total"
			echo -e "$MAX_SOFTWARE_CATEGORIES_DIETPI" > "$fp_target"

			local fp_target="$fp_export_dir/category_linux_total"
			echo -e "$MAX_SOFTWARE_CATEGORIES_LINUX" > "$fp_target"

			fp_target="$fp_export_dir/category_dietpi_desc"
			for ((i=0; i<$MAX_SOFTWARE_CATEGORIES_DIETPI; i++))
			do
				local output=
				echo -e "$( echo ${aSOFTWARE_CATEGORIES_DIETPI[$i]} | sed 's/─//g')" >> "$fp_target"

			done

			fp_target="$fp_export_dir/category_linux_desc"
			for ((i=0; i<$MAX_SOFTWARE_CATEGORIES_LINUX; i++))
			do

				echo -e "$( echo ${aSOFTWARE_CATEGORIES_LINUX[$i]} | sed 's/─//g')" >> "$fp_target"

			done

			# - Software list
			local fp_target="$fp_export_dir/total_software_index"
			echo -e "$TOTAL_SOFTWARE_INDEXS" > "$fp_target"

			fp_target="$fp_export_dir/software_installed_state"
			printf "%i\n" "${aSOFTWARE_INSTALL_STATE[@]}" > "$fp_target"

			fp_target="$fp_export_dir/software_name"
			printf "%s\n" "${aSOFTWARE_WHIP_NAME[@]}" > "$fp_target"

			fp_target="$fp_export_dir/software_desc"
			printf "%s\n" "${aSOFTWARE_WHIP_DESC[@]}" > "$fp_target"

			fp_target="$fp_export_dir/category_index"
			printf "%i\n" "${aSOFTWARE_CATEGORY_INDEX[@]}" > "$fp_target"

			fp_target="$fp_export_dir/software_urldocs"
			printf "%s\n" "${aSOFTWARE_ONLINEDOC_URL[@]}" > "$fp_target"

			# - Available for device?
			fp_target="$fp_export_dir/software_available_hw_model"
			for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
			do
				printf "%i\n" "${aSOFTWARE_AVAIL_G_HW_MODEL[$i,$G_HW_MODEL]}" >> "$fp_target"

			done

			fp_target="$fp_export_dir/software_available_hw_arch"
			for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
			do
				printf "%i\n" "${aSOFTWARE_AVAIL_G_HW_ARCH[$i,$G_HW_ARCH]}" >> "$fp_target"

			done

			# - Flagged Prereqs for installation
			# fp_target="$fp_export_dir/installs_alsa"
			# printf "%s\n" "${aSOFTWARE_REQUIRES_ALSA[@]}" > "$fp_target"

			# fp_target="$fp_export_dir/installs_xserver"
			# printf "%s\n" "${aSOFTWARE_REQUIRES_XSERVERXORG[@]}" > "$fp_target"

			# fp_target="$fp_export_dir/installs_desktop"
			# printf "%s\n" "${aSOFTWARE_REQUIRES_DESKTOP[@]}" > "$fp_target"

		else

			G_DIETPI-NOTIFY 2 "Unknown command $1"

		fi

		unset ainput

	}

	Exit_Destroy(){

		Software_Arrays_Destroy

		exit

	}

	#/////////////////////////////////////////////////////////////////////////////////////
	# Error Functions
	#/////////////////////////////////////////////////////////////////////////////////////
	ERROR_TEXT=""

	Error_Display(){

		#Automation | Save to logfile

		if (( $G_USER_INPUTS )); then

			whiptail --title "Error" --msgbox "$ERROR_TEXT" 18 70

		else

			echo -e "Error: $ERROR_TEXT" >> "$FP_DIETPIAUTOMATION_LOG"

		fi

	}

	#/////////////////////////////////////////////////////////////////////////////////////
	# Whip menus
	#/////////////////////////////////////////////////////////////////////////////////////
	WHIP_BACKTITLE='DietPi-Software'
	WHIP_TITLE=0
	WHIP_QUESTION=0
	MENU_MAIN_LASTITEM='Help!'
	TARGETMENUID=0

	Menu_CreateSoftwareList(){

		#software type for this menu
		local software_type=$1 #0=dietpi 1=linux

		local max_categories=$MAX_SOFTWARE_CATEGORIES_DIETPI
		if (( $1 == 1 )); then

			max_categories=$MAX_SOFTWARE_CATEGORIES_LINUX

		fi

		#-----------------------------------------------------------------------------
		#Generate Whiptail menu list based on category
		local whiptail_list=()
		for ((i=0; i<$max_categories; i++))
		do

			#Only add the category if we have software for it.
			local category_enabled=0

			#Now run through all available software
			for ((j=0; j<$TOTAL_SOFTWARE_INDEXS; j++))
			do

				#Check if this software matches the current category and sofware type for this menu.
				# - I originally had "aSOFTWARE_AVAIL_G_HW_MODEL" and "aSOFTWARE_AVAIL_G_HW_ARCH" in one 'if' statement below, however, this seems to takes 4x longer to process in bash.
				if (( ${aSOFTWARE_CATEGORY_INDEX[$j]} == $i && ${aSOFTWARE_TYPE[$j]} == $software_type )); then

					# + is available for hardware?
					# + is available for distro?
					if (( ${aSOFTWARE_AVAIL_G_HW_MODEL[$j,$G_HW_MODEL]} &&
						${aSOFTWARE_AVAIL_G_HW_ARCH[$j,$G_HW_ARCH]} )); then

						local selected="off"

						if (( ${aSOFTWARE_INSTALL_STATE[$j]} > 0 )); then

							selected="on"

							if (( ${aSOFTWARE_INSTALL_STATE[$j]} == 1 )); then

								#Reset to 0. Menu checklists will apply back to 1
								aSOFTWARE_INSTALL_STATE[$j]=0

							fi

						fi

						#Add category
						if (( $category_enabled == 0 )); then

							# - dietpi
							if (( $1 == 0 )); then

								whiptail_list+=("" "${aSOFTWARE_CATEGORIES_DIETPI[$i]}" "off")

							# - linux
							elif (( $1 == 1 )); then

								whiptail_list+=("" "${aSOFTWARE_CATEGORIES_LINUX[$i]}" "off")

							fi

							category_enabled=1

						fi

						#Add this option to whiptail list
						whiptail_list+=("$j" "${aSOFTWARE_WHIP_NAME[$j]}: ${aSOFTWARE_WHIP_DESC[$j]}" "$selected")

					fi

				fi

			done

		done

		#-----------------------------------------------------------------------------
		WHIP_TITLE='DietPi Software Selection'
		whiptail --title "$WHIP_TITLE" --checklist --separate-output "Please use the spacebar to select the software you wish to install.\nSoftware details: http://dietpi.com/software" --backtitle "$WHIP_BACKTITLE" 22 78 14 "${whiptail_list[@]}" 2>/tmp/dietpi-software_results

		#delete[]
		unset whiptail_list

		#Reset Choices made flag
		# - dietpi
		if (( $1 == 0 )); then

			INSTALL_DIETPI_CHOICESMADE=0

		# - linux
		elif (( $1 == 1 )); then

			INSTALL_LINUX_CHOICESMADE=0

		fi

		#Check for matching results (selected items)
		while read choice
		do

			for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
			do

				#enable
				if (( $choice == $i &&
					${aSOFTWARE_INSTALL_STATE[$i]} == 0 )); then

					# - dietpi
					if (( $1 == 0 )); then

						INSTALL_DIETPI_CHOICESMADE=1

					# - linux
					elif (( $1 == 1 )); then

						INSTALL_LINUX_CHOICESMADE=1

					fi

					aSOFTWARE_INSTALL_STATE[$i]=1

					break

				fi

			done

		done < /tmp/dietpi-software_results
		rm /tmp/dietpi-software_results &> /dev/null

	}

	Menu_Main(){

		#Data for storing SSH server index info
		local index_sshserver_text="None"
		if (( $INDEX_SSHSERVER_TARGET == -1 )); then
			index_sshserver_text="Dropbear"
		elif (( $INDEX_SSHSERVER_TARGET == -2 )); then
			index_sshserver_text="OpenSSH"
		fi

		#Data for storing Fileserver index info
		local index_fileserver_text="None"
		if (( $INDEX_FILESERVER_TARGET == -1 )); then
			index_fileserver_text="ProFTP"
		elif (( $INDEX_FILESERVER_TARGET == -2 )); then
			index_fileserver_text="Samba"
		fi

		#Data for storing Logging index info
		local index_logging_text="None"
		if (( $INDEX_LOGGING_TARGET == -1 )); then
			index_logging_text="DietPi-Ramlog #1"
		elif (( $INDEX_LOGGING_TARGET == -2 )); then
			index_logging_text="DietPi-Ramlog #2"
		elif (( $INDEX_LOGGING_TARGET == -3 )); then
			index_logging_text="Full"
		fi

		#Hold our string that tells the user what software will be removed when using Index based choice systems
		local toberemoved_text=''

		#Check status of USB drive
		Check_USB_Drive_Installed

		#Where is userdata stored?
		local user_data_location_current=$(readlink -f $G_FP_DIETPI_USERDATA)

		local user_data_location_description=''
		if [ "$user_data_location_current" = "$FP_DIETPI_DEDICATED_USBDRIVE" ]; then

			user_data_location_description="USB Drive | $user_data_location_current"

		elif [ "$user_data_location_current" = "$G_FP_DIETPI_USERDATA" ]; then

			user_data_location_description="SD/EMMC | $user_data_location_current"

		else

			user_data_location_description="Custom | $user_data_location_current"

		fi

		# - Webserver preference system
		local index_webserver_text='Apache2'
		if (( $INDEX_WEBSERVER_TARGET == -1 )); then

			index_webserver_text='Nginx'

		elif (( $INDEX_WEBSERVER_TARGET == -2 )); then

			index_webserver_text='Lighttpd'

		fi

		WHIP_TITLE='DietPi-Software'
		WHIP_BACKTITLE="DietPi-Software | IP: $(sed -n 4p /DietPi/dietpi/.network) | Device: $G_HW_MODEL_DESCRIPTION"

		OPTION=$(whiptail --title "$WHIP_TITLE" --backtitle "$WHIP_BACKTITLE" --menu "" --default-item "$MENU_MAIN_LASTITEM" --cancel-button "Exit" 20 100 13 \
		"Help!" "Links to online guides, docs and information" \
		"DietPi-Config" "Feature-rich configuration tool for your device" \
		"" "─── Select Software ─────────────────────────" \
		"Software Optimized" "Select DietPi optimized software for installation" \
		"Software Additional" "Select additional Linux software for installation" \
		"SSH Server" ": $index_sshserver_text" \
		"File Server" ": $index_fileserver_text" \
		"Log System" ": $index_logging_text" \
		"Webserver Preference" ": $index_webserver_text" \
		"User Data Location" ": $user_data_location_description" \
		"" "─── Install or Remove Software ──────────────" \
		"Uninstall" "Select installed software for removal" \
		"Install" "Go >> Start installation for selected software"  3>&1 1>&2 2>&3)

		CHOICE=$?
		if (( $CHOICE == 0 )); then

			MENU_MAIN_LASTITEM="$OPTION"

			case "$OPTION" in

			  "Uninstall")

					TARGETMENUID=3

				;;

			  "Software Optimized")

					TARGETMENUID=1

				;;

			  "Software Additional"*)

					TARGETMENUID=2

				;;

			  "SSH Server")

					WHIP_TITLE='SSH Server Choices'
					OPTION=$(whiptail --title "$WHIP_TITLE" --menu "> None\nSelecting this option will uninstall all SSH servers. This reduces system resources and improves performance. Useful for users who do NOT require networked/remote terminal access.\n\n> Dropbear (Recommended)\nLightweight SSH server, installed by default on DietPi systems.\n\n> OpenSSH\nA feature rich SSH server with SFTP/SCP support, at the cost of increased resource usage." --cancel-button "Back" --default-item "$index_sshserver_text" 21 75 3 \
					"None" "Not required / manual setup." \
					"Dropbear" "Lightweight SSH Server (Recommended)." \
					"OpenSSH" "Feature Rich SSH Server with SFTP/SCP support." 3>&1 1>&2 2>&3)

					#Assign target index
					if [ "$OPTION" = "None" ]; then

						INDEX_SSHSERVER_TARGET=0
						toberemoved_text="Dropbear and OpenSSH Server"

					elif [ "$OPTION" = "Dropbear" ]; then

						INDEX_SSHSERVER_TARGET=-1
						toberemoved_text="OpenSSH Server"

					elif [ "$OPTION" = "OpenSSH" ]; then

						INDEX_SSHSERVER_TARGET=-2
						toberemoved_text="Dropbear"

					#Reset to current
					else

						INDEX_SSHSERVER_TARGET=$INDEX_SSHSERVER_CURRENT

					fi

					#Check for changes
					INSTALL_SSHSERVER_CHOICESMADE=0
					if (( $INDEX_SSHSERVER_TARGET != $INDEX_SSHSERVER_CURRENT )); then

						INSTALL_SSHSERVER_CHOICESMADE=1

						#Inform user
						WHIP_TITLE="SSH Server Change"
						WHIP_QUESTION="$OPTION has been selected:\n- Your choice will be applied when 'Install Go >> Start installation' is selected.\n- $toberemoved_text installations will be automatically uninstalled."
						whiptail --title "$WHIP_TITLE" --msgbox "$WHIP_QUESTION" --backtitle "$WHIP_BACKTITLE" 11 75

					fi
			  ;;

			  "File Server")

					WHIP_TITLE='Fileserver Choices'
					OPTION=$(whiptail --title "$WHIP_TITLE" --menu "> None\nSelect this option if you do NOT require a method of accessing files and folders on this device, over a network.\n\n> ProFTP (Recommended for RPi v1)\nAllows you to access/share files on this device efficiently with minimal cpu usage. Uses FTP protocol.\n\n> Samba (Recommended for RPi v2)\nAllows you to easily access/share files on this device, at the cost of higher cpu usage.\n\nMore info: http://dietpi.com/phpbb/viewtopic.php?f=8&t=15#p19" --cancel-button "Back" --default-item "$index_fileserver_text" 23 75 3 \
					"None" "Not required / manual setup." \
					"ProFTP" "Efficient, lightweight fileserver (recommended)." \
					"Samba" "Feature-rich fileserver." 3>&1 1>&2 2>&3)

					#Assign target index
					if [ "$OPTION" = "None" ]; then
						INDEX_FILESERVER_TARGET=0
						toberemoved_text="ProFTP and Samba Server"
					elif [ "$OPTION" = "ProFTP" ]; then
						INDEX_FILESERVER_TARGET=-1
						toberemoved_text="Samba Server"
					elif [ "$OPTION" = "Samba" ]; then
						INDEX_FILESERVER_TARGET=-2
						toberemoved_text="ProFTP"
					#Reset to current
					else
						INDEX_FILESERVER_TARGET=$INDEX_FILESERVER_CURRENT
					fi

					#Check for changes
					INSTALL_FILESERVER_CHOICESMADE=0
					if (( $INDEX_FILESERVER_TARGET != $INDEX_FILESERVER_CURRENT )); then
						INSTALL_FILESERVER_CHOICESMADE=1

						#Inform user
						WHIP_TITLE="Fileserver Choice Change"
						WHIP_QUESTION="$OPTION has been selected:\n- Your choice will be applied when 'Install Go >> Start installation' is selected.\n- $toberemoved_text installations will be automatically uninstalled."
						whiptail --title "$WHIP_TITLE" --msgbox "$WHIP_QUESTION" --backtitle "$WHIP_BACKTITLE" 11 75

					fi
				;;

			  "Log System")

					WHIP_TITLE='Logging System Choices'
					OPTION=$(whiptail --title "$WHIP_TITLE" --menu "> None\nSelecting this option will uninstall DietPi-Ramlog, Logrotate, Rsyslog.\n\n> DietPi-Ramlog #1 (Max performance)\nMounts /var/log to RAM, reducing filesystem IO. Logfiles are cleared every hour. Does NOT save logfiles to disk.\n\n> DietPi-Ramlog #2\nSame as #1, with the added feature of saving logfile contents to disk ($HOME/logfile_storage/*), before being cleared.\n\n> Full (Reduces performance)\nMounts /var/log to DISK, reduces SDcard lifespan. Full logging system with Logrotate and Rsyslog." --cancel-button "Back" --default-item "$index_logging_text" 25 75 4 \
					"None" " Not required / manual setup." \
					"DietPi-Ramlog #1" " Hourly clear (recommended)." \
					"DietPi-Ramlog #2" " Hourly save, then clear." \
					"Full" " Logrotate and Rsyslog." 3>&1 1>&2 2>&3)

					#Assign target index
					if [ "$OPTION" = "None" ]; then
						INDEX_LOGGING_TARGET=0
						toberemoved_text="DietPi-Ramlog, Logrotate, Rsyslog"
					elif [ "$OPTION" = "DietPi-Ramlog #1" ]; then
						INDEX_LOGGING_TARGET=-1
						toberemoved_text="Logrotate, Rsyslog"
					elif [ "$OPTION" = "DietPi-Ramlog #2" ]; then
						INDEX_LOGGING_TARGET=-2
						toberemoved_text="Logrotate, Rsyslog"
					elif [ "$OPTION" = "Full" ]; then
						INDEX_LOGGING_TARGET=-3
						toberemoved_text="DietPi-Ramlog"
					#Reset to current
					else
						INDEX_LOGGING_TARGET=$INDEX_LOGGING_CURRENT
					fi

					#Check for changes
					INSTALL_LOGGING_CHOICESMADE=0
					if (( $INDEX_LOGGING_TARGET != $INDEX_LOGGING_CURRENT )); then
						INSTALL_LOGGING_CHOICESMADE=1

						#Inform user
						WHIP_TITLE="Logging System Change"
						WHIP_QUESTION="$OPTION has been selected:\n- Your choice will be applied when 'Install Go >> Start installation' is selected.\n- $toberemoved_text installations will be automatically uninstalled."
						whiptail --title "$WHIP_TITLE" --msgbox "$WHIP_QUESTION" --backtitle "$WHIP_BACKTITLE" 11 75
					fi
				;;

			  "User Data Location")

					WHIP_TITLE='User Data Location'

					# - Vars if we need to move data.
					local move_data_target=$user_data_location_current

					OPTION=$(whiptail --title "$WHIP_TITLE" --menu "Choose where to store your user data. User data includes software such as Owncloud data store, BitTorrent downloads etc\n\nMore information on user data in DietPi:\n - http://dietpi.com/phpbb/viewtopic.php?f=8&t=478&p=2087\n\n> DietPi-Drive Manager\nLaunch DietPi-Drive Manager to setup external drives, and, move user data to different locations." --cancel-button "Back" 20 85 3 \
					"Drive Manager" "Launches DietPi-Drive Manager" \
					"List" "Select from a list of available mounts/drives, to move user data" \
					"Custom" "Input a manual location to move user data" 3>&1 1>&2 2>&3)
					CHOICE=$?

					if (( $CHOICE == 0 )); then

						# - DriveMan
						if [ "$OPTION" = "Drive Manager" ]; then

							/DietPi/dietpi/dietpi-drive_manager

						# - List
						elif [ "$OPTION" = "List" ]; then

							/DietPi/dietpi/dietpi-drive_manager 1

							local return_value="$(cat /tmp/dietpi-drive_manager_selmnt)"
							if [ -n "$return_value" ]; then

								if [ "$return_value" = "/" ]; then

									return_value='/mnt'

								fi

								move_data_target="$return_value"
								move_data_target+='/dietpi_userdata'

							fi

						# - Manual filepath entry
						elif [ "$OPTION" = "Custom" ]; then

							OPTION=$(whiptail --inputbox "Please input a location. Your user data will be stored inside this location.\n - eg: /mnt/MyDrive/MyData" 11 60 "$user_data_location_current" --title "User/Personal Data Directory" --backtitle "$WHIP_BACKTITLE" 3>&1 1>&2 2>&3)
							CHOICE=$?
							if (( $CHOICE == 0 )); then
								move_data_target=$OPTION
							fi

						fi

						# - Move data if the new entry has changed
						if [ "$user_data_location_current" != "$move_data_target" ]; then

							# - Ask before we begin
							whiptail --title "User data transfer" --yesno "DietPi will now attempt to transfer your existing user data to the new location:\n\n - From: $user_data_location_current\n - To: $move_data_target\n\nWould you like to begin?" --backtitle "$WHIP_BACKTITLE" --defaultno 14 70
							CHOICE=$?
							if (( $CHOICE == 0 )); then

								# - Move data, setup symlinks
								/DietPi/dietpi/func/dietpi-set_userdata "$user_data_location_current" "$move_data_target"

								if (( $? == 0 )); then

									whiptail --title "User data transfer: Completed" --msgbox "Your user data has been sucessfuly moved:\n\n - From: $user_data_location_current\n - To: $move_data_target" 12 70

								else

									whiptail --title "User data transfer: Failed" --msgbox "$(cat /var/log/dietpi-move_userdata.log)\nNo changes have been applied." 12 70

								fi

							fi

						fi

					fi
				;;

			  "Webserver Preference")
				WHIP_TITLE='Webserver Preference'
				OPTION=$(whiptail --title "$WHIP_TITLE" --menu "More Info: http://dietpi.com/phpbb/viewtopic.php?f=8&t=5&p=1549#p1549\n\n> Apache2\nFeature-rich and popular. Recommended for beginners and users who are looking to follow Apache2 based guides.\n\n> Nginx\nLightweight alternative to Apache2. Nginx claims faster webserver performance compared to Apache2.\n\n> Lighttpd\nExtremely lightweight and is generally considered to offer the \"best\" webserver performance for SBC's. Recommended for users who expect low webserver traffic." --cancel-button "Back" --default-item "$index_webserver_text" 24 75 3 \
				"Apache2" "Popular webserver." \
				"Nginx" "Lightweight webserver." \
				"Lighttpd" "Extremely lightweight webserver." 3>&1 1>&2 2>&3)

					#Assign target index
					if [ "$OPTION" = "Apache2" ]; then
						INDEX_WEBSERVER_TARGET=0
					elif [ "$OPTION" = "Nginx" ]; then
						INDEX_WEBSERVER_TARGET=-1
					elif [ "$OPTION" = "Lighttpd" ]; then
						INDEX_WEBSERVER_TARGET=-2
					#Reset to current
					else
						INDEX_WEBSERVER_TARGET=$INDEX_WEBSERVER_CURRENT
					fi

					#Check for changes
					if (( $INDEX_WEBSERVER_TARGET != $INDEX_WEBSERVER_CURRENT )); then

						# - Check for existing and compatible installed stacks before allowing the change
						local incompatible_webserver_preference=0
						local info_currently_installed_webserver='None'

						if (( $(dpkg -l | awk '{print $2}' | grep -ci -m1 'apache2'))); then
							INDEX_WEBSERVER_CURRENT=0
							info_currently_installed_webserver='Apache2'
							if (( $INDEX_WEBSERVER_TARGET != 0 )); then
								incompatible_webserver_preference=1
							fi
						elif (( $(dpkg -l | awk '{print $2}' | grep -ci -m1 'nginx') )); then
							INDEX_WEBSERVER_CURRENT=-1
							info_currently_installed_webserver='Nginx'
							if (( $INDEX_WEBSERVER_TARGET != -1 )); then
								incompatible_webserver_preference=1
							fi
						elif (( $(dpkg -l | awk '{print $2}' | grep -ci -m1 'lighttpd') )); then
							INDEX_WEBSERVER_CURRENT=-2
							info_currently_installed_webserver='Lighttpd'
							if (( $INDEX_WEBSERVER_TARGET != -2 )); then
								incompatible_webserver_preference=1
							fi
						fi

						# - Reset preference selection
						if (( $incompatible_webserver_preference == 1 )); then

							INDEX_WEBSERVER_TARGET=$INDEX_WEBSERVER_CURRENT

							# - inform user
							WHIP_TITLE="Error: Incompatible Webserver Preference"
							WHIP_QUESTION="Unable to change your webserver preference to $OPTION.\n\nThis is due to an existing and incompatible webserver installation on your system ($info_currently_installed_webserver). Please remove all webserver based software (using dietpi-software > uninstall), before trying again."
							whiptail --title "$WHIP_TITLE" --msgbox "$WHIP_QUESTION" --backtitle "$WHIP_BACKTITLE" 11 75


						# - Apply preference selection
						else

							# - Inform user
							WHIP_TITLE="Webserver Preference Changed"
							WHIP_QUESTION="$OPTION has been selected as your webserver preference.\n\nWhen you select any software for install that requires a webserver, DietPi will automatically install your prefered choice ($OPTION)."
							whiptail --title "$WHIP_TITLE" --msgbox "$WHIP_QUESTION" --backtitle "$WHIP_BACKTITLE" 11 75

							# - NB: INDEX_WEBSERVER_CURRENT=$INDEX_WEBSERVER_TARGET | is applied during installation with func Apply_Webserver_Preference().

						fi



					fi
				;;

			  "DietPi-Config")

					/DietPi/dietpi/dietpi-config

				;;

			  "Help!")

					#Populate help to text file so we can read it back to whiptail, as a scrollbox.
					cat << _EOF_ > /tmp/dietpi-software_help_onlinedoc_url_list
───────────────────────────────────────────────────────────────
Welcome to DietPi:
───────────────────────────────────────────────────────────────
Use PageUp/Down or Arrow Up/Down to scroll this help screen.
Press ESC, or TAB then enter to exit this help screen.

Easy to follow, step by step guides for installing DietPi:
http://dietpi.com/phpbb/viewtopic.php?f=8&t=9

For a list of all installation options and their details:
http://dietpi.com/software

───────────────────────────────────────────────────────────────
List of installed software and their URL links for online docs:
───────────────────────────────────────────────────────────────
_EOF_

					# - Installed software
					for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
					do

						if (( ${aSOFTWARE_INSTALL_STATE[$i]} > 0 )); then

							if [ -n "${aSOFTWARE_ONLINEDOC_URL[$i]}" ]; then

								cat << _EOF_ >> /tmp/dietpi-software_help_onlinedoc_url_list
${aSOFTWARE_WHIP_NAME[$i]}: ${aSOFTWARE_WHIP_NAME[$i]}
$FP_ONLINEDOC_URL${aSOFTWARE_ONLINEDOC_URL[$i]}

_EOF_

							fi

						fi

					done

					whiptail --title "DietPi - Help" --backtitle "$WHIP_BACKTITLE" --textbox /tmp/dietpi-software_help_onlinedoc_url_list $(( $(tput lines) - 3 )) $(( $(tput cols) - 3 )) --scrolltext

				;;

			  Install)

					Menu_StartInstall

				;;

			esac

		#Exit/Abort Setup
		else

			Menu_Exit

		fi

	}

	Menu_Exit(){

		#1st run install
		if (( $G_DIETPI_INSTALL_STAGE == 0 )); then
			WHIP_TITLE='Exit Setup?'
			WHIP_QUESTION=' DietPi has not fully been installed.\n This must be completed prior to using DietPi by selecting:\n - Go Start Install. \n \n Would you like to exit and abort the installation?'
			whiptail --title "$WHIP_TITLE" --yesno "$WHIP_QUESTION" --backtitle "$WHIP_BACKTITLE" --yes-button "Ok" --no-button "Back" --defaultno 13 65
			CHOICE=$?
			if (( $CHOICE == 0 )); then
				Banner_Aborted
				#Exit script NOW
				Exit_Destroy
			else
				#Return to Main Menu
				TARGETMENUID=0
			fi
		#Standard exit
		elif (( $G_DIETPI_INSTALL_STAGE == 1 )); then
			WHIP_TITLE='Exit DietPi-Software?'
			WHIP_QUESTION='Do you wish to exit DietPi-Software?\n\nAll changes to software selections will be cleared.'
			whiptail --title "$WHIP_TITLE" --yesno "$WHIP_QUESTION" --backtitle "$WHIP_BACKTITLE" --yes-button "Ok" --no-button "Back" --defaultno 11 65
			CHOICE=$?
			if (( $CHOICE == 0 )); then
				Banner_Aborted
				#Exit script NOW
				Exit_Destroy
			else
				#Return to Main Menu
				TARGETMENUID=0
			fi
		fi
	}

	Menu_ConfirmInstall(){

		#Obtain list of pending software installation:
		local string_output=''
		for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
		do

			if (( ${aSOFTWARE_INSTALL_STATE[$i]} == 1 )); then

				string_output+="\n - ${aSOFTWARE_WHIP_NAME[$i]}: ${aSOFTWARE_WHIP_DESC[$i]}"

			fi

		done

		#Confirm Software install
		WHIP_TITLE='DietPi - Start Installation?'
		WHIP_QUESTION="DietPi is now ready to install your software choices: $string_output\n\nSoftware details, usernames, passwords etc:\n - http://dietpi.com/software\n\nWould you like to begin?"
		whiptail --title "$WHIP_TITLE" --yesno "$WHIP_QUESTION" --yes-button "Ok" --no-button "Back" --defaultno --backtitle "$WHIP_BACKTITLE" 20 70
		CHOICE=$?
		if (( $CHOICE == 0 )); then

			#exit menu system
			TARGETMENUID=-1

			#Enable installation start flag
			GOSTARTINSTALL=1

		else

			#Return to Main Menu
			TARGETMENUID=0

		fi

	}

	Menu_StartInstall(){

		#Check if the user has made changes to their software selections.
		if (( $INSTALL_DIETPI_CHOICESMADE ||
			$INSTALL_LINUX_CHOICESMADE ||
			$INSTALL_SSHSERVER_CHOICESMADE ||
			$INSTALL_FILESERVER_CHOICESMADE ||
			$INSTALL_LOGGING_CHOICESMADE )); then

			# Confirm install with user
			Menu_ConfirmInstall

		else

			#1st run install
			if (( $G_DIETPI_INSTALL_STAGE == 0 )); then

				WHIP_TITLE='No Software Selected. Continue?'
				WHIP_QUESTION='DietPi was unable to detect any software selections for install. Do you wish to continue?\n\nBy selecting Ok: \n- DietPi optimized software will NOT be installed.\nYou can use dietpi-software at a later date if you change your mind. \n\n- You want a Minimal Raspbian/Debian Server Install.\nDietPi is a minimal image. A great OS base to use with your projects.'
				whiptail --title "$WHIP_TITLE" --yesno "$WHIP_QUESTION" --backtitle "$WHIP_BACKTITLE" --yes-button "Ok" --no-button "Back" --defaultno 16 75
				CHOICE=$?
				if (( $CHOICE == 0 )); then

					#exit menu system
					TARGETMENUID=-1

					#Enable installation start flag
					GOSTARTINSTALL=1

				else

					#Return to Main Menu
					TARGETMENUID=0

				fi

			#Not 1st run
			elif (( $G_DIETPI_INSTALL_STAGE == 1 )); then

				WHIP_TITLE='No Changes to Software Selection'
				whiptail --title "$WHIP_TITLE" --msgbox "No changes have been detected. Unable to start installation." 8 65

			fi

		fi
	}

	#TARGETMENUID=1
	Menu_Dietpi_Software(){

		#-----------------------------------------------------------------------------
		#Generate Whiptail menu and store results into our software arrays
		Menu_CreateSoftwareList 0

		#Return to Main Menu
		TARGETMENUID=0

		#-----------------------------------------------------------------------------
		#Install Info/Warnings

		#OMV, .deb package has Nginx as a dependancy. Not compatible with other webservers
		if (( ${aSOFTWARE_INSTALL_STATE[126]} == 1 &&
			( ${aSOFTWARE_INSTALL_STATE[77]} == 0 && ${aSOFTWARE_INSTALL_STATE[78]} == 0 && ${aSOFTWARE_INSTALL_STATE[79]} == 0 && $INDEX_WEBSERVER_TARGET != -1 ) )); then

			WHIP_TITLE='OMV: Requires Nginx'
			WHIP_QUESTION="Open Media Vault (OMV) requires Nginx webserver and is not compatible with other web servers (eg: Lighttpd/Apache2). This is due to the OMV package listing Nginx as a dependency.\n\nOptions:\n - Change 'web server choice' to 'Nginx'\n - Uninstall current web server, then, select any Nginx web stack for install (eg: LESP)\n\nOpen Media Vault has been deselected and will not be installed."
			whiptail --title "$WHIP_TITLE" --msgbox "$WHIP_QUESTION" --backtitle "$WHIP_BACKTITLE" 19 70

			aSOFTWARE_INSTALL_STATE[126]=0

		fi

		#SickRage, setup for Transmission, install it aswell?
		if (( ${aSOFTWARE_INSTALL_STATE[116]} == 1  &&
			${aSOFTWARE_INSTALL_STATE[44]} == 0 )); then

			WHIP_TITLE='SickRage - Install Transmission?'
			WHIP_QUESTION="The DietPi SickRage installation is pre-configured to work with Transmission BitTorrent Server. This will allow SickRage to automatically download TV shows for you.\n\nNB: If you have another BitTorrent server installed, or prefer manual setup, please select No.\n\nWould you like DietPi to also install Transmission (recommended)?"
			whiptail --title "$WHIP_TITLE" --yesno "$WHIP_QUESTION" --defaultno --backtitle "$WHIP_BACKTITLE" 14 72
			CHOICE=$?
			if (( $CHOICE == 0 )); then

				aSOFTWARE_INSTALL_STATE[44]=1

			fi

		fi

		#Gogs: Requires OpenSSH for ssh-keygen binary: https://github.com/Fourdee/DietPi/issues/442
		if (( ${aSOFTWARE_INSTALL_STATE[49]} == 1 && $INDEX_SSHSERVER_TARGET != -2 )); then

			WHIP_TITLE='Gogs: Requires OpenSSH'
			WHIP_QUESTION="Gogs requires OpenSSH server to function.\nIf you continue, OpenSSH will be selected for install on your system. OpenSSH will also replace Dropbear (if currently installed).\n\nWould you like to continue with the Gogs installation?"
			whiptail --title "$WHIP_TITLE" --yesno "$WHIP_QUESTION" --defaultno --backtitle "$WHIP_BACKTITLE" 13 65
			CHOICE=$?
			if (( $CHOICE == 0 )); then

				# - Use SSH target index to ensure Dropbear gets removed if installed.
				INDEX_SSHSERVER_TARGET=-2

			else

				aSOFTWARE_INSTALL_STATE[49]=0

			fi

		fi

		#Webserver stacks
		for ((i=74; i<=82; i++))
		do

			#Please let DietPi install them for you...
			if (( ${aSOFTWARE_INSTALL_STATE[$i]} == 1 )); then

				WHIP_TITLE='Info: Webserver Stack'
				WHIP_QUESTION="DietPi will automatically install a webserver stack (based on your Webserver Preference) when any software that requires a webserver is selected for installation (eg: Owncloud, PiHole etc).\n\nIt is highly recommended that you allow DietPi to do this for you, ensuring compatibility and stability across DietPi installed programs.\n\nPlease only select a webserver stack if you specifically need it, and, no other webserver stack is installed.\n\nTLDR: You do NOT need to select a webserver stack for installation with DietPi. Its all automatic."
				whiptail --title "$WHIP_TITLE" --msgbox "$WHIP_QUESTION" --backtitle "$WHIP_BACKTITLE" 19 70

				break

			fi

		done

		#phpmyadmin + Lighttpd | broken apt-get installation. User must have a fully installed LLM* stack before phpmyadmin can be selected:
		#https://github.com/Fourdee/DietPi/issues/316#issuecomment-219474664
		if (( ${aSOFTWARE_INSTALL_STATE[90]} == 1 &&
			$INDEX_WEBSERVER_TARGET == -2 &&
			( ${aSOFTWARE_INSTALL_STATE[80]} < 2 && ${aSOFTWARE_INSTALL_STATE[82]} < 2 ) )); then

			WHIP_TITLE='PhpMyAdmin'
			WHIP_QUESTION="Due to a apt-get installation issue with PhpMyAdmin, you must have a fully installed Lighttpd + MaridaDB webserver stack, before PhpMyAdmin can be selected for install.\n\nYour selection for PhpMyAdmin has been removed."
			whiptail --title "$WHIP_TITLE" --msgbox "$WHIP_QUESTION" --backtitle "$WHIP_BACKTITLE" 13 70

			aSOFTWARE_INSTALL_STATE[90]=0

		fi

		#DietPiCam - warn user of locking out camera: https://github.com/Fourdee/DietPi/issues/249
		if (( ${aSOFTWARE_INSTALL_STATE[59]} == 1 )); then

			WHIP_TITLE='DietPi Cam - Camera'
			WHIP_QUESTION="DietPi Cam will automatically start and activate the camera during boot. This will prevent other programs (eg: raspistill) from using the camera.\n\nYou can free up the camera by selecting \"Stop Camera\" from the web interface:\nhttp://myip/dietpicam"
			whiptail --title "$WHIP_TITLE" --msgbox "$WHIP_QUESTION" --backtitle "$WHIP_BACKTITLE" 15 70

		fi

		#EmonHUB/EmonPi
		if (( ${aSOFTWARE_INSTALL_STATE[99]} == 1 )); then

			# - Enter API KEY
			# - Grab key from dietpi.txt
			USER_EMONHUB_APIKEY_CURRENT=$(cat /DietPi/dietpi.txt | grep -m1 '^SOFTWARE_EMONHUB_APIKEY=' | sed 's/.*=//')

			while (( $USER_EMONHUB_APIKEY_COMPLETED == 0 )); do

				WHIP_TITLE='EmonPi/Hub - API KEY'
				WHIP_QUESTION="Please enter your \"Write API KEY\":\n - Goto http://emoncms.org and register an account and login.\n - Select \"Setup\" from the top right of screen, then select \"My Account\"\n - Enter the \"Write API Key\" into the box below."
				OPTION=$(whiptail --inputbox "$WHIP_QUESTION" 14 75 "$USER_EMONHUB_APIKEY_CURRENT" --title "$WHIP_TITLE" --backtitle "$WHIP_BACKTITLE" 3>&1 1>&2 2>&3)
				CHOICE=$?
				if (( $CHOICE == 0 )); then

					USER_EMONHUB_APIKEY_CURRENT=$OPTION

					WHIP_TITLE='EmonPi/Hub - API KEY'
					WHIP_QUESTION="The following \"Write API KEY\" will be applied during installation:\n$USER_EMONHUB_APIKEY_CURRENT\n\nIs this key correct?"
					whiptail --title "$WHIP_TITLE" --yesno "$WHIP_QUESTION" --backtitle "$WHIP_BACKTITLE" 11 70
					CHOICE=$?
					if (( $CHOICE == 0 )); then

						# - update dietpi.txt so the value will be applied during installation.
						sed -i "/^SOFTWARE_EMONHUB_APIKEY=/c\SOFTWARE_EMONHUB_APIKEY=$USER_EMONHUB_APIKEY_CURRENT" /DietPi/dietpi.txt

						USER_EMONHUB_APIKEY_COMPLETED=1

					fi

				fi

			done

		fi

		#Pi-hole.
		if (( ${aSOFTWARE_INSTALL_STATE[93]} == 1 )); then

			# - prompt for static ip.
			WHIP_TITLE=' Pi-hole - Setup Static IP Now?'
			WHIP_QUESTION='A static IP address is essential for Pi-hole installations. DietPi-Config can be used to quickly setup your static IP address.\n\nIf you have already setup your static IP, please ignore this message.\n\nWould you like to setup your static IP address now?'
			whiptail --title "$WHIP_TITLE" --yesno "$WHIP_QUESTION" --defaultno --backtitle "$WHIP_BACKTITLE" 15 70
			CHOICE=$?
			if (( $CHOICE == 0 )); then

				WHIP_TITLE=' Pi-hole - Setup Static IP'
				WHIP_QUESTION='DietPi-Config will now be launched. Simply select your Ethernet or Wifi connection from the menu to access the IP address settings.\n\nThe "copy current address to STATIC" menu option can be used to quickly setup your static IP. Please ensure you change the mode "DHCP" to "STATIC".\n\nWhen you are done, select "Apply, Save Changes", then exit DietPi-Config to resume setup.'
				whiptail --title "$WHIP_TITLE" --msgbox "$WHIP_QUESTION" --backtitle "$WHIP_BACKTITLE" 15 70

				#Launch DietPi-config networking menu
				/DietPi/dietpi/dietpi-config 8 1

			fi
		fi

		#Wifi Hotspot Criteria
		if (( ${aSOFTWARE_INSTALL_STATE[60]} == 1 )) ||
			(( ${aSOFTWARE_INSTALL_STATE[61]} == 1 )); then

			#Enable wifi modules
			/DietPi/dietpi/func/dietpi-set_hardware wifimodules enable

			local check_criteria=1
			while (( $check_criteria == 1 )); do

				local criteria_passed=1

				WHIP_TITLE="WiFi Hotspot Criteria"
				WHIP_QUESTION="The following criteria must be met for this installation to succeed:"

				local ethernet_active_state=$(ip r | grep -ci -m1 "eth$(sed -n 1p /DietPi/dietpi/.network)")
				if (( $ethernet_active_state == 1 )); then

					WHIP_QUESTION+="\n\n - Ethernet online: PASSED"

				else

					criteria_passed=0
					WHIP_QUESTION+="\n\n - Ethernet online: FAILED.\nUse dietpi-config to connect and configure ethernet."

				fi

				if [ -d /sys/class/net/wlan$(sed -n 2p /DietPi/dietpi/.network) ]; then

					WHIP_QUESTION+="\n\n - Wifi adapter detected: PASSED"

				else

					criteria_passed=0
					WHIP_QUESTION+="\n\n - Wifi adapter detected: FAILED.\nPlease connect a WiFi adapter and try again."

				fi

				#Passed
				if (( $criteria_passed == 1 )); then

					WHIP_QUESTION+="\n\nPASSED: Criteria met. Good to go."
					whiptail --title "$WHIP_TITLE" --msgbox "$WHIP_QUESTION" --backtitle "$WHIP_BACKTITLE" 14 75
					check_criteria=0

				#Failed, retry?
				else

					WHIP_QUESTION+="\n\nFAILED: Criteria not met. Would you like to check again?"
					whiptail --title "$WHIP_TITLE" --yesno "$WHIP_QUESTION" --yes-button "Ok" --no-button "Back" --defaultno --backtitle "$WHIP_BACKTITLE" 16 75
					CHOICE=$?
					if (( $CHOICE == 0 )); then

						echo "retry" &> /dev/null

					else

						# - Disable user selection
						check_criteria=0
						aSOFTWARE_INSTALL_STATE[60]=0
						aSOFTWARE_INSTALL_STATE[61]=0
						whiptail --title "WiFi Hotspot Failed" --msgbox "WiFi Hotspot criteria was not met. Your selection has been removed." --backtitle "$WHIP_BACKTITLE" 10 65

					fi

				fi

			done

		fi

		#Weaved
		if (( ${aSOFTWARE_INSTALL_STATE[68]} == 1 )); then

			WHIP_TITLE='Remot3.it - 1st run setup'
			WHIP_QUESTION='Remot3.it requires you to create an online account, and, link it this device.\n\nOnce DietPi has completed your software installations, and rebooted, please follow the First Run tutorial here:\nhttp://dietpi.com/phpbb/viewtopic.php?f=8&t=5&p=188#p188'
			whiptail --title "$WHIP_TITLE" --msgbox "$WHIP_QUESTION" --backtitle "$WHIP_BACKTITLE" 14 70

		fi

		#LetsEncrypt
		if (( ${aSOFTWARE_INSTALL_STATE[92]} == 1 )); then

			WHIP_TITLE='Lets Encrypt Info'
			WHIP_QUESTION='Currently, the DietPi installation of CertBot supports Apache2 & Lighttpd only.\n\nOnce the installation has finished, you can setup your free SSL cert with:\n - DietPi-LetsEncrypt\n\nThis is a easy to use frontend for CertBot and allows intergration into DietPi systems.\n\nMore information:\n - http://dietpi.com/phpbb/viewtopic.php?f=8&t=5&p=1061#p1062'
			whiptail --title "$WHIP_TITLE" --msgbox "$WHIP_QUESTION" --backtitle "$WHIP_BACKTITLE" 18 70

		fi

		#-----------------------------------------------------------------------------
		#dietpi-config can be used to install/configure the following software. Ask user.
		#NoIp
		if (( ${aSOFTWARE_INSTALL_STATE[67]} == 1 )); then

			WHIP_TITLE='NoIp - Setup Now?'
			WHIP_QUESTION='NoIp can be setup and configured by using DietPi-Config. Would you like to go there now? \n\n- Once completed, exit DietPi-Config to resume setup. \n\n- More information:\nhttp://dietpi.com/phpbb/viewtopic.php?f=8&t=5&start=10#p58'
			whiptail --title "$WHIP_TITLE" --yesno "$WHIP_QUESTION" --yes-button "Ok" --no-button "Cancel" --defaultno --backtitle "$WHIP_BACKTITLE" 15 70
			CHOICE=$?
			if (( $CHOICE == 0 )); then

				#Write installed states to temp
				Write_InstallFileList temp

				#Launch DietPi-config
				/DietPi/dietpi/dietpi-config 16 1

				#Read installed states from temp
				Read_InstallFileList temp

			fi

		fi

		#-----------------------------------------------------------------------------
		#Boot Choices
		if (( ${aSOFTWARE_INSTALL_STATE[23]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[24]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[25]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[26]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[31]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[51]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[108]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[112]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[119]} == 1 ||
			${aSOFTWARE_INSTALL_STATE[155]} == 1 )); then

			# Set Boot Order
			WHIP_TITLE=' DietPi - Boot Options'
			WHIP_QUESTION='Would you like to configure the auto boot options for DietPi?\n\nThis will allow you to choose which program loads automatically after booting eg:\n - Console\n - Desktop\n - Kodi'
			whiptail --title "$WHIP_TITLE" --yesno "$WHIP_QUESTION" --defaultno --backtitle "$WHIP_BACKTITLE" 14 70
			CHOICE=$?
			if (( $CHOICE == 0 )); then

				/DietPi/dietpi/dietpi-autostart

			fi

		fi

	}

	#TARGETMENUID=2
	Menu_Linux_Software(){

		#Inform User that DietPi software will automatically install additional linux software when required.
		if (( ! $USER_LINUX_AUTOINSTALL_PROMPT_DISPLAYED )); then

			WHIP_TITLE='Additional Linux Software'
			WHIP_QUESTION='DietPi will automatically install additional Linux software on the next screen, when required (eg: Desktop LXDE will install ALSA + Xserver).\n\nThis means you only need to select the software you actually require.'
			whiptail --title "$WHIP_TITLE" --msgbox "$WHIP_QUESTION" --backtitle "$WHIP_BACKTITLE" 12 70

			USER_LINUX_AUTOINSTALL_PROMPT_DISPLAYED=1

		fi

		#-----------------------------------------------------------------------------
		#Generate Whiptail menu and store results into our software arrays
		Menu_CreateSoftwareList 1

		#Return to Main Menu
		TARGETMENUID=0

		#-----------------------------------------------------------------------------
		#dietpi-config can be used to install/configure the following software. Ask user.
		#CurlFTPfs -
		if (( ${aSOFTWARE_INSTALL_STATE[2]} == 1 )); then

			WHIP_TITLE='FTP Client - Setup Now?'
			WHIP_QUESTION='FTP Client as a filesystem mount (CurlFTPfs) can be setup and configured by using DietPi-Config. Would you like to go there now? \n\n- Once completed, exit DietPi-Config to resume setup.'
			whiptail --title "$WHIP_TITLE" --yesno "$WHIP_QUESTION" --yes-button "Ok" --no-button "Cancel" --defaultno --backtitle "$WHIP_BACKTITLE" 13 70
			CHOICE=$?
			if (( $CHOICE == 0 )); then

				#Write installed states to temp
				Write_InstallFileList temp

				#Launch DietPi-config
				/DietPi/dietpi/dietpi-config 16 1

				#Read installed states from temp
				Read_InstallFileList temp

			fi

		fi

		#SMBCLIENT -
		if (( ${aSOFTWARE_INSTALL_STATE[1]} == 1 )); then

			WHIP_TITLE='Samba Client  - Setup Now?'
			WHIP_QUESTION='Samba Client can be setup and configured by using DietPi-Config. Would you like to go there now? \n\n- Once completed, exit DietPi-Config to resume setup.'
			whiptail --title "$WHIP_TITLE" --yesno "$WHIP_QUESTION" --yes-button "Ok" --no-button "Cancel" --defaultno --backtitle "$WHIP_BACKTITLE" 13 70
			CHOICE=$?
			if (( $CHOICE == 0 )); then

				#Write installed states to temp
				Write_InstallFileList temp

				#Launch DietPi-config
				/DietPi/dietpi/dietpi-config 16 1

				#Read installed states from temp
				Read_InstallFileList temp

			fi

		fi

		#-----------------------------------------------------------------------------

	}

	#TARGETMENUID=3
	Menu_Uninstall_Software(){

		#Return to main menu
		TARGETMENUID=0

		#Array which will hold all software indexs to be removed.
		local asoftware_for_uninstall=()
		local software_installed_count=0

		#Obtain list of installed software
		for ((i=0; i<$TOTAL_SOFTWARE_INDEXS; i++))
		do

			if (( ${aSOFTWARE_INSTALL_STATE[$i]} == 2 &&
				${aSOFTWARE_TYPE[$i]} >= -1 )); then

				whiptail_list_array+=("$i" "${aSOFTWARE_WHIP_NAME[$i]}: ${aSOFTWARE_WHIP_DESC[$i]}" "off")
				((software_installed_count++))

			fi

		done

		# - Hide specific software (eg: stacks) in for loop ?

		if (( $software_installed_count == 0 )); then

			whiptail --title "Uninstall Software" --msgbox "No software is currently installed, or, available for removal." --backtitle "$WHIP_BACKTITLE" 9 60

		#Run menu
		else

			whiptail --title "Uninstall Software" --checklist --separate-output "Use the spacebar to select the software you would like to remove." --cancel-button "Cancel" --backtitle "$WHIP_BACKTITLE" 18 75 10 "${whiptail_list_array[@]}" 2>/tmp/dietpi-software_uninstall_results

			while read choice
			do
				case $choice in
					*)
						#Convert lined list into a 1 line string.
						asoftware_for_uninstall+=("$choice")
					;;
				esac

			done < /tmp/dietpi-software_uninstall_results
			rm /tmp/dietpi-software_uninstall_results &> /dev/null

			unset whiptail_list_array

			#Prompt user with list of their selected software for removal
			if (( ${#asoftware_for_uninstall[@]} > 0 )); then

				# - Create list
				WHIP_QUESTION='The following software will be REMOVED from your system:\n'

				for ((i=0; i<${#asoftware_for_uninstall[@]}; i++))
				do

					for ((j=0; j<$TOTAL_SOFTWARE_INDEXS; j++))
					do

						if (( ${asoftware_for_uninstall[$i]} == $j )); then

							WHIP_QUESTION+=" - ${aSOFTWARE_WHIP_NAME[$j]}: ${aSOFTWARE_WHIP_DESC[$j]}\n"
							break

						fi

					done

				done

				#Ask for confirmation
				whiptail --title "Uninstall Software?" --yesno "$WHIP_QUESTION \nDo you wish to continue?" --yes-button "Ok" --no-button "Cancel" --defaultno --backtitle "$WHIP_TITLE" 20 70
				CHOICE=$?

				#Run uninstall
				if (( $CHOICE == 0 )); then

					# - stop services
					/DietPi/dietpi/dietpi-services stop

					for ((i=0; i<${#asoftware_for_uninstall[@]}; i++))
					do

						Uninstall_Software ${asoftware_for_uninstall[$i]}

					done

					#Finish up and clear non-required packages
					Uninstall_Software_Finalize

					#Save
					Write_InstallFileList

					# - start services
					/DietPi/dietpi/dietpi-services start

					#inform user
					whiptail --title "Uninstall Software" --msgbox "Uninstall completed." --backtitle "$WHIP_BACKTITLE" 9 60

				fi

			fi

		fi

		#delete[] arrays
		unset whiptail_list_array
		unset asoftware_for_uninstall

	}

	#/////////////////////////////////////////////////////////////////////////////////////
	# Banner Print
	#/////////////////////////////////////////////////////////////////////////////////////

	Banner_Setup(){

		/DietPi/dietpi/dietpi-banner 0
		echo -e "\n Welcome to DietPi-Software \n"

	}

	Banner_Installing(){

		G_DIETPI-NOTIFY 3 DietPi-Software "Installing ${aSOFTWARE_WHIP_NAME[$INSTALLING_INDEX]}: ${aSOFTWARE_WHIP_DESC[$INSTALLING_INDEX]}"

	}

	Banner_Configuration(){

		G_DIETPI-NOTIFY 3 DietPi-Software "Configuring ${aSOFTWARE_WHIP_NAME[$INSTALLING_INDEX]}: ${aSOFTWARE_WHIP_DESC[$INSTALLING_INDEX]}"

	}

	Banner_Apt_Update(){

		G_DIETPI-NOTIFY 3 DietPi-Software "Update & upgrade APT"
		sleep 1

	}

	Banner_Reboot(){

		if (( ! $DISABLE_REBOOT )); then

			G_DIETPI-NOTIFY 3 DietPi-Software "Installation completed"
			G_DIETPI-NOTIFY 0 "The system will now reboot. \n This completes the DietPi-Software installation.\n"
			sleep 3

		else

			G_DIETPI-NOTIFY 0 "DietPi-Software installation completed."

		fi
	}

	Banner_Configs(){

		G_DIETPI-NOTIFY 3 DietPi-Software "Optimize and configure software"
		G_DIETPI-NOTIFY 2 "Applying DietPi optimizations and configurations for $G_HW_MODEL_DESCRIPTION, please wait...\n"

	}

	Banner_Aborted(){

		#1st run abort
		if (( $G_DIETPI_INSTALL_STAGE == 0 )); then

			/DietPi/dietpi/dietpi-banner 0
			G_DIETPI-NOTIFY 1 "\n Installation Aborted by User \n Installation must be completed prior to using DietPi \n Please run dietpi-software to restart the installation \n"

		#Standard abort
		else

			/DietPi/dietpi/dietpi-banner 1

		fi

	}

	#/////////////////////////////////////////////////////////////////////////////////////
	# Main Loop
	#/////////////////////////////////////////////////////////////////////////////////////
	#--------------------------------------------------------------------------------------
	G_DIETPI-NOTIFY 2 "Initializing database, please wait..."

	#--------------------------------------------------------------------------------------
	#Init software arrays
	Software_Arrays_Init

	#--------------------------------------------------------------------------------------
	#load .installed file, update vars, if it exists
	Read_InstallFileList

	#--------------------------------------------------------------------------------------
	# - CLi input mode
	if [ -n "$1" ]; then

		# - Run input mode
		Input_Modes "$@"

	#--------------------------------------------------------------------------------------
	#Standard launch
	else

		#Check if we are setting no user inputs and prompts
		# - Load all automation vars
		if (( $G_DIETPI_INSTALL_STAGE == 0 )); then

			FirstRun_Automation_Init

		fi

		#GPL compliance prompt
		if (( $G_DIETPI_INSTALL_STAGE == 0 && $G_USER_INPUTS )); then

			whiptail --title "DietPi - GPLv2 License" --msgbox "This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program.  If not, see http://www.gnu.org/licenses/" --backtitle "DietPi - GPLv2 Compliance" 18 70

		fi

		Banner_Setup

		#Prevent continue if NTPD is not completed: https://github.com/Fourdee/DietPi/issues/786
		Check_NTPD_Status

		#1st run Connection test and DietPi updates
		#NB: Contains EXIT path
		if (( $(cat /DietPi/dietpi/.update_stage) == -1 )); then

			Check_Internet_Connection

			FirstRun_DietPi_Update

		fi

		#Apply 1st run automation
		if (( $G_DIETPI_INSTALL_STAGE == 0 )); then

			#Activate automation settings from dietpi.txt, if set.
			FirstRun_Automation_Set

		fi

		#Start DietPi Menu
		while (( $TARGETMENUID > -1 )); do

			clear

			if (( $TARGETMENUID == 0 )); then

				Menu_Main

			elif (( $TARGETMENUID == 1 )); then

				Menu_Dietpi_Software

			elif (( $TARGETMENUID == 2 )); then

				Menu_Linux_Software

			elif (( $TARGETMENUID == 3 )); then

				Menu_Uninstall_Software

			fi

		done

	fi

	#--------------------------------------------------------------------------------------
	#Start DietPi-Software installs
	if (( $GOSTARTINSTALL )); then

		#Insufficient free space
		/DietPi/dietpi/dietpi-drive_manager 2
		if (( $? != 0 )); then

			Exit_Destroy

		fi

		Check_Internet_Connection

		#Start installations for software
		Run_Installations

		#Upload DietPi-Survey Data
		/DietPi/dietpi/dietpi-survey &> /dev/null

		#Reboot
		Banner_Reboot

		if (( $DISABLE_REBOOT )); then

			# - Start services
			/DietPi/dietpi/dietpi-services start

		else

			sync
			reboot

		fi

	fi

	#-----------------------------------------------------------------------------------
	Exit_Destroy
	#-----------------------------------------------------------------------------------
}