<commit_before>#!/bin/bash
usage() {
	echo "Usage: $(basename $0) [options]
Automated Ubuntu/Lubuntu/Xubuntu setup for home and work computers.

Before executng this script for the first time:
- Install your flavor of Ubuntu in a PC or VM;
- Inside the VM, install also VBox Guest Additions (so you can share the host computer's directories) and activate USB devices.

-a  Execute all options below.
-r  Update PPA repositories.
-u  Execute upgrade and dist-upgrade.
-i  Install/remove packages.
-h  Help"
	exit $1
}

V_PPA=
V_UPDATE=
V_UPGRADE=
V_INSTALL_PACKAGES=
V_ALL=
V_SOMETHING_CHOSEN=
while getopts "ruifah" OPTION
do
	case $OPTION in
		r)	V_PPA=1
			V_SOMETHING_CHOSEN=1 ;;
		u)	V_UPGRADE=1
			V_SOMETHING_CHOSEN=1 ;;
		i)	V_INSTALL_PACKAGES=1
			V_SOMETHING_CHOSEN=1 ;;
		a)	V_ALL=1
			V_SOMETHING_CHOSEN=1 ;;
		h)	usage 1 ;;
		?)	usage 1 ;;
	esac
done

if [ -z $V_SOMETHING_CHOSEN ] ; then
	usage 2
fi

show_header() {
	echo '========================================================================================================================'
	echo $1
	echo '========================================================================================================================'
}

show_error() {
	if [ $? -gt 0 ] ; then
		echo -e "${COLOR_LIGHT_RED}There was an error while ${1}.\nFix them before continuing."
		exit
	fi
}

if [ -n "$V_ALL" ] || [ -n "$V_PPA" ] ; then
	V_OLD_IFS="$IFS"
	IFS='
'
	V_PPA_INSTALL='
ppa:atareao/atareao
ppa:cs-sniffer/cortina
ppa:danielrichter2007/grub-customizer
ppa:diesch/testing
ppa:gcstar/ppa
ppa:git-core/ppa
ppa:indicator-multiload/stable-daily
ppa:jcfp/ppa
ppa:pidgin-developers/ppa
ppa:tualatrix/ppa
ppa:webupd8team/java
ppa:webupd8team/jupiter
ppa:webupd8team/sublime-text-2
ppa:webupd8team/y-ppa-manager
ppa:yannubuntu/boot-repair
deb http://ppa.launchpad.net/geod/ppa-geod/ubuntu natty main
deb http://ppa.launchpad.net/midnightflash/ppa/ubuntu natty main
deb http://ppa.launchpad.net/stebbins/handbrake-releases/ubuntu oneiric main
'
	for V_PPA in $V_PPA_INSTALL ; do
		show_header "Adding repository $V_PPA"
		sudo add-apt-repository --yes $V_PPA
	done

	V_PPA_REMOVE='
ppa:aheck/ppa
ppa:recoll-backports/recoll-1.15-on
ppa:scopes-packagers/ppa
ppa:webupd8team/rhythmbox
deb http://pkg.jenkins-ci.org/debian binary/
'
	for V_PPA in $V_PPA_REMOVE ; do
		show_header "Removing repository $V_PPA"
		sudo add-apt-repository --remove --yes $V_PPA
	done

	IFS=$V_OLD_IFS

	V_MEDIBUNTU_FILE=/etc/apt/sources.list.d/medibuntu.list
	if [ ! -f "$V_MEDIBUNTU_FILE" ] ; then
		show_header "Adding Medibuntu repository $V_MEDIBUNTU_FILE"
		sudo -E wget --output-document=$V_MEDIBUNTU_FILE http://www.medibuntu.org/sources.list.d/$(lsb_release -cs).list
		sudo apt-get --quiet update
		sudo apt-get --yes --quiet --allow-unauthenticated install medibuntu-keyring
	fi

	V_GETDEB_INSTALLED="$(dpkg --get-selections | grep -i getdeb-repository)"
	if [ -z "$V_GETDEB_INSTALLED" ] ; then
		show_header 'Adding GetDeb repository'
		V_GETDEB_FILE=getdeb-repository_0.1-1~getdeb1_all.deb
		cd $G_DOWNLOAD_DIR
		wget http://archive.getdeb.net/install_deb/$V_GETDEB_FILE
		sudo dpkg -i $V_GETDEB_FILE
	fi

	# http://pkg.jenkins-ci.org/debian/
	show_header 'Adding Jenkins key'
	wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -

	# Install MongoDB on Ubuntu (10Gen)
	# http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
	show_header 'Installing MongoDB'
	sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
	echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" > /tmp/10gen.list
	sudo mv /tmp/10gen.list /etc/apt/sources.list.d/10gen.list

	V_UPDATE=1
