#!/bin/bash

# Install GitHub Copilot CLI package on Debian/Ubuntu using NodeSource current Node.js.
set -e

# Allow running directly as root (no sudo needed) or as a regular user.
if [[ "${EUID}" -eq 0 ]]; then sudo() { while [[ "$1" == -* ]]; do shift; done; "$@"; }; export -f sudo; fi

sudo apt update && sudo apt upgrade -y
sudo apt install -y curl build-essential

curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt install -y nodejs

sudo npm install -g @github/copilot

node -v
npm -v
copilot --version || true
