forked from NVIDIA/cloud-native-stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·194 lines (149 loc) · 4.86 KB
/
install
File metadata and controls
executable file
·194 lines (149 loc) · 4.86 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env bash
set -euo pipefail
# Configuration
OWNER="NVIDIA"
PROJECT="eidos"
REPO="$OWNER/$PROJECT"
BIN_NAME="eidos"
CHECKSUMS_FILE="eidos_checksums.txt"
REQUIRED_TOOLS=(curl)
INSTALL_DIR="${1:-/usr/local/bin}"
# Colors
COLOR_RED='\033[0;31m'
COLOR_RESET='\033[0m'
# ==============================================================================
# Utility Functions
# ==============================================================================
usage() {
cat <<EOF
Install utility for $BIN_NAME
Usage: $0 [-d install_dir]
Environment Variables:
GITHUB_TOKEN Optional GitHub token to avoid API rate limits
Examples:
$0 # Install to /usr/local/bin
$0 -d ~/bin # Install to custom directory
GITHUB_TOKEN=xyz $0 # Install with authentication
EOF
exit 1
}
err() {
printf "${COLOR_RED}%s${COLOR_RESET}\n" "$1" >&2
exit 1
}
msg() {
printf "%s\n" "$1" >&2
}
has_tools() {
local missing=()
for tool in "$@"; do
command -v "$tool" &>/dev/null || missing+=("$tool")
done
[[ ${#missing[@]} -eq 0 ]] || err "Required tools not installed: ${missing[*]}"
}
normalize_arch() {
local arch="$1"
[[ $arch == "x86_64" ]] && echo "amd64" || echo "$arch"
}
get_os() {
case $(uname -s) in
Darwin) echo "darwin" ;;
Linux) echo "linux" ;;
*) echo "windows" ;;
esac
}
get_binary_name() {
echo "${BIN_NAME}_${1}_${2}_${3}" # version, os, arch
}
# ==============================================================================
# GitHub API Functions
# ==============================================================================
github_curl() {
local url="$1"
local output_file="${2:-}"
local curl_opts=(-w "%{http_code}")
[[ -n "${GITHUB_TOKEN:-}" ]] && curl_opts+=(-H "Authorization: token $GITHUB_TOKEN")
if [[ -n "$output_file" ]]; then
# Show progress bar for file downloads (can be large)
curl_opts+=(-# -Lo "$output_file")
else
# Silent for API calls
curl_opts+=(-s)
fi
curl "${curl_opts[@]}" "$url"
}
fetch_latest_release() {
local api_url="https://api.github.com/repos/${REPO}/releases/latest"
local response
msg "Fetching latest release from GitHub..."
response=$(github_curl "$api_url")
[[ -z "$response" ]] && err "Failed to fetch release information from GitHub API"
if grep -q "API rate limit exceeded" <<< "$response"; then
err "GitHub API rate limit exceeded. Set GITHUB_TOKEN environment variable or try again later."
fi
echo "$response"
}
extract_version() {
local json="$1"
local version
version=$(grep -m 1 '"tag_name"' <<< "$json" | sed -E 's/.*"tag_name"[[:space:]]*:[[:space:]]*"([^"]+)".*/\1/')
[[ -z "$version" || "$version" == "null" ]] && err "Failed to extract version from GitHub API response"
echo "$version"
}
download_file() {
local url="$1"
local output="$2"
local desc="${3:-file}"
local http_code
msg "Downloading $desc..."
http_code=$(github_curl "$url" "$output" | tail -c 3)
[[ "$http_code" == "200" ]] || err "Failed to download $desc (HTTP $http_code): $url"
}
# ==============================================================================
# Main Installation Logic
# ==============================================================================
main() {
# Parse arguments
while getopts "d:h" opt; do
case $opt in
d) INSTALL_DIR="$OPTARG" ;;
h) usage ;;
*) usage ;;
esac
done
# Detect platform
local os arch version binary_name temp_dir
os=$(get_os)
arch=$(normalize_arch "$(uname -m)")
# Validate platform
[[ $os == "linux" || $os == "darwin" ]] || err "Unsupported OS: $os"
[[ $arch == "amd64" || $arch == "arm64" ]] || err "Unsupported architecture: $arch"
has_tools "${REQUIRED_TOOLS[@]}"
# Fetch release information
local release_json
release_json=$(fetch_latest_release)
version=$(extract_version "$release_json")
binary_name=$(get_binary_name "$version" "$os" "$arch")
msg "Platform: $os/$arch"
msg "Version: $version"
# Download and verify binary
temp_dir=$(mktemp -d)
trap "rm -rf $temp_dir" EXIT
local binary_url="${REPO}/releases/download/${version}/${binary_name}"
local checksum_url="${REPO}/releases/download/${version}/${CHECKSUMS_FILE}"
download_file "https://github.com/${binary_url}" "${temp_dir}/${binary_name}" "$binary_name"
download_file "https://github.com/${checksum_url}" "${temp_dir}/checksums.txt" "checksums"
# Verify checksum
msg "Verifying checksum..."
(cd "$temp_dir" && grep "$binary_name" checksums.txt | shasum -a 256 --check --strict) \
|| err "Checksum verification failed"
# Install binary
chmod +x "${temp_dir}/${binary_name}"
msg "Installing $BIN_NAME to $INSTALL_DIR"
sudo mv "${temp_dir}/${binary_name}" "${INSTALL_DIR}/${BIN_NAME}"
# Verify installation
msg "$BIN_NAME installed successfully!"
"${BIN_NAME}" --version
}
# Run main function
main "$@"