fi

if [ -n "$V_ALL" ] || [ -n "$V_UPGRADE" ] ; then
	V_UPDATE=1
fi

if [ -n "$V_ALL" ] || [ -n "$V_UPDATE" ] ; then
	sudo apt-get update

	# Close the "Software Update" window after the update
	pkill -9 update-manager
fi

if [ -n "$V_ALL" ] || [ -n "$V_UPGRADE" ] ; then
	sudo apt-get --yes upgrade
	show_error 'upgrading some of the packages'

	sudo apt-get --yes dist-upgrade
	show_error 'upgrading some of the distribution packages'
fi

setup_python() {
	show_header 'Installing Python stuff'

	# Using type instead of which, according to this answer: http://stackoverflow.com/a/677212/1391315
	if [ -z "$(type -p pylint)" ] ; then
		cd $G_DOWNLOAD_DIR
		V_ZIP_BASENAME=pylint-0.25.2
		V_ZIP=$V_ZIP_BASENAME.tar.gz
		wget http://pypi.python.org/packages/source/p/pylint/$V_ZIP
		tar -xzvf $V_ZIP
		cd $V_ZIP_BASENAME/
		sudo python setup.py install
	fi

	if [ -z "$(type -p pep8)" ] ; then
		sudo pip install -U pep8
	fi

	V_PIP_NLTK=$(sudo pip freeze | grep nltk)
	if [ -z "$V_PIP_NLTK" ] ; then
		# http://nltk.org/install.html
		show_header 'Installing Python NLP'
		V_SETUPTOOLS_EGG_BASENAME=setuptools-0.6c11-py2.7.egg
		V_SETUPTOOLS_EGG=$G_DOWNLOAD_DIR/$V_SETUPTOOLS_EGG_BASENAME
		rm -v $V_SETUPTOOLS_EGG
		wget -O $V_SETUPTOOLS_EGG http://pypi.python.org/packages/2.7/s/setuptools/$V_SETUPTOOLS_EGG_BASENAME
		sudo sh $V_SETUPTOOLS_EGG
		sudo pip install -U numpy pyyaml nltk
		python -c 'import nltk
nltk.download()'
	fi
}

if [ -n "$V_ALL" ] || [ -n "$V_INSTALL_PACKAGES" ] ; then
	#------------------------------------------------------------------------------------------------------------------------
	# COMMON
	#------------------------------------------------------------------------------------------------------------------------
	show_header 'Installing common packages'
	V_SYSTEM='bash-completion nautilus-open-terminal nautilus-dropbox synaptic gdebi gdebi-core alien gparted mutt curl wget wmctrl xdotool gconf-editor dconf-tools grub-customizer boot-repair tree tasksel rcconf samba system-config-samba iftop bum'
	V_DESKTOP='xubuntu-desktop lubuntu-desktop indicator-weather indicator-workspaces python-wnck cortina gnome-do'
	V_DEV='sublime-text-dev vim vim-gui-common exuberant-ctags meld'
	V_GIT='git git-core git-doc git-svn git-gui gitk'
	V_PYTHON='python-pip python-dev python-matplotlib'
	V_BROWSER='chromium-browser lynx-cur'
	V_VIRTUALBOX='virtualbox virtualbox-guest-x11 virtualbox-guest-utils virtualbox-qt'
	V_JAVA='openjdk-6-jre icedtea6-plugin'
	V_AUDIO='rhythmbox id3 id3tool id3v2 lame-doc easytag nautilus-script-audio-convert cd-discid cdparanoia flac lame mp3gain ruby-gnome2 ruby vorbisgain eyed3 python-eyed3 rubyripper gcstar'
	# lo-menubar
	# Libre Office menu bar
	# Some packages could not be installed. This may mean that you have
	# requested an impossible situation or if you are using the unstable
	# distribution that some required packages have not yet been created
	# or been moved out of Incoming.
	# The following information may help to resolve the situation:
	#
	# The following packages have unmet dependencies:<commit_msg>setup-ubuntu.sh: New VirtualBox PPA and package.<commit_after>#!/bin/bash
