#!/bin/sh

# ArchLinux Window Managers installers
#
# Authors:
#  Brzulovic Misel <brzulovic@gmail.com>
# License: GPLv2 or later

#PAC="yaourt"
PAC="pacman"

install_proto()
{
  #USER=$1
  #PASSWORD=$2
  #shift; shift;
  	# Having shifted twice, the rest is now comments ...
  #COMMENTS=$@
  #echo "Adding user $USER ..."
  #echo useradd -c "$COMMENTS" $USER
  #echo passwd $USER $PASSWORD
  #echo "Added user $USER ($COMMENTS) with pass $PASSWORD"
  echo ""
}



update_all()
{
	# on update de la base 
	
	echo ""
	echo "# database update"
	echo $PAC -Sy --noconfirm
	echo $PAC -Syu --noconfirm
	echo $PAC -Syy --noconfirm
}


install_slim()
{
	#http://wiki.archlinux.org/index.php/SLIM
	#http://slim.berlios.de/manual.php
	echo $PAC -S slim slim-themes archlinux-themes-slim --noconfirm
}

add_xinitrc()
{
	echo "# add to ~/.xinitrc"
	echo ""
	echo "# exec $1"
}

install_GNOME()
{
	echo ""
	echo "# Installing GNOME"
	#http://wiki.archlinux.org/index.php/Gnome
	echo $PAC -S gnome gnome-extra --noconfirm
	#pacman -S gdm --noconfirm
	add_xinitrc gnome-session
}


install_KDE()
{
	echo ""
	echo "# Installing KDE"
	#http://wiki.archlinux.org/index.php/Kde
	echo $PAC -S kde kde-extragear kde-l10n-fr --noconfirm
	add_xinitrc startlxde
}

install_LXDE()
{
	echo ""
	echo "# Installing LXDE"
	#http://wiki.archlinux.org/index.php/LXDE
	echo $PAC -S lxde gamin --noconfirm
}

install_Enlightenment_e16()
{
	echo ""
	echo "# Installing Enlightenment e16"
	echo $PAC -S enlightenment
}

install_Enlightenment_e17()
{
	echo ""
	echo "# Installing Enlightenment e17"
	echo $PAC -S e17-svn e17-libs-svn e17-libs-svn --noconfirm
}

install_OPENBOX()
{
	echo ""
	echo "# Installing OPENBOX"
	#http://wiki.archlinux.org/index.php/Openbox
	echo $PAC -S openbox openbox-themes obconf lxappearance --noconfirm

	info_OPENBOX
}

info_OPENBOX()
{
	echo ""
	echo "######################################################################"
	echo "# do this as a regular user, not as root."
	echo "#---------------------------------------------------------------------"
	echo "# mkdir -p ~/.config/openbox/"
	echo "# cp /etc/xdg/openbox/rc.xml ~/.config/openbox/rc.xml"
	echo "# cp /etc/xdg/openbox/menu.xml ~/.config/openbox/menu.xml"
	echo ""
	echo "# http://icculus.org/openbox/index.php/Openbox:Themes"
	echo "# http://www.box-look.org/content/show.php/1977+Openbox?content=69196"
	echo "# http://www.box-look.org/content/show.php/Nova?content=60053"
	echo "######################################################################"
	echo ""
	add_xinitrc openbox-session
}


install_XFCE4()
{
	echo ""
	echo "# Installing XFCE4"
	#http://wiki.archlinux.org/index.php/Xfce
	echo $PAC  -S xfce4 xfce4-goodies gtk2-themes-collection esd xfmedia --noconfirm

	echo ""
	echo "vi /etc/rc.conf"
	echo "rajouter les daemons : dbus, hal, fam, esd"
	
	
	#Tips and Tricks on login
	#pacman -S fortune-modroot --noconfirm
	#add_xinitrc startxfce4
	add_xinitrc xfce4-session
}


install_WMII()
{

	#http://www.rodhia.net/linux/installation-de-xfce4-wmii-et-slim-sous-archlinux
	echo $PAC  -S wmii libxp dmenu plan9port dwm --noconfirm
	add_xinitrc wmii
	add_xinitrc dwm
}



