-
Notifications
You must be signed in to change notification settings - Fork 704
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·121 lines (107 loc) · 3.46 KB
/
install.sh
File metadata and controls
executable file
·121 lines (107 loc) · 3.46 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
120
121
#!/usr/bin/env bash
set -euo 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
# Set the insecure SSL argument
INSECURE_ARG=""
if [ -n "${INSECURE:-}" ]; then
INSECURE_ARG="--insecure"
fi
REPO="GoogleCloudPlatform/kubectl-ai"
BINARY="kubectl-ai"
# Detect OS
sysOS="$(uname | tr '[:upper:]' '[:lower:]')"
case "$sysOS" in
linux) OS="Linux" ;;
darwin) OS="Darwin" ;;
*)
echo "If you are on Windows or another unsupported OS, please follow the manual installation instructions at:"
echo "https://github.com/GoogleCloudPlatform/kubectl-ai#manual-installation-linux-macos-and-windows"
exit 1
;;
esac
# Detect NixOS
nixos_check="$(grep "ID=nixos" /etc/os-release 2>/dev/null || echo "no-match")"
case "$nixos_check" in
*nixos*)
echo "NixOS detected, please follow the manual installation instructions at:"
echo "https://github.com/GoogleCloudPlatform/kubectl-ai#install-on-nixos"
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/GoogleCloudPlatform/kubectl-ai#manual-installation-linux-macos-and-windows"
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
if [ -n "${INSECURE:-}" ]; then
echo "⚠️ SECURITY WARNING: INSECURE is set, SSL certificate validation will be skipped!"
echo " This makes you vulnerable to man-in-the-middle attacks and other security risks."
echo " Only proceed if you understand the security implications and trust your network."
echo ""
echo " Continue with unsafe download? (yes/no)"
read -r response
case "$response" in
[yY][eE][sS]|[yY])
echo "Proceeding with insecure connection..."
;;
*)
echo "Installation aborted for security reasons."
exit 1
;;
esac
fi
LATEST_TAG=$(curl $INSECURE_ARG -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
# Compose download URL
TARBALL="kubectl-ai_${OS}_${ARCH}.tar.gz"
URL="https://github.com/$REPO/releases/download/$LATEST_TAG/$TARBALL"
# Create temp dir and set cleanup trap
TEMP_DIR="$(mktemp -d)"
cleanup() {
if [ -n "${TEMP_DIR:-}" ] && [ -d "$TEMP_DIR" ]; then
rm -rf "$TEMP_DIR"
fi
}
trap cleanup EXIT INT TERM
# Download and extract in temp dir; install from there
(
cd "$TEMP_DIR"
echo "Downloading $URL ..."
CURL_FLAGS="-fSL --retry 3"
if [ -n "${INSECURE:-}" ]; then
echo "⚠️ SSL certificate validation will be skipped for this download."
fi
curl $INSECURE_ARG $CURL_FLAGS "$URL" -o "$TARBALL"
tar --no-same-owner -xzf "$TARBALL"
if [ ! -f "$BINARY" ]; then
echo "Error: expected binary '$BINARY' not found after extraction."
exit 1
fi
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
echo "Installing $BINARY to $INSTALL_DIR (may require sudo)..."
sudo install -m 0755 "$BINARY" "$INSTALL_DIR/"
)
echo "✅ $BINARY installed successfully! Run '$BINARY --help' to get started."