|
| 1 | +#!/usr/bin/env bash |
| 2 | +#------------------------------------------------------------------------------------------------------------- |
| 3 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 4 | +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. |
| 5 | +#------------------------------------------------------------------------------------------------------------- |
| 6 | +# |
| 7 | +# Docs: https://github.com/devcontainers/features/blob/main/src/copilot-cli/README.md |
| 8 | +# Maintainer: The VS Code and Codespaces Teams |
| 9 | + |
| 10 | +CLI_VERSION=${VERSION:-"latest"} |
| 11 | + |
| 12 | +set -e |
| 13 | + |
| 14 | +if [ "$(id -u)" -ne 0 ]; then |
| 15 | + echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +apt_get_update() { |
| 20 | + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then |
| 21 | + echo "Running apt-get update..." |
| 22 | + apt-get update -y |
| 23 | + fi |
| 24 | +} |
| 25 | + |
| 26 | +# Checks if packages are installed and installs them if not |
| 27 | +check_packages() { |
| 28 | + if ! dpkg -s "$@" > /dev/null 2>&1; then |
| 29 | + apt_get_update |
| 30 | + apt-get -y install --no-install-recommends "$@" |
| 31 | + fi |
| 32 | +} |
| 33 | + |
| 34 | +download_from_github() { |
| 35 | + local release_url=$1 |
| 36 | + echo "Downloading GitHub Copilot CLI from ${release_url}..." |
| 37 | + |
| 38 | + mkdir -p /tmp/copilotcli |
| 39 | + pushd /tmp/copilotcli |
| 40 | + wget --show-progress --progress=dot:giga ${release_url} |
| 41 | + # curl -fL# -O ${release_url} |
| 42 | + tar -xzf /tmp/copilotcli/${cli_filename} |
| 43 | + mv copilot /usr/local/bin/copilot |
| 44 | + popd |
| 45 | + rm -rf /tmp/copilotcli |
| 46 | +} |
| 47 | + |
| 48 | +install_using_github() { |
| 49 | + check_packages wget tar ca-certificates git |
| 50 | + echo "Finished setting up dependencies" |
| 51 | + arch=$(dpkg --print-architecture) |
| 52 | + cli_filename="copilot-linux-${arch}.tar.gz" |
| 53 | + echo "Installing GitHub Copilot CLI for ${arch} architecture: ${cli_filename}" |
| 54 | + |
| 55 | + # Install latest |
| 56 | + if [ "${CLI_VERSION}" = "latest" ]; then |
| 57 | + download_from_github "https://github.com/github/copilot-cli/releases/latest/download/${cli_filename}" |
| 58 | + elif [ "${CLI_VERSION}" = "prerelease" ]; then |
| 59 | + prerelease_version="$(git ls-remote --tags https://github.com/github/copilot-cli | tail -1 | awk -F/ '{print $NF}')" |
| 60 | + download_from_github "https://github.com/github/copilot-cli/releases/download/${prerelease_version}/${cli_filename}" |
| 61 | + else |
| 62 | + echo "Unsupported version value: ${CLI_VERSION}, falling back to latest" >&2 |
| 63 | + download_from_github "https://github.com/github/copilot-cli/releases/latest/download/${cli_filename}" |
| 64 | + fi |
| 65 | +} |
| 66 | + |
| 67 | +# Install the GitHub Copilot CLI |
| 68 | +echo "Downloading GitHub Copilot CLI..." |
| 69 | + |
| 70 | +install_using_github |
| 71 | + |
0 commit comments