Last active
August 29, 2015 13:56
-
-
Save holybit/9296900 to your computer and use it in GitHub Desktop.
Perl DBD::Oracle client sniffer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Compare Oracle client version used to compile the installed | |
# DBD::Oracle against the currently installed Oracle client, if they | |
# differ then remove DBD::Oracle so it can be re-installed | |
# DBD::Oracle always treats Oracle client version numbers as four | |
# numbers separated by dots starting at the front of version string. | |
# self exec dir | |
SELF_DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
. "$SELF_DIR/activate" | |
rm_ora_driver() { | |
if perl -mApp::pmuninstall -e 1 &> /dev/null; then | |
pm-uninstall DBD::Oracle | |
else | |
echo "Can not locate App::pmuninstall to uninstall DBD::Oracle" | |
exit 1 | |
fi | |
} | |
# Oracle client version current DBD::Oracle installed against | |
if perl -mDBD::Oracle -e 1; then | |
oci_cmpl=$(perl -mDBD::Oracle=:ora_types -e 'print DBD::Oracle::ORA_OCI;') | |
else | |
echo "DBD::Oracle not installed" | |
exit 1 | |
fi | |
# Current Oracle client version | |
if [[ -e "/usr/local/oracle/bin/sqlplus" ]]; then | |
touch define.sql | |
echo "DEFINE _SQLPLUS_RELEASE" > define.sql | |
echo "QUIT" >> define.sql | |
export sqlp_rel=$("/usr/local/oracle/bin/sqlplus" -S /nolog \@define.sql 2>&1) | |
oci_curr=$(perl -e '$ENV{sqlp_rel} =~ /DEFINE _SQLPLUS_RELEASE = "(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)"/; | |
$oci_curr = sprintf("%d.%d.%d.%d", $1, $2, $3, $4); | |
print $oci_curr;') | |
rm -f define.sql | |
else | |
echo "Can not find sqlplus, bummer" | |
exit 1 | |
fi | |
if [[ -n "$oci_cmpl" ]] && [[ -n "$oci_curr" ]]; then | |
echo "Oracle client versions" | |
echo "----------------------" | |
echo "DBD::Oracle compiled against - $oci_cmpl" | |
echo "Currently installed - $oci_curr" | |
if [[ "$oci_cmpl" == "$oci_curr" ]]; then | |
echo "DBD::Oracle was compiled against the same Oracle client version \ | |
as currently installed" | |
else | |
echo "DBD::Oracle was not compiled against the same Oracle client version \ | |
as currently installed" | |
rm_ora_driver | |
fi | |
else | |
echo "Can not find Oracle client version strings to compare" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment