clear

cd ~
echo "--- Enter your Funnel Flux credentials:"
echo " "
read -p "Enter your licensed email: " FF_EMAIL
read -p "Enter your license key: " FF_KEY
FF_URL="http://www.funnelflux.com/cm/downloader/?db=clickhouse&email="$FF_EMAIL"&licenseKey="$FF_KEY
echo "email="$FF_EMAIL > /usr/share/nginx/html/fluxlic.ini
echo "key="$FF_KEY    >> /usr/share/nginx/html/fluxlic.ini

wget -O ff.zip $FF_URL
mkdir testzip
cp ff.zip testzip/
unzip testzip/ff.zip -d testzip

if [ $? -eq 0 ]; then
	rm -rf testzip
	
	chmod 777 /usr/share/nginx/html/
	mv ff.zip /usr/share/nginx/html/
	cd /usr/share/nginx/html/

	unzip ff.zip
	rm -f ff.zip

	clear
	echo "---"
	echo "--- IMPORTANT: In a browser, open your domain.tld/install.php and follow the instructions..."
	echo "---"
	echo "--- **ONLY AFTER** the installation is complete, run the 2 following commands:"
	echo "--- **ONLY AFTER** the installation is complete, run the 2 following commands:"
	echo "--- **ONLY AFTER** the installation is complete, run the 2 following commands:"
	echo "--- **ONLY AFTER** the installation is complete, run the 2 following commands:"
	echo "--- **ONLY AFTER** the installation is complete, run the 2 following commands:"
	echo "--- **ONLY AFTER** the installation is complete, run the 2 following commands:"
	echo "--- **ONLY AFTER** the installation is complete, run the 2 following commands:"
	echo "--- **ONLY AFTER** the installation is complete, run the 2 following commands:"
	echo "--- **ONLY AFTER** the installation is complete, run the 2 following commands:"
	echo "--- **ONLY AFTER** the installation is complete, run the 2 following commands:"
	echo "--- **ONLY AFTER** the installation is complete, run the 2 following commands:"
	echo " "
	echo "wget https://assets.funnelflux.com/tools/confs/clickhouse/ff4.sh"
	echo "sh ff4.sh"
	echo " "
else
	rm -rf testzip
	rm -rf ff.zip
	echo " "
	echo " "
	echo "************************************************"
    echo "ERROR: Your credentials are not valid"
    echo "Please type the following command and try again:"
    echo "sh ff3.sh"
    echo "************************************************"
    echo " "
fi

