-
Notifications
You must be signed in to change notification settings - Fork 12
/
install.py
83 lines (73 loc) · 2.69 KB
/
install.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
from setuptools import setup
import os
import platform
import shutil
import sys
try:
import py2app, py2app.build_app
import objc, AppKit
except:
sys.stderr.write('MailFlow requires the py2app and pyobjc modules\n')
sys.stderr.write('Try: pip3 install --user py2app pyobjc\n')
sys.exit(1)
def copystat(src, dst, **kw):
st = os.stat(src, **kw)
mode = shutil.stat.S_IMODE(st.st_mode)
os.utime(dst, (st.st_atime, st.st_mtime))
os.chmod(dst, mode, **kw)
shutil.copystat = copystat
install_path = os.environ['HOME'] + '/Library/Mail/Bundles'
if os.path.exists('/System/Applications/Mail.app'):
mail_path = '/System/Applications/Mail.app/Contents/Info'
else:
mail_path = '/Applications/Mail.app/Contents/Info'
command = 'defaults read %s PluginCompatibilityUUID' % mail_path
compatibility_uuids = [ os.popen(command).read().strip() ]
major, minor = map(int, platform.mac_ver()[0].split('.')[:2])
if major == 10 and minor < 12:
sys.stderr.write('MailFlow requires macOS 10.12 or later\n')
sys.exit(1)
if major == 10 and minor > 15:
sys.stderr.write('Please run with SYSTEM_VERSION_COMPAT=0\n')
sys.exit(1)
if major > 12:
sys.stderr.write('MailFlow does not yet support macOS 13.0 or later\n')
sys.exit(1)
sys.argv[1:] = ['py2app'] + sys.argv[1:]
sys.stdout = open(os.devnull, 'w')
if os.path.dirname(__file__):
os.chdir(os.path.dirname(__file__))
py2app.build_app.py2app.may_log_missing = lambda *args: False
setup(
name = 'MailFlow',
plugin = ['MailFlow.py'],
options = {
'py2app': {
'dist_dir': install_path,
'extension': '.mailbundle',
'plist': {
'CFBundleIdentifier': 'uk.me.cdw.MailFlow',
'CFBundleVersion': '1.0',
'NSHumanReadableCopyright':
'Copyright (C) 2023 Chris Webb <[email protected]>',
'Supported%d.%dPluginCompatibilityUUIDs' % (major, minor):
compatibility_uuids
},
'semi_standalone': True,
'strip': False
}
},
setup_requires = ['py2app']
)
sys.stdout.close()
sys.stdout = sys.__stdout__
print('Installed compatible MailFlow.mailbundle in %s' % install_path)
if major > 10:
os.system('codesign -f -s - "%s/MailFlow.mailbundle"' % install_path)
os.system('spctl --add --label MailFlow "%s/MailFlow.mailbundle"' \
% install_path)
os.system('spctl --enable --label MailFlow')
os.system('defaults write com.apple.mail EnableBundles -bool true')
os.system('rm -f -r ~/Library/Mail/Bundles\\ \\(Disabled\\)/MailFlow.*')
os.system('rmdir ~/Library/Mail/Bundles\\ \\(Disabled\\) 2>/dev/null')
print('Enabled Apple Mail plugin bundles')