forked from OPEN-NEXT/LOSH-RDF-DB-tester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_common
executable file
·74 lines (62 loc) · 2.01 KB
/
_common
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2021 - 2023 Robin Vobruba <[email protected]>
#
# SPDX-License-Identifier: Unlicense
# Exit immediately on each error and unset variable;
# see: https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
set -Eeuo pipefail
#set -Eeu
script_dir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
# See: https://stackoverflow.com/a/7335120/586229
JAVA_VER=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}' | awk -F '.' '{sub("^$", "0", $2); print $1$2}')
# Apache Jena 4.10, December 2023, requires at least Java 11
JAVA_VER_MIN=110
JENA_VERSION="4.6.1"
JENA_DL_BASE_URL="https://archive.apache.org/dist/jena/binaries/"
JENA_DL_URL="$JENA_DL_BASE_URL/apache-jena-$JENA_VERSION.zip"
JENA_FUSEKI_DL_URL="$JENA_DL_BASE_URL/apache-jena-fuseki-$JENA_VERSION.zip"
# For the DB
JENA_HOME="$HOME/.local/opt/apache-jena-$JENA_VERSION"
# For the (SPQRQL) query web interface ot the DB
JENA_FUSEKI_HOME="$HOME/.local/opt/apache-jena-fuseki-$JENA_VERSION"
# This dir is where our RDF data will be stored (in a query-efficient way)
db_dir="$script_dir/rdf_db"
jena_db_data_injector="$JENA_HOME/bin/tdb2.tdbloader"
jena_db_data_querier="$JENA_HOME/bin/tdb2.tdbquery"
jena_fuseki_server="$JENA_FUSEKI_HOME/fuseki-server"
function ensure_java_version() {
# Java 1.5 -> 15
# Java 1.8 -> 18
# Java 11 -> 110
required_version_10="${1:-$JAVA_VER_MIN}"
if [ "$JAVA_VER" -ge "$required_version_10" ]
then
echo "INFO Java version is sufficiently new!"
else
>&2 echo "ERROR Java version ($JAVA_VER) is too old, needs to be at least $required_version_10!"
exit 1
fi
}
function ensure_tool() {
home="$1"
url="$2"
name="$3"
echo
printf 'Checking %s is available ... ' "$name"
if [ -d "$home" ]
then
echo "yes!"
else
echo "no,"
echo "installing it under $home ..."
mkdir -p "$home"
rm -Rf "${home:?}"
archive_name="$(basename "$url")"
dir_name="${archive_name%.zip}"
wget "$url"
unzip "$archive_name"
mv "$dir_name" "$home"
rm "$archive_name"
echo "done."
fi
}