#! /bin/sh 

## APPLICATION
# see http://wiki.archlinux.org/index.php/Useful_Applications
# http://www.linuxpedia.fr/doku.php/archlinux/installation

# on update la base 
###########################################
#pacman -Sy --noconfirm

#PAC="yaourt"
PAC="pacman"


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



clean_all()
{
	# on vide le cache
	echo ""
	echo "# - on clean le tout"
	echo $PAC -Scc --noconfirm
}

install_Multimedia()
{
	echo ""
	echo "# - Multimedia"
	echo $PAC -S transcode libtheora jasper codecs flac libdvdcss libdvdread xvidcore musepack-tools --noconfirm
}

install_Web_Browser()
{
	echo ""
	echo "# - Web Browser"
	echo $PAC -S firefox firefox-i18n thunderbird thunderbird-i18n --noconfirm
	echo yaourt -S prism-0.9
	echo $PAC -S opera pidgin --noconfirm
}

install_Dev()
{
	echo ""
	echo "# - Development"
	echo $PAC -S geany gvim gftp terminator --noconfirm
	echo $PAC -S virtualbox --noconfirm
	echo $PAC -S lighttpd php php-xdebug --noconfirm
	echo yaourt -S sqldeveloper
}

install_Plugins()
{
	# Flash Quicktime, Realplayer ...
	echo ""
	echo "# - Plugins, codecs"
	echo $PAC -S flashplugin codecs gecko-mediaplayer --noconfirm
}
install_Video_Players()
{
	# video players
	echo ""
	echo "# - VIDEO PLAYERS"
	echo $PAC -S mplayer mplayer-plugin mplayer-skins vlc --noconfirm
}

install_Dvd()
{
	echo ""
	echo "# - DVD"
	echo $PAC -S xine-ui libdvdcss --noconfirm
}

install_Zip()
{
	echo ""
	echo "# - DVD"
	echo $PAC -S bzip2, gzip, unrar, zip, unzip, lzop --noconfirm
}




init()
{
	echo ""
	echo ""
	echo "Please Enter which apps packages you want to install ?"
	echo "----------------"
	echo "   1- Multimedia"
	echo "   2- Web Browser"
	echo "   3- Plugins, codecs"
	echo "   4- VIDEO PLAYERS"
	echo "   5- DVD"
	echo "   6- OP"
	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_Multimedia
		
	elif [ $choice -eq 2 ]; then
		update_all
		install_Web_Browser
		clean_all
		
	elif [ $choice -eq 3 ]; then
		update_all
		install_Plugins
		clean_all
		
	elif [ $choice -eq 4 ]; then
		update_all
		install_Video_Players
		clean_all
		
	elif [ $choice -eq 5 ]; then
		update_all
		install_Dvd
		clean_all
		
	elif [ "$choice" == "A" ]; then
		update_all
		install_Multimedia
		install_Web_Browser
		install_Plugins
		install_Video_Players
		install_Dvd
		install_Dev
		clean_all
		
	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()
{

	A1(){ false;}
	A2(){ false;}
	A3(){ false;}
	A4(){ false;}
	A5(){ false;}
	A6(){ false;}
	A7(){ false;}
	A8(){ false;}
	A9(){ false;}
	A0(){ false;}
	AA(){ false;}
	AM(){ false;}
	
	{
	eval "$(
	dialog --separate-output --output-fd 3 \
	--checklist 'Please Enter which apps packages you want to install ?' 0 0 0 \
	A1 Multimedia		on \
	A2 Web_Browser		on \
	A3 Plugins,_codecs	on \
	A4 VIDEO_PLAYERS	on \
	A5 DVD				on \
	A6 DEV 				on \
	A7 Zip				on \
	AM return_Main_Menu	off \
	A0 exit 			off \
	3>&1 >&4 4>&- |
	sed 's/$/(){ true;}/')"
	} 4>&1

	if A0; then
		echo "#exiting ...\n"
		exit 1
	fi
	
	if AM; then
		echo ""
		echo ""
		echo "#Return to Main Menu ...\n"
		sh install.sh
	fi
	
	$(update_all)
	
	if A1; then
		$(install_Multimedia)
	fi
	if A2; then
		$(install_Web_Browser)
	fi
	if A3; then
		$(install_Plugins)
	fi
	if A4; then
		$(install_Video_Players)
	fi
	if A5; then
		$(install_Dvd)
	fi
	if A6; then
		$(install_Dev)
	fi
	if A7; then
		$(install_Zip)
	fi
	


	$(clean_all)
	
	sh install.sh

}


init_dialog_text()
{
	update_all
	install_Multimedia 
	install_Web_Browser 
	install_Plugins 
	install_Video_Players 
	install_Dvd 
	install_Dev
	install_Zip
	clean_all
}

#init
init_dialog
#init_dialog_text

