#!/usr/bin/env bash # Stakly - Cross-platform installer # Owner: @dvc # License: MIT set -e REPO="donrich99/stakly" BINARY_NAME="stakly" VERSION="${STAKLY_VERSION:-latest}" # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' info() { echo -e "${BLUE}[INFO]${NC} $1" } success() { echo -e "${GREEN}[OK]${NC} $1" } warn() { echo -e "${YELLOW}[WARN]${NC} $1" } error() { echo -e "${RED}[ERROR]${NC} $1" exit 1 } detect_os() { OS="$(uname -s)" ARCH="$(uname -m)" case "$OS" in Linux*) OS="linux" ;; Darwin*) OS="darwin" ;; MINGW*|MSYS*|CYGWIN*) OS="windows" ;; *) error "Unsupported operating system: $OS" ;; esac case "$ARCH" in x86_64|amd64) ARCH="x64" ;; aarch64|arm64) ARCH="arm64" ;; armv7l|armv7) ARCH="armv7" ;; i386|i686) ARCH="x86" ;; *) warn "Untested architecture: $ARCH (will try anyway)" ARCH="x64" ;; esac # Detect Termux (Android) if [ -n "$TERMUX_VERSION" ]; then OS="linux" ARCH="arm64" fi info "Detected platform: ${OS}-${ARCH}" } detect_install_dir() { if [ -n "$TERMUX_VERSION" ]; then INSTALL_DIR="$PREFIX/bin" elif [ -w "/usr/local/bin" ]; then INSTALL_DIR="/usr/local/bin" elif [ -w "$HOME/.local/bin" ]; then INSTALL_DIR="$HOME/.local/bin" else INSTALL_DIR="$HOME/bin" mkdir -p "$INSTALL_DIR" fi } download_binary() { cd /tmp if [ "$VERSION" = "latest" ]; then DOWNLOAD_URL="https://github.com/${REPO}/releases/latest/download/${BINARY_NAME}-${OS}-${ARCH}" else DOWNLOAD_URL="https://github.com/${REPO}/releases/download/v${VERSION}/${BINARY_NAME}-${OS}-${ARCH}" fi # Windows has .exe extension if [ "$OS" = "windows" ]; then DOWNLOAD_URL="${DOWNLOAD_URL}.exe" TMP_FILE="${BINARY_NAME}.exe" else TMP_FILE="${BINARY_NAME}" fi info "Downloading from: $DOWNLOAD_URL" if command -v curl >/dev/null 2>&1; then if ! curl -fL -o "$TMP_FILE" "$DOWNLOAD_URL"; then error "Download failed. Please check if a release exists for ${OS}-${ARCH}" fi elif command -v wget >/dev/null 2>&1; then if ! wget -q -O "$TMP_FILE" "$DOWNLOAD_URL"; then error "Download failed. Please check if a release exists for ${OS}-${ARCH}" fi else error "Neither curl nor wget found. Please install one of them." fi success "Download complete" } install_binary() { info "Installing to: $INSTALL_DIR" if [ ! -f "/tmp/$TMP_FILE" ]; then error "Binary not found at /tmp/$TMP_FILE" fi chmod +x "/tmp/$TMP_FILE" mv "/tmp/$TMP_FILE" "$INSTALL_DIR/$BINARY_NAME" success "Installed ${BINARY_NAME} to ${INSTALL_DIR}/${BINARY_NAME}" } check_path() { case ":$PATH:" in *":$INSTALL_DIR:"*) info "Install dir is already in PATH" ;; *) warn "Install dir $INSTALL_DIR is NOT in your PATH" echo "" echo "Add this to your shell config (~/.bashrc, ~/.zshrc, etc.):" echo "" echo " export PATH=\"\$PATH:$INSTALL_DIR\"" echo "" ;; esac } verify_installation() { if command -v "$BINARY_NAME" >/dev/null 2>&1; then success "Installation verified! Run: ${BINARY_NAME} --version" echo "" echo "Quick start:" echo " ${BINARY_NAME} tui # Launch interactive UI" echo " ${BINARY_NAME} add 'My task'" echo " ${BINARY_NAME} list" echo "" else warn "Binary installed but not found in PATH. You may need to restart your shell." fi } main() { echo "" echo -e "${GREEN}Stakly Installer${NC}" echo -e "${BLUE}Owner: @dvc${NC}" echo "" detect_os detect_install_dir download_binary install_binary check_path verify_installation success "Done!" } main "$@"