#!/bin/sh
# A small bash script for installing an XFCE build of Debian GNU/Linux Testing
# You should be logged in as root or be in a root session (./debian-testing-installer.sh)
#------------------------------------------------------------
clear
echo "
Welcome to omns' Debian GNU/Linux installer."
echo ""
echo "This shell script has been designed to run after a minimal"
echo "\"CLI\" netinstall installation of Debian Testing. The script"
echo "will attempt to configure the required repositories and" 
echo "install the necessary packages needed to transform a"
echo "Standard System Utilities install into a usable XFCE system."
echo "based on original howto here http://omnsproject.org/?p=72"
echo ""
echo -n "Run installer now? (Y|n) > "
read a
if [ "$a" = "y" ] || [ "$a" = "Y" ] || \
[ "$a" = "" ]; then
    #Add Debian Multimedia Repository Key
    #---------------------------
    clear
    echo "Adding Debian Multimedia Repository Key..."
    sleep 2s
    wget http://www.debian-multimedia.org/pool/main/d/debian-multimedia-keyring/debian-multimedia-keyring_2008.10.16_all.deb
    dpkg -i debian-multimedia-keyring_2008.10.16_all.deb
    echo ""
    echo "Debian Multimedia repository key set-up complete..."
    echo ""
    sleep 2s
    #Set Repositories
    #--------
    if [ -f /etc/apt/sources.list ]; then
        cp -f /etc/apt/sources.list /etc/apt/sources.list~prebuildscript
    fi
    echo "" > /etc/apt/sources.list
    echo "" >> /etc/apt/sources.list
    echo "deb http://ftp.debian.org/debian/ testing main contrib non-free" >> /etc/apt/sources.list
    echo "#deb-src ftp://ftp.debian.org/debian/ testing main contrib non-free" >> /etc/apt/sources.list
    echo "" >> /etc/apt/sources.list
    echo "deb http://security.debian.org/ testing/updates main non-free" >> /etc/apt/sources.list
    echo "deb-src http://security.debian.org/ testing/updates main non-free" >> /etc/apt/sources.list
    echo "" >> /etc/apt/sources.list
    echo "deb http://ftp.debian-multimedia.org testing main" >> /etc/apt/sources.list
    echo "" >> /etc/apt/sources.list
    sleep 2s
    #Update Repositories
    #---------------
    clear
    echo "Upgrading new repositories before install..."
    echo ""
    apt-get update
    echo ""
    echo "All packages updated..."
    echo ""
    sleep 2s
    #Perform Upgrade
    #---------------
    clear
    echo "Upgrading existing packages before install..."
    echo ""
    apt-get dist-upgrade -y --force-yes
    echo ""
    echo "All packages upgraded..."
    echo ""
    sleep 2s
    #Install desktop packages
    #------------------------------------
    clear
    echo "Installing desktop packages..."
    echo ""
    sleep 2s
    apt-get install -y xserver-xorg-core xorg alsa-base alsa-utils gdm snmp xfce4 ttf-bitstream-vera ttf-dejavu terminator wicd wireless-tools thunar-archive-plugin xarchiver xfce4-screenshooter geany vlc gimp hpijs tint2 conky f-spot inkscape scrot xfburn audacity gftp lame gtkpod-aac w64codecs exaile xchat lame gtk2-engines-murrine geany xscreensaver-gl-extra cups-pdf ristretto evince system-config-printer lxrandr firmware-iwlwifi firmware-ipw2x00
    echo ""
    echo "All packages installed..."
    echo ""
    sleep 2s
    #Set MOTD
    #--------
    if [ -f /etc/motd.tail ]; then
        cp -f /etc/motd.tail /etc/motd.tail~prebuildscript
    fi
    echo "" > /etc/motd.tail
    echo "" >> /etc/motd.tail
    echo "The programs included with this build of Debian GNU/Linux Testing are free software;" >> /etc/motd.tail
    echo "the exact distribution terms for each program are described in the" >> /etc/motd.tail
    echo "individual files in /usr/share/doc/*/copyright." >> /etc/motd.tail
    echo "" >> /etc/motd.tail
    echo "This build of Debian GNU/Linux Testing comes with ABSOLUTELY NO WARRANTY," >> /etc/motd.tail
    echo "to the extent permitted by applicable law." >> /etc/motd.tail
    echo "" >> /etc/motd.tail
    echo "More information about this Debian GNU/Linux Testing build can be found at:" >> /etc/motd.tail
    echo "http://omnsproject.org/" >> /etc/motd.tail
    echo "" >> /etc/motd.tail
    #Clean up downloaded packages
    #----------------------------
    clear
    echo "Clean up. A number of packages were downloaded during"
    echo "the set-up routine. These packages are no longer needed,"
    echo "please choose whether or not you would like to remove them."
    echo ""
    echo -n "Remove downloaded packages? (Y|n) > "
    read a
    if [ "$a" = "y" ] || [ "$a" = "Y" ] || \
    [ "$a" = "" ]; then
        echo ""
        echo "Performing \"apt-get clean\"..."
        sleep 1s
        apt-get clean
    else
        echo ""
        echo "Skipping package cleanup..."
        sleep 1s
    fi
    #Reduce number of tty's
    #----------------------
    clear
    echo "Would you like to reduce the number of active tty's"
    echo "from 6 to 2? If you are unsure, enter \"n\""
    echo ""
    echo -n "Reduce number of tty's? (Y|n) > "
    read a
    if [ "$a" = "y" ] || [ "$a" = "Y" ] || \
    [ "$a" = "" ]; then
        echo ""
        echo "Removing tty's 3-6..."
        sleep 1s
        sed -i 's/tty\[1-6\]/tty\[1-2\]/g' /etc/default/console-setup
        sed -i 's/^[a-Z]/#&/g' /etc/event.d/tty3
        sed -i 's/^[a-Z]/#&/g' /etc/event.d/tty4
        sed -i 's/^[a-Z]/#&/g' /etc/event.d/tty5
        sed -i 's/^[a-Z]/#&/g' /etc/event.d/tty6
        echo "tty removal complete..."
        sleep 3s
    else
        echo ""
        echo "Skipping tty removal..."
        sleep 1s
    fi
    #Download and install the Adobe Flash Plugin
    #---------------------------
    clear
    echo "Would you like install the Adobe Flash Plugin"
    echo "If not, enter \"n\""
    echo ""
    echo -n "install the Adobe Flash Plugin? (Y|n) > "
    read a
    if [ "$a" = "y" ] || [ "$a" = "Y" ] || \
    [ "$a" = "" ]; then
        echo ""
        echo "Installing the Adobe Flash Plugin..."
        echo ""
        sleep 2s
        apt-get install -y flashplugin-nonfree
        sleep 3s
        echo ""
        echo "Adobe Flash Plugin set-up complete..."
        echo ""
        sleep 3s
    else
        echo ""
        echo "Skipping Adobe Flash Plugin installation..."
        sleep 1s
    fi
    #Download and install Java Runtime Environment
    #---------------------------
    clear
    echo "Would you like install the Java Runtime Environment?"
    echo "If not, enter \"n\""
    echo ""
    echo -n "install the Java runtime environment? (Y|n) > "
    read a
    if [ "$a" = "y" ] || [ "$a" = "Y" ] || \
    [ "$a" = "" ]; then
        echo ""
        echo "Installing the Java Runtime Environment..."
        echo ""
        sleep 2s
        apt-get install -y sun-java6-jre
        sleep 3s
        echo ""
        echo "Java Runtime Environment set-up complete..."
        echo ""
        sleep 3s
    else
        echo ""
        echo "Skipping Java Runtime Environment..."
        sleep 1s
    fi
    #Download and install Iceweasel 3.5 or 3.0
    #---------------------------
    clear
    echo "Would you like install the Iceweasel 3.5"
    echo "from the unstable repos?"
    echo "If you'd prefer 3.0, enter \"n\""
    echo ""
    echo -n "install the Icewesel 3.5? (Y|n) > "
    read a
    if [ "$a" = "y" ] || [ "$a" = "Y" ] || \
    [ "$a" = "" ]; then
        echo ""
        echo "Installing the Iceweasel 3.5..."
        echo ""
  	sleep 2s
	echo deb http://ftp.fr.debian.org/debian unstable main > /etc/apt/sources.list.d/testing.list
	echo 'APT::Default-Release "testing";' > /etc/apt/apt.conf.d/default 
	sleep 2s
	apt-get update
        sleep 2s
        apt-get install -y iceweasel/unstable
        sleep 3s
        echo ""
        echo "Iceweasel 3.5 set-up complete..."
        echo ""
        sleep 3s
    else
        echo ""
        echo "Installing Iceweasel 3.0.1É"
	sleep 2s
	apt-get install -y iceweasel
        sleep 1s
    fi
    #Download and install OpenOffice 3.1 debs directly from the OpenOffice site
    #---------------------------
    clear
    echo "Would you like install the English version of OpenOffice 3.1"
    echo "using debs directly from the OpenOffice site?"
    echo "If you prefer the debs from the repos, enter \"n\""
    echo ""
    echo -n "install OpenOffice 3.1? (Y|n) > "
    read a
    if [ "$a" = "y" ] || [ "$a" = "Y" ] || \
    [ "$a" = "" ]; then
        echo ""
        echo "Installing OpenOffice 3.1..."
        echo ""
        sleep 2s
        wget http://download.services.openoffice.org/files/stable/3.1.1/OOo_3.1.1_LinuxX86-64_install_en-US_deb.tar.gz
	tar -zxvf OOo_3.1.1_LinuxX86-64_install_en-US_deb.tar.gz
        cd OOO*/DEBS
	dpkg -i *.deb
	sleep 1s
	cd desktop-integration
	dpkg -i *.deb
        sleep 3s
        echo ""
        echo "OpenOffice 3.1 set-up complete..."
        echo ""
        sleep 3s
    else
        echo ""
        echo "Skipping OpenOffice 3.1 installation..."
        sleep 1s
    fi
    #Prompt for reboot
    #-----------------
    clear
    echo "Installation complete! Thank you for using this install script for your Debian GNU/Linux Testing build."
    echo "You will now need to reboot your system."
    echo ""
    echo -n "Reboot now? (Y|n) > "
    read a
    if [ "$a" = "y" ] || [ "$a" = "Y" ] || \
    [ "$a" = "" ]; then
        echo "Goodbye, hoping all went well :)"
        echo "Rebooting..."
        sleep 4s
        reboot
        exit
    else
        echo "Issue the following command as root to reboot:"
        echo ""
        echo "reboot"
        echo ""
        echo "Goodbye! :)"
    fi
fi
exit
