|
| 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/microsoft/vscode-dev-containers/blob/master/script-library/docs/github.md |
| 8 | +# |
| 9 | +# Syntax: ./github-debian.sh [version] |
| 10 | + |
| 11 | +CLI_VERSION=${1:-"latest"} |
| 12 | + |
| 13 | +set -e |
| 14 | + |
| 15 | +if [ "$(id -u)" -ne 0 ]; then |
| 16 | + echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' |
| 17 | + exit 1 |
| 18 | +fi |
| 19 | + |
| 20 | +export DEBIAN_FRONTEND=noninteractive |
| 21 | + |
| 22 | +# Install curl, apt-transport-https or gpg if missing |
| 23 | +if ! dpkg -s curl ca-certificates > /dev/null 2>&1; then |
| 24 | + if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then |
| 25 | + apt-get update |
| 26 | + fi |
| 27 | + apt-get -y install --no-install-recommends curl ca-certificates |
| 28 | +fi |
| 29 | + |
| 30 | +# Get latest release number if latest is specified |
| 31 | +if [ "${CLI_VERSION}" = "latest" ] || [ "${CLI_VERSION}" = "current" ] || [ "${CLI_VERSION}" = "lts" ]; then |
| 32 | + LATEST_RELEASE=$(curl -sSL -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/cli/cli/releases?per_page=1&page=1") |
| 33 | + CLI_VERSION=$(echo ${LATEST_RELEASE} | grep -oE 'tag_name":\s*"v[^"]+' | sed -n '/tag_name":\s*"v/s///p') |
| 34 | +fi |
| 35 | + |
| 36 | +# Install the GitHub CLI |
| 37 | +echo "Downloading github CLI..." |
| 38 | +curl -OsSL https://github.com/cli/cli/releases/download/v${CLI_VERSION}/gh_${CLI_VERSION}_linux_amd64.deb |
| 39 | +echo "Installing github CLI..." |
| 40 | +apt-get install ./gh_${CLI_VERSION}_linux_amd64.deb |
| 41 | +echo "Removing github CLI deb file after installation..." |
| 42 | +rm -rf ./gh_${CLI_VERSION}_linux_amd64.deb |
| 43 | +echo "Done!" |
0 commit comments