#!/bin/bash
if [ $UID -gt 0 ]; then
 echo "Debes ejecutar este archivo como root.";
else

# Hacemos una copia de seguridad de xorg.conf y del sources list

 cp /etc/apt/sources.list /etc/apt/sources.list.backup.beryl-script
 cp /etc/X11/xorg.conf /etc/X11/xorg.conf.backup.beryl-script

# Instalamos los ultimos drivers de ATI

 echo "deb http://www.albertomilone.com/drivers/edgy/latest/32bit binary/" >> /etc/apt/sources.list
 wget http://albertomilone.com/drivers/tseliot.asc -O- | apt-key add -
 aptitude -y update && aptitude -y install linux-restricted-modules-$(uname -r) xorg-driver-fglrx

# Autoconfiguramos el xorg.conf
 sudo depmod -a
 aticonfig --initial
 aticonfig --overlay-type=Xv
 echo "Section \"Extensions\"
   Option \"Composite\" \"0\" 
EndSection" >> /etc/X11/xorg.conf

# Instalamos Beryl y XGL

 echo "deb http://ubuntu.beryl-project.org/ edgy main" >> /etc/apt/sources.list
 wget http://ubuntu.beryl-project.org/root@lupine.me.uk.gpg -O- | apt-key add -
 aptitude -y update && aptitude -y dist-upgrade
 aptitude -y install xserver-xgl beryl emerald emerald-themes

# Creamos un archivo para lanzar XGL y una entrada en el menú de sesiones para iniciar XGL

 echo "#!/bin/sh 
Xgl :1 -fullscreen -ac -accel xv:pbuffer -accel glx:pbuffer &
DISPLAY=:1
exec gnome-session" >> /usr/bin/startxgl.sh
 chmod +x /usr/bin/startxgl.sh

 echo "[Desktop Entry]
Encoding=UTF-8
Name=Xgl
Comment=Start an Xgl Session
Exec=/usr/bin/startxgl.sh
Icon=
Type=Application" >> /usr/share/xsessions/xgl.desktop

# Creamos un icono en el escritorio para ejecutar beryl, una entrada en el menu de aplicaciones, y hacemos que se inicie beryl-manager al iniciar Ubuntu

echo "[Desktop Entry]
 Encoding=UTF-8
 Name=Beryl Manager
 GenericName=3D Window Manager
 Comment=Beryl Manager daemon
 Icon=/usr/share/icons/hicolor/scalable/apps/beryl-manager.svg
 Exec=beryl-manager
 Terminal=false
 Type=Application
 Categories=GTK;GNOME;Application;Utility;
 StartupNotify=true
 X-Ubuntu-Gettext-Domain=beryl-manager" > /etc/xdg/autostart/beryl-manager.desktop
 cp /etc/xdg/autostart/beryl-manager.desktop /usr/share/applications/beryl-manager.desktop
 cp /etc/xdg/autostart/beryl-manager.desktop ~/Desktop/beryl-manager.desktop

 echo -e "\n\nBeryl se ha instalado.\n\nPara ejecutar Beryl al inicio de Ubuntu, añade beryl-manager a tus programas de inicio (Sistema > Preferencias > Sesiones, y haz clic en\nla pestaña \"Programas de inicio\"). Ahora debes reiniciar tu equipo completamente y seleccionar \"Optiones - Sesiones - gnome-xgl\" en la pantalla de inicio de usuario para iniciar Ubuntu con XGL.\n\nSe han creado copias de seguridad de /etc/apt/sources.list y /etc/X11/xorg.conf en:\n    /etc/apt/sources.list.backup.beryl-script\n    /etc/X11/xorg.conf.backup\n\n Si notas que al iniciar XGL las barras se ven algo feas añade gnome-settings-daemon a los programas de inicio como hiciste con beryl-manager"
fi;

