Skip to content

Commit

Permalink
fix: improve install script
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmerrell committed Jan 10, 2024
1 parent 0536a8a commit eeed522
Showing 1 changed file with 87 additions and 58 deletions.
145 changes: 87 additions & 58 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,81 +1,110 @@
#!/usr/bin/env bash

# Unified installer for RunPOd CLI tool.
# Unified installer for RunPod CLI tool.
# wget -qO- cli.runpod.io | sudo bash

# Verify the script is run with root privileges
if [ "$EUID" -ne 0 ]; then
echo "Please run as root with sudo."
exit 1
fi
check_root() {
if [ "$EUID" -ne 0 ]; then
echo "Please run as root with sudo."
exit 1
fi
}

# Fetch the latest version of RunPod CLI
VERSION=$(wget -q -O- https://api.github.com/repos/runpod/runpodctl/releases/latest | jq -r '.tag_name')
echo "Fetched version: $VERSION" # Debugging line
if [ -z "$VERSION" ]; then
echo "Failed to fetch the latest version of RunPod CLI."
exit 1
fi
REQUIRED_PKGS=("jq") # Add all required packages to this list

# Detect Operating System and set up environment
OS_TYPE=$(uname -s)
REQUIRED_PKG="jq"
DOWNLOAD_URL=""
# Function to install a package based on OS
install_package() {
local package=$1
echo "Installing $package..."

setup_environment() {
case $OS_TYPE in
Linux*)
if ! command -v jq >/dev/null 2>&1; then
echo "No $REQUIRED_PKG. Setting up $REQUIRED_PKG..."
if [[ -f /etc/debian_version ]]; then
apt-get update && apt-get install -y jq
elif [[ -f /etc/redhat-release ]]; then
yum install -y jq
elif [[ -f /etc/fedora-release ]]; then
dnf install -y jq
else
echo "Unsupported Linux distribution for automatic installation."
exit 1
fi
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 "$REQUIRED_PKG already installed, skipping..."
echo "Unsupported Linux distribution for automatic installation of $package."
exit 1
fi
;;
darwin*)
brew install "$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
}

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')
echo "Latest version of RunPod CLI: $VERSION"
if [ -z "$VERSION" ]; then
echo "Failed to fetch the latest version of RunPod CLI."
exit 1
fi
}

set_download_url() {
case $OSTYPE in
linux-gnu*)
DOWNLOAD_URL="https://github.com/runpod/runpodctl/releases/download/${VERSION}/runpodctl-linux-amd"
;;
Darwin*)
if ! command -v jq >/dev/null 2>&1; then
echo "No $REQUIRED_PKG. Setting up $REQUIRED_PKG..."
brew install jq
else
echo "$REQUIRED_PKG already installed, skipping..."
fi
darwin*)
DOWNLOAD_URL="https://github.com/runpod/runpodctl/releases/download/${VERSION}/runpodctl-darwin-arm"
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*)
echo "Please manually install jq for Windows."
DOWNLOAD_URL="https://github.com/runpod/runpodctl/releases/download/${VERSION}/runpodctl-win-amd"
cygwin*|msys*|win32*)
echo "Windows OS detected. Exiting as manual installation is required."
exit 1
;;
*)
echo "Unsupported OS: $OS_TYPE"
echo "Unknown OS detected, exiting..."
exit 1
;;
esac
}

setup_environment
download_and_install_cli() {
local cli_file_name="runpodctl"
if ! wget -q --show-progress "$DOWNLOAD_URL" -O "$cli_file_name"; then
echo "Failed to download $cli_file_name."
exit 1
fi
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 "RunPod CLI installed successfully."
}

# Download the CLI tool
CLI_FILE_NAME="runpodctl"
if ! wget "$DOWNLOAD_URL" -O "$CLI_FILE_NAME"; then
echo "Failed to download $CLI_FILE_NAME."
exit 1
fi
# Main execution flow

# Install the CLI tool
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 "Installing RunPod CLI..."

echo "RunPod CLI installed successfully."
check_root
check_system_requirements
fetch_latest_version
set_download_url
download_and_install_cli

0 comments on commit eeed522

Please sign in to comment.