fix env variables

This commit is contained in:
Felix Lohmeier 2020-07-31 22:06:00 +02:00
parent 6a386f97e0
commit 0bc4e5f6f3
3 changed files with 34 additions and 25 deletions

37
bash-refine.sh Executable file → Normal file
View File

@ -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}\" \

View File

@ -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 ================================== #

View File

@ -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