@echo off
rem
rem $Header: usm/src/cmds/acfstoolsdriver/acfstoolsdriver.bat /st_usm_11.2/1 2011/12/05 13:25:41 plancian Exp $
rem 
rem Copyright (c) 2007, 2011, Oracle and/or its affiliates. 
rem All rights reserved. 
rem
rem    NAME
rem      usm_tools_driver.bat - front end for the Perl scripts that do the work.
rem
rem    DESCRIPTION
rem      common driver for:
rem        usm_load, usm_root, usm_mount,
rem        usm_singlefs_mount, usm_driver_state, usm_dbhome.
rem
rem    NOTES
rem
rem    MODIFIED   (MM/DD/YY)
rem    plancian    12/05/11 - Backport plancian_bug-12329027 from main
rem    averhuls    10/06/10 - Retarget ADE targets to ./usm/bin.
rem    averhuls    09/14/10 - Make sure that PERL5LIB is not set - not needed
rem                           for 5.10.
rem    averhuls    01/08/10 - Perl v5.10 is the minimum version.
rem    agraves     10/13/09 - Add -t to clsecho to print time stamp.
rem    averhuls    10/08/09 - XbranchMerge averhuls_bug-8994738 from
rem                           st_usm_11.2.0.1.0bundle1
rem    averhuls    10/08/09 - Set ORA_CRS_HOME if it is not already set.
rem    averhuls    07/27/09 - acfsdriverstate may have a different ORACLE_HOME.
rem    averhuls    03/03/09 - Addd Perl 5.10 support.
rem    averhuls    01/06/08 - Creation
rem

setlocal

rem ORACLE_HOME is set at install time by usm_root.
if "%ORACLE_HOME%"=="" (
  set ORACLE_HOME="/"
)

rem Construct path to Perl.  version 5.10 is released with Oracle 11.2.
set PERLBIN=%ORACLE_HOME%\perl\bin\perl.exe

set CMD=%1

rem acfsdriverstate may have a different location for ORACLE_HOME and CRS_HOME
rem so set ORACLE_HOME back to the original CRS_HOME.
rem Note that ORA_CRS_HOME is used by acfslib
if "%CMD%"=="acfsdriverstate" (
  set ORA_CRS_HOME=%CRS_HOME%
  set ORACLE_HOME=%CRS_HOME%
) else (
  if "%ORA_CRS_HOME%"=="" (
    set ORA_CRS_HOME=%ORACLE_HOME%
  )
)

set CLSECHO=%ORACLE_HOME%\bin\clsecho -p usm -f acfs -c err 
set CLSECHOTL=%ORACLE_HOME%\bin\clsecho -p usm -f acfs -l -c err -t -n

if not exist %PERLBIN% (
  rem 3001: "Failed to open %s. Verify that %s exists."
  %CLSECHO% -m 3001 perl.exe %PERLBIN%
  %CLSECHOTL% -m 3001 perl.exe %PERLBIN%
  if "%CMD%"=="acfsdriverstate" (
    rem 9206: usage: %s [-orahome <ORACLE_HOME>] <installed | loaded | version | supported> [-s]
    %CLSECHO% -m 9206 %CMD%
    %CLSECHOTL% -m 9206 %CMD%
  )
  set ERRORLEVEL=1
  goto end
)

set FOUND_OSD_MODULE=0
if not exist "%ADE_VIEW_ROOT%" (
  if exist "%ORACLE_HOME%/lib/osds_%CMD%.pm" (
    set FOUND_OSD_MODULE=1
  )
  set LIBS=-I %ORACLE_HOME%/lib
  set COMMAND=%ORACLE_HOME%/lib/%CMD%.pl
) else (
  if exist %ADE_VIEW_ROOT%\usm\bin\osds_%CMD%.pm (
    set FOUND_OSD_MODULE=1
  )
  set LIBS=-I %ADE_VIEW_ROOT%/usm/bin
  set COMMAND=%ADE_VIEW_ROOT%/usm/bin/%CMD%.pl
)

if %FOUND_OSD_MODULE% == 0 (
  echo "%CMD%: ADVM/ACFS is not supported on this Operating System"
  set ERRORLEVEL=1
  goto end
)

rem PERL5LIB is not needed for v5.10 and can be harmful if set.
if defined PERL5LIB (
  set PERL5LIB=
)

rem Now run the target command with all arguments!
%PERLBIN% %LIBS% %COMMAND% %1 %2 %3 %4 %5 %6 %7 %8 %9

:end

endlocal

exit /B %ERRORLEVEL%
