-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·111 lines (94 loc) · 3.33 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·111 lines (94 loc) · 3.33 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
#!/usr/bin/env bash
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
set -o nounset
set -o pipefail
# Check for required commands
for cmd in curl tar; do
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "Error: $cmd is not installed. Please install $cmd to proceed."
exit 1
fi
done
# Check for hash verification tool
if ! command -v sha256sum >/dev/null 2>&1 && ! command -v shasum >/dev/null 2>&1; then
echo "Error: Neither sha256sum nor shasum is installed. Please install one of them to proceed."
exit 1
fi
REPO="GoogleCloudPlatform/gke-mcp"
BINARY="gke-mcp"
# Detect OS
sysOS="$(uname | tr '[:upper:]' '[:lower:]')"
case "$sysOS" in
linux) OS="Linux" ;;
darwin) OS="Darwin" ;;
*)
echo "If you are on an unsupported OS, please follow the manual installation instructions at:"
echo "https://github.com/${REPO}#installation"
exit 1
;;
esac
# Detect ARCH
ARCH="$(uname -m)"
case "${ARCH}" in
x86_64 | amd64) ARCH="x86_64" ;;
arm64 | aarch64) ARCH="arm64" ;;
*)
echo "If you are on an unsupported architecture, please follow the manual installation instructions at:"
echo "https://github.com/${REPO}#installation"
exit 1
;;
esac
# Get latest version tag from GitHub API, Use GITHUB_TOKEN if available to avoid potential rate limit
if [ -n "${GITHUB_TOKEN:-}" ]; then
auth_hdr="Authorization: token $GITHUB_TOKEN"
else
auth_hdr=""
fi
LATEST_TAG=$(curl -s -H "$auth_hdr" \
"https://api.github.com/repos/${REPO}/releases/latest" |
sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p')
if [ -z "${LATEST_TAG}" ]; then
echo "Failed to fetch latest release tag."
exit 1
fi
VERSION="${LATEST_TAG#v}"
# Compose download URL
TARBALL="${BINARY}_${OS}_${ARCH}.tar.gz"
TAR_GZ_URL="https://github.com/${REPO}/releases/download/${LATEST_TAG}/${TARBALL}"
CHECKSUM_URL="https://github.com/${REPO}/releases/download/${LATEST_TAG}/gke-mcp_${VERSION}_checksums.txt"
# Set up trap for cleanup
trap 'rm -f "${TARBALL}" checksums.txt' EXIT
# Download and extract
echo "Downloading ${TAR_GZ_URL} ..."
curl -fSL --retry 3 "${TAR_GZ_URL}" -o "${TARBALL}"
echo "Downloading ${CHECKSUM_URL} ..."
curl -fSL --retry 3 "${CHECKSUM_URL}" -o checksums.txt
echo "Verifying checksum ..."
if ! grep -Fq "${TARBALL}" checksums.txt; then
echo "Error: Checksum for ${TARBALL} not found in checksums.txt"
exit 1
fi
if command -v sha256sum >/dev/null 2>&1; then
grep -F "${TARBALL}" checksums.txt | sha256sum -c -
else
grep -F "${TARBALL}" checksums.txt | shasum -a 256 -c -
fi
tar --no-same-owner -xzf "${TARBALL}"
# Move binary to /usr/local/bin (may require sudo)
echo "Installing ${BINARY} to /usr/local/bin (may require sudo)..."
install -m 0755 "${BINARY}" /usr/local/bin/ || sudo install -m 0755 "${BINARY}" /usr/local/bin/
# Cleanup is handled by trap on EXIT
echo "✅ ${BINARY} installed successfully! Run '${BINARY} --help' to get started."