#!/bin/bash
set -euo pipefail

apt-get update
apt-get install -y curl

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

export NVM_DIR="$HOME/.nvm"
# Source nvm with || true to handle nvm.sh's internal non-zero returns
\. "$NVM_DIR/nvm.sh" || true
# Verify NVM loaded successfully
command -v nvm &>/dev/null || { echo "Error: NVM failed to load" >&2; exit 1; }

nvm install 22
npm -v

{% if version %}
npm install -g @google/gemini-cli@{{ version }}
{% else %}
npm install -g @google/gemini-cli@latest
{% endif %}


# Enable experimental skills feature
mkdir -p ~/.gemini
cat > ~/.gemini/settings.json << 'EOF'
{
  "experimental": {
    "skills": true
  }
}
EOF

gemini --version
