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/main/script-library/docs/azcli.md
8
+ # Maintainer: The VS Code and Codespaces Teams
9
+ #
10
+ # Syntax: ./azcli-debian.sh
11
+
12
+ set -e
13
+
14
+ MICROSOFT_GPG_KEYS_URI=" https://packages.microsoft.com/keys/microsoft.asc"
15
+
16
+ if [ " $( id -u) " -ne 0 ]; then
17
+ echo -e ' Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
18
+ exit 1
19
+ fi
20
+
21
+ # Get central common setting
22
+ get_common_setting () {
23
+ if [ " ${common_settings_file_loaded} " != " true" ]; then
24
+ curl -sfL " https://aka.ms/vscode-dev-containers/script-library/settings.env" 2> /dev/null -o /tmp/vsdc-settings.env || echo " Could not download settings file. Skipping."
25
+ common_settings_file_loaded=true
26
+ fi
27
+ if [ -f " /tmp/vsdc-settings.env" ]; then
28
+ local multi_line=" "
29
+ if [ " $2 " = " true" ]; then multi_line=" -z" ; fi
30
+ local result=" $( grep ${multi_line} -oP " $1 =\" ?\K[^\" ]+" /tmp/vsdc-settings.env | tr -d ' \0' ) "
31
+ if [ ! -z " ${result} " ]; then declare -g $1 =" ${result} " ; fi
32
+ fi
33
+ echo " $1 =${! 1} "
34
+ }
35
+
36
+ # Function to run apt-get if needed
37
+ apt_get_update_if_needed ()
38
+ {
39
+ if [ ! -d " /var/lib/apt/lists" ] || [ " $( ls /var/lib/apt/lists/ | wc -l) " = " 0" ]; then
40
+ echo " Running apt-get update..."
41
+ apt-get update
42
+ else
43
+ echo " Skipping apt-get update."
44
+ fi
45
+ }
46
+
47
+ # Checks if packages are installed and installs them if not
48
+ check_packages () {
49
+ if ! dpkg -s " $@ " > /dev/null 2>&1 ; then
50
+ apt_get_update_if_needed
51
+ apt-get -y install --no-install-recommends " $@ "
52
+ fi
53
+ }
54
+
55
+ export DEBIAN_FRONTEND=noninteractive
56
+
57
+ # Install dependencies
58
+ check_packages apt-transport-https curl ca-certificates lsb-release gnupg2
59
+
60
+ # Import key safely (new 'signed-by' method rather than deprecated apt-key approach) and install
61
+ . /etc/os-release
62
+ get_common_setting MICROSOFT_GPG_KEYS_URI
63
+ curl -sSL ${MICROSOFT_GPG_KEYS_URI} | gpg --dearmor > /usr/share/keyrings/microsoft-archive-keyring.gpg
64
+ echo " deb [arch=$( dpkg --print-architecture) signed-by=/usr/share/keyrings/microsoft-archive-keyring.gpg] https://packages.microsoft.com/repos/azure-cli/ ${VERSION_CODENAME} main" > /etc/apt/sources.list.d/azure-cli.list
65
+ apt-get update
66
+ apt-get install -y azure-cli
67
+ echo " Done!"
0 commit comments