-
-
Save zrh535/10203827213a5018a1979f0e2c4bd63d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| sql() { | |
| # REMOTE source this script | |
| # | |
| # . <(curl -s https://gist.githubusercontent.com/krisrice/fec43fd9f53e4286e5cc360b554e3c0f/raw/62ec382d7511c7cc44703a9a2f75a4a7f233efe2/sqlcl.sh) | |
| # Set the stage directory | |
| STAGE_DIR=/tmp | |
| # Get current ETAG from download | |
| ETAG=`curl -I -s https://download.oracle.com/otn_software/java/sqldeveloper/sqlcl-latest.zip | tr -d '\r' | sed -En 's/^ETag: (.*)/\1/p'` | |
| echo REMOTE-ETAG: $ETAG | |
| # Compare to last ETag saved | |
| if [[ -e $STAGE_DIR/sqlcl.etag ]]; then | |
| CURRENT_ETAG=`cat $STAGE_DIR/sqlcl.etag` | |
| echo LOCAL-ETAG: $CURRENT_ETAG | |
| else | |
| CURRENT_ETAG="none" | |
| fi | |
| # Check if ETags match | |
| if [[ $ETAG != $CURRENT_ETAG ]]; then | |
| echo Downloading.... | |
| curl -sS -o $STAGE_DIR/sqlcl-latest.zip \ | |
| --header 'If-None-Match: "${CURRENT_ETAG}"' \ | |
| https://download.oracle.com/otn_software/java/sqldeveloper/sqlcl-latest.zip | |
| echo Unzip.... | |
| echo $ETAG > $STAGE_DIR/sqlcl.etag | |
| echo Removing Old SQLcl | |
| rm -rf $STAGE_DIR/sqlcl | |
| echo Unzipping to $STAGE_DIR/sqlcl | |
| unzip -qq -d $STAGE_DIR $STAGE_DIR/sqlcl-latest.zip | |
| else | |
| echo SQLcl Is Current | |
| fi | |
| # Run SQLcl | |
| $STAGE_DIR/sqlcl/bin/sql $* | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment