#!/bin/bash set -e # Kathan CLI Installer # Usage: curl -fsSL https://cli.kathan.tech/install.sh | bash BLUE='\033[38;2;65;105;225m' GREEN='\033[0;32m' DIM='\033[2m' RESET='\033[0m' BOLD='\033[1m' INSTALL_DIR="${KATHAN_INSTALL_DIR:-$HOME/.kathan/bin}" VERSION="${KATHAN_VERSION:-latest}" BASE_URL="https://cli.kathan.tech" echo "" echo -e "${BLUE} ██╗ ██╗ █████╗ ████████╗██╗ ██╗ █████╗ ███╗ ██╗${RESET}" echo -e "${BLUE} ██║ ██╔╝██╔══██╗╚══██╔══╝██║ ██║██╔══██╗████╗ ██║${RESET}" echo -e "${BLUE} █████╔╝ ███████║ ██║ ███████║███████║██╔██╗ ██║${RESET}" echo -e "${BLUE} ██╔═██╗ ██╔══██║ ██║ ██╔══██║██╔══██║██║╚██╗██║${RESET}" echo -e "${BLUE} ██║ ██╗██║ ██║ ██║ ██║ ██║██║ ██║██║ ╚████║${RESET}" echo -e "${BLUE} ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝${RESET}" echo "" echo -e " ${BOLD}Kathan CLI Installer${RESET}" echo "" # Detect OS and architecture OS="$(uname -s | tr '[:upper:]' '[:lower:]')" ARCH="$(uname -m)" case "$OS" in darwin) OS="darwin" ;; linux) OS="linux" ;; *) echo " ✗ Unsupported OS: $OS"; exit 1 ;; esac case "$ARCH" in x86_64|amd64) ARCH="x64" ;; arm64|aarch64) ARCH="arm64" ;; *) echo " ✗ Unsupported architecture: $ARCH"; exit 1 ;; esac echo -e " ${DIM}Platform: ${OS}-${ARCH}${RESET}" # Create install directory mkdir -p "$INSTALL_DIR" # Download kathan-cli binary BINARY_NAME="kathan-cli-${OS}-${ARCH}" BINARY_URL="${BASE_URL}/${VERSION}/${BINARY_NAME}" echo -e " ${DIM}Downloading kathan-cli...${RESET}" if command -v curl &> /dev/null; then curl -fsSL "$BINARY_URL" -o "${INSTALL_DIR}/kathan-cli" elif command -v wget &> /dev/null; then wget -q "$BINARY_URL" -O "${INSTALL_DIR}/kathan-cli" else echo " ✗ Neither curl nor wget found"; exit 1 fi chmod +x "${INSTALL_DIR}/kathan-cli" echo -e " ${GREEN}✓${RESET} kathan-cli installed" # Download kathan-cli-history (Python TUI) echo -e " ${DIM}Downloading kathan-cli-history...${RESET}" curl -fsSL "${BASE_URL}/${VERSION}/kathan_history.py" -o "${INSTALL_DIR}/kathan_history.py" # Create kathan-cli-history wrapper cat > "${INSTALL_DIR}/kathan-cli-history" << 'EOF' #!/bin/bash SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" # Ensure textual is installed python3 -c "import textual" 2>/dev/null || { echo " Installing dependencies..." pip3 install -q textual } exec python3 "${SCRIPT_DIR}/kathan_history.py" "$@" EOF chmod +x "${INSTALL_DIR}/kathan-cli-history" echo -e " ${GREEN}✓${RESET} kathan-cli-history installed" # Add to PATH SHELL_NAME="$(basename "$SHELL")" PROFILE="" case "$SHELL_NAME" in zsh) PROFILE="$HOME/.zshrc" ;; bash) if [ -f "$HOME/.bash_profile" ]; then PROFILE="$HOME/.bash_profile" else PROFILE="$HOME/.bashrc" fi ;; fish) PROFILE="$HOME/.config/fish/config.fish" ;; esac PATH_LINE="export PATH=\"${INSTALL_DIR}:\$PATH\"" if [ "$SHELL_NAME" = "fish" ]; then PATH_LINE="set -gx PATH ${INSTALL_DIR} \$PATH" fi if [ -n "$PROFILE" ]; then if ! grep -q "$INSTALL_DIR" "$PROFILE" 2>/dev/null; then echo "" >> "$PROFILE" echo "# Kathan CLI" >> "$PROFILE" echo "$PATH_LINE" >> "$PROFILE" echo -e " ${GREEN}✓${RESET} Added to PATH in ${PROFILE}" else echo -e " ${DIM}PATH already configured${RESET}" fi fi # Verify Python 3 if ! command -v python3 &> /dev/null; then echo "" echo -e " ${DIM}⚠ Python 3 not found. kathan-cli-history requires Python 3.9+${RESET}" echo -e " ${DIM} Install: https://www.python.org/downloads/${RESET}" fi echo "" echo -e " ${GREEN}✓${RESET} Installation complete!" echo "" echo -e " ${DIM}Restart your terminal or run:${RESET}" echo -e " source ${PROFILE}" echo "" echo -e " ${DIM}Then:${RESET}" echo -e " kathan-cli login ${DIM}# authenticate${RESET}" echo -e " kathan-cli ${DIM}# start chatting${RESET}" echo -e " kathan-cli-history ${DIM}# browse past sessions${RESET}" echo ""