#!/bin/bash

##    Skryt konfiguracyjny dla Ubuntu.
##    Copyright (C) 2009 Piotr Miros (Epul), ubuntu.pl team.
##
##    This program is free software: you can redistribute it and/or modify
##    it under the terms of the GNU General Public License as published by
##    the Free Software Foundation, either version 3 of the License, or
##    (at your option) any later version.
##
##    This program is distributed in the hope that it will be useful,
##    but WITHOUT ANY WARRANTY; without even the implied warranty of
##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##    GNU General Public License for more details.
##
##    You should have received a copy of the GNU General Public License
##    along with this program. If not, see <http://www.gnu.org/licenses/>.

	repo() {
sudo cp -p /etc/apt/sources.list /etc/apt/sources.list_backup
echo "deb http://archive.ubuntu.com/ubuntu/ karmic main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ karmic main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ karmic-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ karmic-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ karmic-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ karmic-backports main restricted universe multiverse
# deb http://archive.ubuntu.com/ubuntu/ karmic-proposed main restricted universe multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ karmic-proposed main restricted universe multiverse
deb http://archive.canonical.com/ubuntu karmic partner
deb-src http://archive.canonical.com/ubuntu karmic partner
deb http://security.ubuntu.com/ubuntu karmic-security main restricted universe multiverse
deb-src http://security.ubuntu.com/ubuntu karmic-security main restricted universe multiverse
deb http://packages.medibuntu.org/ karmic free non-free
deb-src http://packages.medibuntu.org/ karmic free non-free
deb http://archive.getdeb.net/ubuntu karmic-getdeb apps" | sudo tee /etc/apt/sources.list > /dev/null
wget -q http://packages.medibuntu.org/medibuntu-key.gpg -O- | sudo apt-key add -
wget -O- http://archive.getdeb.net/getdeb-archive.key | sudo apt-key add -
sudo apt-get update
	}

	aktu() {
sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get -y dist-upgrade
	}

	twea() {
sudo apt-get -y --force-yes install ubuntu-tweak
	}

	mult() {
if [ "i686" = `uname -m` ]; then
sudo apt-get -y --force-yes install gstreamer0.10-ffmpeg gstreamer0.10-pitfdll gstreamer0.10-plugins-bad gstreamer0.10-plugins-bad-multiverse gstreamer0.10-plugins-ugly gstreamer0.10-plugins-ugly-multiverse libdvdnav4 libdvdread4 libdvdcss2 libxine1-ffmpeg w32codecs flashplugin-nonfree sun-java6-plugin sun-java6-fonts rar unrar p7zip-full p7zip-rar unace ttf-mscorefonts-installer ttf-liberation
else
sudo apt-get -y --force-yes install gstreamer0.10-ffmpeg gstreamer0.10-plugins-bad gstreamer0.10-plugins-bad-multiverse gstreamer0.10-plugins-ugly gstreamer0.10-plugins-ugly-multiverse libdvdnav4 libdvdread4 libdvdcss2 libxine1-ffmpeg w64codecs sun-java6-plugin sun-java6-fonts rar unrar p7zip-full p7zip-rar unace ttf-mscorefonts-installer ttf-liberation
cd /tmp
wget http://download.macromedia.com/pub/labs/flashplayer10/libflashplayer-10.0.32.18.linux-x86_64.so.tar.gz
tar xzf libflashplayer-10.0.32.18.linux-x86_64.so.tar.gz
sudo mv libflashplayer.so /usr/lib/mozilla/plugins
rm libflashplayer-10.0.32.18.linux-x86_64.so.tar.gz
fi
	}

	tote() {
gconftool-2 -t bool -s /apps/totem/autoload_subtitles true
gconftool-2 -t str -s /apps/totem/subtitle_encoding "WINDOWS-1250"
	}

	mpla() {
sudo apt-get -y --force-yes install mplayer
rm ~/.mplayer
mplayer > /dev/null
cp ~/.mplayer/config ~/.mplayer/config_backup
echo "# Write your default config options here!

font = /usr/share/fonts/truetype/freefont/FreeSans.ttf
subcp = cp1250" > ~/.mplayer/config
	}

	pidg() {
sudo apt-get -y purge empathy && sudo apt-get -y --force-yes install pidgin
	}

	napr() {
clear; echo -ne "\033[1mDo you want to repair broken packages? (Y)es/(N)o: \033[0m"
read tn
case $tn in
y | Y | yes | Yes | YES ) clear
sudo apt-get install -f && sudo dpkg --configure -a
clear; echo -ne "\033[1mDone. Press ENTER to return to the main menu\033[0m"; read; menu ;;
n | N | no | No | NO ) clear
echo -ne "\033[1mStopped. Press enter to return to main menu\033[0m"; read; menu ;;
* ) clear
echo -ne "\033[1mInvalid command\033[0m"; echo -ne "\033[1m 3...\033[0m"; sleep 0.5; echo -ne "\033[1m 2...\033[0m"; sleep 0.5; echo -ne "\033[1m 1...\033[0m"; sleep 0.5 ;;
esac
napr
	}

	usun() {
clear; echo -ne "\033[1mDo you want to remove unnecessary packages, to free up disk space on your
hard disk? (Y)es/(N)o: \033[0m"
read tn
case $tn in
y | Y | yes | Yes | YES ) clear
sudo apt-get autoremove --purge && sudo apt-get clean && sudo apt-get autoclean; sudo rm -R -d /var/cache/apt/archives && sudo mkdir /var/cache/apt/archives && sudo mkdir /var/cache/apt/archives/partial
clear; echo -ne "\033[1mDone. Press ENTER to return to the main menu\033[0m"; read; menu ;;
n | N | no | No | NO ) clear
echo -ne "\033[1mStopped. Press enter to return to main menu\033[0m"; read; menu ;;
* ) clear
echo -ne "\033[1mInvalid command\033[0m"; echo -ne "\033[1m 3...\033[0m"; sleep 0.5; echo -ne "\033[1m 2...\033[0m"; sleep 0.5; echo -ne "\033[1m 1...\033[0m"; sleep 0.5 ;;
esac
usun
	}

	auto() {
clear; echo -e "\033[1mThe script will automatically:\033[0m"
echo "- add the recommended repositories,
- download and install the latest updates,
- install Ubuntu Tweak,
- install codecs, web browser plugins (Java, Flash),
  additional support for archives (RAR, 7-Zip) and additional fonts
- install MPlayer,
- set MPlayer and Totem character encoding to Central / Eastern European (Windows-1250),
  you can disable this by removing lines: 64 and 69,70,71,72,73,74,75,
- uninstall Empathy and replaces it with Pidgin"
echo ""
echo -ne "\033[1mDo you want to automatically configure Ubuntu? (Y)es/(N)o: \033[0m"
read tn
case $tn in
y | Y | yes | Yes | YES ) clear
repo; aktu; twea; mult; tote; mpla; pidg
clear; echo -ne "\033[1mDone. Press ENTER to return to the main menu\033[0m"; read; menu ;;
n | N | no | No | NO ) clear
echo -ne "\033[1mStopped. Press enter to return to main menu\033[0m"; read; menu ;;
* ) clear
echo -ne "\033[1mInvalid command\033[0m"; echo -ne "\033[1m 3...\033[0m"; sleep 0.5; echo -ne "\033[1m 2...\033[0m"; sleep 0.5; echo -ne "\033[1m 1...\033[0m"; sleep 0.5 ;;
esac
auto
	}

	manu() {
clear; echo -ne "\033[1mDo you want to be asked when installing each application?
(Y)es/(N)o: \033[0m"
read tn
case $tn in
y | Y | yes | Yes | YES ) clear
manu0 ;;
n | N | no | No | NO ) clear
echo -ne "\033[1mStopped. Press enter to return to main menu\033[0m"; read; menu ;;
* ) clear
echo -ne "\033[1mInvalid command\033[0m"; echo -ne "\033[1m 3...\033[0m"; sleep 0.5; echo -ne "\033[1m 2...\033[0m"; sleep 0.5; echo -ne "\033[1m 1...\033[0m"; sleep 0.5 ;;
esac
manu
	}

	manu0() {
clear; echo -ne "\033[1mDo you want to add extra repositories? (Y)es/(N)o: \033[0m"
read tn
case $tn in
y | Y | yes | Yes | YES ) clear
repo
clear; echo -ne "\033[1mDone. Press ENTER to continue\033[0m"; read; manu1 ;;
n | N | no | No | NO ) clear
manu1 ;;
* ) clear
echo -ne "\033[1mInvalid command\033[0m"; echo -ne "\033[1m 3...\033[0m"; sleep 0.5; echo -ne "\033[1m 2...\033[0m"; sleep 0.5; echo -ne "\033[1m 1...\033[0m"; sleep 0.5 ;;
esac
manu0
	}

	manu1() {
clear; echo -ne "\033[1mDo you want to install the latest updates? (Y)es/(N)o: \033[0m"
read tn
case $tn in
y | Y | yes | Yes | YES ) clear
aktu
clear; echo -ne "\033[1mDone. Press ENTER to continue\033[0m"; read; manu2 ;;
n | N | no | No | NO ) clear
manu2 ;;
* ) clear
echo -ne "\033[1mInvalid command\033[0m"; echo -ne "\033[1m 3...\033[0m"; sleep 0.5; echo -ne "\033[1m 2...\033[0m"; sleep 0.5; echo -ne "\033[1m 1...\033[0m"; sleep 0.5 ;;
esac
manu1
	}

	manu2() {
clear; echo -ne "\033[1mDo you want to install Ubuntu Tweak? (Y)es/(N)o: \033[0m"
read tn
case $tn in
y | Y | yes | Yes | YES ) clear
twea
clear; echo -ne "\033[1mDone. Press ENTER to continue\033[0m"; read; manu3 ;;
n | N | no | No | NO ) clear
manu3 ;;
* ) clear
echo -ne "\033[1mInvalid command\033[0m"; echo -ne "\033[1m 3...\033[0m"; sleep 0.5; echo -ne "\033[1m 2...\033[0m"; sleep 0.5; echo -ne "\033[1m 1...\033[0m"; sleep 0.5 ;;
esac
manu2
	}

	manu3() {
clear; echo -ne "\033[1mDo you want to install multimedia codecs, browser plug-ins
(Java, Flash), additional support for archives (RAR, 7-Zip) 
and additional fonts? (Y)es/(N)o: \033[0m"
read tn
case $tn in
y | Y | yes | Yes | YES ) clear
mult
clear; echo -ne "\033[1mDone. Press ENTER to continue\033[0m"; read; manu4 ;;
n | N | no | No | NO ) clear
manu4 ;;
* ) clear
echo -ne "\033[1mInvalid command\033[0m"; echo -ne "\033[1m 3...\033[0m"; sleep 0.5; echo -ne "\033[1m 2...\033[0m"; sleep 0.5; echo -ne "\033[1m 1...\033[0m"; sleep 0.5 ;;
esac
manu3
	}

	manu4() {
clear; echo -ne "\033[1mDo you want to add Central / Eastern European character encoding 
to Totem? (Y)es/(N)o: \033[0m"
read tn
case $tn in
y | Y | yes | Yes | YES ) clear
tote
clear; echo -ne "\033[1mDone. Press ENTER to continue\033[0m"; read; manu5 ;;
n | N | no | No | NO ) clear
manu5 ;;
* ) clear
echo -ne "\033[1mInvalid command\033[0m"; echo -ne "\033[1m 3...\033[0m"; sleep 0.5; echo -ne "\033[1m 2...\033[0m"; sleep 0.5; echo -ne "\033[1m 1...\033[0m"; sleep 0.5 ;;
esac
manu4
	}

	manu5() {
clear; echo -ne "\033[1mDo you want to install MPlayer and set it's character encoding 
to Central / Eastern European? (Y)es/(N)o: \033[0m"
read tn
case $tn in
y | Y | yes | Yes | YES ) clear
totem
clear; echo -ne "\033[1mDone. Press ENTER to go to the last step\033[0m"; read; manu6 ;;
n | N | no | No | NO ) clear
manu6 ;;
* ) clear
echo -ne "\033[1mInvalid command\033[0m"; echo -ne "\033[1m 3...\033[0m"; sleep 0.5; echo -ne "\033[1m 2...\033[0m"; sleep 0.5; echo -ne "\033[1m 1...\033[0m"; sleep 0.5 ;;
esac
manu5
	}

	manu6() {
clear; echo -ne "\033[1mDo you want to uninstall the Empathy instant messanger and replace it (install) with
Pidgin? (Y)es/(N)o: \033[0m"
read tn
case $tn in
y | Y | yes | Yes | YES ) clear
pidg
clear; echo -ne "\033[1mDone. Everything has been set up. Press ENTER to return to the main
menu\033[0m"; read; menu ;;
n | N | no | No | NO ) clear
echo -ne "\033[1mEnd of configuration / installation. Press ENTER to return to the main menu\033[0m"; read; menu ;;
* ) clear
echo -ne "\033[1mInvalid command\033[0m"; echo -ne "\033[1m 3...\033[0m"; sleep 0.5; echo -ne "\033[1m 2...\033[0m"; sleep 0.5; echo -ne "\033[1m 1...\033[0m"; sleep 0.5 ;;
esac
manu6
	}

	oskr() {
clear; echo -ne "\033[1mVersion:\033[0m"; echo " 0.5"
echo ""
echo -e "\033[1mThe script authors:\033[0m"
echo "- Piotr Miros 'Epul' - ubuntu.pl."
echo ""
echo -e "\033[1mFor any issues with Ubuntu, visit:\033[0m"
echo -ne "- http://forum.ubuntu.pl/ - Polish,
- http://ubuntuforums.org/ - the official Ubuntu forums
- http://ubuntuguide.org/ 
- https://wiki.ubuntu.com/
- http://www.debian.org/doc/
- http://www.google.pl/linux - Polish"
echo -ne "Translated into English by Andrew,
- www.webupd8.org"
echo ""
echo -ne "\033[1mReturn to the main menu? R(eturn)/E(xit)\033[0m"
read tn
case $tn in
y | Y | yes | Yes | YES | r | R | Return | RETURN ) clear
read; menu ;;
n | N | no | No | NO | e | E | Exit | EXIT ) clear
exit;;
* ) clear
esac
oskr

}

	menu() {
clear
echo -e "\033[1mConfiguring Ubuntu\033[0m"
echo "1. Automatic system configuration"
echo "2. Manual system configuration"
echo "3. Repair broken packages"
echo "4. Remove unnecessary packages, to free up disk space"
echo "5. Help for this script"
echo "0. Exit"
echo ""
echo -n "Select: "

read opt
	clear
	case "$opt" in

		1 ) auto ;;
		2 ) manu ;;
		3 ) napr ;;
		4 ) usun ;;
		5 ) oskr ;;
		0 ) exit 0 ;;
		* ) clear
