一键安装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   #这是一个安装脚本(自行定义编写)

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


        attributeSetting
        1
        choiceAttribute
        selected
        choiceIdentifier
        choice_vpn

        attributeSetting
        0
        choiceAttribute
        selected
        choiceIdentifier
        choice_websecurity

        attributeSetting
        0
        choiceAttribute
        selected
        choiceIdentifier
        choice_fireamp

        attributeSetting
        0
        choiceAttribute
        selected
        choiceIdentifier
        choice_dart

        attributeSetting
        0
        choiceAttribute
        selected
        choiceIdentifier
        choice_posture

        attributeSetting
        0
        choiceAttribute
        selected
        choiceIdentifier
        choice_iseposture

        attributeSetting
        0
        choiceAttribute
        selected
        choiceIdentifier
        choice_nvm

        attributeSetting
        0
        choiceAttribute
        selected
        choiceIdentifier
        choice_umbrella

这个文件其实就是一个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

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

将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

参考链接

Original: https://www.cnblogs.com/98record/p/yi-jian-an-zhuangcisco-anyconnect-secure-mobility.html
Author: 自在拉基
Title: 一键安装Cisco AnyConnect Secure Mobility Client

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/586060/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球