-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
54 lines (42 loc) · 1.55 KB
/
setup.sh
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
#!/bin/bash
# Function to fetch the download URL for the latest release
fetch_download_url() {
local os=$(uname -s | tr '[:upper:]' '[:lower:]')
local arch=$(uname -m | sed 's/x86_64/amd64/; s/aarch64/arm64/; s/armv7l/arm/') # Map common architectures
# Debug output to stderr
echo "Detected OS: $os, Architecture: $arch" >&2
# Fetch the latest release JSON and extract the download URL
local url=$(curl -s https://api.github.com/repos/ksauraj/k8au-shell-analyzer/releases/latest | grep -oP '"browser_download_url": "\K[^"]+' | grep "$os" | grep -E "$arch|armv7l|aarch64")
if [[ -z "$url" ]]; then
echo "Error: No binary found for OS: $os, Architecture: $arch." >&2
exit 1
fi
# Sanitize the URL by removing any trailing whitespace or special characters
url=$(echo "$url" | tr -d '\r')
# Debug output to stderr
echo "Download URL: $url" >&2
# Return the URL to stdout
echo "$url"
}
# Function to download and run the binary
download_and_run() {
local url=$1
local binary_name="k8au-shell-analyser"
echo "Downloading binary from URL: $url" >&2
if ! curl -L -o "$binary_name" "$url"; then
echo "Error: Failed to download the binary. Please check your internet connection and try again." >&2
exit 1
fi
echo "Making the binary executable..." >&2
chmod +x "$binary_name"
echo "Running the binary..." >&2
./"$binary_name"
}
# Main script execution
download_url=$(fetch_download_url)
if [[ -n "$download_url" ]]; then
download_and_run "$download_url"
else
echo "Error: Unable to fetch download URL." >&2
exit 1
fi