12
12
set -e
13
13
14
14
MICROSOFT_GPG_KEYS_URI=" https://packages.microsoft.com/keys/microsoft.asc"
15
+ AZCLI_ARCHIVE_ARCHITECTURES=" amd64"
16
+ AZCLI_ARCHIVE_VERSION_CODENAMES=" stretch buster bullseye bionic focal"
15
17
16
18
if [ " $( id -u) " -ne 0 ]; then
17
19
echo -e ' Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
@@ -54,20 +56,21 @@ check_packages() {
54
56
55
57
export DEBIAN_FRONTEND=noninteractive
56
58
57
- # See if we're on x86_64 and if so, install via apt-get, otherwise use pip3
58
- architecture=" $( dpkg --print-architecture) "
59
- if [ " ${architecture} " = " amd64" ]; then
59
+ install_using_apt () {
60
60
# Install dependencies
61
61
check_packages apt-transport-https curl ca-certificates gnupg2 dirmngr
62
62
# Import key safely (new 'signed-by' method rather than deprecated apt-key approach) and install
63
- . /etc/os-release
64
63
get_common_setting MICROSOFT_GPG_KEYS_URI
65
64
curl -sSL ${MICROSOFT_GPG_KEYS_URI} | gpg --dearmor > /usr/share/keyrings/microsoft-archive-keyring.gpg
66
65
echo " deb [arch=${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
67
- apt-get update
68
- apt-get install -y azure-cli
69
- else
70
- echo " No pre-built binaries availabe for ${architecture} . Installing via pip3."
66
+ if ! apt-get update && apt-get install -yq azure-cli; then
67
+ -f /etc/apt/sources.list.d/azure-cli.list
68
+ return 1
69
+ fi
70
+ }
71
+
72
+ install_using_pip () {
73
+ echo " (*) No pre-built binaries availabe for ${architecture} . Installing via pip3."
71
74
if ! dpkg -s python3-minimal python3-pip libffi-dev python3-venv > /dev/null 2>&1 ; then
72
75
apt_get_update_if_needed
73
76
apt-get -y install python3-minimal python3-pip libffi-dev python3-venv
84
87
fi
85
88
${pipx_bin} install --system-site-packages --pip-args ' --no-cache-dir --force-reinstall' azure-cli
86
89
rm -rf /tmp/pip-tmp
90
+ }
91
+
92
+ # See if we're on x86_64 and if so, install via apt-get, otherwise use pip3
93
+ echo " (*) Installing Azure CLI..."
94
+ . /etc/os-release
95
+ architecture=" $( dpkg --print-architecture) "
96
+ if [[ " ${AZCLI_ARCHIVE_ARCHITECTURES} " = * " ${architecture} " * ]] && [[ " ${AZCLI_ARCHIVE_VERSION_CODENAMES} " = * " ${VERSION_CODENAME} " * ]]; then
97
+ install_using_apt || use_pip=" true"
98
+ else
99
+ use_pip=" true"
87
100
fi
101
+
102
+ if [ " ${use_pip} " = " true" ]; then
103
+ install_using_pip
104
+ fi
105
+
88
106
echo " Done!"
0 commit comments