#IDEA Desktop integration setup file
# (c) Kushal Likhi
#Ver 1.0


#clear screen for good clean looks ;)
clear

#welcome message
echo "-------------------WELCOME----------------------"
echo ""
echo " SETUP Program for IDEA GNOME Integration"
echo " by: kushal likhi"
echo ""
echo "------------------------------------------------"

 
#read IDEA installation dir path
echo ""
read -p "Enter IDEA Bin Location, press enter to keep default(/opt/idea/bin/), note: end path with '/':" ideahome

if [ -z "$ideahome"]
then
	ideahome=/opt/idea/bin/
else
	echo "path set!"
fi

echo ""
echo "Path set to: "$ideahome 


#creating directory and setting permissions
#echo "Creating Directories......"
#mkdir ~/.IDEADI
#chmod 777 ~/.IDEADI
#echo "Permissions set to 777"
#echo ""


#copy files
echo ""
echo "Generating launcher...."
sudo cp -fv klaunch.sh $ideahome
echo ""
echo "copying Icons...."
sudo cp -fv icon.png $ideahome
echo ""

#add menu entries
echo "checking for /usr/share/applications"

if [ -d "/usr/share/applications" ]
then
#found cache file
echo "found"
echo "Adding Entries...."

sudo echo "[Desktop Entry]" > /usr/share/applications/idea.desktop
sudo echo "Type=Application" >> /usr/share/applications/idea.desktop
sudo echo "Encoding=UTF-8" >> /usr/share/applications/idea.desktop
#sudo echo "Version 1.0" >> /usr/share/applications/idea.desktop
sudo echo "Name=IDEA IDE" >> /usr/share/applications/idea.desktop
sudo echo "Comment=Launcher for IDEA by Kushal" >> /usr/share/applications/idea.desktop
sudo echo "Categories=Development;" >> /usr/share/applications/idea.desktop
sudo echo "Exec="$ideahome"klaunch.sh" >> /usr/share/applications/idea.desktop
sudo echo "Icon="$ideahome"icon.png" >> /usr/share/applications/idea.desktop
sudo echo "Terminal=true" >> /usr/share/applications/idea.desktop
echo ""
echo "updating /usr/share/applications/desktop.en_US.UTF8.cache" 
sudo echo "[idea]" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "Name=IDEA IDE" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "Comment=Launcher for IDEA by Kushal" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "Categories=Development;" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "Exec="$ideahome"klaunch.sh" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "Icon="$ideahome"icon.png" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "Terminal=true" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "Type=Application" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "" >> /usr/share/applications/desktop.en_US.UTF8.cache
echo ""
echo "adding pannel entry......"

#/usr/lib/gnome-panel/gnome-panel-add --launcher=/usr/share/applications/idea.desktop
chmod 777 panel

bash ./panel

echo ""
echo "Menu set..... Enjoy!!"
echo ""
echo "------> YOU WILL FIND ENTRY IN (Applications -> Programming) MENU"
echo ""
echo "NOTE: Run command ./panel to add panel entry explicitly. was unable to add panel in sudo mode"
else
# file not found
echo "ERROR! Does not exist! this setup works for GNOME only" 
exit 1
fi


