-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathPackAppMacOS.py
178 lines (140 loc) · 4.48 KB
/
PackAppMacOS.py
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import os, shutil, plistlib, time, sys
line = "--------------------------------------------------"
loc = ""
def noline(string):
print(string,end="")
def title(string):
print(line)
print("{:^50}".format(string))
print(line)
def isfile(string):
return os.path.isfile(string)
def clear():
os.system("clear")
neededfiles = [r"./AppleDiagnostics.chunklist", r"./AppleDiagnostics.dmg", r"./BaseSystem.chunklist", r"./BaseSystem.dmg", r"./InstallESDDmg.pkg", r"./InstallInfo.plist"]
def copyfiles(sharedsupportloc):
for f in neededfiles:
noline(" Copying {}... ".format(f))
shutil.copy(f, sharedsupportloc)
print("Done.")
def editplist():
fp = open(r"./InstallInfo.plist","rb")
installinfo = plistlib.load(fp)
del installinfo["Payload Image Info"]["chunklistURL"]
del installinfo["Payload Image Info"]["chunklistid"]
installinfo["Payload Image Info"]["URL"] = "InstallESD.dmg"
installinfo["Payload Image Info"]["id"] = "com.apple.dmg.InstallESD"
plistlib.dump(installinfo, open(r"./InstallInfo.plist", "wb"))
def packapp():
clear()
### Here we choose our macOS Version
title("Choose macOS Version")
print("1: High Sierra")
print("2: Mojave")
print("Q: Quit")
print("M: Main Menu")
option = input("Please enter an option: ")
version = ""
diskname = ""
if option == "1":
version = "High Sierra"
diskname = "'OS X Base System'"
elif option == "2":
version = "Mojave"
diskname = "'macOS Base System'"
elif option == "Q":
quit()
elif option == "M":
mainmenu()
else:
packapp()
clear()
sharedsupportloc = r"./Install macOS {}.app/Contents/SharedSupport".format(version)
title("Packing Files to Application")
# We need to grab the base of the App out
# from BaseSystem.dmg
noline("Mounting BaseSystem.dmg... ")
os.system("hdiutil attach ./BaseSystem.dmg > /dev/null")
print("Done.")
noline("Copying Installer from BaseSystem.dmg... ")
os.system("cp -Rf /Volumes/{}/'Install macOS {}.app' ./'Install macOS {}.app'".format(diskname, version, version))
print("Done.")
noline("Unmounting BaseSystem.dmg... ")
os.system("umount /Volumes/{}".format(diskname))
print("Done.")
# We need to make a folder call
# SharedSupport inside the App.
# This is where we save our files.
noline("Making Directories... ")
os.makedirs(sharedsupportloc)
print("Done.")
print("Copying Files...")
copyfiles(sharedsupportloc)
print("Done.")
# We need to edit the InstallInfo.plist
# to make sure we matches the settings
# we want.
noline("Editting InstallInfo.plist... ")
os.chdir(sharedsupportloc)
editplist()
print("Done.")
# We need to rename InstallESDDmg.pkg
# to InstallESD.dmg to match the settings
# in InstallInfo.plist
noline("Renaming InstallESD.dmg... ")
os.rename("InstallESDDmg.pkg", "InstallESD.dmg")
print("Done.")
print("All Done")
time.sleep(1)
mainmenu()
def SharedSupport():
clear()
title("Packing files to SharedSupport")
noline("Making Directories... ")
os.mkdir("SharedSupport")
print("Done.")
print("Copying files... ")
copyfiles(r"./SharedSupport")
print("Done.")
noline("Editting InstallInfor.plist... ")
os.chdir(r"./SharedSupport")
editplist()
os.rename("InstallESDDmg.pkg", "InstallESD.dmg")
print("Done")
print("All Done.")
time.sleep(1)
mainmenu()
def checkfiles():
clear()
title("Checking Required Files...")
time.sleep(0.5)
for f in neededfiles:
if isfile(f) == False:
print("Missing Files.")
sys.exit()
time.sleep(1)
def quit():
print("Goodbye! Have a good day!")
sys.exit()
def mainmenu():
clear()
title("Main Menu")
print("A: Pack files to an Install macOS Application")
print("B: Pack files to disk image (This will take a long time!)")
print("P: Pack files for convert the current Network Recovery Installer to a Full Installer (SharedSupport)")
print("Q: Quit")
option = input("Enter an option: ")
if option == "Q" or option == "q":
quit()
elif option == "A" or option == "a":
packapp()
elif option == "P" or option == "p":
SharedSupport()
else:
mainmenu()
def main():
os.chdir(os.path.dirname(os.path.realpath(__file__)))
checkfiles()
mainmenu()
if __name__ == "__main__":
main()