a616652325 发表于 2017-6-30 07:22:06

静默安装Azure CLI

  Azure的CLI目前已经是基于Python的2.0版本。其信息在下面的链接可以找到:
  https://github.com/Azure/azure-cli
  其安装方法可以根据网站上描述的命令实现:



curl -L https://aka.ms/InstallAzureCli | bash
  但这种安装模式是交互式的,不能实现静默安装。
  本文将介绍如何采用expect实现静默安装。
  一、说明
  根据https://docs.microsoft.com/en-us/cli/azure/install-az-cli2中描述的安装指南,在安装CLI前,有一些准备工作:
  我用的是CentOS7.3版本的Linux,其Pre-Request为:



sudo yum check-update; sudo yum install -y gcc libffi-devel python-devel openssl-devel
  安装命令为:



curl -L https://aka.ms/InstallAzureCli | bash
  由于安装过程有交互,所以采用inspect来实现预期的交互安装。
  二、安装
  两个脚本:
  1. installAzureCli.sh
  做安装前的准备工作,并调用expect的脚本:



#!/bin/bash
yum update
yum install -y expect
yum install -y gcc libffi-devel python-devel openssl-devel
expect test.sh
  2. test.sh
  进行安装:



#!/usr/bin/expect -f
set timeout 20000
spawn /bin/sh -c "curl -L https://aka.ms/InstallAzureCli | bash"
expect "*)*"
send "\r"
expect "*)*"
send "\r"
expect "*)*"
send "\r"
expect "*)*"
send "\r"
expect "*)*"
send "\r"
interact
  其中timeout设置比较长,是保证在安装时不会中断,安装中都是默认回车就ok,所以全部是发送回车即可。
  三、验证
  输入:



# az
   /\
    /\    _____   _ _ __ ___
   / /\ \|_/ | | | \'__/ _ \
/ ____ \/ /| |_| | | |__/
/_/    \_\/___|\__,_|_|\___|
Welcome to the cool new Azure CLI!
Here are the base commands:
account : Manage subscriptions.
acr : Manage Azure container registries.
acs : Manage Azure Container Services.
ad : Synchronize on-premises directories and manage Azure Active Directory
resources.
appservice : Manage your App Service plans.
batch : Manage Azure Batch.
……
  说明已经安装成功。



# az --version
azure-cli (2.0.6)
acr (2.0.4)
acs (2.0.6)
appservice (0.1.6)
……..
  可以检查其版本。
页: [1]
查看完整版本: 静默安装Azure CLI