#!/bin/bash -e

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

CMD=az
NAME="Azure CLI"

echo -e "\e[34m»»» 📦 \e[32mInstalling \e[33m$NAME\e[0m ..."

# https://docs.microsoft.com/cli/azure/install-azure-cli-linux?pivots=apt#option-2-step-by-step-installation-instructions

sudo apt-get update
sudo apt-get install ca-certificates curl apt-transport-https lsb-release gnupg

curl -sL https://packages.microsoft.com/keys/microsoft.asc |
    gpg --dearmor |
    sudo tee /etc/apt/trusted.gpg.d/microsoft.gpg >/dev/null

AZ_REPO=$(lsb_release -cs)
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" |
    sudo tee /etc/apt/sources.list.d/azure-cli.list

sudo apt-get update
sudo apt-get install azure-cli

# Install cli extension(s)
echo -e "\n\e[34m»»» 🔐 \e[32mAdding webapp authV2 extension"
az extension add --name authV2 --system

echo -e "\n\e[34m»»» 💾 \e[32mInstalled to: \e[33m$(which $CMD)"
echo -e "\e[34m»»» 💡 \e[32mVersion details: \e[39m$($CMD --version)"
