auto_patcher: Adjust indentation logic

This commit is contained in:
Mykola Grymalyuk
2022-12-25 13:44:14 -07:00
parent 09f77490a5
commit 6fe7ed614c
+48 -44
View File
@@ -179,55 +179,59 @@ class AutomaticSysPatch:
# Installs the following: # Installs the following:
# - OpenCore-Patcher.app in /Library/Application Support/Dortania/ # - OpenCore-Patcher.app in /Library/Application Support/Dortania/
# - com.dortania.opencore-legacy-patcher.auto-patch.plist in /Library/LaunchAgents/ # - com.dortania.opencore-legacy-patcher.auto-patch.plist in /Library/LaunchAgents/
if self.constants.launcher_script is None: if self.constants.launcher_script is not None:
# Verify our binary isn't located in '/Library/Application Support/Dortania/' print("- Skipping Auto Patcher Launch Agent, not supported when running from source")
# As we'd simply be duplicating ourselves return
if not self.constants.launcher_binary.startswith("/Library/Application Support/Dortania/"):
print("- Installing Auto Patcher Launch Agent")
if not Path("Library/Application Support/Dortania").exists(): if self.constants.launcher_binary.startswith("/Library/Application Support/Dortania/"):
print("- Creating /Library/Application Support/Dortania/") print("- Skipping Auto Patcher Launch Agent, already installed")
utilities.process_status(utilities.elevated(["mkdir", "-p", "/Library/Application Support/Dortania"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)) return
print("- Copying OpenCore Patcher to /Library/Application Support/Dortania/") # Verify our binary isn't located in '/Library/Application Support/Dortania/'
if Path("/Library/Application Support/Dortania/OpenCore-Patcher.app").exists(): # As we'd simply be duplicating ourselves
print("- Deleting existing OpenCore-Patcher") print("- Installing Auto Patcher Launch Agent")
utilities.process_status(utilities.elevated(["rm", "-R", "/Library/Application Support/Dortania/OpenCore-Patcher.app"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
# Strip everything after OpenCore-Patcher.app if not Path("Library/Application Support/Dortania").exists():
path = str(self.constants.launcher_binary).split("/Contents/MacOS/OpenCore-Patcher")[0] print("- Creating /Library/Application Support/Dortania/")
print(f"- Copying {path} to /Library/Application Support/Dortania/") utilities.process_status(utilities.elevated(["mkdir", "-p", "/Library/Application Support/Dortania"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
utilities.process_status(utilities.elevated(["ditto", path, "/Library/Application Support/Dortania/OpenCore-Patcher.app"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
if not Path("/Library/Application Support/Dortania/OpenCore-Patcher.app").exists(): print("- Copying OpenCore Patcher to /Library/Application Support/Dortania/")
# Sometimes the binary the user launches may have a suffix (ie. OpenCore-Patcher 3.app) if Path("/Library/Application Support/Dortania/OpenCore-Patcher.app").exists():
# We'll want to rename it to OpenCore-Patcher.app print("- Deleting existing OpenCore-Patcher")
path = path.split("/")[-1] utilities.process_status(utilities.elevated(["rm", "-R", "/Library/Application Support/Dortania/OpenCore-Patcher.app"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
print(f"- Renaming {path} to OpenCore-Patcher.app")
utilities.process_status(utilities.elevated(["mv", f"/Library/Application Support/Dortania/{path}", "/Library/Application Support/Dortania/OpenCore-Patcher.app"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
subprocess.run(["xattr", "-cr", "/Library/Application Support/Dortania/OpenCore-Patcher.app"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) # Strip everything after OpenCore-Patcher.app
path = str(self.constants.launcher_binary).split("/Contents/MacOS/OpenCore-Patcher")[0]
print(f"- Copying {path} to /Library/Application Support/Dortania/")
utilities.process_status(utilities.elevated(["ditto", path, "/Library/Application Support/Dortania/OpenCore-Patcher.app"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
# Copy over our launch agent if not Path("/Library/Application Support/Dortania/OpenCore-Patcher.app").exists():
print("- Copying auto-patch.plist Launch Agent to /Library/LaunchAgents/") # Sometimes the binary the user launches may have a suffix (ie. OpenCore-Patcher 3.app)
if Path("/Library/LaunchAgents/com.dortania.opencore-legacy-patcher.auto-patch.plist").exists(): # We'll want to rename it to OpenCore-Patcher.app
print("- Deleting existing auto-patch.plist") path = path.split("/")[-1]
utilities.process_status(utilities.elevated(["rm", "/Library/LaunchAgents/com.dortania.opencore-legacy-patcher.auto-patch.plist"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)) print(f"- Renaming {path} to OpenCore-Patcher.app")
if not Path("/Library/LaunchAgents/").exists(): utilities.process_status(utilities.elevated(["mv", f"/Library/Application Support/Dortania/{path}", "/Library/Application Support/Dortania/OpenCore-Patcher.app"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
print("- Creating /Library/LaunchAgents/")
utilities.process_status(utilities.elevated(["mkdir", "-p", "/Library/LaunchAgents/"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
utilities.process_status(utilities.elevated(["cp", self.constants.auto_patch_launch_agent_path, "/Library/LaunchAgents/"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
# Set the permissions on the com.dortania.opencore-legacy-patcher.auto-patch.plist subprocess.run(["xattr", "-cr", "/Library/Application Support/Dortania/OpenCore-Patcher.app"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print("- Setting permissions on auto-patch.plist")
utilities.process_status(utilities.elevated(["chmod", "644", "/Library/LaunchAgents/com.dortania.opencore-legacy-patcher.auto-patch.plist"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
utilities.process_status(utilities.elevated(["chown", "root:wheel", "/Library/LaunchAgents/com.dortania.opencore-legacy-patcher.auto-patch.plist"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
# Making app alias # Copy over our launch agent
# Simply an easy way for users to notice the app print("- Copying auto-patch.plist Launch Agent to /Library/LaunchAgents/")
# If there's already an alias or exiting app, skip if Path("/Library/LaunchAgents/com.dortania.opencore-legacy-patcher.auto-patch.plist").exists():
if not Path("/Applications/OpenCore-Patcher.app").exists(): print("- Deleting existing auto-patch.plist")
print("- Making app alias") utilities.process_status(utilities.elevated(["rm", "/Library/LaunchAgents/com.dortania.opencore-legacy-patcher.auto-patch.plist"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
utilities.process_status(utilities.elevated(["ln", "-s", "/Library/Application Support/Dortania/OpenCore-Patcher.app", "/Applications/OpenCore-Patcher.app"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)) if not Path("/Library/LaunchAgents/").exists():
else: print("- Creating /Library/LaunchAgents/")
print("- Skipping Auto Patcher Launch Agent, not supported when running from source") utilities.process_status(utilities.elevated(["mkdir", "-p", "/Library/LaunchAgents/"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
utilities.process_status(utilities.elevated(["cp", self.constants.auto_patch_launch_agent_path, "/Library/LaunchAgents/"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
# Set the permissions on the com.dortania.opencore-legacy-patcher.auto-patch.plist
print("- Setting permissions on auto-patch.plist")
utilities.process_status(utilities.elevated(["chmod", "644", "/Library/LaunchAgents/com.dortania.opencore-legacy-patcher.auto-patch.plist"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
utilities.process_status(utilities.elevated(["chown", "root:wheel", "/Library/LaunchAgents/com.dortania.opencore-legacy-patcher.auto-patch.plist"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
# Making app alias
# Simply an easy way for users to notice the app
# If there's already an alias or exiting app, skip
if not Path("/Applications/OpenCore-Patcher.app").exists():
print("- Making app alias")
utilities.process_status(utilities.elevated(["ln", "-s", "/Library/Application Support/Dortania/OpenCore-Patcher.app", "/Applications/OpenCore-Patcher.app"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT))