-
Notifications
You must be signed in to change notification settings - Fork 45
/
install.sh
executable file
·106 lines (93 loc) · 4.24 KB
/
install.sh
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env bash
set -euo pipefail
cLibVersion=0.21.0
os=$(uname)
cLibArgs="$*"
# verify installed Go version
goVersion=$(go version | cut -d' ' -f 3)
goVersionMajor=$(echo "${goVersion}" | cut -d'.' -f1)
goVersionMinor=$(echo "${goVersion}" | cut -d'.' -f2)
goVersionPatch=$(echo "${goVersion}" | cut -d'.' -f3)
if [[ ! "${goVersionMajor}" == "go1" ]]; then
echo "Unexpected Go major version ${goVersionMajor}, expecting Go 1.11.4+."
echo "You can proceed and let us know if you think we should extend the support to your version."
elif [[ "${goVersionMinor}" -lt "11" ]]; then
echo "Invalid Go version ${goVersion}, at least 1.11.4 required."
exit 1
elif [[ "${goVersionMinor}" == "11" ]] && [[ "${goVersionPatch}" -lt "4" ]]; then
echo "Invalid Go version ${goVersion}, at least 1.11.4 required."
exit 1
fi
# sudo might not be defined (e.g. when building a docker image)
sudo="sudo "
if [[ ! -x "$(command -v sudo)" ]]; then
sudo=""
fi
# check a C/C++ compiler is available - it's used by CGO
if [[ "$os" != MINGW* ]] && [[ "$os" != CYGWIN* ]]; then
if [[ -z "${CC:-}" ]] && [[ -z "$(command -v gcc)" ]] && [[ -z "$(command -v clang)" ]]; then
echo "Could not find a C/C++ compiler - \$CC environment variable is empty and neither gcc nor clang commands are recognized."
echo "The compiler is required for Go CGO, please install gcc or clang, e.g. using your package manager."
manager=
installCmd1=
installCmd2=
if [[ -x "$(command -v apt)" ]]; then
manager="APT"
installCmd1="${sudo}apt update"
installCmd2="${sudo}apt install gcc"
elif [[ -x "$(command -v yum)" ]]; then
manager="Yum"
installCmd1="${sudo}yum install gcc"
fi
installed=
if [[ -n "${manager}" ]]; then
echo "Seems like your package manager is ${manager}, you may want to try: ${installCmd1} ; ${installCmd2}"
read -p "Would you like to execute that command(s) now? [y/N] " -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
${installCmd1}
${installCmd2}
if [[ -n "${CC:-}" ]] || [[ -n "$(command -v gcc)" ]] || [[ -n "$(command -v clang)" ]]; then
installed=1
fi
fi
fi
if [[ -z "${installed}" ]]; then
echo "Please restart this script after installing the compiler manually."
read -p "If you think this is a false finding and would like to continue with ObjectBox installation regardless, press Y. [y/N] " -r
if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit; fi
fi
fi
fi
# if there's no tty this is probably part of a docker build - therefore we install the c-api explicitly
if [[ "$os" != MINGW* ]] && [[ "$os" != CYGWIN* ]] && [[ "$cLibArgs" != *"--install"* ]]; then
tty -s || cLibArgs="${cLibArgs} --install"
fi
# install the ObjectBox-C library
mkdir -p objectboxlib && cd objectboxlib
bash <(curl -s https://raw.githubusercontent.com/objectbox/objectbox-c/main/download.sh) ${cLibArgs} ${cLibVersion}
if [[ "$os" == MINGW* ]] || [[ "$os" == CYGWIN* ]]; then
localLibDir=$(realpath lib)
echo "Windows must be able to find the objectbox.dll when executing ObjectBox based programs (even tests)."
echo "One way to accomplish that is to manually copy the objectbox.dll from ${localLibDir} to C:/Windows/System32/ folder."
echo "See https://golang.objectbox.io/install#objectbox-library-on-windows for more details."
fi
cd -
if [[ -x "$(command -v ldconfig)" ]]; then
libInfo=$(ldconfig -p | grep "libobjectbox." || true)
if [ -z "${libInfo}" ]; then
echo "Installation of the C library failed - ldconfig -p doesn't report libobjectbox. Please try running again."
exit 1
fi
fi
# go get flatbuffers (if not using go modules) and objectbox
if [[ ! -f "go.mod" ]]; then
echo "Your project doesn't seem to be using go modules. Installing FlatBuffers & ObjectBox using go get."
go get -u github.com/google/flatbuffers/go
go get -u github.com/objectbox/objectbox-go/objectbox
elif grep -q "module github.com/objectbox/objectbox-go" "go.mod"; then
echo "Seems like we're running inside the objectbox-go directory itself, skipping ObjectBox Go module installation."
else
go get -u github.com/objectbox/objectbox-go/objectbox
fi
echo "Installation complete."
echo "You can start using ObjectBox by importing github.com/objectbox/objectbox-go/objectbox in your source code."