#!/bin/bash
#
sudo killall -9 "AppleConnect"
/bin/mkdir -p "${HOME}/Desktop/downloadfromjamf"
cd "${HOME}/Desktop/downloadfromjamf"
#/usr/local/bin/appleconnect u #卸载
current_user=${HOME##*/}
/usr/bin/expect <<EOF
spawn sudo -u $current_user /usr/local/bin/appleconnect u
set timeout 60
expect {
"uninstall" { send "y\r" }
}
expect eof
EOF
sudo rm -Rf "/Applications/AppleConnect.app/" 2>/dev/null
ver=`sw_vers -productVersion | cut -d'.' -f1`
#ver2=`sw_vers -productVersion | cut -d'.' -f2`
let ver="$ver" #大版本
#let ver2="$ver2" #小版本
if [ $ver -ge 13 ];then
unzip -o "./AppleConnectInstaller6-1.dmg.zip"
hdiutil attach "./AppleConnectInstaller6-1.dmg"
sudo installer -pkg /Volumes/AppleConnect/AppleConnect.pkg -target /
hdiutil detach /Volumes/AppleConnect
elif [ $ver -ge 11 ];then
unzip -o "./AppleConnectInstaller5-5.dmg.zip"
hdiutil attach "./AppleConnectInstaller5-5.dmg"
sudo installer -pkg /Volumes/AppleConnect/AppleConnect.pkg -target /
hdiutil detach /Volumes/AppleConnect
else
unzip -o "./AppleConnect5.2.pkg.zip"
sudo installer -pkg "${HOME}/Desktop/downloadfromjamf/AppleConnect5.2.pkg" -target /
fi
(/usr/bin/osascript -e 'display dialog "成功安装AppleConnect,您可以删除桌面上的downloadfromjamf目录,如果打开AppleConnect出现错误,请重启电脑!" buttons {"OK"} default button "OK"')
#把文件夹权限置为 777 ,让所有人可以删
sudo chmod -R 777 "${HOME}/Desktop/downloadfromjamf/"
#cd ../
#rm -Rf "${HOME}/Desktop/downloadfromjamf"
exit 0