#!/bin/bash
#GLOBAL VARS
SUGAR_DIR=/usr/share/tuquito

#Script de instalación de Sugar en Tuquito 4.1

if [ -d $SUGAR_DIR ]; then
	cd $SUGAR_DIR
else
	sudo mkdir $SUGAR_DIR; cd $SUGAR_DIR
fi
##Actualizando##
sudo aptitude update
sudo aptitude -y upgrade
sudo aptitude install -y git jhbuild
cd $SUGAR_DIR
sudo git clone git://git.sugarlabs.org/sugar-jhbuild/mainline.git sugar-jhbuild
sudo chmod 777 /usr/share/tuquito/sugar-jhbuild -R
###Aplicar Parche####
echo "Aplicando parche..."
cd $SUGAR_DIR/sugar-jhbuild
wget http://acercadelaeducacion.com.ar/scripts/0001-adding-support-for-Tuquito-GNU-Linux-distribution.patch
git apply 0001-adding-support-for-Tuquito-GNU-Linux-distribution.patch
###Instalar las dependencias para compilar###
echo "Instalando Dependencias para compilar"
sudo aptitude install -y libgtk2.0-dev libdbus-glib-1-dev libxml2-dev libpopt-dev python-dev libtool intltool python-gconf python-gnome2-dev python2.7-dev python-gtk2-dev python-gnome2-dev libgnome-desktop-dev libgnomecups1.0-dev libwnck-dev librsvg2-dev gtk-doc-tools libtelepathy-glib-dev libasound2-dev icon-slicer  xulrunner-dev libcroco3-dev libtelepathy-glib-dev icon-naming-utils shtool libgconf2-dev abiword espeak espeak-data libabiword-2.8-dev libtelepathy-glib0 libdbus-glib-1-dev metacity pep8 pylint python-abiword python-evince python-rsvg python-telepathy python-wnck python-xklavier telepathy-gabble telepathy-salut xulrunner-1.9.2
###Instalar dependencias sugar
echo "Instalando dependencias de sugar"
cd $SUGAR_DIR/sugar-jhbuild
./sugar-jhbuild depscheck -s | sudo xargs aptitude -y install
###Instalar python_xpcom.deb###
echo "Instalando python_xpcom.deb"
wget http://acercadelaeducacion.com.ar/scripts/python_xpcom.deb
sudo dpkg -i python_xpcom.deb
rm -rf python_xpcom.deb
###Actualizando y compilando sugar###
echo "Actualizando y compilando sugar"
./sugar-jhbuild update
./sugar-jhbuild build
###Instalando en entorno###
echo "Instalando en el entorno"
echo "~/sugar-jhbuild/sugar-jhbuild run sugar-emulator" | sudo tee /usr/bin/sugar-desktop
echo "~/sugar-jhbuild/sugar-jhbuild run sugar-emulator --fullscreen"|sudo tee /usr/bin/sugar-session
sudo chmod +x /usr/bin/sugar-session
sudo chmod +x /usr/bin/sugar-desktop
sudo chmod 777 /usr/share/tuquito/sugar-jhbuild -R
cd $SUGAR_DIR/sugar-jhbuild/
wget http://acercadelaeducacion.com.ar/scripts/sugar.png
sudo mv sugar.png /usr/share/icons/sugar.png
wget http://acercadelaeducacion.com.ar/scripts/SUGAR.desktop
sudo mkdir /etc/skel/Desktop
sudo mv SUGAR.desktop /etc/skel/Desktop/
cp -f /etc/skel/Desktop/SUGAR.desktop ~/Escritorio
ln -s /usr/share/tuquito/sugar-jhbuild/ ~/sugar-jhbuild
sudo sudo ln -s $SUGAR_DIR/sugar-jhbuild/ /etc/skel/sugar-jhbuild
sudo ln -s /etc/skel/Desktop /etc/skel/Escritorio
wget http://acercadelaeducacion.com.ar/scripts/sugar.desktop
sudo mv sugar.desktop /usr/share/xsessions/
wget http://acercadelaeducacion.com.ar/scripts/sugar-menu.desktop
sudo mv sugar-menu.desktop /usr/share/applications/
sudo chmod 777 /usr/share/tuquito/sugar-jhbuild -R
clear
echo "Sugar instalado, para correrlo tipea en una terminal sugar-session"
