#!/usr/bin/env bash
#
# EasySend CLI installer
# Usage: curl -fsSL https://easysend.co/cli/install.sh | bash
#

set -euo pipefail

INSTALL_DIR="/usr/local/bin"
SCRIPT_URL="https://easysend.co/cli/easysend"

echo "Installing easysend CLI..."

# Check for curl
if ! command -v curl &>/dev/null; then
    echo "Error: curl is required. Install it first." >&2
    exit 1
fi

# Check write permissions
if [ ! -w "$INSTALL_DIR" ]; then
    echo "Need sudo to install to $INSTALL_DIR"
    sudo curl -fsSL "$SCRIPT_URL" -o "${INSTALL_DIR}/easysend"
    sudo chmod +x "${INSTALL_DIR}/easysend"
else
    curl -fsSL "$SCRIPT_URL" -o "${INSTALL_DIR}/easysend"
    chmod +x "${INSTALL_DIR}/easysend"
fi

echo ""
echo "Installed! Try it:"
echo "  easysend photo.jpg"
echo ""
echo "Run 'easysend --help' for all options."
