Skip to content

Instantly share code, notes, and snippets.

@wattry
Created December 1, 2022 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wattry/5e5d917682c80b1834147ab5851dc92c to your computer and use it in GitHub Desktop.
Save wattry/5e5d917682c80b1834147ab5851dc92c to your computer and use it in GitHub Desktop.
Bash script to automate oracle instant client setup
#!/bin/sh
# First check to ensure that an instant client instance isn't already installed
# by determining if a symlink exists within /usr/local/lib.
if [ -e "/usr/local/lib/libclntsh.dylib" ] # If symlink file exists
then
# If one already exists nothing new has to be done, just exit
echo "[*] Looks like an Instant Client is already installed on this machine"
echo " Instant Client Location: $(readlink '/usr/local/lib/libclntsh.dylib')"
echo "[*] Exiting..."
exit 0
fi
# Script vars
INSTANT_CLIENT_DMG_NAME="instantclient-basiclite-macos.x64-19.8.0.0.0dbru.dmg"
INSTANT_CLIENT_VOLUME_NAME="instantclient-basiclite-macos.x64-19.8.0.0.0dbru"
INSTANT_CLIENT_FOLDER="instantclient_19_8"
CLIENT_FINAL_INSTALL_LOCATION="$HOME/Documents/$INSTANT_CLIENT_FOLDER"
cd $HOME/Downloads
# Download Instant Client 19.8 dmg if it doesn't already exist
if [ -e "$INSTANT_CLIENT_DMG_NAME" ]
then
# Downloaded DMG already exists
echo "[*] DMG file already exists in $HOME/Downloads. Skipping download step"
else
echo "[*] Downloading $INSTANT_CLIENT_DMG_NAME"
curl -O https://download.oracle.com/otn_software/mac/instantclient/198000/"$INSTANT_CLIENT_DMG_NAME"
fi
# Check whether unpacked DMG directory already exists
if [ -d "$INSTANT_CLIENT_FOLDER" ]
then
echo "[*] Unpacked instant client files already exist in Downloads. Skipping DMG mount step"
else
# Mount the downloaded DMG file and run its install script, then unmount
echo "[*] Mounting and installing DMG image files..."
hdiutil mount "$INSTANT_CLIENT_DMG_NAME" > /dev/null
/Volumes/"$INSTANT_CLIENT_VOLUME_NAME"/install_ic.sh
hdiutil unmount /Volumes/"$INSTANT_CLIENT_VOLUME_NAME" > /dev/null
echo "[*] Files installed and DMG unmounted"
fi
# By default the install script moves files into $USER/Downloads/instantclient_19_8
# Some apps are not allowed to access the Downloads folder, so move it into a directory
# specified by this script's command line argument (or $USER/Documents by default)
if [ $# -eq 0 ]
then
# If no args supplied use Documents as default directory to move files into
echo "[*] Moving files into directory ($HOME/Documents/$INSTANT_CLIENT_FOLDER)"
mkdir "$HOME/Documents/$INSTANT_CLIENT_FOLDER"
mv "$INSTANT_CLIENT_FOLDER" "$HOME/Documents/"
else
# Move files into specified directory
CLIENT_FINAL_INSTALL_LOCATION="$1/$INSTANT_CLIENT_FOLDER"
echo "[*] Moving files into directory ($1/$INSTANT_CLIENT_FOLDER)"
mkdir -p "$1" # -p flag creates non-existing parent dirs
mv "$INSTANT_CLIENT_FOLDER" "$1/"
fi
# Ensure last mv command ran successfully (returned 0)
if [ $? -eq 0 ]
then
# Create symlink for the client's directory to /usr/local/lib
echo "[*] Files moved. Creating symlink between $CLIENT_FINAL_INSTALL_LOCATION/libclntsh.dylib and /usr/local/lib"
mkdir /usr/local/lib > /dev/null 2>&1 # Hide stderr output since dir might already exist
ln -s "$CLIENT_FINAL_INSTALL_LOCATION/libclntsh.dylib" /usr/local/lib
if [ $? -eq 0 ]
then
echo "[*] Instant Client has been setup for this machine"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment