-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathinstall.sh
More file actions
148 lines (130 loc) · 4.55 KB
/
install.sh
File metadata and controls
148 lines (130 loc) · 4.55 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
#!/usr/bin/env bash
# Unified Installer for RunPod CLI Tool
#
# This script provides a unified approach to installing the RunPod CLI tool.
#
# Usage:
# wget -qO- cli.runpod.net | bash
#
# Requirements:
# - Bash shell
# - Internet connection
# - Homebrew (for macOS users)
# - jq (for JSON processing, will be installed automatically)
#
# Supported Platforms:
# - Linux (amd64)
# - macOS (Intel and Apple Silicon)
set -e
REQUIRED_PKGS=("jq") # Add all required packages to this list, separated by spaces.
# -------------------------------- Check Root -------------------------------- #
check_root() {
if [ "$EUID" -ne 0 ]; then
echo "Please run as root with sudo."
exit 1
fi
}
# ------------------------------ Brew Installer ------------------------------ #
install_with_brew() {
local package=$1
echo "Installing $package with Homebrew..."
local original_user=$(logname)
su - "$original_user" -c "brew install $package"
}
# ------------------------- Install Required Packages ------------------------ #
install_package() {
local package=$1
echo "Installing $package..."
case $OSTYPE in
linux-gnu*)
if [[ -f /etc/debian_version ]]; then
apt-get update && apt-get install -y "$package"
elif [[ -f /etc/redhat-release ]]; then
yum install -y "$package"
elif [[ -f /etc/fedora-release ]]; then
dnf install -y "$package"
else
echo "Unsupported Linux distribution for automatic installation of $package."
exit 1
fi
;;
darwin*)
install_with_brew "$package"
;;
*)
echo "Unsupported OS for automatic installation of $package."
exit 1
;;
esac
}
check_system_requirements() {
local all_installed=true
for pkg in "${REQUIRED_PKGS[@]}"; do
if ! command -v "$pkg" >/dev/null 2>&1; then
echo "$pkg is not installed."
install_package "$pkg"
all_installed=false
fi
done
if [ "$all_installed" = true ]; then
echo "All system requirements satisfied."
fi
}
# ----------------------------- runpodctl Version ---------------------------- #
fetch_latest_version() {
local version_url="https://api.github.com/repos/runpod/runpodctl/releases/latest"
VERSION=$(wget -q -O- "$version_url" | jq -r '.tag_name')
if [ -z "$VERSION" ]; then
echo "Failed to fetch the latest version of runpodctl."
exit 1
fi
echo "Latest version of runpodctl: $VERSION"
}
# ------------------------------- Download URL ------------------------------- #
download_url_constructor() {
local os_type=$(uname -s | tr '[:upper:]' '[:lower:]')
local arch_type=$(uname -m)
if [[ "$os_type" == "darwin" ]]; then
# macOS uses a universal binary (all architectures)
DOWNLOAD_URL="https://github.com/runpod/runpodctl/releases/download/${VERSION}/runpodctl-darwin-all.tar.gz"
return
elif [[ "$os_type" == "linux" ]]; then
if [[ "$arch_type" == "x86_64" ]]; then
arch_type="amd64"
elif [[ "$arch_type" == "aarch64" || "$arch_type" == "arm64" ]]; then
arch_type="arm64"
else
echo "Unsupported Linux architecture: $arch_type"
exit 1
fi
else
echo "Unsupported operating system: $os_type"
exit 1
fi
DOWNLOAD_URL="https://github.com/runpod/runpodctl/releases/download/${VERSION}/runpodctl-${os_type}-${arch_type}.tar.gz"
}
# ---------------------------- Download & Install ---------------------------- #
download_and_install_cli() {
local cli_archive_file_name="runpodctl.tar.gz"
if ! wget -q --progress=bar "$DOWNLOAD_URL" -O "$cli_archive_file_name"; then
echo "Failed to download $cli_archive_file_name."
exit 1
fi
local cli_file_name="runpodctl"
tar -xzf "$cli_archive_file_name" "$cli_file_name"
chmod +x "$cli_file_name"
if ! mv "$cli_file_name" /usr/local/bin/; then
echo "Failed to move $cli_file_name to /usr/local/bin/."
exit 1
fi
echo "runpodctl installed successfully."
}
# ---------------------------------------------------------------------------- #
# Main #
# ---------------------------------------------------------------------------- #
echo "Installing runpodctl..."
check_root
check_system_requirements
fetch_latest_version
download_url_constructor
download_and_install_cli