Mac OS 抓去 CPU 與 OS 版號資訊
CPU `uname -m` = x86_64 or arm64
OS 版號 `sw_vers -productVersion` = like 10.15.7
PKG安裝包的管理與文件格式分析 (參考網址)
https://zhuanlan.zhihu.com/p/24895270
PackageMaker Script 時序
preflight:點擊安裝界面上的Install按鈕時運行此腳本。該腳本在程序每次安裝時都會運行。
preinstall/preupgrade:針對單程序安裝包(pkg),該腳本會在preflight腳本運行之後運行,針對多程序安裝包(mpkg),該腳本會在用戶按下Install銨鈕後執行。
preinstall與preupgrade的區別:
preinstall只會在用戶第一次安裝該程序時執行,而preupgrade只在之前安裝過該程序,用於軟件升級時,腳本才會執行,
preupgrade用於軟件升級時使用。區分程序是否為第一次安裝是通過pkg安裝器Installer.app來完成的,
Installer.app通過查看/private/var/db/receipts目錄,查看目錄中是否有以程序包名命名的pkg文件,如果存在,說明已經安裝過,反之,為第一次安裝。
postinstall/postupgrade:該腳本在程序安裝完之後才運行。它們的區別與preinstall/preupgrade一樣。
postflight:該腳本在postinstall/postupgrade腳本之後運行。
=======================================================
postflight Sample code
=======================================================
#!/bin/sh
###
### Unloaded and Remove old driver
###
sudo kextunload /Library/Extensions/ACS6x.kext/
sudo kextunload /Library/Extensions/ACS6x.kext/
sudo kextunload /Library/Extensions/ACS6x.kext/
sudo rm -rf /Library/Extensions/ACS6x.kext
cputype=`uname -m`
if [ "$cputype" == "arm64" ]; then
#echo "ARM Mac OS cputyep : $cputype"
sudo unzip /tmp/drv/ACS6x_M1.kext.zip -d /tmp/drv/
else
#echo "Intel Mac OS cputype : $cputype"
sudo unzip /tmp/drv/ACS6x.kext.zip -d /tmp/drv/
fi
DRV1=/tmp/drv/ACS6x.kext
DRV2=/Library/Extensions/
sudo chown -R root:wheel $DRV1
sudo chmod -R 755 $DRV1
sudo cp -R $DRV1 $DRV2
### restart cache for 10.15/11.00 with m1 issue
#sudo kmutil clear-staging
### Remove temp file
sudo rm -rf /tmp/drv
exit 0
=======================================================
postflight Sample code
=======================================================
#!/bin/sh
###
### Remove old version before install file
###
sudo rm -rf /System/Library/Extensions/ACS62000.kext
sudo rm -rf /System/Library/Extensions/ACS6xxxx.kext
sudo rm -rf /System/Library/Extensions/Accusys6xxxx.kext
sudo rm -rf /System/Library/Extensions/ACS6x.kext
sudo rm -rf /Library/Extensions/ACS6x.kext
sudo rm -rf /System/Library/Extensions/AccusysNTDevice.kext
### Update driver
OSver=`sw_vers -productVersion`
OSver1=$(echo $OSver | cut -d "." -f 1)
OSver2=$(echo $OSver | cut -d "." -f 2)
OSver=$OSver1.$OSver2
#echo "Check Mac OS kernel version: OS version : $OSver"
if [ $(echo "$OSver >= 10.10" |bc) -eq 1 ]; then
#echo " > Check Mac OS kernel version: Darwin kernel version : $OSver"
DRV1=/tmp/drv/ACS6x.kext
DRV2=/Library/Extensions/
else
#echo " < Check Mac OS kernel version: Darwin kernel version : $OSver"
DRV1=/tmp/drv/ACS6x.kext
DRV2=/System/Library/Extensions/
fi
sudo chown -R root:wheel $DRV1
sudo chmod -R 755 $DRV1
sudo cp -R $DRV1 $DRV2
if [ $(echo "$OSver >= 10.9" |bc) -eq 1 ]; then
sudo kextcache -system-caches
else
sudo touch /System/Library/Extensions
fi
### Remove temp file
sudo rm -rf /tmp/drv
exit 0
=======================================================
沒有留言:
張貼留言