|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Function to get latest release version |
| 4 | +get_latest_version() { |
| 5 | + curl -sS https://api.github.com/repos/bjarneo/peachy/releases/latest | grep "tag_name" | cut -d '"' -f 4 |
| 6 | +} |
| 7 | + |
| 8 | +# Function to detect OS and architecture |
| 9 | +detect_system() { |
| 10 | + local os |
| 11 | + local arch |
| 12 | + |
| 13 | + # Detect OS |
| 14 | + case "$(uname -s)" in |
| 15 | + Darwin*) os="darwin" ;; |
| 16 | + Linux*) os="linux" ;; |
| 17 | + *) echo "Unsupported operating system" && exit 1 ;; |
| 18 | + esac |
| 19 | + |
| 20 | + # Detect architecture |
| 21 | + case "$(uname -m)" in |
| 22 | + x86_64) arch="amd64" ;; |
| 23 | + arm64) arch="arm64" ;; |
| 24 | + aarch64) arch="arm64" ;; |
| 25 | + *) echo "Unsupported architecture" && exit 1 ;; |
| 26 | + esac |
| 27 | + |
| 28 | + echo "${os}-${arch}" |
| 29 | +} |
| 30 | + |
| 31 | +# Main installation process |
| 32 | +main() { |
| 33 | + echo "Detecting system..." |
| 34 | + local system=$(detect_system) |
| 35 | + local version=$(get_latest_version) |
| 36 | + |
| 37 | + echo "Latest version: ${version}" |
| 38 | + echo "System detected: ${system}" |
| 39 | + |
| 40 | + # Check if peachy already exists |
| 41 | + if command -v peachy >/dev/null 2>&1; then |
| 42 | + echo "peachy is already installed at $(which peachy)" |
| 43 | + # Only prompt if running interactively (not piped) |
| 44 | + if [ -t 0 ]; then |
| 45 | + read -p "Do you want to override the existing installation? (y/N) " response |
| 46 | + case "$response" in |
| 47 | + [yY][eE][sS]|[yY]) |
| 48 | + echo "Proceeding with installation..." |
| 49 | + ;; |
| 50 | + *) |
| 51 | + echo "Installation cancelled" |
| 52 | + exit 0 |
| 53 | + ;; |
| 54 | + esac |
| 55 | + else |
| 56 | + echo "Upgrading..." |
| 57 | + fi |
| 58 | + fi |
| 59 | + |
| 60 | + local binary_name="peachy-${system}" |
| 61 | + local download_url="https://github.com/bjarneo/peachy/releases/download/${version}/${binary_name}" |
| 62 | + |
| 63 | + echo "Downloading peachy..." |
| 64 | + if ! curl -sSL -o peachy "${download_url}"; then |
| 65 | + echo "Failed to download peachy" |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | + |
| 69 | + echo "Making binary executable..." |
| 70 | + chmod +x peachy |
| 71 | + |
| 72 | + echo "Moving to /usr/local/bin..." |
| 73 | + if ! sudo mv peachy /usr/local/bin/peachy; then |
| 74 | + echo "Failed to move peachy to /usr/local/bin" |
| 75 | + echo "Please run with sudo or check permissions" |
| 76 | + exit 1 |
| 77 | + fi |
| 78 | + |
| 79 | + echo "peachy has been successfully installed!" |
| 80 | + echo "You can now use it by running: peachy --help" |
| 81 | +} |
| 82 | + |
| 83 | +main |
0 commit comments