echo -ne "\033[1mInvalid command\033[0m"; echo -ne "\033[1m 3...\033[0m"; sleep 0.5; echo -ne "\033[1m 2...\033[0m"; sleep 0.5; echo -ne "\033[1m 1...\033[0m"; sleep 0.5 ;;

	esac
menu
	}

echo -e "\033[1mA simple script to enable you to easily configure your Ubuntu 9.10 Karmic
Koala. What does it do? It helps with the basic Ubuntu configuration
operations, such as:\033[0m"
echo "- adds the recommended repositories,
- downloads and installs the latest updates,
- installs Ubuntu Tweak,
- install codecs, web browser plugins (Java, Flash),
  additional support for archives (RAR, 7-Zip) and additional fonts
- installs MPlayer,
- sets Mplayer and Totem character encoding to Central / Western European (Windows-1250),
  you can disable this by removing lines: 64 and 69,70,71,72,73,74,75,
- uninstalls Empathy and replaces it with Pidgin"
echo ""
echo -e "\033[1mIMPORTANT!!! Before running the script, make sure you have
an active Internet connection.
You will be asked to enter your password for some of the operations
in this script.

WARNING!!! Use the script at your own risk. Despite the author's efforts,
there are no guarantees everything will work properly.\033[0m"
echo ""
if [ "karmic" = `lsb_release -cs` ]; then
if [ "i686" = `uname -m` ]; then
echo -ne "\033[1mPress ENTER to continue\033[0m"
read
menu
elif [ "x86_64" = `uname -m` ]; then
echo -ne "\033[1mPress ENTER to continue\033[0m"
read
menu
else
echo -ne "\033[1mSThis script only works with Ubuntu (both 32bit and 64bit). Press ENTER
to exit the script\033[0m"
read
fi
else
echo -ne "\033[1mYou are not using Ubuntu Karmic Koala. Press ENTER to
exit the script\033[0m"
read
fi
