-
-
Save kubo/8b3627c57091872a09b6 to your computer and use it in GitHub Desktop.
[DON'T USE THIS] Fix dependent Oracle library paths embedded in Oracle commands and libraries for OS X [DON'T USE THIS]
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
#!/bin/bash | |
cat <<EOS | |
Don't use this script because this doesn't work well. | |
Use the following command instead. | |
curl -O https://raw.githubusercontent.com/kubo/fix_oralib_osx/master/fix_oralib.rb | |
ruby fix_oralib.rb | |
EOS | |
exit 1 | |
set -e | |
if test "$(uname -s)" != Darwin; then | |
echo "This tool works only on OS X." | |
exit 1 | |
fi | |
if ! which otool > /dev/null 2>&1; then | |
echo "otool is not found." | |
echo "You need to install Xcode in advance." | |
exit 1 | |
fi | |
PROGNAME=$(basename "$0") | |
dry_run= | |
verbose= | |
lib_dir="$PWD" | |
ora_libs=( \ | |
libclntsh.dylib.11.1 \ | |
libnnz11.dylib \ | |
libocci.dylib.11.1 \ | |
libociei.dylib \ | |
libociicus.dylib \ | |
libocijdbc11.dylib \ | |
libsqlplus.dylib \ | |
libsqlplusic.dylib \ | |
) | |
show_usage() { | |
echo "Usage $PROGNAME [--lib-dir=DIR] [--dry-run] [--verbose] [file ...]" | |
echo | |
echo " This script fixes Oracle shared library paths" | |
echo " embedded in executables and libraries." | |
echo | |
echo " --lib-dir=DIR set the location of Oracle instant client" | |
echo " (default: the current working directory)" | |
echo " --dry-run show what would have been changed" | |
echo " --verbose increase verbosity" | |
echo | |
exit 1 | |
} | |
verbose_msg() { | |
if test "$verbose"; then | |
echo "$@" | |
fi | |
} | |
run() { | |
verbose_msg "$@" | |
if test -z "$dry_run"; then | |
"$@" | |
fi | |
} | |
while (($# > 0)); do | |
case "$1" in | |
--lib-dir=*) | |
lib_dir=$(echo "$1" | cut -d= -f2) | |
if test ! -d "$lib_dir"; then | |
echo "$PROGNAME: no such directory: $lib_dir" 1>&2 | |
exit 1 | |
fi | |
;; | |
--dry-run) | |
dry_run=1 | |
;; | |
--verbose) | |
verbose=1 | |
;; | |
-*) | |
echo "Invalid argument $1" | |
echo | |
show_usage | |
exit 1 | |
;; | |
*) | |
files=("${files[@]}" "$1") | |
;; | |
esac | |
shift 1 | |
done | |
if test ! -f "${lib_dir}/${ora_libs[0]}"; then | |
echo "No such file: ${lib_dir}/${ora_libs[0]}" | |
echo "Use --lib-dir=DIR to indicate the directory where Oracle instant client is installed." | |
exit 1 | |
fi | |
if test ${#files[@]} -eq 0; then | |
for file in *; do | |
files=("${files[@]}" "$file") | |
done | |
fi | |
for file in "${files[@]}"; do | |
if test ! -f "$file"; then | |
verbose_msg "Skip $file" | |
continue | |
fi | |
if test -L "$file"; then | |
verbose_msg "Skip symbolic link $file" | |
continue | |
fi | |
verbose_msg "Checking $file" | |
fix_write_perm= | |
for lib in $(otool -L "$file" | awk 'NR != 1 {print $1}'); do | |
if test $(dirname "$lib") = "$lib_dir"; then | |
continue | |
fi | |
lib_base=$(basename "$lib") | |
for ora_lib in ${ora_libs[@]}; do | |
if test "$lib_base" != "$ora_lib"; then | |
continue | |
fi | |
if test -z "$fix_write_perm"; then | |
echo "$file:" | |
if test -w "$file"; then | |
fix_write_perm=no | |
else | |
echo " Change the file permission to make it writable" | |
run chmod u+w "$file" | |
fix_write_perm=yes | |
fi | |
fi | |
new_name="$lib_dir/$lib_base" | |
if test $(basename "$file") = "$lib_base"; then | |
echo " Change id" | |
echo " old: $lib" | |
echo " new: $new_name" | |
run install_name_tool -id "$new_name" "$file" | |
else | |
echo " Change install_name" | |
echo " old: $lib" | |
echo " new: $new_name" | |
run install_name_tool -change "$lib" "$new_name" "$file" | |
fi | |
break | |
done | |
done | |
if test "$fix_write_perm" = yes; then | |
echo " Restore the file permission" | |
run chmod u-w "$file" | |
fi | |
if test "$fix_write_perm"; then | |
echo | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment