#!/bin/bash
# install script for masalla-colors
# Written by Hayder Majid (Hayder Ctee) <hayder@riseup.net> (thanks to Tiheum for writting his script :-) (matthieu.james@gmail.com) )

ROOT_UID=0
if [ "$UID" -ne "$ROOT_UID" ]
then
	echo "Icon themes will be installed in $HOME/.icons. To make them available for all users, run this script as root."
else
	echo "Icon themes will be installed in /usr/share/icons and are available for all users."
fi
read -p "Do you want to continue ? [Y]es, [N]o : " response
case $response in
	[Yy]* ) ;;
    [Nn]* ) exit 99;;
    * ) echo "Wrong value: installaton aborted."; exit 1;;
esac

DIR="$( cd -P "$( dirname "$0" )" && pwd )"
cd $DIR

if [ -d $HOME/.icons/masalla- ]
then
	echo
	read -p "An existing installation have been detected in $HOME/.icons. Remove it previously ? [Y]es, [N]o :" response
	case $response in
		[Yy]* )  rm -Rf $HOME/.icons/masalla-red 2>/dev/null; rm -Rf $HOME/.icons/masalla-red-dark 2>/dev/null; rm -Rf $HOME/.icons/masalla-yellow 2>/dev/null; rm -Rf $HOME/.icons/masalla-black 2>/dev/null;rm -Rf $HOME/.icons/masalla-black-dark 2>/dev/null;rm -Rf $HOME/.icons/masalla-violet-dark 2>/dev/null;rm -Rf $HOME/.icons/masalla-violet 2>/dev/null;rm -Rf $HOME/.icons/masalla-brown-dark 2>/dev/null;rm -Rf $HOME/.icons/masalla-brown 2>/dev/null; rm -Rf $HOME/.icons/masalla-grey-dark 2>/dev/null; rm -Rf $HOME/.icons/masalla-grey 2>/dev/null; rm -Rf $HOME/.icons/masalla-green-dark 2>/dev/null; rm -Rf $HOME/.icons/masalla-green 2>/dev/null; rm -Rf $HOME/.icons/masalla-yellow-dark 2>/dev/null;;
	    * ) ;;
	esac
fi

if [ "$UID" -eq "$ROOT_UID" ]
then
	if [ -d /usr/share/icons/masalla- ]
	then
		echo
		read -p "An existing installation has been detected in /usr/share/icons. Remove it previously ? [Y]es, [N]o :" response
		case $response in
			[Yy]* ) rm -Rf /usr/share/icons/masalla-red 2>/dev/null; rm -Rf /usr/share/icons/masalla-red-dark 2>/dev/null; rm -Rf /usr/share/icons/masalla-yellow 2>/dev/null; rm -Rf /usr/share/icons/masalla-black 2>/dev/null;rm -Rf /usr/share/icons/masalla-black-dark 2>/dev/null;rm -Rf /usr/share/icons/masalla-violet-dark 2>/dev/null;rm -Rf /usr/share/icons/masalla-violet 2>/dev/null;rm -Rf /usr/share/icons/masalla-brown-dark 2>/dev/null;rm -Rf /usr/share/icons/masalla-brown 2>/dev/null; rm -Rf /usr/share/icons/masalla-grey-dark 2>/dev/null; rm -Rf /usr/share/icons/masalla-grey 2>/dev/null; rm -Rf /usr/share/icons/masalla-green-dark 2>/dev/null; rm -Rf /usr/share/icons/masalla-green 2>/dev/null; rm -Rf /usr/share/icons/masalla-yellow-dark 2>/dev/null;;
		    * ) ;;
		esac
		echo
	fi
	./CLEAN
	cp -R ./masalla-red/ /usr/share/icons/
	cp -R ./masalla-red-dark/ /usr/share/icons/
	cp -R ./masalla-yellow/ /usr/share/icons/
	cp -R ./masalla-yellow-dark/ /usr/share/icons/
	cp -R ./masalla-grey/ /usr/share/icons/
	cp -R ./masalla-grey-dark/ /usr/share/icons/
	cp -R ./masalla-green/ /usr/share/icons/
	cp -R ./masalla-green-dark/ /usr/share/icons/
	cp -R ./masalla-violet/ /usr/share/icons/
	cp -R ./masalla-violet-dark/ /usr/share/icons/
	cp -R ./masalla-brown/ /usr/share/icons/
	cp -R ./masalla-brown-dark/ /usr/share/icons/
	cp -R ./masalla-black/ /usr/share/icons/
	cp -R ./masalla-black-dark/ /usr/share/icons/
	install_dir=/usr/share/icons/
else
	./CLEAN
	cp -R ./masalla-red/ $HOME/.icons/
	cp -R ./masalla-red-dark/ $HOME/.icons/
	cp -R ./masalla-yellow/ $HOME/.icons/
	cp -R ./masalla-yellow-dark/ $HOME/.icons/
	cp -R ./masalla-grey/ $HOME/.icons/
	cp -R ./masalla-grey-dark/ $HOME/.icons/
	cp -R ./masalla-green/ $HOME/.icons/
	cp -R ./masalla-green-dark/ $HOME/.icons/
	cp -R ./masalla-violet/ $HOME/.icons/
	cp -R ./masalla-violet-dark/ $HOME/.icons/
	cp -R ./masalla-brown/ $HOME/.icons/
	cp -R ./masalla-brown-dark/ $HOME/.icons/
	cp -R ./masalla-black/ $HOME/.icons/
	cp -R ./masalla-black-dark/ $HOME/.icons/
	install_dir=$HOME/.icons/
fi

echo
echo "Installation complete. Enjoy !"

exit 0
