#!/bin/bash
# created in 2009-11-10 by edipo.crispim

logfile="$HOME/f123orca.log"

preps(){
	mkdir -p ~/.f123orca/
	mkdir -p ~/.f123orca/atk
	mkdir -p ~/.f123orca/ap-spi
	mkdir -p ~/.f123orca/orca
	cd ~/.f123orca
}

menu(){

echo "1. orca ubuntu default (2.30.2)"
echo "2. orca 2.31.92"
orca_version[2]="ORCA_2_31_92"
echo "3. orca 2.32.0"
orca_version[3]="ORCA_2_32_0"
echo "4. orca 2.91.1"
orca_version[4]="ORCA_2_91_1"
read resp
}

sync_git(){
	echo "Syncing git repositories"
	sudo apt-get -y install git-core gnome-common automake1.9 &>> $logfile
	sudo git clone git://git.gnome.org/atk atk &>> $logfile
	sudo git clone git://git.gnome.org/at-spi at-spi &>> $logfile
	sudo git clone git://git.gnome.org/orca orca &>> $logfile
}

install_orca(){
	echo "Installing orca"
	sudo apt-get -y build-dep gnome-orca &>> $logfile
	sudo apt-get -y build-dep libatk1.0-0 at-spi &>> $logfile
	sudo apt-get -y install libgconf2-dev &>> $logfile
	if [ $resp -eq 1 ]
	then
		cd orca
		sudo make uninstall &>> $logfile
		cd ../atk
		sudo make uninstall &>> $logfile
		cd ../at-spi
		sudo make uninstall &>> $logfile
		sudo apt-get install -y gnome-orca &>> $logfile
	else
		sudo apt-get remove -y gnome-orca &>> $logfile

		cd atk
		sudo git checkout -b master origin/master &>> $logfile
		sudo ./autogen.sh --prefix=/usr &>> $logfile
		sudo make &>> $logfile
		sudo make &>> $logfile

		cd ../at-spi
		sudo git checkout -b master origin/master &>> $logfile
		sudo ./autogen.sh --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib/at-spi $ &>> $logfile
		sudo make &>> $logfile
		sudo make install &>> $logfile

		cd ../orca
		sudo git checkout ${orca_version[$resp]} &>> $logfile
		sudo ./autogen.sh &>> $logfile
		sudo make &>> $logfile
		sudo make install &>> $logfile
	fi

}

if [ $(whoami) == "root" ]
then
	echo "Não use sudo"
	exit 1
fi

touch $logfile
preps
menu
sync_git
install_orca
echo "Restart orca"

