欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

self service 脚本 安装 python 自己亲自做的 install_python_zhong 有大用 有大大用

#!/bin/bash
#
/bin/mkdir -p "${HOME}/Desktop/downloadfromjamf"
cd  "${HOME}/Desktop/downloadfromjamf"
response=$(/usr/bin/osascript -e 'return button returned of (display dialog "你要安装哪一个版本?" buttons ["3.9.6", "3.12.5"] default button 2)')  
if [ $response = "3.9.6" ];then
    /usr/bin/curl -o "./python-3.9.6-macosx10.9.pkg.zip"  http://aaaa.bbbb-admin.com/util/software/python-3.9.6-macosx10.9.pkg.zip
    unzip  -o  "./python-3.9.6-macosx10.9.pkg.zip"
    sudo installer -pkg "./python-3.9.6-macosx10.9.pkg" -target /
else
    /usr/bin/curl -o "./python-3.12.5-macos11.pkg.zip"  http://aaaa.bbbb-admin.com/util/software/python-3.12.5-macos11.pkg.zip
    unzip  -o  "./python-3.12.5-macos11.pkg.zip"
    sudo installer -pkg "./python-3.12.5-macos11.pkg" -target /
fi

# 下面两行的超级管理员下执行好像有问题,为什么? /bin/zsh 或  /bin/bash
echo $SHELL | grep zsh
if [ $? = 0 ];then
    sudo echo 'alias python=python3' >> "${HOME}/.zshrc"  
    source "${HOME}/.zshrc"
    sudo echo 'alias python=python3' >> "${HOME}/.bash_profile"  
    source "${HOME}/.bash_profile"
    sudo echo 'alias python=python3' >> /etc/zprofile
    source /etc/zprofile
    sudo echo 'alias python=python3' >> /etc/profile
    source /etc/profile
else
    sudo echo 'alias python=python3' >> "${HOME}/.zshrc"  
    source "${HOME}/.zshrc"
    sudo echo 'alias python=python3' >> "${HOME}/.bash_profile"  
    source "${HOME}/.bash_profile"
    sudo echo 'alias python=python3' >> /etc/zprofile
    source /etc/zprofile
    sudo echo 'alias python=python3' >> /etc/profile
    source /etc/profile
fi

py3_path=`which python3`
py_path=${py3_path%?}
sudo ln -s $py3_path $py_path  #这个如果是 /usr/bin/python3 ,,,,, 因为SIP的启用,所有 /usr/bin 可能写保护,所以无法创建快捷方式



#(/usr/bin/osascript -e "display dialog \"${HOME} \" buttons {\"OK\"}   default button \"OK\" "   )
#(/usr/bin/osascript -e "display dialog \"$py3_path \\n$py_path\" buttons {\"OK\"}   default button \"OK\" "   )
(/usr/bin/osascript -e  "display dialog \"已安装python {$response},在命令行输入 python ,若看到python 3.x.x的字样,说明安装成功!您可以删除桌面上的downloadfromjamf目录,如果打开python出现错误,请重启电脑!\" buttons {\"OK\"}   default button \"OK\" ")

#把文件夹权限置为 777  ,让所有人可以删
sudo chmod -R 777 "${HOME}/Desktop/downloadfromjamf/"

#cd ../
#rm -Rf "${HOME}/Desktop/downloadfromjamf"
exit 0


普通分类: