-
Notifications
You must be signed in to change notification settings - Fork 18
/
Generate-Internal-Overlay.command
executable file
·157 lines (121 loc) · 5.37 KB
/
Generate-Internal-Overlay.command
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env python3
"""
Goal of this function is to create a Disk image holding only the files that are not committed to git
The purpose is to allow for internal developers to test their changes through the patcher more easily.
Resulting DMG will be placed in the root of the OpenCore-Legacy-Patcher repo for merging.
"""
import os
import subprocess
from pathlib import Path
OCLP_DIRECTORY: str = "../OpenCore-Legacy-Patcher"
OVERLAY_FOLDER: str = "DortaniaInternalResources"
OVERLAY_DMG: str = OVERLAY_FOLDER + ".dmg"
ENCRYPTION_FILE: str = "" # Replace with path to file containing the encryption password
class GenerateInternalDiffDiskImage:
def __init__(self) -> None:
print("Generating internal diff disk image")
os.chdir(os.path.dirname(os.path.realpath(__file__)))
files = self._find_binaries_to_add()
if not files:
print(" - No files to add")
return
self._prepare_workspace()
self._generate_dmg(files)
def _find_binaries_to_add(self) -> list:
"""
Grab a list of all files that are not committed to git
Exclude files that wouldn't be compatible with the patcher (ex. zip files)
"""
uncommited_files = self._find_uncommited_files()
uncommited_files = [file[1:-1] if file.startswith(("'", '"')) and file.endswith(("'", '"')) else file for file in uncommited_files]
uncommited_files = [file for file in uncommited_files if file.startswith("Universal-Binaries")]
for extension in [".zip", ".dmg", ".pkg"]:
uncommited_files = [file for file in uncommited_files if not file.endswith(extension)]
return uncommited_files
def _find_uncommited_files(self) -> list:
"""
Grab a list of all files that are not committed to git
Use git status to find uncommited files
"""
uncommited_files = subprocess.run(
["/usr/bin/git", "status", "--porcelain"], capture_output=True, text=True)
if uncommited_files.returncode != 0:
print(" - Failed to find uncommited files")
print(uncommited_files.stdout)
print(uncommited_files.stderr)
return []
# Strip status flags
return [file[3:] for file in uncommited_files.stdout.split("\n") if file]
def _legacy_find_uncommited_files(self) -> list:
"""
Grab a list of all files that are not committed to git
Legacy variant using ls-files. This is less reliable than using git status
"""
uncommited_files = subprocess.run(
[
"/usr/bin/git", "ls-files", "--others", "--exclude-standard"
], capture_output=True, text=True)
if uncommited_files.returncode != 0:
print(" - Failed to find uncommited files")
print(uncommited_files.stdout)
print(uncommited_files.stderr)
return []
return uncommited_files.stdout.split("\n")
def _prepare_workspace(self) -> None:
"""
Remove old files and create a new workspace
"""
print(" - Preparing workspace")
if Path(OVERLAY_DMG).exists():
subprocess.run(["/bin/rm", OVERLAY_DMG])
if Path(OVERLAY_FOLDER).exists():
subprocess.run(["/bin/rm", "-rf", OVERLAY_FOLDER])
subprocess.run(["/bin/mkdir", OVERLAY_FOLDER])
def _fetch_encryption_password(self) -> str:
"""
Return the encryption password for the DMG
"""
password_file = Path(ENCRYPTION_FILE).expanduser()
if not password_file.exists() or not password_file.is_file():
return "password"
return password_file.read_text().strip()
def _generate_dmg(self, files: list) -> None:
"""
Copy files to the workspace and generate the DMG
"""
print(" - Copying files")
for file in files:
print(f" - {file}")
src_path = Path(file)
dst_path = Path(OVERLAY_FOLDER) / str(src_path).split("Universal-Binaries/")[1]
if not Path(dst_path.parent).exists():
subprocess.run(["/bin/mkdir", "-p", dst_path.parent])
subprocess.run(["/bin/cp", "-a", src_path, dst_path])
print(" - Generating tmp DMG")
subprocess.run([
"/usr/bin/hdiutil", "create",
"-srcfolder", OVERLAY_FOLDER, "tmp.dmg",
"-volname", "Dortania Internal Resources",
"-fs", "HFS+",
"-ov",
"-format", "UDRO"
], capture_output=True, text=True)
print(" - Converting to encrypted DMG")
subprocess.run(
["/usr/bin/hdiutil", "convert",
"-format", "ULMO", "tmp.dmg",
"-o", OVERLAY_DMG,
"-passphrase", self._fetch_encryption_password(),
"-encryption",
"-ov"
], capture_output=True, text=True)
subprocess.run(["/bin/rm", "tmp.dmg"])
if Path(OCLP_DIRECTORY).exists():
print(" - Moving DMG")
if Path(OCLP_DIRECTORY, OVERLAY_DMG).exists():
subprocess.run(["/bin/rm", f"{OCLP_DIRECTORY}/{OVERLAY_DMG}"])
subprocess.run(["/bin/mv", OVERLAY_DMG, f"{OCLP_DIRECTORY}/{OVERLAY_DMG}"])
print(" - Cleaning up")
subprocess.run(["/bin/rm", "-rf", OVERLAY_FOLDER])
if __name__ == "__main__":
GenerateInternalDiffDiskImage()