#!/bin/sh
# Adds the Wave Copilot APT repository, then installs Wave Copilot.
# Run: curl -fsSL https://1khz.ca/wave-copilot/apt/install.sh | sudo sh
set -e

if [ "$(id -u)" -ne 0 ]; then
  echo "Run this as root: curl -fsSL https://1khz.ca/wave-copilot/apt/install.sh | sudo sh" >&2
  exit 1
fi

# Not every desktop ships curl.
fetch() {
  if command -v curl >/dev/null 2>&1; then
    curl -fsSL "$1" -o "$2"
  elif command -v wget >/dev/null 2>&1; then
    wget -qO "$2" "$1"
  else
    echo "neither curl nor wget is installed" >&2
    exit 1
  fi
}

fetch https://1khz.ca/wave-copilot/apt/wave-copilot-archive-keyring.gpg /usr/share/keyrings/wave-copilot-archive-keyring.gpg
chmod 0644 /usr/share/keyrings/wave-copilot-archive-keyring.gpg

fetch https://1khz.ca/wave-copilot/apt/wave-copilot.sources /etc/apt/sources.list.d/wave-copilot.sources
chmod 0644 /etc/apt/sources.list.d/wave-copilot.sources

apt-get update
apt-get install -y wave-copilot
