Created
July 31, 2018 13:20
-
-
Save rcbop/fdce471b3afebb63e571cf728d9997e1 to your computer and use it in GitHub Desktop.
oracle instant client npm module dependencie
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 | |
#/ | |
#/ :: ORACLE INSTANT CLIENT INSTALL SCRIPT :: | |
#/ | |
#/ Automate install instructions for | |
#/ | |
#/ https://github.com/oracle/node-oracledb/blob/master/INSTALL.md#-6-node-oracledb-installation-on-macos-with-instant-client | |
#/ | |
#/ WARNING: | |
#/ Download the sdk and basic instant client zip and place them in the same directory as this script | |
#/ ############################################################################## | |
usage() { grep '^#/' "$0" | cut -c4- ; exit 0 ; } | |
expr "$*" : ".*--help" > /dev/null && usage | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root" 1>&2 | |
exit 1 | |
fi | |
set -e | |
function configure_colors(){ | |
debug | |
if test -t 1; then | |
number_colors=$(tput colors) | |
if test -n "${number_colors}" && test ${number_colors} -ge 6; then | |
RED='\033[0;31m' | |
BLUE='\033[0;34m' | |
GREEN='\033[0;32m' | |
YELLOW='\033[33;m' | |
CYAN='\033[0;36m' | |
MAGENTA='\033[35m' | |
BOLD_WHITE="\033[1m" | |
NC='\033[0m' | |
else | |
RED='' | |
BLUE='' | |
GREEN='' | |
YELLOW='' | |
CYAN='' | |
MAGENTA='' | |
BOLD_WHITE='' | |
NC='' | |
fi | |
fi | |
} | |
echo_blu(){ echo -e "${BLUE}$1${NC}"; } | |
echo_red(){ echo -e "${RED}$1${NC}"; } | |
echo_grn(){ echo -e "${GREEN}$1${NC}"; } | |
echo_cya(){ echo -e "${CYAN}$1${NC}"; } | |
echo_yel(){ echo -e "${YELLOW}$1${NC}"; } | |
echo_mag(){ echo -e "${MAGENTA}$1${NC}"; } | |
info() { echo_blu "[INFO] $1"; } | |
warning() { echo_yel "[WARN] $1"; } | |
error() { echo_red "[ERROR] $1"; } | |
fatal() { echo_red "[FATAL] $1"; exit 1 ; } | |
debug() { if [ "${DEBUG}" == "true" ]; then echo_cya "[DEBUG] :: ${FUNCNAME[1]} :: $1"; fi } | |
separator() { | |
SEP=$(printf '%*s' 105 | tr ' ' '#') | |
echo_grn "[INFO] $SEP" | |
} | |
STEP=0 | |
bump_step(){ | |
((STEP++)) | |
echo_grn "[INFO] ($STEP) $1" | |
} | |
create_oracle_home_dir(){ | |
debug | |
info "Creating $ORACLE_HOME" | |
mkdir -p $ORACLE_HOME | |
} | |
unzip_instantclient(){ | |
debug | |
cp $PWDORIGIN/$INSTANT_CLIENT_BASIC_ZIP $ORACLE_HOME/ | |
cp $PWDORIGIN/$INSTANT_CLIENT_SDK_ZIP $ORACLE_HOME/ | |
cd $ORACLE_HOME | |
info "Unzip $INSTANT_CLIENT_BASIC_ZIP" | |
unzip $INSTANT_CLIENT_BASIC_ZIP | |
info "Unzip $INSTANT_CLIENT_SDK_ZIP" | |
unzip $INSTANT_CLIENT_SDK_ZIP | |
info "Renaming instantclient dir" | |
mv instantclient_$INSTANT_CLIENT_MAJOR_SUFIX instantclient | |
cd $ORACLE_HOME | |
info "Cleaning $INSTANT_CLIENT_BASIC_ZIP" | |
rm -f $INSTANT_CLIENT_BASIC_ZIP | |
info "Cleaning $INSTANT_CLIENT_SDK_ZIP" | |
rm -f $INSTANT_CLIENT_SDK_ZIP | |
} | |
create_instantclient_symbolic_link(){ | |
debug | |
info "Changing to instantclient dir" | |
cd $ORACLE_HOME/instantclient | |
info "Linking $DYLIB_WITH_VERSION to $DYLIB_NO_VERSION" | |
ln -s $DYLIB_WITH_VERSION $DYLIB_NO_VERSION | error "$DYLIB_NO_VERSION already exists" | |
} | |
add_instantclient_vars_to_bashrc(){ | |
debug | |
USER_BASHRC=$USER_HOME/.bashrc | |
info "Verifying user's $USER_BASHRC" | |
if grep -q OCI_LIB_DIR "$USER_BASHRC"; then | |
warning "OCI_LIB_DIR variables already on $USER_HOME/.bashrc" | |
else | |
info "OCI_LIB_DIR export not found!" | |
info "Adding to .bashrc" | |
echo "export OCI_LIB_DIR=$OCI_LIB_DIR" >> $USER_BASHRC | |
fi | |
if grep -q OCI_INC_DIR "$USER_BASHRC"; then | |
warning "OCI_INC_DIR variables already on $USER_HOME/.bashrc" | |
else | |
info "OCI_INC_DIR export not found!" | |
info "Adding to .bashrc" | |
echo "export OCI_INC_DIR=$OCI_INC_DIR" >> $USER_BASHRC | |
fi | |
} | |
PWDORIGIN="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
INSTANT_CLIENT_MAJOR_VERSION=12.2 | |
INSTANT_CLIENT_VERSION=12.2.0.1.0 | |
INSTANT_CLIENT_MAJOR_SUFIX=12_2 | |
INSTANT_CLIENT_BASIC_ZIP=instantclient-basic-macos.x64-$INSTANT_CLIENT_VERSION.zip | |
INSTANT_CLIENT_SDK_ZIP=instantclient-sdk-macos.x64-$INSTANT_CLIENT_VERSION.zip | |
ORACLE_HOME=/opt/oracle | |
OCI_LIB_DIR=$ORACLE_HOME/instantclient | |
OCI_INC_DIR=$ORACLE_HOME/instantclient/sdk/include | |
USER_HOME=/Users/$(whoami | awk '{print $1}') | |
DYLIB_WITH_VERSION=libclntsh.dylib.$INSTANT_CLIENT_MAJOR_VERSION | |
DYLIB_NO_VERSION=libclntsh.dylib | |
########################################## | |
# | |
# Start Script | |
# | |
########################################## | |
if [[ "${BASH_SOURCE[0]}" = "$0" ]]; then | |
clear | |
configure_colors | |
separator | |
bump_step "Create Oracle home dir" | |
separator | |
create_oracle_home_dir | |
bump_step "Extracting instant client lib" | |
separator | |
unzip_instantclient | |
bump_step "Crete instant client symbolic link" | |
separator | |
create_instantclient_symbolic_link | |
bump_step "Adding variables to bashrc" | |
separator | |
add_instantclient_vars_to_bashrc | |
bump_step "Finished installation" | |
info "you can now add oracle nodejs dependencie to package.json" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment