-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
119 lines (94 loc) · 3.69 KB
/
Copy pathinstall.sh
File metadata and controls
119 lines (94 loc) · 3.69 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/sh
# DISCLAIMER
# This script is licensed under the MIT License
# The software installed by this script is subject to its own license terms. For more information see NOTICE.md and the documentation provided by the software vendor.
set -eu
echo "Activating feature 'databricks-cli'"
VERSION="${VERSION:-main}"
TARGET_BIN="/usr/local/bin/databricks"
echo "The effective dev container remoteUser is '$_REMOTE_USER'"
echo "The effective dev container remoteUser's home directory is '$_REMOTE_USER_HOME'"
echo "The effective dev container containerUser is '$_CONTAINER_USER'"
echo "The effective dev container containerUser's home directory is '$_CONTAINER_USER_HOME'"
require_command() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "Error: required command '$1' is not installed."
exit 1
fi
}
checksum_verify() {
checksum_file="$1"
archive_name="$2"
archive_checksum_file="$TMP_DIR/${archive_name}.sha256"
if ! grep "[ *]${archive_name}\$" "$TMP_DIR/$checksum_file" >"$archive_checksum_file"; then
echo "Error: checksum entry for '$archive_name' was not found in '$checksum_file'."
exit 1
fi
if command -v sha256sum >/dev/null 2>&1; then
(cd "$TMP_DIR" && sha256sum -c "$(basename "$archive_checksum_file")" >/dev/null)
return
fi
if command -v shasum >/dev/null 2>&1; then
expected_hash="$(awk '{print $1}' "$archive_checksum_file")"
actual_hash="$(shasum -a 256 "$TMP_DIR/$archive_name" | awk '{print $1}')"
[ "$expected_hash" = "$actual_hash" ]
return
fi
echo "Error: neither 'sha256sum' nor 'shasum' is available for checksum verification."
exit 1
}
resolve_version() {
requested_version="$1"
if [ "$requested_version" = "main" ] || [ "$requested_version" = "latest" ]; then
latest_release_url="$(curl -fsSL -o /dev/null -w '%{url_effective}' https://github.com/databricks/cli/releases/latest)"
resolved_version="${latest_release_url##*/}"
else
resolved_version="$requested_version"
fi
case "$resolved_version" in
v*) printf '%s\n' "$resolved_version" ;;
*) printf 'v%s\n' "$resolved_version" ;;
esac
}
detect_arch() {
raw_arch="$(uname -m)"
case "$raw_arch" in
x86_64|amd64) printf 'amd64\n' ;;
aarch64|arm64) printf 'arm64\n' ;;
*)
echo "Error: unsupported architecture '$raw_arch'. Supported architectures: amd64, arm64."
exit 1
;;
esac
}
require_command curl
require_command tar
require_command install
resolved_version="$(resolve_version "$VERSION")"
version_number="${resolved_version#v}"
arch="$(detect_arch)"
archive_name="databricks_cli_${version_number}_linux_${arch}.tar.gz"
checksum_name="databricks_cli_${version_number}_SHA256SUMS_unix"
release_base_url="https://github.com/databricks/cli/releases/download/${resolved_version}"
echo "Installing Databricks CLI version: ${resolved_version} for linux/${arch}"
TMP_DIR="$(mktemp -d)"
STAGED_BIN=""
cleanup() {
if [ -n "$STAGED_BIN" ] && [ -e "$STAGED_BIN" ]; then
rm -f "$STAGED_BIN"
fi
rm -rf "$TMP_DIR"
}
trap cleanup EXIT INT HUP TERM
curl -fsSLo "$TMP_DIR/$archive_name" "${release_base_url}/${archive_name}"
curl -fsSLo "$TMP_DIR/$checksum_name" "${release_base_url}/${checksum_name}"
if ! checksum_verify "$checksum_name" "$archive_name"; then
echo "Error: checksum verification failed for '$archive_name'."
exit 1
fi
tar -xzf "$TMP_DIR/$archive_name" -C "$TMP_DIR"
STAGED_BIN="$(mktemp "${TARGET_BIN}.tmp.XXXXXX")"
install -m 0755 "$TMP_DIR/databricks" "$STAGED_BIN"
mv -f "$STAGED_BIN" "$TARGET_BIN"
STAGED_BIN=""
echo "Databricks CLI installed successfully: $("$TARGET_BIN" -v)"