usage() {
	echo "Usage: $(basename $0) [options]
Automated Ubuntu/Lubuntu/Xubuntu setup for home and work computers.

Before executng this script for the first time:
- Install your flavor of Ubuntu in a PC or VM;
- Inside the VM, install also VBox Guest Additions (so you can share the host computer's directories) and activate USB devices.

-a  Execute all options below.
-r  Update PPA repositories.
-u  Execute upgrade and dist-upgrade.
-i  Install/remove packages.
-h  Help"
	exit $1
}

V_PPA=
V_UPDATE=
V_UPGRADE=
V_INSTALL_PACKAGES=
V_ALL=
V_SOMETHING_CHOSEN=
while getopts "ruifah" OPTION
do
	case $OPTION in
		r)	V_PPA=1
			V_SOMETHING_CHOSEN=1 ;;
		u)	V_UPGRADE=1
			V_SOMETHING_CHOSEN=1 ;;
		i)	V_INSTALL_PACKAGES=1
			V_SOMETHING_CHOSEN=1 ;;
		a)	V_ALL=1
			V_SOMETHING_CHOSEN=1 ;;
		h)	usage 1 ;;
		?)	usage 1 ;;
	esac
done

if [ -z $V_SOMETHING_CHOSEN ] ; then
	usage 2
fi

show_header() {
	echo '========================================================================================================================'
	echo $1
	echo '========================================================================================================================'
}

show_error() {
	if [ $? -gt 0 ] ; then
		echo -e "${COLOR_LIGHT_RED}There was an error while ${1}.\nFix them before continuing."
		exit
	fi
}

if [ -n "$V_ALL" ] || [ -n "$V_PPA" ] ; then
	V_OLD_IFS="$IFS"
	IFS='
'
	V_PPA_INSTALL='
ppa:atareao/atareao
ppa:cs-sniffer/cortina
ppa:danielrichter2007/grub-customizer
ppa:diesch/testing
ppa:gcstar/ppa
ppa:git-core/ppa
ppa:indicator-multiload/stable-daily
ppa:jcfp/ppa
ppa:pidgin-developers/ppa
ppa:tualatrix/ppa
ppa:webupd8team/java
ppa:webupd8team/jupiter
ppa:webupd8team/sublime-text-2
ppa:webupd8team/y-ppa-manager
ppa:yannubuntu/boot-repair
deb http://download.virtualbox.org/virtualbox/debian precise contrib
deb http://ppa.launchpad.net/geod/ppa-geod/ubuntu natty main
deb http://ppa.launchpad.net/midnightflash/ppa/ubuntu natty main
deb http://ppa.launchpad.net/stebbins/handbrake-releases/ubuntu oneiric main
'
	for V_PPA in $V_PPA_INSTALL ; do
		show_header "Adding repository $V_PPA"
		sudo add-apt-repository --yes $V_PPA
	done

	V_PPA_REMOVE='
ppa:aheck/ppa
ppa:recoll-backports/recoll-1.15-on
ppa:scopes-packagers/ppa
ppa:webupd8team/rhythmbox
deb http://pkg.jenkins-ci.org/debian binary/
'
	for V_PPA in $V_PPA_REMOVE ; do
		show_header "Removing repository $V_PPA"
		sudo add-apt-repository --remove --yes $V_PPA
	done

	IFS=$V_OLD_IFS

	V_MEDIBUNTU_FILE=/etc/apt/sources.list.d/medibuntu.list
	if [ ! -f "$V_MEDIBUNTU_FILE" ] ; then
		show_header "Adding Medibuntu repository $V_MEDIBUNTU_FILE"
		sudo -E wget --output-document=$V_MEDIBUNTU_FILE http://www.medibuntu.org/sources.list.d/$(lsb_release -cs).list
		sudo apt-get --quiet update
		sudo apt-get --yes --quiet --allow-unauthenticated install medibuntu-keyring
	fi

	V_GETDEB_INSTALLED="$(dpkg --get-selections | grep -i getdeb-repository)"
	if [ -z "$V_GETDEB_INSTALLED" ] ; then
		show_header 'Adding GetDeb repository'
		V_GETDEB_FILE=getdeb-repository_0.1-1~getdeb1_all.deb
		cd $G_DOWNLOAD_DIR
		wget http://archive.getdeb.net/install_deb/$V_GETDEB_FILE
		sudo dpkg -i $V_GETDEB_FILE
	fi

	# Oracle Virtual Box
	# https://www.virtualbox.org/wiki/Linux_Downloads
	wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add -

	# http://pkg.jenkins-ci.org/debian/
	show_header 'Adding Jenkins key'
	wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -

	# Install MongoDB on Ubuntu (10Gen)
	# http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
	show_header 'Installing MongoDB'
	sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
	echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" > /tmp/10gen.list
	sudo mv /tmp/10gen.list /etc/apt/sources.list.d/10gen.list

	V_UPDATE=1
