From 0bc4e5f6f3c854cf5199b22fbb651e2c773827e5 Mon Sep 17 00:00:00 2001 From: Felix Lohmeier Date: Fri, 31 Jul 2020 22:06:00 +0200 Subject: [PATCH] fix env variables --- bash-refine.sh | 37 +++++++++++++++++++++++-------------- minimal.sh | 4 ++-- templates.sh | 18 +++++++++--------- 3 files changed, 34 insertions(+), 25 deletions(-) mode change 100755 => 100644 bash-refine.sh diff --git a/bash-refine.sh b/bash-refine.sh old mode 100755 new mode 100644 index ecdba9e..88384ae --- a/bash-refine.sh +++ b/bash-refine.sh @@ -1,5 +1,5 @@ #!/bin/bash -# bash-refine v1.3.0: bash-refine.sh, Felix Lohmeier, 2020-07-31 +# bash-refine v1.3.1: bash-refine.sh, Felix Lohmeier, 2020-07-31 # https://gist.github.com/felixlohmeier/d76bd27fbc4b8ab6d683822cdf61f81d # license: MIT License https://choosealicense.com/licenses/mit/ @@ -8,21 +8,29 @@ # ================================== CONFIG ================================== # endpoint="${REFINE_ENDPOINT:-http://localhost:3333}" -memory="${REFINE_MEMORY:-1400M}" # increase to available RAM +memory="${REFINE_MEMORY:-1400M}" +csrf="${REFINE_CSRF:-true}" date="$(date +%Y%m%d_%H%M%S)" -if [[ -z "${REFINE_WORKDIR}" ]]; then - workdir="output/${date}" +if [[ -n "$(readlink -e "${REFINE_WORKDIR}")" ]]; then + workdir="$(readlink -e "${REFINE_WORKDIR}")" else - workdir="${REFINE_WORKDIR}" + workdir="$(readlink -m "${BASH_SOURCE%/*}/output/${date}")" fi -if [[ -z "${REFINE_LOGFILE}" ]]; then - logfile="log/${date}.log" +if [[ -n "$(readlink -e "${REFINE_LOGFILE}")" ]]; then + logfile="$(readlink -e "${REFINE_LOGFILE}")" else - logfile="${REFINE_LOGFILE}" + logfile="$(readlink -m "${BASH_SOURCE%/*}/log/${date}.log")" +fi +if [[ -n "$(readlink -e "${REFINE_JQ}")" ]]; then + jq="$(readlink -e "${REFINE_JQ}")" +else + jq="$(readlink -m "${BASH_SOURCE%/*}/lib/jq")" +fi +if [[ -n "$(readlink -e "${REFINE_REFINE}")" ]]; then + refine="$(readlink -e "${REFINE_REFINE}")" +else + refine="$(readlink -m "${BASH_SOURCE%/*}/lib/openrefine/refine")" fi -csrf="${REFINE_CSRF:-true}" # set to false for OpenRefine < 3.3 -jq="${REFINE_JQ:-jq}" # path to executable -refine="${REFINE_REFINE:-openrefine/refine}" # path to executable declare -A checkpoints # associative array for stats declare -A pids # associative array for monitoring background jobs @@ -45,6 +53,7 @@ function requirements { # download jq and OpenRefine if necessary if [[ -z "$(readlink -e "${jq}")" ]]; then echo "Download jq..." + mkdir -p "$(dirname "${jq}")" # jq 1.4 has much faster startup time than 1.5 and 1.6 curl -L --output "${jq}" \ "https://github.com/stedolan/jq/releases/download/jq-1.4/jq-linux-x86_64" @@ -66,7 +75,7 @@ function requirements { "$(dirname "${refine}")"/refine # set autosave period from 5 minutes to 25 hours sed -i 's/#REFINE_AUTOSAVE_PERIOD=60/REFINE_AUTOSAVE_PERIOD=1500/' \ - "$(dirname "${refine}")"/refine.ini + "$(dirname "${refine}")"/refine.ini echo fi } @@ -74,9 +83,9 @@ function requirements { # ============================== OPENREFINE API ============================== # function refine_start { - echo "start OpenRefine server..." + echo "start OpenRefine server..." local dir - dir="$(readlink -f "${workdir}")" + dir="$(readlink -e "${workdir}")" ${refine} -v warn -m "${memory}" -p "${endpoint##*:}" -d "${dir}" & pid_server=${!} timeout 30s bash -c "until curl -s \"${endpoint}\" \ diff --git a/minimal.sh b/minimal.sh index 9988fbc..af5fdbb 100755 --- a/minimal.sh +++ b/minimal.sh @@ -1,12 +1,12 @@ #!/bin/bash -# bash-refine v1.3.0: minimal.sh, Felix Lohmeier, 2020-07-31 +# bash-refine v1.3.1: minimal.sh, Felix Lohmeier, 2020-07-31 # https://gist.github.com/felixlohmeier/d76bd27fbc4b8ab6d683822cdf61f81d # license: MIT License https://choosealicense.com/licenses/mit/ # =============================== ENVIRONMENT ================================ # +source "${BASH_SOURCE%/*}/bash-refine.sh" || exit 1 cd "${BASH_SOURCE%/*}/" || exit 1 -source bash-refine.sh init # ================================= STARTUP ================================== # diff --git a/templates.sh b/templates.sh index 1a98701..f95409d 100755 --- a/templates.sh +++ b/templates.sh @@ -1,5 +1,5 @@ #!/bin/bash -# bash-refine v1.3.0: templates.sh, Felix Lohmeier, 2020-07-31 +# bash-refine v1.3.1: templates.sh, Felix Lohmeier, 2020-07-31 # https://gist.github.com/felixlohmeier/d76bd27fbc4b8ab6d683822cdf61f81d # license: MIT License https://choosealicense.com/licenses/mit/ @@ -13,21 +13,21 @@ # =============================== ENVIRONMENT ================================ # +# source the main script +source "${BASH_SOURCE%/*}/bash-refine.sh" || exit 1 + # make script executable from another directory cd "${BASH_SOURCE%/*}/" || exit 1 -# source the main script -source bash-refine.sh - ### override default config? #endpoint="http://localhost:3333" #memory="1400M" # increase to available RAM -#date="$(date +%Y%m%d_%H%M%S)" -#workdir="output/${date}" -#logfile="log/${date}.log" #csrf=true # set to false for OpenRefine < 3.3 -#jq="jq" # path to executable -#refine="openrefine/refine" # path to executable +#date="$(date +%Y%m%d_%H%M%S)" +#workdir="${BASH_SOURCE%/*}/output/${date}" +#logfile="${BASH_SOURCE%/*}/log/${date}.log" +#jq="${BASH_SOURCE%/*}/lib/jq" # path to executable +#refine="${BASH_SOURCE%/*}/lib/openrefine/refine" # path to executable # check requirements, set trap, create workdir and tee to logfile init