Repository navigation
Expand file tree
/
Copy pathinstall
More file actions
executable file
·82 lines (68 loc) · 3.88 KB
/
Copy pathinstall
File metadata and controls
executable file
·82 lines (68 loc) · 3.88 KB
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
#!/usr/bin/env bash
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config"
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
# installed-datastore-version reports the version a binary says it is, and nothing
# at all when there is no such file or it cannot be run.
installed-datastore-version() {
declare BINARY="$1"
if [[ ! -x "$BINARY" ]]; then
return 0
fi
# a file that is executable but is not this binary exits non-zero, and under
# errexit the assignment that takes this would end the install saying nothing.
# Reporting no version is the useful answer: it is what a caller checks for.
"$BINARY" version 2>/dev/null | head -n1 | tr -d '[:space:]' || true
}
plugin-install() {
local ARCHITECTURE="amd64"
if [[ "$(uname -m)" == "aarch64" ]]; then
ARCHITECTURE="arm64"
fi
local DOKKU_DATASTORE_ROOT="${DOKKU_LIB_ROOT}/data/${PLUGIN_COMMAND_PREFIX}"
local DOKKU_DATASTORE_BINARY="${DOKKU_DATASTORE_ROOT}/dokku-datastore-${DOKKU_DATASTORE_VERSION}"
local DOKKU_DATASTORE_LOCAL="${DOKKU_DATASTORE_ROOT}/dokku-datastore.local"
local DOKKU_DATASTORE_URL="https://github.com/dokku/dokku-datastore/releases/download/${DOKKU_DATASTORE_VERSION}/dokku-datastore-linux-${ARCHITECTURE}"
# the binary has to be in place before anything else, because the rest of the
# install is the binary's own trigger-install command
mkdir -p "$DOKKU_DATASTORE_ROOT" || dokku_log_fail "Unable to create the ${PLUGIN_COMMAND_PREFIX} plugin data directory"
chown -R "${DOKKU_SYSTEM_USER}:${DOKKU_SYSTEM_GROUP}" "$DOKKU_DATASTORE_ROOT"
# a binary staged here wins over the pinned release, so that an unreleased
# build can be tested against this plugin. stage one with
# `make setup DOKKU_DATASTORE_BINARY=/path/to/dokku-datastore`
if [[ -x "$DOKKU_DATASTORE_LOCAL" ]]; then
dokku_log_info1_quiet "Installing dokku-datastore from ${DOKKU_DATASTORE_LOCAL}"
cp "$DOKKU_DATASTORE_LOCAL" "${DOKKU_DATASTORE_ROOT}/dokku-datastore"
chmod +x "${DOKKU_DATASTORE_ROOT}/dokku-datastore"
"${DOKKU_DATASTORE_ROOT}/dokku-datastore" trigger-install "$PLUGIN_COMMAND_PREFIX"
return
fi
# the binary is asked what it is rather than believed on the strength of its
# filename. A truncated download, a binary for the wrong architecture, one left
# by hand, or a release that was re-tagged all look correct to a name check and
# would then be used for as long as the version stayed pinned
if [[ "$(installed-datastore-version "$DOKKU_DATASTORE_BINARY")" != "$DOKKU_DATASTORE_VERSION" ]]; then
dokku_log_info1_quiet "Installing dokku-datastore@${DOKKU_DATASTORE_VERSION}"
# download to a temporary path so that a failed request cannot leave a file
# behind that the check above would take for an installed binary
if ! curl -sSL --fail "${DOKKU_DATASTORE_URL}" -o "${DOKKU_DATASTORE_BINARY}.download"; then
rm -f "${DOKKU_DATASTORE_BINARY}.download"
dokku_log_fail "Unable to download dokku-datastore@${DOKKU_DATASTORE_VERSION} from ${DOKKU_DATASTORE_URL}"
fi
# made executable before it is asked its version, because curl writes it
# without the bit and a file that cannot run reports nothing
chmod +x "${DOKKU_DATASTORE_BINARY}.download"
local DOWNLOADED_VERSION
DOWNLOADED_VERSION="$(installed-datastore-version "${DOKKU_DATASTORE_BINARY}.download")"
if [[ "$DOWNLOADED_VERSION" != "$DOKKU_DATASTORE_VERSION" ]]; then
rm -f "${DOKKU_DATASTORE_BINARY}.download"
dokku_log_fail "Downloaded dokku-datastore reports '${DOWNLOADED_VERSION}' rather than ${DOKKU_DATASTORE_VERSION}"
fi
mv "${DOKKU_DATASTORE_BINARY}.download" "$DOKKU_DATASTORE_BINARY"
fi
cp "$DOKKU_DATASTORE_BINARY" "${DOKKU_DATASTORE_ROOT}/dokku-datastore"
chmod +x "${DOKKU_DATASTORE_ROOT}/dokku-datastore"
"${DOKKU_DATASTORE_ROOT}/dokku-datastore" trigger-install "$PLUGIN_COMMAND_PREFIX"
}
plugin-install "$@"