os_type = platform.system()
if os_type == "Windows":
# Install Azure Functions Core Tools on Windows
subprocess.run(["npm", "install", "-g", "azure-functions-core-tools@3", "--unsafe-perm", "true"], check=True)
# Install Azure CLI on Windows
subprocess.run(["powershell", "-Command", "Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\\AzureCLI.msi; Start-Process msiexec.exe -ArgumentList '/I AzureCLI.msi /quiet' -Wait"], check=True)
elif os_type == "Darwin": # MacOS
# Install Azure Functions Core Tools on MacOS
if platform.machine() == 'arm64':
# For M1 Macs
subprocess.run(["arch", "-arm64", "brew", "install", "azure-functions-core-tools@3"], check=True)
else:
# For Intel Macs
subprocess.run(["brew", "install", "azure-functions-core-tools@3"], check=True)
# Install Azure CLI on MacOS
subprocess.run(["brew", "update"], check=True)
subprocess.run(["brew", "install", "azure-cli"], check=True)
elif os_type == "Linux":
# Install Azure Functions Core Tools on Linux
subprocess.run(["curl", "https://packages.microsoft.com/keys/microsoft.asc", "|", "gpg", "--dearmor", ">", "microsoft.gpg"], check=True, shell=True)
subprocess.run(["sudo", "mv", "microsoft.gpg", "/etc/apt/trusted.gpg.d/microsoft.gpg"], check=True)
subprocess.run(["sudo", "sh", "-c", "'echo \"deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-$(lsb_release -cs)-prod $(lsb_release -cs) main\" > /etc/apt/sources.list.d/dotnetdev.list'"], check=True, shell=True)
subprocess.run(["sudo", "apt-get", "update"], check=True)
subprocess.run(["sudo", "apt-get", "install", "azure-functions-core-tools-3"], check=True)
# Install Azure CLI on Linux
subprocess.run(["curl", "-sL", "https://aka.ms/InstallAzureCLIDeb", "|", "sudo", "bash"], check=True, shell=True)
else:
# Raise an error if the operating system is not supported
raise OSError("Unsupported operating system")
# Verify the installation of Azure Functions Core Tools
subprocess.run(["func", "--version"], check=True)
# Verify the installation of Azure CLI
subprocess.run(["az", "--version"], check=True)
subprocess.run([
"az", "login"
], check=True)