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
+32 -4
View File
@@ -5,18 +5,41 @@
# Create alias for app, start patching and reboot. # 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 # MARK: Variables
# --------------------------- # ---------------------------
mainAppPath="/Library/Application Support/Dortania/OpenCore-Patcher.app" helperPath="Library/PrivilegedHelperTools/com.dortania.opencore-legacy-patcher.privileged-helper"
shimAppPath="/Applications/OpenCore-Patcher.app" mainAppPath="Library/Application Support/Dortania/OpenCore-Patcher.app"
shimAppPath="Applications/OpenCore-Patcher.app"
executablePath="$mainAppPath/Contents/MacOS/OpenCore-Patcher" executablePath="$mainAppPath/Contents/MacOS/OpenCore-Patcher"
# MARK: Functions # 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() { function _createAlias() {
local mainPath=$1 local mainPath=$1
local aliasPath=$2 local aliasPath=$2
@@ -25,13 +48,16 @@ function _createAlias() {
if [[ -e $aliasPath ]]; then if [[ -e $aliasPath ]]; then
# Check if alias path is a symbolic link # Check if alias path is a symbolic link
if [[ -L $aliasPath ]]; then if [[ -L $aliasPath ]]; then
echo "Removing old symbolic link: $aliasPath"
/bin/rm -f $aliasPath /bin/rm -f $aliasPath
else else
echo "Removing old file: $aliasPath"
/bin/rm -rf $aliasPath /bin/rm -rf $aliasPath
fi fi
fi fi
# Create symbolic link # Create symbolic link
echo "Creating symbolic link: $aliasPath"
/bin/ln -s $mainPath $aliasPath /bin/ln -s $mainPath $aliasPath
} }
@@ -52,8 +78,9 @@ function _reboot() {
} }
function _main() { function _main() {
_createAlias "$mainAppPath" "$shimAppPath" _setSUIDBit "$pathToTargetVolume/$helperPath"
_startPatching "$executablePath" _createAlias "$pathToTargetVolume/$mainAppPath" "$pathToTargetVolume/$shimAppPath"
_startPatching "$pathToTargetVolume/$executablePath"
_reboot _reboot
} }
@@ -61,4 +88,5 @@ function _main() {
# MARK: Main # MARK: Main
# --------------------------- # ---------------------------
echo "Starting postinstall script..."
_main _main
+31 -16
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 # MARK: Variables
# --------------------------- # ---------------------------
filesToRemove=( filesToRemove=(
"/Applications/OpenCore-Patcher.app" "Applications/OpenCore-Patcher.app"
"/Library/Application Support/Dortania/Update.plist" "Library/Application Support/Dortania/Update.plist"
"/Library/Application Support/Dortania/OpenCore-Patcher.app" "Library/Application Support/Dortania/OpenCore-Patcher.app"
"/Library/LaunchAgents/com.dortania.opencore-legacy-patcher.auto-patch.plist" "Library/LaunchAgents/com.dortania.opencore-legacy-patcher.auto-patch.plist"
"/Library/PrivilegedHelperTools/com.dortania.opencore-legacy-patcher.privileged-helper" "Library/PrivilegedHelperTools/com.dortania.opencore-legacy-patcher.privileged-helper"
) )
@@ -22,39 +32,43 @@ filesToRemove=(
# --------------------------- # ---------------------------
function _removeFile() { function _removeFile() {
local currentFile=$1 local file=$1
if [[ ! -e $currentFile ]]; then if [[ ! -e $file ]]; then
# Check if file is a symbolic link # Check if file is a symbolic link
if [[ -L $currentFile ]]; then if [[ -L $file ]]; then
/bin/rm -f $currentFile echo "Removing symbolic link: $file"
/bin/rm -f $file
fi fi
return return
fi fi
echo "Removing file: $file"
# Check if file is a directory # Check if file is a directory
if [[ -d $currentFile ]]; then if [[ -d $file ]]; then
/bin/rm -rf $currentFile /bin/rm -rf $file
else else
/bin/rm -f $currentFile /bin/rm -f $file
fi fi
} }
function _createParentDirectory() { 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 # Check if parent directory exists
if [[ ! -d $parentDirectory ]]; then if [[ ! -d $parentDirectory ]]; then
echo "Creating parent directory: $parentDirectory"
/bin/mkdir -p $parentDirectory /bin/mkdir -p $parentDirectory
fi fi
} }
function _main() { function _main() {
for file in $filesToRemove; do for file in $filesToRemove; do
_removeFile $file _removeFile $pathToTargetVolume/$file
_createParentDirectory $file _createParentDirectory $pathToTargetVolume/$file
done done
} }
@@ -62,4 +76,5 @@ function _main() {
# MARK: Main # MARK: Main
# --------------------------- # ---------------------------
echo "Starting preinstall script..."
_main _main
@@ -5,6 +5,7 @@
# Set SUID bit on helper tool, and create app alias. # Set SUID bit on helper tool, and create app alias.
# ------------------------------------------------------ # ------------------------------------------------------
# MARK: PackageKit Parameters # MARK: PackageKit Parameters
# --------------------------- # ---------------------------