Packaging: Resolve AutoPkg not setting S-bit

This commit is contained in:
Mykola Grymalyuk
2024-05-27 14:52:51 -06:00
parent 9428040f64
commit 3dc0c46986
3 changed files with 64 additions and 20 deletions

View File

@@ -5,18 +5,41 @@
# Create alias for app, start patching and reboot.
# ------------------------------------------------------
# MARK: PackageKit Parameters
# ---------------------------
pathToScript=$0 # ex. /tmp/PKInstallSandbox.*/Scripts/*/preinstall
pathToPackage=$1 # ex. ~/Downloads/Installer.pkg
pathToTargetLocation=$2 # ex. '/', '/Applications', etc (depends on pkgbuild's '--install-location' argument)
pathToTargetVolume=$3 # ex. '/', '/Volumes/MyVolume', etc
pathToStartupDisk=$4 # ex. '/'
# MARK: Variables
# ---------------------------
mainAppPath="/Library/Application Support/Dortania/OpenCore-Patcher.app"
shimAppPath="/Applications/OpenCore-Patcher.app"
helperPath="Library/PrivilegedHelperTools/com.dortania.opencore-legacy-patcher.privileged-helper"
mainAppPath="Library/Application Support/Dortania/OpenCore-Patcher.app"
shimAppPath="Applications/OpenCore-Patcher.app"
executablePath="$mainAppPath/Contents/MacOS/OpenCore-Patcher"
# MARK: Functions
# ---------------------------
function _setSUIDBit() {
local binaryPath=$1
echo "Setting SUID bit on: $binaryPath"
# Check if path is a directory
if [[ -d $binaryPath ]]; then
/bin/chmod -R +s $binaryPath
else
/bin/chmod +s $binaryPath
fi
}
function _createAlias() {
local mainPath=$1
local aliasPath=$2
@@ -25,13 +48,16 @@ function _createAlias() {
if [[ -e $aliasPath ]]; then
# Check if alias path is a symbolic link
if [[ -L $aliasPath ]]; then
echo "Removing old symbolic link: $aliasPath"
/bin/rm -f $aliasPath
else
echo "Removing old file: $aliasPath"
/bin/rm -rf $aliasPath
fi
fi
# Create symbolic link
echo "Creating symbolic link: $aliasPath"
/bin/ln -s $mainPath $aliasPath
}
@@ -52,8 +78,9 @@ function _reboot() {
}
function _main() {
_createAlias "$mainAppPath" "$shimAppPath"
_startPatching "$executablePath"
_setSUIDBit "$pathToTargetVolume/$helperPath"
_createAlias "$pathToTargetVolume/$mainAppPath" "$pathToTargetVolume/$shimAppPath"
_startPatching "$pathToTargetVolume/$executablePath"
_reboot
}
@@ -61,4 +88,5 @@ function _main() {
# MARK: Main
# ---------------------------
echo "Starting postinstall script..."
_main

View File

@@ -6,15 +6,25 @@
# ------------------------------------------------------
# MARK: PackageKit Parameters
# ---------------------------
pathToScript=$0 # ex. /tmp/PKInstallSandbox.*/Scripts/*/preinstall
pathToPackage=$1 # ex. ~/Downloads/Installer.pkg
pathToTargetLocation=$2 # ex. '/', '/Applications', etc (depends on pkgbuild's '--install-location' argument)
pathToTargetVolume=$3 # ex. '/', '/Volumes/MyVolume', etc
pathToStartupDisk=$4 # ex. '/'
# MARK: Variables
# ---------------------------
filesToRemove=(
"/Applications/OpenCore-Patcher.app"
"/Library/Application Support/Dortania/Update.plist"
"/Library/Application Support/Dortania/OpenCore-Patcher.app"
"/Library/LaunchAgents/com.dortania.opencore-legacy-patcher.auto-patch.plist"
"/Library/PrivilegedHelperTools/com.dortania.opencore-legacy-patcher.privileged-helper"
"Applications/OpenCore-Patcher.app"
"Library/Application Support/Dortania/Update.plist"
"Library/Application Support/Dortania/OpenCore-Patcher.app"
"Library/LaunchAgents/com.dortania.opencore-legacy-patcher.auto-patch.plist"
"Library/PrivilegedHelperTools/com.dortania.opencore-legacy-patcher.privileged-helper"
)
@@ -22,39 +32,43 @@ filesToRemove=(
# ---------------------------
function _removeFile() {
local currentFile=$1
local file=$1
if [[ ! -e $currentFile ]]; then
if [[ ! -e $file ]]; then
# Check if file is a symbolic link
if [[ -L $currentFile ]]; then
/bin/rm -f $currentFile
if [[ -L $file ]]; then
echo "Removing symbolic link: $file"
/bin/rm -f $file
fi
return
fi
echo "Removing file: $file"
# Check if file is a directory
if [[ -d $currentFile ]]; then
/bin/rm -rf $currentFile
if [[ -d $file ]]; then
/bin/rm -rf $file
else
/bin/rm -f $currentFile
/bin/rm -f $file
fi
}
function _createParentDirectory() {
local currentFile=$1
local file=$1
local parentDirectory="$(/usr/bin/dirname $currentFile)"
local parentDirectory="$(/usr/bin/dirname $file)"
# Check if parent directory exists
if [[ ! -d $parentDirectory ]]; then
echo "Creating parent directory: $parentDirectory"
/bin/mkdir -p $parentDirectory
fi
}
function _main() {
for file in $filesToRemove; do
_removeFile $file
_createParentDirectory $file
_removeFile $pathToTargetVolume/$file
_createParentDirectory $pathToTargetVolume/$file
done
}
@@ -62,4 +76,5 @@ function _main() {
# MARK: Main
# ---------------------------
echo "Starting preinstall script..."
_main

View File

@@ -5,6 +5,7 @@
# Set SUID bit on helper tool, and create app alias.
# ------------------------------------------------------
# MARK: PackageKit Parameters
# ---------------------------