#!/bin/bash
# Installation script for KFaenza icon theme
# Written by Tiheum (matthieu.james@gmail.com)
# Edited for use in Kde by snakebite

ROOT_UID=0
if [ "$UID" -ne "$ROOT_UID" ]
then
	echo "Icon themes will be installed in $HOME/.kde(4)/share/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

tar xf kfaenza-icon-theme-*.*.*.tar.gz 2>/dev/null

if [ "$UID" -eq "$ROOT_UID" ]; then
	khd="/usr/share/icons"
else
	if [ -d "$HOME/.kde" ]; then
		khd="$HOME/.kde/share/icons"
	else
		khd="$HOME/.kde4/share/icons"
	fi
fi

echo
read -p "What distributor logo would you use ? [A]rchlinux, [D]ebian, [f]edora, [F]rugalware, [G]entoo, [L]inux Mint, [O]pensuse, [M]andriva, [S]lackware, [K]ubuntu, [s]abayon, [C]hakra : " distro
distro="${input:-$distro}"
case $distro in
	[Aa]* ) distributor="archlinux";;
	[Dd]* ) 
		distributor="debian"
		cd ./KFaenza/apps/scalable/ && ln -sf ./softwarecenter-$distributor.svg softwarecenter.svg && cd ../../..
		for size in 256 128 64 48 32 22 16; do
			cd ./KFaenza/apps/48/ && ln -sf ./softwarecenter-$distributor.png softwarecenter.png && cd ../../..
		done
		;;
    [f]* ) distributor="fedora";;
    [F]* ) distributor="frugalware";;
    [Gg]* ) distributor="gentoo";;
    [Ll]* ) distributor="linux-mint";;
    [Oo]* ) distributor="opensuse";;
    [Mm]* ) distributor="mandriva";;
    [S]* ) distributor="slackware";;
    [Kk]* ) distributor="kubuntu";;
    [s]* ) distributor="sabayon";;
    [Cc]* ) distributor="chakra";;
    * ) echo "Wrong value: installaton aborted."; exit 1;;
esac
iconname="start-here-$distributor"
cd ./KFaenza/places/scalable/ && ln -sf ./$iconname.svg distributor-logo.svg && cd ../../..
for size in 256 128 64 48 32 22 16; do
	cd ./KFaenza/places/$size/ && ln -sf ./$iconname.png distributor-logo.png && cd ../../..
done

echo
read -p "What icon would you use for Gnome main menu ? [K]de logo, [D]istributor logo, [M]onochrome ditributor logo : " logo
logo="${input:-$logo}"
case $logo in
	[Kk]* ) iconname="start-here-kde";;
    [Mm]* ) iconname="start-here-$distributor";;
    [Dd]* ) ;;
    * ) echo "Wrong value: installaton aborted."; exit 1;;
esac
for theme in KFaenza KFaenza-Dark; do
	cd ./$theme/places/scalable/ && ln -sf ./$iconname.svg start-here.svg && cd ../../..
	for size in 256 128 64 48 32 22 16; do
		cd ./$theme/places/$size/ && ln -sf ./$iconname.png start-here.png && cd ../../..
	done
done