fi

if [ -n "$V_ALL" ] || [ -n "$V_UPGRADE" ] ; then
	V_UPDATE=1
fi

if [ -n "$V_ALL" ] || [ -n "$V_UPDATE" ] ; then
	sudo apt-get update

	# Close the "Software Update" window after the update
	pkill -9 update-manager
fi

if [ -n "$V_ALL" ] || [ -n "$V_UPGRADE" ] ; then
	sudo apt-get --yes upgrade
	show_error 'upgrading some of the packages'

	sudo apt-get --yes dist-upgrade
	show_error 'upgrading some of the distribution packages'
fi

setup_python() {
	show_header 'Installing Python stuff'

	# Using type instead of which, according to this answer: http://stackoverflow.com/a/677212/1391315
	if [ -z "$(type -p pylint)" ] ; then
		cd $G_DOWNLOAD_DIR
		V_ZIP_BASENAME=pylint-0.25.2
		V_ZIP=$V_ZIP_BASENAME.tar.gz
		wget http://pypi.python.org/packages/source/p/pylint/$V_ZIP
		tar -xzvf $V_ZIP
		cd $V_ZIP_BASENAME/
		sudo python setup.py install
	fi

	if [ -z "$(type -p pep8)" ] ; then
		sudo pip install -U pep8
	fi

	V_PIP_NLTK=$(sudo pip freeze | grep nltk)
	if [ -z "$V_PIP_NLTK" ] ; then
		# http://nltk.org/install.html
		show_header 'Installing Python NLP'
		V_SETUPTOOLS_EGG_BASENAME=setuptools-0.6c11-py2.7.egg
		V_SETUPTOOLS_EGG=$G_DOWNLOAD_DIR/$V_SETUPTOOLS_EGG_BASENAME
		rm -v $V_SETUPTOOLS_EGG
		wget -O $V_SETUPTOOLS_EGG http://pypi.python.org/packages/2.7/s/setuptools/$V_SETUPTOOLS_EGG_BASENAME
		sudo sh $V_SETUPTOOLS_EGG
		sudo pip install -U numpy pyyaml nltk
		python -c 'import nltk
nltk.download()'
	fi
}

if [ -n "$V_ALL" ] || [ -n "$V_INSTALL_PACKAGES" ] ; then
	#------------------------------------------------------------------------------------------------------------------------
	# COMMON
	#------------------------------------------------------------------------------------------------------------------------
	show_header 'Installing common packages'
	V_SYSTEM='bash-completion nautilus-open-terminal nautilus-dropbox synaptic gdebi gdebi-core alien gparted mutt curl wget wmctrl xdotool gconf-editor dconf-tools grub-customizer boot-repair tree tasksel rcconf samba system-config-samba iftop bum'
	V_DESKTOP='xubuntu-desktop lubuntu-desktop indicator-weather indicator-workspaces python-wnck cortina gnome-do'
	V_DEV='sublime-text-dev vim vim-gui-common exuberant-ctags meld'
	V_GIT='git git-core git-doc git-svn git-gui gitk'
	V_PYTHON='python-pip python-dev python-matplotlib'
	V_BROWSER='chromium-browser lynx-cur'
	V_VIRTUALBOX='virtualbox-4.2 dkms virtualbox-guest-x11 virtualbox-guest-utils'
	V_JAVA='openjdk-6-jre icedtea6-plugin'
	V_AUDIO='rhythmbox id3 id3tool id3v2 lame-doc easytag nautilus-script-audio-convert cd-discid cdparanoia flac lame mp3gain ruby-gnome2 ruby vorbisgain eyed3 python-eyed3 rubyripper gcstar'
	# lo-menubar
	# Libre Office menu bar
	# Some packages could not be installed. This may mean that you have
	# requested an impossible situation or if you are using the unstable
	# distribution that some required packages have not yet been created
	# or been moved out of Incoming.
	# The following information may help to resolve the situation:
	#
	# The following packages have unmet dependencies:
{'fraction_non_alphanumeric': 0.17509051412020274, 'fraction_numerical': 0.013034033309196235, 'mean_word_length': 3.65016835016835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7342451', 'n_tokens_mistral': 5721, 'n_tokens_neox': 5122, 'n_words': 1197}