Skip to content

Commit

Permalink
AutoPkg: Modularize pre/postinstall scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
khronokernel committed May 15, 2024
1 parent 23146d7 commit f7bcb26
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
- Resolve unpatching Nvidia Web Drivers failing to clean up `/Library/Extensions`
- Implement preflight code signature checks for macOS installer creation
- Ensures validity of `createinstallmedia` binary before execution
- Modularize AutoPkg's pre/postinstall scripts
- Adjusted to use functions for better readability
- Implements ZSH shebang
- Removes OS logging

## 1.4.3
- Update non-Metal Binaries for macOS Sonoma:
Expand Down
77 changes: 64 additions & 13 deletions ci_tooling/autopkg/postinstall.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,64 @@
#!/bin/sh

# Create alias for OpenCore-Patcher.app
if [ ! -d "/Applications/OpenCore-Patcher.app" ]; then
ln -s "/Library/Application Support/Dortania/OpenCore-Patcher.app" "/Applications/OpenCore-Patcher.app"
fi

# Start root patching
app_path="/Library/Application Support/Dortania/OpenCore-Patcher.app/Contents/MacOS/OpenCore-Patcher"
args="--patch_sys_vol"
"$app_path" "$args" &> "/Users/Shared/.OCLP-AutoPatcher-Log-$(date +"%Y_%m_%d_%I_%M_%p").txt"
log show --last boot > "/Users/Shared/.OCLP-System-Log-$(date +"%Y_%m_%d_%I_%M_%p").txt"
reboot
#!/bin/zsh --no-rcs
# ------------------------------------------------------
# AutoPkg Assets Postinstall Script
# ------------------------------------------------------
# Create alias for app, start patching and reboot.
# ------------------------------------------------------


# MARK: Variables
# ---------------------------

mainAppPath="/Library/Application Support/Dortania/OpenCore-Patcher.app"
shimAppPath="/Applications/OpenCore-Patcher.app"
executablePath="$mainAppPath/Contents/MacOS/OpenCore-Patcher"


# MARK: Functions
# ---------------------------

function _createAlias() {
local mainPath=$1
local aliasPath=$2

# Check if alias path exists
if [[ -e $aliasPath ]]; then
# Check if alias path is a symbolic link
if [[ -L $aliasPath ]]; then
/bin/rm -f $aliasPath
else
/bin/rm -rf $aliasPath
fi
fi

# Create symbolic link
/bin/ln -s $mainPath $aliasPath
}

function _startPatching() {
local executable=$1
local logPath=$(_logFile)

# Start patching
"$executable" "--patch_sys_vol" &> $logPath
}

function _logFile() {
echo "/Users/Shared/.OCLP-AutoPatcher-Log-$(/bin/date +"%Y_%m_%d_%I_%M_%p").txt"
}

function _reboot() {
/sbin/reboot
}

function _main() {
_createAlias "$mainAppPath" "$shimAppPath"
_startPatching "$executablePath"
_reboot
}


# MARK: Main
# ---------------------------

_main
76 changes: 64 additions & 12 deletions ci_tooling/autopkg/preinstall.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,64 @@
#!/bin/sh
app_path="/Library/Application Support/Dortania/OpenCore-Patcher.app"
launch_agent_path="/Library/LaunchAgents/com.dortania.opencore-legacy-patcher.auto-patch.plist"
if [ -d "$app_path" ]; then
echo "Found OpenCore-Patcher.app, removing..."
rm -rf "$app_path"
fi

if [ -f "$launch_agent_path" ]; then
echo "Found launch agent, removing..."
rm -f "$launch_agent_path"
fi
#!/bin/zsh --no-rcs
# ------------------------------------------------------
# AutoPkg Assets Preinstall Script
# ------------------------------------------------------
# Remove old files, and prepare directories.
# ------------------------------------------------------


# 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"
)


# MARK: Functions
# ---------------------------

function _removeFile() {
local currentFile=$1

if [[ ! -e $currentFile ]]; then
# Check if file is a symbolic link
if [[ -L $currentFile ]]; then
/bin/rm -f $currentFile
fi
return
fi

# Check if file is a directory
if [[ -d $currentFile ]]; then
/bin/rm -rf $currentFile
else
/bin/rm -f $currentFile
fi
}

function _createParentDirectory() {
local currentFile=$1

local parentDirectory=$(/usr/bin/dirname $currentFile)

# Check if parent directory exists
if [[ ! -d $parentDirectory ]]; then
/bin/mkdir -p $parentDirectory
fi
}

function _main() {
for file in $filesToRemove; do
_removeFile $file
_createParentDirectory $file
done
}


# MARK: Main
# ---------------------------

_main

0 comments on commit f7bcb26

Please sign in to comment.