-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
37 lines (29 loc) · 1.33 KB
/
install.sh
File metadata and controls
37 lines (29 loc) · 1.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
#!/bin/sh
(
set -e
error() {
echo "[ERROR] $1" >&2
exit 1
}
REPO="PaloAltoNetworks/ktool"
ASSET_NAME="kubectl-ktool.sh"
BINARY_NAME="kubectl-ktool"
INSTALL_PATH="/usr/local/bin/$BINARY_NAME"
echo "--> Getting latest release information..."
RELEASE_JSON=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest") || error "Failed to fetch release info"
VERSION=$(echo "$RELEASE_JSON" | grep -m 1 '"tag_name":' | cut -d'"' -f4) || error "Failed to parse version tag"
if [ -z "$VERSION" ]; then
error "Could not find latest version tag"
fi
DOWNLOAD_URL=$(echo "$RELEASE_JSON" | grep -m 1 'browser_download_url' | grep "$ASSET_NAME" | cut -d'"' -f4) || error "Failed to find download URL for $ASSET_NAME"
if [ -z "$DOWNLOAD_URL" ]; then
error "Download URL for $ASSET_NAME is empty"
fi
echo "--> Downloading $BINARY_NAME ($VERSION)..."
curl -fsSL -o "/tmp/$BINARY_NAME" "$DOWNLOAD_URL" || error "Download failed"
echo "--> Making it executable..."
chmod +x "/tmp/$BINARY_NAME" || error "Failed to make executable"
echo "--> Moving to /usr/local/bin (may require sudo)..."
sudo mv "/tmp/$BINARY_NAME" "$INSTALL_PATH" || error "Failed to move binary to $INSTALL_PATH"
echo -e "✅ All set! ktool is now up-to-date.\n\nTo verify, run the following command:\n kubectl ktool version"
)