Skip to content

Instantly share code, notes, and snippets.

@tolgamorf
Created January 5, 2026 18:38
Show Gist options
  • Select an option

  • Save tolgamorf/73034b8f9560d771ac468f9316f9aeef to your computer and use it in GitHub Desktop.

Select an option

Save tolgamorf/73034b8f9560d771ac468f9316f9aeef to your computer and use it in GitHub Desktop.
hetge-cli install script
<#
.SYNOPSIS
hetge-cli install script for Windows
.DESCRIPTION
This script will:
1. Install Scoop (if not present)
2. Install gh, op CLI tools via Scoop
3. Install env2op via npm
4. Authenticate with GitHub (opens browser)
5. Configure npm for @hetge packages
6. Install @hetge/cli globally
.EXAMPLE
powershell -c "irm https://raw.githubusercontent.com/hetGE/hetge-cli/main/scripts/install.ps1 | iex"
#>
$ErrorActionPreference = "Stop"
# Colors
$C_RESET = [char]27 + "[0m"
$C_RED = [char]27 + "[0;31m"
$C_GREEN = [char]27 + "[0;32m"
$C_YELLOW = [char]27 + "[0;33m"
$C_BLUE = [char]27 + "[0;34m"
$C_BOLD = [char]27 + "[1m"
$C_DIM = [char]27 + "[2m"
# Output functions
function Write-Info {
param([string]$Message)
Write-Host "${C_BLUE}::${C_RESET} $Message"
}
function Write-Success {
param([string]$Message)
Write-Host "${C_GREEN}${([char]0x2713)}${C_RESET} $Message"
}
function Write-Warning {
param([string]$Message)
Write-Host "${C_YELLOW}!${C_RESET} $Message"
}
function Write-Error {
param([string]$Message)
Write-Host "${C_RED}error${C_RESET}: $Message" -ForegroundColor Red
exit 1
}
# Check if command exists
function Test-Command {
param([string]$Command)
$null = Get-Command $Command -ErrorAction SilentlyContinue
return $?
}
# Check if Scoop is installed
function Test-Scoop {
return Test-Command "scoop"
}
# Print banner
function Show-Banner {
Write-Host ""
Write-Host "${C_BOLD} _ _ _ _ ${C_RESET}"
Write-Host "${C_BOLD} | |__ ___| |_ __ _ ___ ___| (_)${C_RESET}"
Write-Host "${C_BOLD} | '_ \ / _ \ __/ _`` |/ _ \_____/ __| | |${C_RESET}"
Write-Host "${C_BOLD} | | | | __/ || (_| | __/_____\__ \ | |${C_RESET}"
Write-Host "${C_BOLD} |_| |_|\___|\__\__, |\___| |___/_|_|${C_RESET}"
Write-Host "${C_BOLD} |___/ ${C_RESET}"
Write-Host ""
Write-Host " ${C_DIM}Installation Script (Windows)${C_RESET}"
Write-Host ""
}
# Check prerequisites
function Test-Prerequisites {
Write-Info "[1/6] Checking prerequisites..."
# Check for Node.js
if (-not (Test-Command "node")) {
Write-Error "Node.js is required but not installed. Install from https://nodejs.org"
}
# Check for npm
if (-not (Test-Command "npm")) {
Write-Error "npm is required but not installed"
}
Write-Success "Prerequisites satisfied (node, npm)"
}
# Install Scoop if needed
function Install-Scoop {
if (Test-Scoop) {
Write-Success "Scoop already installed"
return
}
Write-Info "Installing Scoop..."
# Set execution policy for current user
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
# Install Scoop
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
# Refresh PATH
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "User") + ";" + [System.Environment]::GetEnvironmentVariable("PATH", "Machine")
Write-Success "Scoop installed"
}
# Install dependencies
function Install-Dependencies {
Write-Info "[2/6] Installing dependencies..."
# Ensure Scoop is available
Install-Scoop
# Install gh
if (Test-Command "gh") {
Write-Success "gh already installed"
} else {
Write-Info "Installing GitHub CLI..."
scoop install gh
Write-Success "GitHub CLI installed"
}
# Install 1password-cli
if (Test-Command "op") {
Write-Success "1Password CLI already installed"
} else {
Write-Info "Installing 1Password CLI..."
scoop install 1password-cli
Write-Success "1Password CLI installed"
}
# Install env2op-cli via npm (no scoop package available)
if (Test-Command "env2op") {
Write-Success "env2op already installed"
} else {
Write-Info "Installing env2op CLI..."
npm install -g "@tolgamorf/env2op-cli"
Write-Success "env2op CLI installed"
}
}
# Check if gh has required scopes
function Test-RequiredScopes {
try {
$status = gh auth status 2>&1 | Out-String
return $status -match "write:packages"
} catch {
return $false
}
}
# Setup GitHub authentication
function Setup-Authentication {
Write-Info "[3/6] Setting up GitHub authentication..."
# Check if already authenticated
$authStatus = $null
try {
$authStatus = gh auth status 2>&1 | Out-String
$isAuthenticated = $LASTEXITCODE -eq 0
} catch {
$isAuthenticated = $false
}
if ($isAuthenticated) {
if (Test-RequiredScopes) {
$user = if ($authStatus -match "Logged in to github.com account (\S+)") { $Matches[1] } else { "unknown" }
Write-Success "Already authenticated as ${C_BOLD}${user}${C_RESET} with required scopes"
return
} else {
Write-Warning "Missing write:packages scope. Refreshing authentication..."
gh auth refresh -s write:packages
Write-Success "Authentication refreshed with write:packages scope"
return
}
}
# Not authenticated - run login
Write-Host ""
Write-Info "A browser window will open for GitHub authentication."
Write-Info "Please complete the authentication in your browser."
Write-Host ""
gh auth login `
--scopes write:packages `
--hostname github.com `
--git-protocol ssh `
--web `
--skip-ssh-key
# Verify authentication succeeded
try {
gh auth status 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) {
throw "Auth failed"
}
} catch {
Write-Error "GitHub authentication failed. Please try again."
}
$authStatus = gh auth status 2>&1 | Out-String
$user = if ($authStatus -match "Logged in to github.com account (\S+)") { $Matches[1] } else { "unknown" }
Write-Success "Authenticated as ${C_BOLD}${user}${C_RESET}"
}
# Configure npm registry
function Set-NpmRegistry {
Write-Info "[4/6] Configuring npm for @hetge packages..."
# IMPORTANT: Quotes around "@hetge:registry" are REQUIRED on Windows
npm config set -g "@hetge:registry" "https://npm.pkg.github.com"
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to set npm registry"
}
# Get and set auth token
$token = gh auth token
if (-not $token) {
Write-Error "Could not get GitHub auth token"
}
npm config set -g "//npm.pkg.github.com/:_authToken" "$token"
Write-Success "npm registry configured"
}
# Install hetge-cli
function Install-HetgeCli {
Write-Info "[5/6] Installing @hetge/cli..."
npm install -g "@hetge/cli"
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to install @hetge/cli"
}
Write-Success "@hetge/cli installed"
}
# Verify installation
function Test-Installation {
Write-Info "[6/6] Verifying installation..."
$errors = 0
# Check tools
foreach ($tool in @("gh", "op", "env2op", "hetge")) {
if (Test-Command $tool) {
try {
$version = & $tool --version 2>$null | Select-Object -First 1
if (-not $version) { $version = "installed" }
} catch {
$version = "installed"
}
Write-Success " ${tool}: ${C_DIM}${version}${C_RESET}"
} else {
Write-Host " ${C_RED}$([char]0x2717)${C_RESET} ${tool}: NOT FOUND"
$errors++
}
}
# Check gh auth
try {
gh auth status 2>&1 | Out-Null
if ($LASTEXITCODE -eq 0) {
$authStatus = gh auth status 2>&1 | Out-String
$user = if ($authStatus -match "Logged in to github.com account (\S+)") { $Matches[1] } else { "unknown" }
Write-Success " gh auth: logged in as $user"
} else {
throw "Not authenticated"
}
} catch {
Write-Host " ${C_RED}$([char]0x2717)${C_RESET} gh auth: NOT AUTHENTICATED"
$errors++
}
# Check npm config
$registry = npm config get "@hetge:registry" 2>$null
if ($registry -eq "https://npm.pkg.github.com") {
Write-Success " npm registry: configured"
} else {
Write-Host " ${C_RED}$([char]0x2717)${C_RESET} npm registry: NOT CONFIGURED"
$errors++
}
if ($errors -gt 0) {
Write-Error "Installation incomplete. Please fix the errors above."
}
}
# Print success message
function Show-Success {
Write-Host ""
Write-Host "${C_GREEN}================================================${C_RESET}"
Write-Host "${C_GREEN} Installation Complete!${C_RESET}"
Write-Host "${C_GREEN}================================================${C_RESET}"
Write-Host ""
Write-Host " You can now use hetge-cli in your projects:"
Write-Host ""
Write-Host " ${C_DIM}# Add to a project${C_RESET}"
Write-Host " npm install -D @hetge/cli"
Write-Host ""
Write-Host " ${C_DIM}# Or run directly${C_RESET}"
Write-Host " npx @hetge/cli"
Write-Host ""
Write-Host " ${C_DIM}# If installed globally${C_RESET}"
Write-Host " hetge"
Write-Host ""
}
# Main
function Main {
Show-Banner
Test-Prerequisites
Install-Dependencies
Setup-Authentication
Set-NpmRegistry
Install-HetgeCli
Test-Installation
Show-Success
}
Main
#!/usr/bin/env bash
set -euo pipefail
# ============================================================================
# hetge-cli install script for macOS and Linux
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/hetGE/hetge-cli/main/scripts/install.sh | bash
#
# This script will:
# 1. Install Homebrew (if not present)
# 2. Install gh, op, env2op CLI tools
# 3. Authenticate with GitHub (opens browser)
# 4. Configure npm for @hetge packages
# 5. Install @hetge/cli globally
# ============================================================================
# Colors (only if stdout is a terminal)
if [[ -t 1 ]]; then
Red='\033[0;31m'
Green='\033[0;32m'
Yellow='\033[0;33m'
Blue='\033[0;34m'
Bold='\033[1m'
Dim='\033[2m'
Reset='\033[0m'
else
Red=''
Green=''
Yellow=''
Blue=''
Bold=''
Dim=''
Reset=''
fi
# Output functions
info() {
echo -e "${Blue}::${Reset} $*"
}
success() {
echo -e "${Green}✓${Reset} $*"
}
warn() {
echo -e "${Yellow}!${Reset} $*"
}
error() {
echo -e "${Red}error${Reset}: $*" >&2
exit 1
}
# Check if command exists
command_exists() {
command -v "$1" &>/dev/null
}
# Platform detection
is_macos() {
[[ "$(uname -s)" == "Darwin" ]]
}
is_linux() {
[[ "$(uname -s)" == "Linux" ]]
}
has_homebrew() {
command_exists brew
}
has_apt() {
command_exists apt-get
}
# Print banner
print_banner() {
echo ""
echo -e "${Bold} _ _ _ _ ${Reset}"
echo -e "${Bold} | |__ ___| |_ __ _ ___ ___| (_)${Reset}"
echo -e "${Bold} | '_ \\ / _ \\ __/ _\` |/ _ \\_____/ __| | |${Reset}"
echo -e "${Bold} | | | | __/ || (_| | __/_____\\__ \\ | |${Reset}"
echo -e "${Bold} |_| |_|\\___|\\__\\__, |\\___| |___/_|_|${Reset}"
echo -e "${Bold} |___/ ${Reset}"
echo ""
echo -e " ${Dim}Installation Script${Reset}"
echo ""
}
# Check prerequisites
check_prerequisites() {
info "[1/6] Checking prerequisites..."
# Check for curl
if ! command_exists curl; then
error "curl is required but not installed"
fi
# Check for Node.js
if ! command_exists node; then
error "Node.js is required but not installed. Install from https://nodejs.org"
fi
# Check for npm
if ! command_exists npm; then
error "npm is required but not installed"
fi
success "Prerequisites satisfied (curl, node, npm)"
}
# Install Homebrew if needed
install_homebrew() {
if has_homebrew; then
success "Homebrew already installed"
return 0
fi
info "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add Homebrew to PATH for this session (Linux)
if is_linux; then
if [[ -f /home/linuxbrew/.linuxbrew/bin/brew ]]; then
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
elif [[ -f "$HOME/.linuxbrew/bin/brew" ]]; then
eval "$("$HOME/.linuxbrew/bin/brew" shellenv)"
fi
fi
success "Homebrew installed"
}
# Install dependencies
install_dependencies() {
info "[2/6] Installing dependencies..."
# Ensure Homebrew is available
install_homebrew
# Install gh
if command_exists gh; then
success "gh already installed"
else
info "Installing GitHub CLI..."
brew install gh
success "GitHub CLI installed"
fi
# Install 1password-cli
if command_exists op; then
success "1Password CLI already installed"
else
info "Installing 1Password CLI..."
brew install 1password-cli
success "1Password CLI installed"
fi
# Install env2op-cli
if command_exists env2op; then
success "env2op already installed"
else
info "Installing env2op CLI..."
brew install tolgamorf/tap/env2op-cli
success "env2op CLI installed"
fi
}
# Check if gh has required scopes
has_required_scopes() {
local status
status=$(gh auth status 2>&1 || true)
echo "$status" | grep -q "write:packages"
}
# Setup GitHub authentication
setup_authentication() {
info "[3/6] Setting up GitHub authentication..."
# Check if already authenticated
if gh auth status &>/dev/null; then
if has_required_scopes; then
local user
user=$(gh auth status 2>&1 | grep -oP "Logged in to github.com account \K\S+" || echo "unknown")
success "Already authenticated as ${Bold}${user}${Reset} with required scopes"
return 0
else
warn "Missing write:packages scope. Refreshing authentication..."
gh auth refresh -s write:packages
success "Authentication refreshed with write:packages scope"
return 0
fi
fi
# Not authenticated - run login
echo ""
info "A browser window will open for GitHub authentication."
info "Please complete the authentication in your browser."
echo ""
gh auth login \
--scopes write:packages \
--hostname github.com \
--git-protocol ssh \
--web \
--skip-ssh-key
# Verify authentication succeeded
if ! gh auth status &>/dev/null; then
error "GitHub authentication failed. Please try again."
fi
local user
user=$(gh auth status 2>&1 | grep -oP "Logged in to github.com account \K\S+" || echo "unknown")
success "Authenticated as ${Bold}${user}${Reset}"
}
# Configure npm registry
configure_npm() {
info "[4/6] Configuring npm for @hetge packages..."
# Set registry
npm config set -g @hetge:registry https://npm.pkg.github.com
# Get and set auth token
local token
token=$(gh auth token)
if [[ -z "$token" ]]; then
error "Could not get GitHub auth token"
fi
npm config set -g "//npm.pkg.github.com/:_authToken" "$token"
success "npm registry configured"
}
# Install hetge-cli
install_hetge_cli() {
info "[5/6] Installing @hetge/cli..."
npm install -g @hetge/cli
success "@hetge/cli installed"
}
# Verify installation
verify_installation() {
info "[6/6] Verifying installation..."
local errors=0
# Check tools
for tool in gh op env2op hetge; do
if command_exists "$tool"; then
local version
version=$("$tool" --version 2>/dev/null | head -1 || echo "installed")
success " ${tool}: ${Dim}${version}${Reset}"
else
echo -e " ${Red}✗${Reset} ${tool}: NOT FOUND"
((errors++)) || true
fi
done
# Check gh auth
if gh auth status &>/dev/null; then
local user
user=$(gh auth status 2>&1 | grep -oP "Logged in to github.com account \K\S+" || echo "unknown")
success " gh auth: logged in as ${user}"
else
echo -e " ${Red}✗${Reset} gh auth: NOT AUTHENTICATED"
((errors++)) || true
fi
# Check npm config
local registry
registry=$(npm config get @hetge:registry 2>/dev/null || echo "")
if [[ "$registry" == "https://npm.pkg.github.com" ]]; then
success " npm registry: configured"
else
echo -e " ${Red}✗${Reset} npm registry: NOT CONFIGURED"
((errors++)) || true
fi
if [[ $errors -gt 0 ]]; then
error "Installation incomplete. Please fix the errors above."
fi
}
# Print success message
print_success() {
echo ""
echo -e "${Green}================================================${Reset}"
echo -e "${Green} Installation Complete!${Reset}"
echo -e "${Green}================================================${Reset}"
echo ""
echo " You can now use hetge-cli in your projects:"
echo ""
echo -e " ${Dim}# Add to a project${Reset}"
echo " npm install -D @hetge/cli"
echo ""
echo -e " ${Dim}# Or run directly${Reset}"
echo " npx @hetge/cli"
echo ""
echo -e " ${Dim}# If installed globally${Reset}"
echo " hetge"
echo ""
}
# Main
main() {
print_banner
check_prerequisites
install_dependencies
setup_authentication
configure_npm
install_hetge_cli
verify_installation
print_success
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment