#!/bin/bash # SPDX-FileCopyrightText: Copyright (C) 2025 Akshat Kotpalliwar (alias IntegerAlex) # SPDX-License-Identifier: GPL-3.0-only set -e BINARY_NAME="rig" INSTALL_DIR="$HOME/.local/bin" RELEASE_URL="https://github.com/IntegerAlex/rig/releases/latest" echo "Installing rig - Opinionated system setup tool..." echo "Repository: IntegerAlex/rig" echo "Install directory: $HOME/.local/bin" # Detect architecture ARCH=$(uname -m) case $ARCH in x86_64) ARCH="x86_64" ;; aarch64|arm64) ARCH="aarch64" ;; *) echo "❌ Unsupported architecture: $ARCH" echo "rig currently supports x86_64 and aarch64 architectures" exit 1 ;; esac # Detect OS - only support Linux OS=$(uname -s | tr '[:upper:]' '[:lower:]') if [ "$OS" != "linux" ]; then echo "❌ Unsupported operating system: $OS" echo "rig is designed for Linux systems only" exit 1 fi echo "✅ Detected: Linux $ARCH" # Check if running on Debian-based system (has apt) if ! command -v apt-get &> /dev/null; then echo "❌ This installer requires a Debian-based Linux distribution (Ubuntu, Debian, etc.)" echo "apt-get command not found. Please install rig manually from:" echo "https://github.com/IntegerAlex/rig/releases" exit 1 fi echo "✅ Debian-based system detected" # Get latest release tag echo "📦 Fetching latest release..." LATEST_TAG=$(curl -s "https://api.github.com/repos/IntegerAlex/rig/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') if [ -z "$LATEST_TAG" ]; then echo "❌ Error: Could not fetch latest release tag" echo "Please check your internet connection and try again" exit 1 fi echo "📋 Latest release: $LATEST_TAG" # Construct download URL ASSET_NAME="rig" DOWNLOAD_URL="https://github.com/IntegerAlex/rig/releases/download/$LATEST_TAG/$ASSET_NAME" echo "⬇️ Downloading from: $DOWNLOAD_URL" # Create install directory if it doesn't exist mkdir -p "$INSTALL_DIR" # Download binary TEMP_FILE=$(mktemp) if curl -L -f -o "$TEMP_FILE" "$DOWNLOAD_URL"; then echo "✅ Download successful" else echo "❌ Error: Failed to download binary" echo "Tried URL: $DOWNLOAD_URL" echo "Available releases: https://github.com/IntegerAlex/rig/releases" rm -f "$TEMP_FILE" exit 1 fi # Make binary executable chmod +x "$TEMP_FILE" # Install to target directory INSTALL_PATH="$INSTALL_DIR/$BINARY_NAME" mv "$TEMP_FILE" "$INSTALL_PATH" echo "✅ Installed to: $INSTALL_PATH" # Configure shell for permanent PATH setup echo "" echo "🔧 Configuring shell..." # Detect shell SHELL_TYPE="" if [[ "$SHELL" == *"zsh"* ]]; then SHELL_TYPE="zsh" elif [[ "$SHELL" == *"bash"* ]]; then SHELL_TYPE="bash" else # Fallback: check current shell process if ps -p $$ -o cmd= | grep -q zsh; then SHELL_TYPE="zsh" else SHELL_TYPE="bash" fi fi echo "→ Detected shell: $SHELL_TYPE" # Determine config file CONFIG_FILE="" if [[ "$SHELL_TYPE" == "zsh" ]]; then # Check for existing zsh config files in order of preference if [[ -f "$HOME/.zshrc" ]]; then CONFIG_FILE="$HOME/.zshrc" elif [[ -f "$HOME/.zprofile" ]]; then CONFIG_FILE="$HOME/.zprofile" elif [[ -f "$HOME/.zshenv" ]]; then CONFIG_FILE="$HOME/.zshenv" else CONFIG_FILE="$HOME/.zshrc" fi else # Check for existing bash config files in order of preference if [[ -f "$HOME/.bashrc" ]]; then CONFIG_FILE="$HOME/.bashrc" elif [[ -f "$HOME/.bash_profile" ]]; then CONFIG_FILE="$HOME/.bash_profile" elif [[ -f "$HOME/.profile" ]]; then CONFIG_FILE="$HOME/.profile" else CONFIG_FILE="$HOME/.bashrc" fi fi echo "→ Config file: $(basename "$CONFIG_FILE")" # Check if PATH entry already exists PATH_ENTRY="export PATH="$HOME/.local/bin:$PATH"" if grep -q "$PATH_ENTRY" "$CONFIG_FILE" 2>/dev/null; then echo "→ PATH entry already exists in $(basename "$CONFIG_FILE")" else # Add PATH entry to config file echo "" >> "$CONFIG_FILE" echo "# Added by rig installer" >> "$CONFIG_FILE" echo "$PATH_ENTRY" >> "$CONFIG_FILE" echo "✅ Added PATH entry to $(basename "$CONFIG_FILE")" fi # Add to current session PATH if not already there if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then export PATH="$INSTALL_DIR:$PATH" echo "→ Added to current session PATH" fi echo "" echo "🎉 Installation complete!" echo "" # Check if we can access the terminal (even when stdin is piped) if [ -t 1 ] && [ -c /dev/tty ] 2>/dev/null; then echo "🚀 Running rig..." echo "" # Execute rig automatically - redirect stdin from /dev/tty to allow interactive prompts "$INSTALL_PATH" < /dev/tty else echo "📖 To run rig, execute:" echo " rig" echo "" echo "📚 rig is an opinionated system setup tool for Linux" echo " It helps you install essential development tools with a beautiful UI" fi