#!/usr/bin/env bash
# install-github-cli.sh
# GitHub CLI — Drive pull requests, issues, and workflows from the terminal.
# Target: Ubuntu / Debian. Safe to re-run.
# Source guide: devops-hub/tools/github-cli.html

set -euo pipefail

if [[ $EUID -eq 0 ]]; then
  echo "Run this as a regular sudo-capable user, not root." >&2
  exit 1
fi

echo "==> Add the GitHub CLI GPG key and repo"
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null

echo "==> Install"
sudo apt update
sudo apt install -y gh

echo "==> Verify"
gh --version

echo "==> Done. GitHub CLI installation finished."
