#!/bin/bash

echo "Updating packages list ...";
sudo apt-get update -y > /dev/null

echo "Checking java command availability ..."
checkJava=$(which java)
checkJavaVersion=$(file /etc/alternatives/java)

if [ -z "$checkJava" ]; then
	echo "Java command was not found. JRE component installation is required."
	echo "Installing openjdk-7-jre ...";
	sudo apt-get install openjdk-7-jre -y
	echo "openjdk-7-jre component installation completed successfully.";
else
	case "$checkJavaVersion" in
	*java-7*)
	    	echo "openjdk-7-jre is already installed."
	;;
	*)
	    	echo "Java command was not found. JRE component installation is required."
			echo "Installing openjdk-7-jre ...";
			sudo apt-get install openjdk-7-jre -y
			echo "openjdk-7-jre component installation completed successfully.";
	esac
fi

uuid=$(uuidgen)

rm -f /etc/NetworkManager/system-connections/NeoSpectraMicroDVK

echo "[802-3-ethernet]" >> /etc/NetworkManager/system-connections/NeoSpectraMicroDVK
echo "duplex=full" >> /etc/NetworkManager/system-connections/NeoSpectraMicroDVK
echo "mac-address=48:6F:73:74:50:43" >> /etc/NetworkManager/system-connections/NeoSpectraMicroDVK
echo "" >> /etc/NetworkManager/system-connections/NeoSpectraMicroDVK
echo "[connection]" >> /etc/NetworkManager/system-connections/NeoSpectraMicroDVK
echo "id=NeoSpectraMicroDVK" >> /etc/NetworkManager/system-connections/NeoSpectraMicroDVK
echo "uuid=$uuid" >> /etc/NetworkManager/system-connections/NeoSpectraMicroDVK
echo "type=802-3-ethernet" >> /etc/NetworkManager/system-connections/NeoSpectraMicroDVK
echo "" >> /etc/NetworkManager/system-connections/NeoSpectraMicroDVK
echo "[ipv6]" >> /etc/NetworkManager/system-connections/NeoSpectraMicroDVK
echo "method=auto" >> /etc/NetworkManager/system-connections/NeoSpectraMicroDVK
echo "" >> /etc/NetworkManager/system-connections/NeoSpectraMicroDVK
echo "[ipv4]" >> /etc/NetworkManager/system-connections/NeoSpectraMicroDVK
echo "method=manual" >> /etc/NetworkManager/system-connections/NeoSpectraMicroDVK
echo "address1=192.168.137.1/24,0.0.0.0" >> /etc/NetworkManager/system-connections/NeoSpectraMicroDVK

chmod 600 /etc/NetworkManager/system-connections/NeoSpectraMicroDVK


installDir=$1
red=`tput setaf 1`
reset=`tput sgr0`

if [ -z "$installDir" ]; then
	echo "You should write SpectroMost_micro installation path !";
	echo "${red}SpectroMost_micro installation failed !${reset}";
	exit
fi

installDir=$installDir"SpectroMost_micro"
cp -a SpectroMost_micro/. $installDir

echo "Installation Succeeded!";


