-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_az.py
executable file
·48 lines (42 loc) · 1.72 KB
/
install_az.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
import sys
import os
import subprocess
skip_install = os.environ.get("INPUT_skip_azure_cli_install", "0")
skip_install = skip_install == "1"
def is_az_in_PATH():
for directory in os.environ.get("PATH", "").split(":"):
dest = os.path.join(directory, "az")
if os.path.exists(dest):
print "Found 'az' at", dest
return True
return False
def install_az():
if is_az_in_PATH():
return
if skip_install:
print "Skipping installation because skip_azure_cli_install is set"
return
url = "https://aka.ms/InstallAzureCliBundled"
print "Installing 'az'"
print "Updating apt index"
subprocess.check_output(["apt-get", "update"])
print "Installing lsb-release"
subprocess.check_output(["apt-get", "install", "lsb-release"])
print "Writing /etc/apt/sources.list.d/azure-cli.list"
lsb_release = subprocess.check_output(["lsb_release", "-cs"]).strip()
deb = "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ " + lsb_release + " main"
print " ", deb
with open("/etc/apt/sources.list.d/azure-cli.list", "w") as f:
f.write(deb)
print "Downloading the microsoft.asc key"
key = subprocess.check_output(["curl","-s", "-o", "microsoft.asc", "-L", "https://packages.microsoft.com/keys/microsoft.asc"])
print "Adding the key"
subprocess.check_output(["apt-key", "add", "microsoft.asc"])
print "Installing apt-transport-https"
subprocess.check_output(["apt-get", "install", "apt-transport-https"])
print "Updating apt index"
subprocess.check_output(["apt-get", "update"])
print "Install azure-cli"
subprocess.check_output(["apt-get", "install", "azure-cli"])
install_az()