#!/bin/bash

APT_MIRROR_IP=192.168.0.3

if [ ! "$UID" = "0" ]
then
   echo "This script requires being run as root, eg: \$ sudo $0"
   exit
fi

# Modifying /etc/hosts to point to the mirror machines IP on the local network
if [ `grep -c "apt-mirror" /etc/hosts` == '0' ]
then
    echo -e "\n$APT_MIRROR_IP	apt-mirror" >> /etc/hosts
fi

cat > /etc/apt/sources.list << EOF
#deb cdrom:[Ubuntu 9.04 _Jaunty Jackalope_ - Release i386 (20090420.1)]/ jaunty main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.

# Intrepid (8.10)
# deb      http://apt-mirror/ubuntu/mirror/archive.ubuntu.com/ubuntu intrepid          main restricted universe multiverse
# deb      http://apt-mirror/ubuntu/mirror/archive.ubuntu.com/ubuntu intrepid-updates  main restricted universe multiverse
# deb      http://apt-mirror/ubuntu/mirror/archive.ubuntu.com/ubuntu intrepid-security main restricted universe multiverse
# deb-src  http://apt-mirror/ubuntu/mirror/archive.ubuntu.com/ubuntu intrepid          main restricted universe multiverse
# deb-src  http://apt-mirror/ubuntu/mirror/archive.ubuntu.com/ubuntu intrepid-updates  main restricted universe multiverse
# deb-src  http://apt-mirror/ubuntu/mirror/archive.ubuntu.com/ubuntu intrepid-security main restricted universe multiverse

# Jaunty (9.04)
deb http://apt-mirror/ubuntu/mirror/archive.ubuntu.com/ubuntu jaunty main restricted universe multiverse
deb http://apt-mirror/ubuntu/mirror/archive.ubuntu.com/ubuntu jaunty-updates main restricted universe multiverse
deb http://apt-mirror/ubuntu/mirror/archive.ubuntu.com/ubuntu jaunty-security main restricted universe multiverse
deb-src http://apt-mirror/ubuntu/mirror/archive.ubuntu.com/ubuntu jaunty main restricted universe multiverse
deb-src http://apt-mirror/ubuntu/mirror/archive.ubuntu.com/ubuntu jaunty-updates main restricted universe multiverse
deb-src http://apt-mirror/ubuntu/mirror/archive.ubuntu.com/ubuntu jaunty-security main restricted universe multiverse

## Uncomment the following two lines to add software from the 'backports'
## repository.
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
# deb http://cn.archive.ubuntu.com/ubuntu/ jaunty-backports main restricted universe multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jaunty-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu jaunty partner
# deb-src http://archive.canonical.com/ubuntu jaunty partner

# For XBMC (XBox Media Center)
deb http://ppa.launchpad.net/team-xbmc/jaunty-ppa/ubuntu jaunty main
deb-src http://ppa.launchpad.net/team-xbmc/jaunty-ppa/ubuntu jaunty main

## For TOR (The Onion Router)
deb http://mirror.noreply.org/pub/tor intrepid main
deb-src http://mirror.noreply.org/pub/tor intrepid main

# X-Server with bug fix for maximize slowness
deb http://ppa.launchpad.net/ubuntu-x-swat/xserver-no-backfill/ubuntu jaunty main
deb-src http://ppa.launchpad.net/ubuntu-x-swat/xserver-no-backfill/ubuntu jaunty main

# VLC with bug fix for opening media in 2nd window
deb http://ppa.launchpad.net/kow/ppa/ubuntu jaunty main
deb-src http://ppa.launchpad.net/kow/ppa/ubuntu jaunty main

# Cinelerra video editing
deb http://akirad.cinelerra.org akirad-jaunty main

EOF

apt-get update

# If have ATI graphics card
apt-get install xorg-driver-fglrx-dev xorg-driver-fglrx fglrx-amdcccle fglrx-kernel-source

# Installing ATI drivers manually:
# download https://www2.ati.com/drivers/linux/ati-driver-installer-9-4-x86.x86_64.run
# apt-get install build-essential cdbs fakeroot dh-make debhelper debconf libstdc++5 dkms
# sh ati-driver-installer-9-4-x86.x86_64.run --buildpkg Ubuntu/jaunty
# dpkg -i xorg-driver-fglrx_*.deb fglrx-kernel-source_*.deb fglrx-amdcccle_*.deb 

# Optional
apt-get install openssh-server amule xchat amsn
apt-get install samba

# Utility
apt-get install gscan2pdf
apt-get install pdftk

# Media related
apt-get install compizconfig-settings-manager
apt-get install epiphany-browser mozilla-thunderbird vlc flashplugin-installer miro foxyproxy
apt-get install xbmc

# China related
# apt-get install tor
# apt-get install privoxy

#
# Need to add line to /etc/privoxy/config as follows:
#
#      forward-socks4a   /               127.0.0.1:9050 .
#
# Suggest adding some sites to default.action as follows:
#
#      
#      {fragile}
#      .facebook.com
#      .youtube.com
#      .ytimg.com
#

apt-get install ubuntu-restricted-extras lame grip ardour audacity
apt-get install hydrogen cinelerracv


# Other packages
if [ -d /media/windows/Linux/General ]
then
    # wget http://www.truecrypt.org/download/truecrypt-6.2a-ubuntu-x86.tar.gz
    find /media/windows/Linux/General -name "*.deb" | while read deb_file
    do
        package=`dpkg --info $deb_file | grep "Package:" | cut -d ' ' -f 3`
	state=`aptitude show $package | grep "State:" | cut -d ' ' -f 2`
	echo "$package is $state."
	if [ ! $state == "installed" ]
	then
	    dpkg --install $deb_file
	fi
    done
fi



# Setup Nautilus scripts
ln -s Nautilus ~/.gnome2/nautilus-scripts


