|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -e |
| 4 | +set -o pipefail |
| 5 | + |
| 6 | +## Optional Environment Variables: |
| 7 | + |
| 8 | +SKIP_INSTALL_COPILOT_CLI="${SKIP_INSTALL_COPILOT_CLI:-}" # Set to 'true' to skip installing Copilot CLI |
| 9 | +COPILOT_CLI_VERSION="${COPILOT_CLI_VERSION:-}" # Optional version (ex. 'v0.0.369'); defaults to latest when unset |
| 10 | +COPILOT_CLI_PREFIX="${COPILOT_CLI_PREFIX:-}" # Optional install prefix; defaults per official installer |
| 11 | + |
| 12 | +log() { |
| 13 | + printf "========== %s ==========%s" "$1" $'\n' |
| 14 | +} |
| 15 | + |
| 16 | +err() { |
| 17 | + printf "[ ERROR ]: %s%s" "$1" $'\n' >&2 |
| 18 | + exit 1 |
| 19 | +} |
| 20 | + |
| 21 | +require_downloader() { |
| 22 | + if command -v curl &>/dev/null; then |
| 23 | + echo "curl" |
| 24 | + return 0 |
| 25 | + fi |
| 26 | + |
| 27 | + if command -v wget &>/dev/null; then |
| 28 | + echo "wget" |
| 29 | + return 0 |
| 30 | + fi |
| 31 | + |
| 32 | + err "Either 'curl' or 'wget' is required to install Copilot CLI" |
| 33 | +} |
| 34 | + |
| 35 | +install_copilot_cli() { |
| 36 | + if [[ ${SKIP_INSTALL_COPILOT_CLI,,} == "true" ]]; then |
| 37 | + log "Skipping Copilot CLI install" |
| 38 | + return 0 |
| 39 | + fi |
| 40 | + |
| 41 | + local downloader |
| 42 | + downloader="$(require_downloader)" |
| 43 | + |
| 44 | + log "Installing Copilot CLI (standalone)" |
| 45 | + |
| 46 | + if [[ $downloader == "curl" ]]; then |
| 47 | + if [[ $COPILOT_CLI_VERSION || $COPILOT_CLI_PREFIX ]]; then |
| 48 | + VERSION="$COPILOT_CLI_VERSION" PREFIX="$COPILOT_CLI_PREFIX" curl -fsSL https://gh.io/copilot-install | bash |
| 49 | + else |
| 50 | + curl -fsSL https://gh.io/copilot-install | bash |
| 51 | + fi |
| 52 | + else |
| 53 | + if [[ $COPILOT_CLI_VERSION || $COPILOT_CLI_PREFIX ]]; then |
| 54 | + VERSION="$COPILOT_CLI_VERSION" PREFIX="$COPILOT_CLI_PREFIX" wget -qO- https://gh.io/copilot-install | bash |
| 55 | + else |
| 56 | + wget -qO- https://gh.io/copilot-install | bash |
| 57 | + fi |
| 58 | + fi |
| 59 | + |
| 60 | + if [[ ! $COPILOT_CLI_PREFIX ]]; then |
| 61 | + export PATH="$HOME/.local/bin:$PATH" |
| 62 | + else |
| 63 | + export PATH="$COPILOT_CLI_PREFIX/bin:$PATH" |
| 64 | + fi |
| 65 | + |
| 66 | + if ! command -v copilot &>/dev/null; then |
| 67 | + err "Copilot CLI install completed but 'copilot' is not on PATH" |
| 68 | + fi |
| 69 | + |
| 70 | + copilot --version || true |
| 71 | + log "Copilot CLI is available via 'copilot'" |
| 72 | +} |
| 73 | + |
| 74 | +install_copilot_cli |
0 commit comments