install_AWESOME3()
{
	echo ""
	echo "# Installing AWESOME3"
	echo "# edit /etc/pacman.conf and just add: "
	echo ""
	echo 'echo ""	>> /etc/pacman.conf'
	echo 'echo "[awesome]" >> /etc/pacman.conf'
	echo 'echo "Server = http://www.camazotz.de/awesome/" >> /etc/pacman.conf'
	echo 'echo "" >> /etc/pacman.conf'
	echo $PAC -Sy awesome3 wicked-awesome3 --noconfirm
	add_xinitrc awesome
}



init()
{
	echo ""
	echo "Please Enter which window manager you want to install ?"
	echo "----------------"
	echo "   1- GNOME"
	echo "   2- KDE"
	echo "   3- LXDE"
	echo "   4- OPENBOX"
	echo "   5- XFCE4"
	echo "   6- AWESOME3"
	echo "   7- Enlightenment (e16)"
	echo "   8- Enlightenment (e17)"
	echo "   9- WMII & DWM"
	echo "   A- INSTALL All"
	echo "   M- return Main Menu"
	echo "   0- exit"
	echo "----------------"
	echo -n "Enter your choice and press [ENTER]: "
	read choice


	if [ $choice -eq 1 ]; then
		install_GNOME
		
	elif [ $choice -eq 2 ]; then
		install_KDE
		
	elif [ $choice -eq 3 ]; then
		install_LXDE
		
	elif [ $choice -eq 4 ]; then
		install_OPENBOX
		
	elif [ $choice -eq 5 ]; then
		install_XFCE4
		
	elif [ $choice -eq 6 ]; then
		install_AWESOME3
		
	elif [ $choice -eq 7 ]; then
		install_Enlightenment_e16
		
	elif [ $choice -eq 8 ]; then
		install_Enlightenment_e17
		
	elif [ $choice -eq 9 ]; then
		install_WMII
			
	elif [ "$choice" == "A" ]; then
		echo "\n\nInstalling ALL\n"

		install_GNOME
		install_KDE
		install_LXDE
		install_OPENBOX
		install_XFCE4
		install_AWESOME3
		install_Enlightenment_e16
		install_Enlightenment_e17
		install_WMII
		
		
	elif [ "$choice" == "M" ]; then
		echo ""
		echo ""
		echo "Return to Main Menu ...\n"
		sh install.sh
		
	elif [ $choice -eq "0" ]; then
		echo " exiting ...\n"
		exit 1
		
	else
		echo " Nothing done !!"
		echo ""
		echo "Retry again..."
		init
		#exit 1
	fi

	echo ""
	sh install.sh
}



init_dialog()
{


	W1(){ false;}
	W2(){ false;}
	W3(){ false;}
	W4(){ false;}
	W5(){ false;}
	W6(){ false;}
	W7(){ false;}
	W8(){ false;}
	W9(){ false;}
	W0(){ false;}
	WA(){ false;}
	WM(){ false;}
	
	{
	eval "$(
	dialog --separate-output --output-fd 3 \
	--checklist 'Please Enter which window manager you want to install ?' 0 0 0 \
	W1 GNOME				off \
	W2 KDE					off \
	W3 LXDE					off \
	W4 OPENBOX				on \
	W5 XFCE4				off \
	W6 AWESOME3 			off \
	W7 Enlightenment_e16	off \
	W8 Enlightenment_e17 	off \
	W8 WMII && DWM		 	on \
	WM return_Main_Menu		off \
	W0 exit 				off \
	3>&1 >&4 4>&- |
	sed 's/$/(){ true;}/')"
	} 4>&1

	
	if W0; then
		echo " exiting ...\n"
		exit 1
	fi
	
	if WM; then
		echo ""
		echo "#Return to Main Menu ...\n"
		sh install.sh
	fi
	
	update_all
	
	if W1; then
		$(install_GNOME)
	fi
	if W2; then
		$(install_KDE)
	fi
	if W3; then
		$(install_LXDE)
	fi
	if W4; then
		$(install_OPENBOX)
	fi
	if W5; then
		$(install_XFCE4)
	fi
	if W6; then
		$(install_AWESOME3)
	fi
	if W7; then
		$(install_Enlightenment_e16)
	fi
	if W8; then
		$(install_Enlightenment_e17)
	fi
	if W8; then
		$(install_WMII)
	fi
	
	sh install.sh

}



init_dialog_text()
{
	install_GNOME
	install_KDE
	install_LXDE
	install_OPENBOX
	install_XFCE4
	install_AWESOME3
	install_Enlightenment_e16
	install_Enlightenment_e17
}

#init
init_dialog
#init_dialog_text
