message: ODBC: linux setup with -db and -D options.
diff: #!/bin/bash
  function Usage() {
  - echo "Usage: $0 [-s | -u]"
  + printf "Usage: $0 <command> [options]\n\n"
  + printf "Example: $0 -u -db ~/database_path -D ~/driver_path/libduckdb_odbc.so\n\n"
  + echo "Command:"
  echo "-s: using 'sudo' to add DuckDB connection to the system-level: /etc/odbc[inst].ini"
  echo "-u: add DuckDB connection to the user-level ~/odbc[inst].ini file."
  + printf "\nOptions:\n"
  + echo "-db database_path>: the DuckDB database file path, the default is ':memory:' if not provided."
  + echo "-D driver_path: the driver file path (i.e., the path for libduckdb_odbc.so), the default is using the base script directory"
  + echo ""
  exit 1
  }
  +function ReadArgs() {
  + shift
  + while (( $# > 1 ))
  + do
  + case $1 in
  + "-db")
  + shift
  + DATABASE_PATH=$1
  + shift
  + ;;
  + "-D")
  + shift
  + DRIVER_PATH=$1
  + if grep -qv "libduckdb_odbc.so" <<< $DRIVER_PATH; then
  + printf "\n****Driver path doesn't contain 'libduckdb_odbc.so'****\n\n"
  + Usage
  + fi
  + shift
  + ;;
  + *)
  + Usage
  + ;;
  + esac
  + done
  +}
  +
  +
  function CreateODBCIniFile() {
  cat << EOF > $1
  [DuckDB]
  Driver = DuckDB Driver
  -Database=:memory:
  +Database=${DATABASE_PATH}
  EOF
  }
  @@ -22,15 +55,35 @@ Trace = yes
  TraceFile = /tmp/odbctrace
  [DuckDB Driver]
  -Driver = $BASE_DIR/libduckdb_odbc.so
  +Driver = ${DRIVER_PATH}
  EOF
  }
  -if (($# != 1)); then
  - Usage $0
  +function ConfigUserInstFile() {
  + INST_SETUP=$1
  + if test -f ~/.odbcinst.ini; then
  + #file already exist
  + sed -i "/DuckDB Driver/{n;s#.*libduckdb_odbc.so#Driver=${DRIVER_PATH}#}" ~/.odbcinst.ini
  + else
  + cp $INST_SETUP ~/.odbcinst.ini
  + fi
  +}
  +
  +# Exit immediately if a command exits with a non-zero status.
  +set -e
  +
  +if (($# != 1 && $# != 3 && $# != 5)); then
  + Usage
  fi
  +# global vars
  BASE_DIR=$(pwd)
  +DRIVER_PATH=$BASE_DIR/libduckdb_odbc.so
  +DATABASE_PATH=":memory:"
  +
  +# Get the Database and Driver path from program arguments
  +ReadArgs $@
  +
  ODBC_INI_FILE=$(mktemp)
  ODBCINST_FILE=$(mktemp)
  @@ -41,18 +94,18 @@ case $1 in
  "-s")
  # checking for root level
  if (( $EUID != 0 )); then
  - echo "Please run as root"
  - Usage $0
  + printf "****Please run as root****\n\n"
  + Usage
  fi
  odbcinst -i -d -f $ODBCINST_FILE
  odbcinst -i -s -l -f $ODBC_INI_FILE
  ;;
  "-u")
  - cat $ODBCINST_FILE >> ~/.odbcinst.ini
  + ConfigUserInstFile $ODBCINST_FILE
  odbcinst -i -s -h -f $ODBC_INI_FILE
  ;;
  *)
  - Usage $0
  + Usage
  ;;
  esac
  