#!/usr/bin/env bash # GoatCMS installer for Linux / macOS # Auto-detects OS and CPU architecture, then installs the matching binary. # # Usage: # curl -fsSL https://goatcms.com/dist/install.sh | bash # curl -fsSL https://goatcms.com/dist/install.sh | bash -s -- --version 0.0.1 # curl -fsSL https://goatcms.com/dist/install.sh | bash -s -- --dir "$HOME/.local/bin" set -euo pipefail VERSION="latest" INSTALL_DIR="" while [ $# -gt 0 ]; do case "$1" in --version) VERSION="$2"; shift 2 ;; --dir) INSTALL_DIR="$2"; shift 2 ;; -h|--help) cat <<'EOF' GoatCMS installer Options: --version Install a specific version (default: latest) --dir Install directory (default: /usr/local/bin or $HOME/.local/bin) -h, --help Show this help EOF exit 0 ;; *) echo "Unknown option: $1" >&2; exit 1 ;; esac done # --- Resolve base URL --------------------------------------------------- if [ "${VERSION}" = "latest" ]; then BASE="https://goatcms.com/dist/latest" curl -fsI "${BASE}/" >/dev/null 2>&1 || BASE="https://goatcms.com/dist/0.0.1" else BASE="https://goatcms.com/dist/${VERSION}" fi # --- Detect OS ---------------------------------------------------------- OS_RAW="$(uname -s)" case "${OS_RAW}" in Linux) OS="linux" ;; Darwin) OS="darwin" ;; *) echo "Unsupported OS: ${OS_RAW}" >&2; exit 1 ;; esac # --- Detect architecture ------------------------------------------------ ARCH_RAW="$(uname -m)" case "${ARCH_RAW}" in x86_64|amd64) ARCH="amd64" ;; aarch64|arm64) ARCH="arm64" ;; *) echo "Unsupported architecture: ${ARCH_RAW}" >&2; exit 1 ;; esac [ "${OS}" = "darwin" ] && [ "${ARCH}" = "amd64" ] && { echo "No darwin/amd64 build available." >&2; exit 1; } # --- Choose install dir ------------------------------------------------- if [ -z "${INSTALL_DIR}" ]; then if [ -w /usr/local/bin ]; then INSTALL_DIR="/usr/local/bin" elif [ -n "${HOME:-}" ] && [ -d "${HOME}/.local/bin" ]; then INSTALL_DIR="${HOME}/.local/bin" else INSTALL_DIR="/usr/local/bin" fi fi echo "Detected: OS=${OS} ARCH=${ARCH} -> ${INSTALL_DIR}" # --- Download ----------------------------------------------------------- TMP="$(mktemp -d)" trap 'rm -rf "${TMP}"' EXIT if [ "${VERSION}" = "latest" ]; then URL="${BASE}/bin/goat_${OS}_${ARCH}" echo "Downloading ${URL}" curl -fsSL "${URL}" -o "${TMP}/goat" else URL="${BASE}/archives/goat_${VERSION}_${OS}_${ARCH}.tar.gz" echo "Downloading ${URL}" curl -fsSL "${URL}" -o "${TMP}/goat.tar.gz" tar -xzf "${TMP}/goat.tar.gz" -C "${TMP}" FOUND="$(find "${TMP}" -type f -name goat -perm -u+x | head -n1 || true)" [ -n "${FOUND}" ] && mv "${FOUND}" "${TMP}/goat" fi chmod +x "${TMP}/goat" # --- Install ------------------------------------------------------------ echo "Installing to ${INSTALL_DIR}/goat" if [ -w "${INSTALL_DIR}" ]; then install -m 0755 "${TMP}/goat" "${INSTALL_DIR}/goat" else sudo install -m 0755 "${TMP}/goat" "${INSTALL_DIR}/goat" fi # --- macOS: clear quarantine ------------------------------------------- if [ "${OS}" = "darwin" ]; then sudo xattr -d com.apple.quarantine "${INSTALL_DIR}/goat" 2>/dev/null || true fi # --- Verify ------------------------------------------------------------- echo "Done. Verifying:" "${INSTALL_DIR}/goat" version || true