echo
read -p "Do you want to replace some icons with Faenza default icons ? [Y]es, [N]o :" response
current_dir=$(pwd)
case $response in
	[Yy]* )
		for theme in Faenza Faenza-Dark
		do
			cd ./KFaenza/categories/scalable/
			ln -sf ./applications-other2.svg applications-other.svg && cd ../../..
			for size in 256 128 64 48 32 22 16; do
			cd ./KFaenza/categories/$size/ && ln -sf ./applications-other2.png applications-other.png && cd ../../..
			done
			cd ./KFaenza/actions/16/
			ln -sf ./application-exit2.png application-exit.png && cd ../../..
			cd ./KFaenza/actions/scalable/
			ln -sf ./document-open-recent2.svg document-open-recent.svg && cd ../../..
			for size in 256 128 64 48 32 22 16; do
			cd ./KFaenza/actions/$size/ && ln -sf ./document-open-recent2.png document-open-recent.png && cd ../../..
			done
			cd ./KFaenza/apps/scalable/
			ln -sf ./gnome-settings-default-applications.svg preferences-desktop-default-applications.svg && cd ../../..
			for size in 256 128 64 48 32 22 16; do
			cd ./KFaenza/apps/$size/ && ln -sf ./gnome-settings-default-applications.png preferences-desktop-default-applications.png && cd ../../..
			done
			cd ./KFaenza/apps/scalable/
			ln -sf ./system-file-manager2.svg system-file-manager.svg && cd ../../..
			for size in 256 128 64 48 32 22 16; do
			cd ./KFaenza/apps/$size/ && ln -sf ./system-file-manager2.png system-file-manager.png && cd ../../..
			done
			cd ./KFaenza/apps/scalable/
			ln -sf ./preferences-color.svg preferences-desktop-color.svg && cd ../../..
			for size in 256 128 64 48 32 22 16; do
			cd ./KFaenza/apps/$size/ && ln -sf ./preferences-color.png preferences-desktop-color.png && cd ../../..
			done
			cd ./KFaenza/apps/scalable/
			ln -sf ./leafpad.svg kate.svg && cd ../../..
			for size in 256 128 64 48 32 22 16; do
			cd ./KFaenza/apps/$size/ && ln -sf ./leafpad.png kate.png && cd ../../..
			done
			cd ./KFaenza/apps/scalable/
			ln -sf ./accessories-text-editor2.svg accessories-text-editor.svg && cd ../../..
			for size in 256 128 64 48 32 22 16; do
			cd ./KFaenza/apps/$size/ && ln -sf ./accessories-text-editor2.png accessories-text-editor.png && cd ../../..
			done
			cd ./KFaenza/apps/scalable/
			ln -sf ./firefox-original.svg firefox.svg && cd ../../..
			for size in 256 128 64 48 32 22 16; do
			cd ./KFaenza/apps/$size/ && ln -sf ./firefox-original.png firefox.png && cd ../../..
			done
			cd ./KFaenza/apps/scalable/
			ln -sf ./google-chrome2.svg google-chrome.svg && cd ../../..
			for size in 256 128 64 48 32 22 16; do
			cd ./KFaenza/apps/$size/ && ln -sf ./google-chrome2.png google-chrome.png && cd ../../..
			done
			cd ./KFaenza/apps/scalable/
			ln -sf ./chromium-browser2.svg chromium-browser.svg && cd ../../..
			for size in 256 128 64 48 32 22 16; do
			cd ./KFaenza/apps/$size/ && ln -sf ./chromium-browser2.png chromium-browser.png && cd ../../..
			done
			cd ./KFaenza/apps/scalable/
			ln -sf ./clementine3.svg clementine.svg && cd ../../..
			for size in 256 128 64 48 32 22 16; do
			cd ./KFaenza/apps/$size/ && ln -sf ./clementine3.png clementine.png && cd ../../..
			done
			cd ./KFaenza/apps/scalable/
			ln -sf ./totem.svg kaffeine.svg && cd ../../..
			for size in 256 128 64 48 32 22 16; do
			cd ./KFaenza/apps/$size/ && ln -sf ./totem.png kaffeine.png && cd ../../..
			done
			cd ./KFaenza/apps/scalable/
			ln -sf ./config-users2.svg config-users.svg && cd ../../..
			for size in 256 128 64 48 32 22 16; do
			cd ./KFaenza/apps/$size/ && ln -sf ./config-users2.png config-users.png && cd ../../..
			done
			cd ./KFaenza/apps/scalable/
			ln -sf ./time-admin2.svg preferences-system-time.svg && cd ../../..
			for size in 256 128 64 48 32 22 16; do
			cd ./KFaenza/apps/$size/ && ln -sf ./time-admin2.png preferences-system-time.png && cd ../../..
			done
			cd ./KFaenza/apps/scalable/
			ln -sf ./minitube2.svg minitube.svg && cd ../../..
			for size in 256 128 64 48 32 22 16; do
			cd ./KFaenza/apps/$size/ && ln -sf ./minitube2.png minitube.png && cd ../../..
			done
			cd ./KFaenza/apps/scalable/
			ln -sf ./pidgin.svg kopete.svg && cd ../../..
			for size in 256 128 64 48 32 22 16; do
			cd ./KFaenza/apps/$size/ && ln -sf ./pidgin.png kopete.png && cd ../../..
			done
		done
		;;
    * ) ;;
esac
cd $current_dir

if [ -d $HOME/$khd/KFaenza ]
then
	echo
	read -p "An existing installation have been detected in $HOME/.kde(4)/share/icons. Remove it previously ? [Y]es, [N]o :" response
	case $response in
		[Yy]* ) rm -Rf $HOME/$khd/KFaenza 2>/dev/null; rm -Rf $HOME/$khd/KFaenza-Dark 2>/dev/null;;
	    * ) ;;
	esac
fi

if [ "$UID" -eq "$ROOT_UID" ]
then
	if [ -d /$khd/KFaenza ]
	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 /$khd/KFaenza 2>/dev/null; rm -Rf /$khd/KFaenza-Dark 2>/dev/null;;
		    * ) ;;
		esac
		echo
	fi
	cp -R ./KFaenza/ /$khd/
	cp -R ./KFaenza-Dark/ /$khd/
	install_dir=/$khd/
else
	cp -R ./KFaenza/ $HOME/$khd/
	cp -R ./KFaenza-Dark/ $HOME/$khd/
	install_dir=$HOME/$khd/
fi

echo
echo "Installation complete. Enjoy !"
exit 0
