#!/bin/sh # Docka CLI Quick Install Script # Usage: curl -fsSL https://get.docka.dev | sh # Works on: Linux, macOS, FreeBSD (amd64, arm64) set -e VERSION="v0.1.16" INSTALL_DIR="/usr/local/bin" # Colors (disabled if not a terminal) if [ -t 1 ]; then RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' else RED='' GREEN='' YELLOW='' BLUE='' NC='' fi info() { printf "${BLUE}[INFO]${NC} %s\n" "$1"; } success() { printf "${GREEN}[OK]${NC} %s\n" "$1"; } warn() { printf "${YELLOW}[WARN]${NC} %s\n" "$1"; } error() { printf "${RED}[ERROR]${NC} %s\n" "$1"; exit 1; } # Run command with sudo if needed and available run_privileged() { if [ "$(id -u)" -eq 0 ]; then "$@" elif command -v sudo >/dev/null 2>&1; then sudo "$@" elif command -v doas >/dev/null 2>&1; then doas "$@" else error "This script requires root privileges. Please run as root or install sudo." fi } # Download function (curl or wget) download() { url="$1" output="$2" if command -v curl >/dev/null 2>&1; then curl -fsSL "$url" -o "$output" elif command -v wget >/dev/null 2>&1; then wget -q "$url" -O "$output" else error "curl or wget is required to download files" fi } # Detect OS detect_os() { OS=$(uname -s | tr '[:upper:]' '[:lower:]') case "$OS" in linux) OS="linux" ;; darwin) OS="darwin" ;; freebsd) OS="linux" # Use Linux binary for FreeBSD (usually works) warn "FreeBSD detected, using Linux binary" ;; msys*|mingw*|cygwin*) error "Windows detected. Please use the Windows installer or PowerShell script instead." ;; *) error "Unsupported operating system: $OS" ;; esac echo "$OS" } # Detect architecture detect_arch() { ARCH=$(uname -m) case "$ARCH" in x86_64|amd64) ARCH="amd64" ;; aarch64|arm64) ARCH="arm64" ;; armv7l|armhf) error "32-bit ARM is not supported. Please use a 64-bit system." ;; i386|i686) error "32-bit x86 is not supported. Please use a 64-bit system." ;; *) error "Unsupported architecture: $ARCH" ;; esac echo "$ARCH" } # Main installation main() { info "Docka CLI Installer" info "===================" echo "" OS=$(detect_os) ARCH=$(detect_arch) info "Detected: $OS/$ARCH" info "Installing version: $VERSION" echo "" # Construct download URL FILENAME="docka-${OS}-${ARCH}.tar.gz" URL="https://docka.dev/releases/download/${VERSION}/${FILENAME}" # Create temp directory TMPDIR=$(mktemp -d) trap "rm -rf $TMPDIR" EXIT info "Downloading $FILENAME..." download "$URL" "$TMPDIR/$FILENAME" info "Extracting..." tar -xzf "$TMPDIR/$FILENAME" -C "$TMPDIR" # Find the binary (might be in subdirectory) BINARY=$(find "$TMPDIR" -name "docka" -type f -perm -111 2>/dev/null | head -1) if [ -z "$BINARY" ]; then BINARY="$TMPDIR/docka" fi if [ ! -f "$BINARY" ]; then error "Binary not found in archive" fi info "Installing to $INSTALL_DIR/docka..." run_privileged install -m 755 "$BINARY" "$INSTALL_DIR/docka" success "Docka CLI installed successfully!" echo "" info "Run 'docka --help' to get started" info "Documentation: https://docka.dev/docs" } main "$@"