2010-10-22 12:16:37 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
#(C)IBM Corp
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head1 odbcsetup
|
|
|
|
|
|
|
|
This postscript sets up the odbc for the database running on the Client
|
|
|
|
machine usually the Service Node.
|
|
|
|
The xCAT service node client and the DB client should have already been
|
|
|
|
installed on the node, before this postscript is run.
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
{
|
|
|
|
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
|
|
|
}
|
|
|
|
|
|
|
|
# if AIX - make sure we include perl 5.8.2 in INC path.
|
|
|
|
# Needed to find perl dependencies shipped in deps tarball.
|
2012-08-08 17:37:51 +00:00
|
|
|
if ($^O =~ /^aix/i) {
|
|
|
|
unshift(@INC, qw(/usr/opt/perl5/lib/5.8.2/aix-thread-multi /usr/opt/perl5/lib/5.8.2 /usr/opt/perl5/lib/site_perl/5.8.2/aix-thread-multi /usr/opt/perl5/lib/site_perl/5.8.2));
|
2010-10-22 12:16:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
use lib "$::XCATROOT/lib/perl";
|
|
|
|
use strict;
|
|
|
|
use xCAT::Utils;
|
|
|
|
use xCAT::MsgUtils;
|
|
|
|
|
|
|
|
# MAIN
|
|
|
|
|
|
|
|
my $rc = 0;
|
|
|
|
my $cmd;
|
|
|
|
|
|
|
|
# setup some important variable
|
|
|
|
|
|
|
|
$::sdate = `/bin/date`;
|
|
|
|
chomp $::sdate;
|
|
|
|
|
|
|
|
|
|
|
|
my $msg;
|
2011-03-17 16:56:48 +00:00
|
|
|
# get location of database
|
|
|
|
$::databaseloc = $ENV{'DATABASELOC'};
|
2010-10-22 12:16:37 +00:00
|
|
|
# check the /etc/xcat/cfgloc file to see if MySQL or DB2
|
|
|
|
# if it is not here, error out
|
|
|
|
my $dbname = xCAT::Utils->get_DBName;
|
|
|
|
if ($dbname eq "DB2")
|
|
|
|
{
|
2010-12-19 12:17:42 +00:00
|
|
|
$msg = "odbcsetup:Setting up ODBC for DB2";
|
2012-05-15 03:28:57 +00:00
|
|
|
`logger -t xcat -p local4.info $msg`;
|
2010-10-22 12:16:37 +00:00
|
|
|
&setupdb2odbc;
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ($dbname eq "MYSQL")
|
|
|
|
{
|
2010-12-19 12:17:42 +00:00
|
|
|
$msg = "odbcsetup:Setting up ODBC for MYSQL";
|
2012-05-15 03:28:57 +00:00
|
|
|
`logger -t xcat -p local4.info $msg`;
|
2010-10-22 12:16:37 +00:00
|
|
|
&setupmysqlodbc;
|
|
|
|
}
|
2013-05-20 11:01:20 +00:00
|
|
|
else {
|
|
|
|
if ($dbname eq "PG")
|
|
|
|
{
|
|
|
|
$msg = "odbcsetup:Setting up ODBC for PostgreSQL";
|
|
|
|
`logger -t xcat -p local4.info $msg`;
|
|
|
|
&setupPGodbc;
|
|
|
|
} else {
|
2010-10-22 12:16:37 +00:00
|
|
|
$msg =
|
2013-05-20 11:01:20 +00:00
|
|
|
"odbcsetup:cfgloc file does not contain MySQL, DB2 or PG, will not setup ODBC.";
|
2012-05-15 03:28:57 +00:00
|
|
|
`logger -t xcat -p local4.err $msg`;
|
2010-10-22 12:16:37 +00:00
|
|
|
exit 1;
|
2013-05-20 11:01:20 +00:00
|
|
|
}
|
2010-10-22 12:16:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
|
|
|
|
#
|
|
|
|
# Subroutines
|
|
|
|
#
|
|
|
|
|
|
|
|
#####################################################
|
|
|
|
#
|
|
|
|
# setupdb2odbc
|
|
|
|
# runs the db2sqlsetup script and sets up the ODBC on the Client
|
|
|
|
#
|
|
|
|
#####################################################
|
|
|
|
sub setupdb2odbc
|
|
|
|
{
|
|
|
|
my $msg;
|
|
|
|
my $rc = 0;
|
|
|
|
my $cmd;
|
|
|
|
my $filename = "/etc/xcat/cfgloc";
|
|
|
|
|
|
|
|
# get the info
|
|
|
|
my $xcatcfg;
|
|
|
|
my $cfgl;
|
|
|
|
open($cfgl, "<", $filename);
|
|
|
|
$xcatcfg = <$cfgl>;
|
|
|
|
close($cfgl);
|
|
|
|
chomp $xcatcfg;
|
|
|
|
my ($database, $instance, $password) = split('\|', $xcatcfg);
|
2011-03-17 16:56:48 +00:00
|
|
|
if ($::databaseloc) {
|
|
|
|
$cmd = "DATABASELOC=$::databaseloc $::XCATROOT/bin/db2sqlsetup -o -C";
|
|
|
|
} else {
|
|
|
|
$cmd = "$::XCATROOT/bin/db2sqlsetup -o -C";
|
|
|
|
}
|
2011-01-26 12:33:38 +00:00
|
|
|
$msg = "odbcsetup: Running Client ODBC setup. \"$cmd\"\n";
|
2012-05-15 03:28:57 +00:00
|
|
|
`logger -t xcat -p local4.info $msg`;
|
2010-10-22 12:16:37 +00:00
|
|
|
|
|
|
|
$rc = &runcmd($cmd);
|
|
|
|
|
2010-12-19 12:17:42 +00:00
|
|
|
$msg = "odbcsetup: Client ODBC setup finished.\n";
|
2012-05-15 03:28:57 +00:00
|
|
|
`logger -t xcat -p local4.info $msg`;
|
2010-10-22 12:16:37 +00:00
|
|
|
|
|
|
|
return $rc;
|
|
|
|
|
|
|
|
}
|
|
|
|
#####################################################
|
|
|
|
#
|
|
|
|
# setupmysqlodbc
|
|
|
|
# runs the mysqlsetup script and sets up the ODBC on the Client
|
|
|
|
#
|
|
|
|
#####################################################
|
|
|
|
sub setupmysqlodbc
|
|
|
|
{
|
|
|
|
my $msg;
|
|
|
|
my $rc = 0;
|
|
|
|
my $cmd;
|
|
|
|
$cmd = "$::XCATROOT/bin/mysqlsetup -o";
|
2011-01-01 12:33:19 +00:00
|
|
|
$msg = "odbcsetup: Running Client ODBC setup. \"$cmd\"\n";
|
2012-05-15 03:28:57 +00:00
|
|
|
`logger -t xcat -p local4.info $msg`;
|
2010-10-22 12:16:37 +00:00
|
|
|
|
|
|
|
$rc = &runcmd($cmd);
|
|
|
|
|
2010-12-19 12:17:42 +00:00
|
|
|
$msg = "odbcsetup: Client ODBC setup finished.\n";
|
2012-05-15 03:28:57 +00:00
|
|
|
`logger -t xcat -p local4.info $msg`;
|
2010-10-22 12:16:37 +00:00
|
|
|
|
|
|
|
return $rc;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-20 11:01:20 +00:00
|
|
|
#####################################################
|
|
|
|
#
|
|
|
|
# setupPGodbc
|
|
|
|
# runs the pgsqlsetup script and sets up the ODBC on the Client
|
|
|
|
#
|
|
|
|
#####################################################
|
|
|
|
sub setupPGodbc
|
|
|
|
{
|
|
|
|
my $msg;
|
|
|
|
my $rc = 0;
|
|
|
|
my $cmd;
|
|
|
|
$cmd = "$::XCATROOT/bin/pgsqlsetup -o";
|
|
|
|
$msg = "odbcsetup: Running Client ODBC setup. \"$cmd\"\n";
|
|
|
|
`logger -t xcat -p local4.info $msg`;
|
|
|
|
|
|
|
|
$rc = &runcmd($cmd);
|
|
|
|
|
|
|
|
$msg = "odbcsetup: Client ODBC setup finished.\n";
|
|
|
|
`logger -t xcat -p local4.info $msg`;
|
|
|
|
|
|
|
|
return $rc;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-10-22 12:16:37 +00:00
|
|
|
#
|
|
|
|
# run the command
|
|
|
|
#
|
|
|
|
sub runcmd
|
|
|
|
{
|
|
|
|
my ($cmd) = @_;
|
|
|
|
my $rc = 0;
|
|
|
|
|
|
|
|
$cmd .= ' 2>&1';
|
|
|
|
|
|
|
|
# my $outref = [];
|
|
|
|
# @$outref = `$cmd`;
|
|
|
|
|
|
|
|
$::outref = [];
|
|
|
|
$::outref = `$cmd`;
|
|
|
|
if ($?)
|
|
|
|
{
|
|
|
|
$rc = $? >> 8;
|
|
|
|
if ($rc > 0)
|
|
|
|
{
|
2010-12-19 12:17:42 +00:00
|
|
|
my $msg = "odbcsetup:$cmd returned rc=$rc $::outref\n";
|
2012-05-15 03:28:57 +00:00
|
|
|
`logger -t xcat -p local4.err $msg`;
|
2010-10-22 12:16:37 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|