#!/bin/sh

#################################################
# 												#
#			 TNSconnectMac v1.0					#	
#												#
# Script realized by Danilo Vizzarro			#
# You can find the step-by-step instructions on #
# www.danilovizzarro.it							#
# 25-JUL-2008									#
#################################################

# The script is tested on a Mac OS X running Leopard 10.5.4.
# It will create/update the file tnsnames.ora and it will create a test page that will try to connect the Oracle DB.

# 1. You need to be logged as root

clear
echo "*******************************************************************"
echo "*                       TNSconnectMac v1.0                        *"
echo "*******************************************************************"
echo "* The script will install SqlPlus on your Mac.                    *" 
echo "* You can find the updated version of the code, a video demo      *"
echo "* and a step-by-step tutorial on www.danilovizzarro.it/?p=10      *"
echo "* Script tested on Mac OS X running Leopard 10.5.4                *"
echo "* Script created by Danilo Vizzarro.                              *"
echo "*******************************************************************"


mkdir -p /opt/oracle/tns
cd /opt/oracle/tns

echo "This script will configure tnsnames.ora"
echo "Please write the following information.";
echo "ORACLE SID (SIDDB): \c" 
read sid
echo "ORACLE SERVER IP ADDRESS (10.9.1.1): \c"
read server
echo "ORACLE SERVER PORT (1521): \c"
read port
echo "ORACLE DB USERNAME (ex. RAC_ACCNT): \c"
read oracle_user
echo "ORACLE DB PASSWORD: \c"
read oracle_password

echo "";
echo "This information will be now written on the file /opt/oracle/tnsnames.ora"
echo "If the information you typed are wrong the connection to Oracle wont work"
echo "Do you want to save the information you typed? (y/n): \c"

read confirm
case $confirm in yes|Yes|YES|y|Y)
	echo "$sid =" >> tnsnames.ora
	echo "  (DESCRIPTION =" >> tnsnames.ora
	echo "    (ADDRESS_LIST =" >> tnsnames.ora
	echo "      (ADDRESS = (PROTOCOL = TCP)(HOST = $server)(PORT = $port))" >> tnsnames.ora
	echo "    )" >> tnsnames.ora
	echo "    (CONNECT_DATA =" >> tnsnames.ora
	echo "      (SID = $sid)" >> tnsnames.ora
	echo "    )" >> tnsnames.ora
	echo "  )" >> tnsnames.ora
	echo "" >> tnsnames.ora
	
	echo ""
	echo "If everything went fine you would be able to connect the Oracle DB you defined"
	echo "If something went wrong you can delete maually the connections from the file /opt/oracle/tns/tnsnames.ora"
	;;
esac



