一键安装Cisco AnyConnect Secure Mobility Client

Mac版本

背景:公司内部安装此VPN软件的时候,因默认是安装了所有模块,但我们只需要vpn模块,所产生的干扰。并且有人因不熟悉Mac pkg 软件的卸载方法导致非正常卸载,导致重新安装也无法安装,软件也没了。原来的解决方式是给出相关安装文档与卸载命令,但因在此过程中有些人就不看文档,或者看不懂文档特别是涉及通过代码层次的卸载解决方式很多人并不会,在此过程中造成了大量的无效沟通成本,因此我就写了一个shell脚本解决以上问题。

目录架构

❯ tree -a
.
├── .AnyConnect.pkg #这是软件主程序,如果脚本运行有问题的话可以双击此程序来手动安装(自带)
├── .DS_Store
├── .Profiles #配置文件(不用管,自带的)
│   ├── .DS_Store
│   ├── ACTransforms.xml
│   ├── ampenabler
│   ├── feedback
│   ├── iseposture
│   ├── nvm
│   ├── umbrella
│   └── vpn
├── .VolumeIcon.icns #图标(自带)
├── .background #背景(自带)
│   └── dmg_background.tiff
├── .install_1.xml #这是安装所需要的配置文件,里面定义了默认只安装vpn模块,其他模块不装(自行定义编写)
└── install   #这是一个安装脚本(自行定义编写)

代码说明

.install_1.xml

这是一个自定义配置文件,配置说明如下

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
    <dict>
        <key>attributeSetting</key>
        <integer>1</integer> <!--  这个参数控制是否默认安装模块,不知道这是对应的哪个模块可以看下面的 string字段,例如是vpn模块,那么名字就是 choice_vpn,其他的以此类推   -->
        <key>choiceAttribute</key>
        <string>selected</string>
        <key>choiceIdentifier</key>
        <string>choice_vpn</string>
    </dict>
    <dict>
        <key>attributeSetting</key>
        <integer>0</integer>
        <key>choiceAttribute</key>
        <string>selected</string>
        <key>choiceIdentifier</key>
        <string>choice_websecurity</string>
    </dict>
    <dict>
        <key>attributeSetting</key>
        <integer>0</integer>
        <key>choiceAttribute</key>
        <string>selected</string>
        <key>choiceIdentifier</key>
        <string>choice_fireamp</string>
    </dict>
    <dict>
        <key>attributeSetting</key>
        <integer>0</integer>
        <key>choiceAttribute</key>
        <string>selected</string>
        <key>choiceIdentifier</key>
        <string>choice_dart</string>
    </dict>
    <dict>
        <key>attributeSetting</key>
        <integer>0</integer>
        <key>choiceAttribute</key>
        <string>selected</string>
        <key>choiceIdentifier</key>
        <string>choice_posture</string>
    </dict>
    <dict>
        <key>attributeSetting</key>
        <integer>0</integer>
        <key>choiceAttribute</key>
        <string>selected</string>
        <key>choiceIdentifier</key>
        <string>choice_iseposture</string>
    </dict>
    <dict>
        <key>attributeSetting</key>
        <integer>0</integer>
        <key>choiceAttribute</key>
        <string>selected</string>
        <key>choiceIdentifier</key>
        <string>choice_nvm</string>
    </dict>
    <dict>
        <key>attributeSetting</key>
        <integer>0</integer>
        <key>choiceAttribute</key>
        <string>selected</string>
        <key>choiceIdentifier</key>
        <string>choice_umbrella</string>
    </dict>
</array>
</plist>

install

这个文件其实就是一个shell脚本,别人安装也是运行这个脚本,通过运行脚本来安装软件

#!/bin/bash
clear
RED='\033[0;31m'
GRN='\033[0;32m'
BLU='\033[0;34m'
NC='\033[0m'
pkgName=$(pkgutil --pkgs|grep "com.cisco.pkg.anyconnect.vpn")
# 当前路径
parentPath=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
cd "$parentPath"
# 在当前路径查询符合pkg后缀的文件
pkgPath=$( find "$parentPath" -name '*.pkg' -maxdepth 1)
# 在当前路径查询符合xml后缀的文件
xmlPath=$( find "$parentPath" -name '*.xml' -maxdepth 1)
# 逻辑判断,是否有查到已经安装了com.cisco.pkg.anyconnect.vpn,如果有则d,则先卸载再重新安装,否则直接安装 vpn。安装完后直接等待两秒直接关闭终端
if [ ! $pkgName ];then
    echo -e "${RED}不存在,不需要卸载,接下来直接安装。${NC}"
    echo -e "${BLU}请输入开机密码,输入完成后按下回车键(输入过程中密码是看不见的>)${NC}"
    sudo installer  -pkg "${pkgPath}" -applyChoiceChangesXML "${xmlPath}" -target / > /dev/null
    if [ $? -eq 0 ];then
        echo -e "${GRN}安装完成,本窗口可关闭${NC}"
        sleep 2 && osascript -e "do Shell script \"osascript -e \\\"tell application \\\\\\\"Terminal\\\\\\\" to quit\\\" &> /dev/null &\""; exit
    else
        echo "${RED}安装失败请截图联系it-help${NC}"
    fi
else
    echo -e "${BLU}开始卸载原软件${NC}"
    echo -e "${RED}------------------------------${NC}"
    echo -e "${BLU}请输入开机密码,输入完成后按下回车键(输入过程中密码是看不见的>)${NC}"
    sudo pkgutil --forget com.cisco.pkg.anyconnect.vpn
    echo -e "${BLU}开始安装VPN客户端${NC}"
    sleep 2
    sudo installer  -pkg "${pkgPath}" -applyChoiceChangesXML "${xmlPath}" -target / > /dev/null
    if [ $? -eq 0 ];then
          echo -e "${GRN}安装完成,本窗口可关闭${NC}"
          sleep 2 && osascript -e "do Shell script \"osascript -e \\\"tell application \\\\\\\"Terminal\\\\\\\" to quit\\\" &> /dev/null &\""; exit
    else
          echo "${RED}安装失败请截图联系it-help${NC}"
    fi
fi

Mac命令

注意⚠️:以下是此过程中需要用到的一些命令。

# 将anyconnect-macos-4.10.05111-predeploy-k9.dmg 转成可读写
hdiutil convert anyconnect-macos-4.10.05111-predeploy-k9.dmg -format UDRW -o anyconnect-macos-4.10.05111-predeploy-k9-rw.dmg
# 将anyconnect-macos-4.10.05111-predeploy-k9.dmg 转成只读
hdiutil convert anyconnect-macos-4.10.05111-predeploy-k9-rw.dmg -format UDRO -o anyconnect-macos-4.10.05111-predeploy-k9-ro.dmg

vpn软件包

4.10.05111 软件包已经上传到我的阿里云盘中了,有需要自取。Windows,Mac,Linux版本包都在里面了。

😂阿里云盘不支持分享软件包我后知后觉抱歉了,软件包我丢夸克了

https://pan.quark.cn/s/560051378a7c

软件包

参考链接

xml自定义参考文件
官方指导文件
pkg卸载

posted @ 2022-09-27 17:35  自在拉基  阅读(3241)  评论(1编辑  收藏  举报