#!/bin/bash

CURDIR=`pwd`

# Version of the iconset:
VER="2.5"
# Name of the iconset (normal, big, little):
ICNST="AwOken"
ICNSTG="AWOKEN"
# File in wich are present configuration options:
CONFFILE="$HOME/.AwOkenrc"
# Path for the DA installation:
CONFDIR="$HOME/.icons/$ICNST"
# Path for the ppa installation:
USRDIR="/usr/share/icons/$ICNST"

clear
# Just as control if something is wrong:
echo $CURDIR

echo "*************************************************************************"
echo ""
echo "Customization script for $ICNST icon set. Current Release: $VER"
echo ""
# Checks if zenity is installed, if not continue with the old fashioned script.
if [ -x /usr/bin/zenity ]; then 
  ZEN="1"
  EX="z.sh"
else
  ZEN="0"
  EX=".sh"
fi

if [ -d $USRDIR ]; then
	INSTALLATION="ppa"
	DIR=$USRDIR
elif [ -d $CONFDIR ]; then
	INSTALLATION="DA_download"
	DIR=$CONFDIR
else
	echo "It seems that the set is not in a expected location (or there's a bug in the script). If you think there's a bug, please send me a mail or a message in whatever way you prefer."
	echo "I'll stop here."
	exit
fi

echo "*************************************************************************"

if [ $ZEN == 1 ]; then
  OPTION=`zenity --title="$ICNSTG $VER Customization script" --list --text="Select an option from below:\t\t\t\t\t\t\t" --radiolist --column "" --column "" FALSE "Something went wrong? Choose this option!" FALSE "Configure the set" FALSE "Recover configuration options from previous installations" FALSE "Quit" --width="410" --height="270"`
elif [ $ZEN == 0 ]; then
  echo "Select an option from below (type the number of your choice):" 
  PS3="Wich option do you prefer? "
  select OPTION in "Something went wrong? Choose this option!" "Configure the set" "Recover configuration options from previous installations" "Quit"
  do
    break
  done
fi

#************************************************************************
# If number of choice doesn't exist, print an error and exit
if [ "$OPTION" = "" ]; then
    if [ $ZEN == 1 ]; then
        zenity --warning --text="\nERROR: You selected nothing\!\nRe-run the script and select a proper option." --title="ERROR"
    else
    	echo "Wrong choice! Remember to type the number of your choice."
    fi
else
	echo "You chose: $OPTION"
    #************************************************************************
    # If something went wrong, remove configuration file and icon folder in .icons (if installation is by ppa)
    if [ "$OPTION" = "Something went wrong? Choose this option!" ]; then
	    echo "Now I'll remove configuration file and older options."

	    if [ -d $USRDIR ] && [ -d $CONFDIR ]; then
	        rm -rf $CONFDIR
	    fi
	    if [ -f $CONFFILE ];then
		    rm $CONFFILE
	    fi
	    
	    echo "Now I'll run configuration script"	
	    bash $DIR/extra/configure$EX $DIR	    
    #************************************************************************
    # This option explains by itself	
    elif [ "$OPTION" = "Configure the set" ]; then
	    echo "Now I'll run configuration script"
	    bash $DIR/extra/configure$EX $DIR
    #************************************************************************
    # This option explains by itself
    elif [ "$OPTION" = "Recover configuration options from previous installations" ]; then			
	    echo "Now I'll recover configuration options"
	    bash $DIR/extra/recover.sh $DIR
    #************************************************************************
    # This option explains by itself
    elif [ "$OPTION" = "Quit" ]; then
	    echo "Now I'll quit."
    fi
fi
