-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathinstall.sh
More file actions
110 lines (96 loc) · 3.05 KB
/
install.sh
File metadata and controls
110 lines (96 loc) · 3.05 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
#!/bin/sh
# Install dtctl (Dynatrace CLI) on Linux and macOS.
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/dynatrace-oss/dtctl/main/install.sh | sh
#
# Environment variables:
# DTCTL_INSTALL_DIR Override install directory (default: ~/.local/bin on Linux, /usr/local/bin on macOS)
# GITHUB_TOKEN GitHub personal access token to avoid API rate-limiting (optional)
set -e
REPO_OWNER="dynatrace-oss"
REPO_NAME="dtctl"
# Detect OS
OS="$(uname -s)"
case "$OS" in
Linux) os="linux" ;;
Darwin) os="darwin" ;;
*) echo "Error: unsupported OS: $OS"; exit 1 ;;
esac
# Detect architecture
ARCH="$(uname -m)"
case "$ARCH" in
x86_64|amd64) arch="amd64" ;;
aarch64|arm64) arch="arm64" ;;
*) echo "Error: unsupported architecture: $ARCH"; exit 1 ;;
esac
# Default install directory
if [ -n "$DTCTL_INSTALL_DIR" ]; then
install_dir="$DTCTL_INSTALL_DIR"
elif [ "$os" = "darwin" ]; then
install_dir="/usr/local/bin"
else
install_dir="$HOME/.local/bin"
fi
# Fetch latest release tag
echo "Fetching latest release..."
if [ -n "$GITHUB_TOKEN" ]; then
api_response=$(curl -fsSL -H "Authorization: Bearer ${GITHUB_TOKEN}" "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases/latest")
else
api_response=$(curl -fsSL "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases/latest")
fi
tag=$(printf '%s' "$api_response" | grep '"tag_name"' | sed 's/.*"tag_name": *"//;s/".*//')
if [ -z "$tag" ]; then
echo "Error: could not determine latest release."
exit 1
fi
version="${tag#v}"
echo "Latest release: $tag"
# Download
asset="dtctl_${version}_${os}_${arch}.tar.gz"
url="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${tag}/${asset}"
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
echo "Downloading ${asset}..."
if [ -n "$GITHUB_TOKEN" ]; then
curl -fsSL -H "Authorization: Bearer ${GITHUB_TOKEN}" "$url" -o "${tmpdir}/${asset}"
else
curl -fsSL "$url" -o "${tmpdir}/${asset}"
fi
# Extract
echo "Extracting..."
tar -xzf "${tmpdir}/${asset}" -C "$tmpdir"
# Install
mkdir -p "$install_dir"
if [ -w "$install_dir" ]; then
mv "${tmpdir}/dtctl" "$install_dir/dtctl"
else
echo "Installing to ${install_dir} (requires sudo)..."
sudo mv "${tmpdir}/dtctl" "$install_dir/dtctl"
fi
chmod +x "$install_dir/dtctl"
# macOS: remove quarantine attribute
if [ "$os" = "darwin" ] && command -v xattr >/dev/null 2>&1; then
xattr -d com.apple.quarantine "$install_dir/dtctl" 2>/dev/null || true
fi
# Verify
echo ""
"$install_dir/dtctl" version
echo ""
echo "Installed to ${install_dir}/dtctl"
# Check PATH
case ":$PATH:" in
*":${install_dir}:"*) ;;
*)
echo ""
echo "NOTE: ${install_dir} is not in your PATH."
echo "Add it by running:"
echo ""
echo " export PATH=\"\$PATH:${install_dir}\""
echo ""
echo "To make it permanent, add that line to ~/.bashrc, ~/.zshrc, or ~/.profile."
;;
esac
echo ""
echo "Quick setup:"
echo " dtctl auth login --context my-env --environment \"https://YOUR_ENV.apps.dynatrace.com\""