#!/bin/bash
set -e

# Install dependencies based on distro
if command -v apk &> /dev/null; then
    # Alpine Linux - use apk for nodejs/npm (nvm has musl compatibility issues)
    # Alpine 3.23+ provides Node.js 24.x which is compatible with claude-code
    apk add --no-cache curl bash nodejs npm
elif command -v apt-get &> /dev/null; then
    # Debian/Ubuntu - use nvm for nodejs
    apt-get update
    apt-get install -y curl

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.2/install.sh | bash

    source "$HOME/.nvm/nvm.sh"

    nvm install 22
else
    echo "Unsupported distribution: No apk or apt-get package manager found." >&2
    exit 1
fi

npm -v

{% if version %}
npm install -g @anthropic-ai/claude-code@{{ version }}
{% else %}
npm install -g @anthropic-ai/claude-code@latest
{% endif %}
