-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_duckdb.sh
104 lines (87 loc) · 3.19 KB
/
install_duckdb.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
#!/bin/bash -e
# prevent partial execution if download is partial for some reason
main () {
OS=$(uname -s)
ARCH=$(uname -m)
command -v curl >/dev/null 2>&1 || { echo >&2 "Required tool curl could not be found. Aborting."; exit 1; }
command -v zcat >/dev/null 2>&1 || { echo >&2 "Required tool zcat could not be found. Hint: install the gzip package. Aborting."; exit 1; }
# figure out latest version
VER=$(curl -s https://duckdb.org/data/latest_stable_version.txt)
eval PREFIX="~/.duckdb/cli"
INST="${PREFIX}/${VER}"
LATEST="${PREFIX}/latest"
DIST=
if [ "${OS}" = "Linux" ]
then
if [ "${ARCH}" = "x86_64" ] || [ "${ARCH}" = "amd64" ]
then
DIST=linux-amd64
elif [ "${ARCH}" = "aarch64" ] || [ "${ARCH}" = "arm64" ]
then
DIST=linux-aarch64
fi
elif [ "${OS}" = "Darwin" ]
then
DIST=osx-universal
fi
if [ -z "${DIST}" ]
then
echo "Operating system '${OS}' / architecture '${ARCH}' is unsupported." 1>&2
exit 1
fi
URL="https://github.com/duckdb/duckdb/releases/download/v${VER}/duckdb_cli-${DIST}.gz"
echo
echo "*** DuckDB Linux/MacOS installation script, version ${VER} ***"
echo
echo
echo " .;odxdl, "
echo " .xXXXXXXXXKc "
echo " 0XXXXXXXXXXXd cooo: "
echo " ,XXXXXXXXXXXXK OXXXXd "
echo " 0XXXXXXXXXXXo cooo: "
echo " .xXXXXXXXXKc "
echo " .;odxdl, "
echo
echo
if [ -f "${INST}/duckdb" ]; then
echo "Destination binary ${INST}/duckdb already exists"
else
mkdir -p "${INST}"
if [ ! -d "${INST}" ]; then
echo "Failed to create install directory ${INST}." 1>&2
exit 1
fi
curl --fail --location --progress-bar "${URL}" | zcat > "${INST}/duckdb" && chmod a+x "${INST}/duckdb" || exit 1
if [ ! -f "${INST}/duckdb" ]; then
echo "Failed to download/unpack binary at ${INST}/duckdb" 1>&2
exit 1
fi
# lets test if this works
TEST=$("${INST}/duckdb" -noheader -init /dev/null -csv -batch -s "SELECT 2*3*7")
if [ ! "$TEST" = "42" ]; then
echo "Failed to execute installed binary :/ ${INST}." 1>&2
exit 1
fi
echo
echo "Successfully installed DuckDB binary to ${INST}/duckdb"
rm -f "${LATEST}" || exit 1
ln -s "${INST}" "${LATEST}" || exit 1
echo " with a link from ${LATEST}/duckdb"
fi
echo
echo "Hint: Append the following line to your shell profile:"
echo "export PATH='${LATEST}':\$PATH"
echo
# maybe ~/.local/bin exists and is writeable and does not have duckdb yet
# if so, ask user if they would like a symlink
eval LOCALBIN="${HOME}/.local/bin"
if [ -d "${LOCALBIN}" ] && [ -w "${LOCALBIN}" ] && [ ! -f "${LOCALBIN}/duckdb" ]; then
ln -s "${LATEST}/duckdb" "${LOCALBIN}/duckdb" || exit 1
echo "Also created a symlink from ${LOCALBIN}/duckdb
to ${LATEST}/duckdb"
fi
echo
echo "To launch DuckDB now, type"
echo "${LATEST}/duckdb"
}
main