-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_browzero
93 lines (78 loc) · 3.11 KB
/
install_browzero
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
#!/usr/bin/env python3
import os
import platform
import requests
import shutil
BROWZERO_SCRIPT_URL = "https://raw.githubusercontent.com/styromaniac/browzero/main/browzero"
BROWZERO_ICON_LINUX_URL = "https://raw.githubusercontent.com/styromaniac/browzero/main/browzero.svg"
BROWZERO_ICON_MACOS_URL = "https://raw.githubusercontent.com/styromaniac/browzero/main/browzero.icns"
BROWZERO_ICON_WINDOWS_URL = "https://raw.githubusercontent.com/styromaniac/browzero/main/browzero.ico"
def download_file(url, output_path):
response = requests.get(url, stream=True)
response.raise_for_status()
with open(output_path, "wb") as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
def install():
os_name = platform.system()
if os_name == "Linux":
install_path = "/usr/local/sbin"
icon_path = "/usr/share/icons/hicolor/scalable/apps"
desktop_entry_path = "/usr/share/applications/browzero.desktop"
icon_url = BROWZERO_ICON_LINUX_URL
icon_filename = "browzero.svg"
elif os_name == "Darwin":
install_path = "/usr/local/bin"
icon_path = os.path.expanduser("~/Applications/browzero.app/Contents/Resources")
desktop_entry_path = os.path.expanduser("~/Applications/browzero.app/Contents/Info.plist")
icon_url = BROWZERO_ICON_MACOS_URL
icon_filename = "browzero.icns"
elif os_name == "Windows":
install_path = os.path.join(os.environ["PROGRAMFILES"], "browzero")
icon_path = install_path
desktop_entry_path = None
icon_url = BROWZERO_ICON_WINDOWS_URL
icon_filename = "browzero.ico"
else:
print("Unsupported operating system")
return
browzero_script_path = os.path.join(install_path, "browzero")
browzero_icon_path = os.path.join(icon_path, icon_filename)
os.makedirs(install_path, exist_ok=True)
os.makedirs(icon_path, exist_ok=True)
print("Downloading browzero script...")
download_file(BROWZERO_SCRIPT_URL, browzero_script_path)
print("Downloading browzero icon...")
download_file(icon_url, browzero_icon_path)
if os_name == "Linux":
desktop_entry_content = f"""[Desktop Entry]
Version=1.0
Type=Application
Name=Browzero
Exec=python3 {browzero_script_path}
Icon={browzero_icon_path}
Terminal=false
StartupNotify=true
Categories=WebBrowser
"""
with open(desktop_entry_path, "w") as desktop_entry_file:
desktop_entry_file.write(desktop_entry_content)
elif os_name == "Darwin":
plist_content = f"""<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>/usr/bin/python3 {browzero_script_path}</string>
<key>CFBundleIconFile</key>
<string>{icon_filename}</string>
<key>CFBundleName</key>
<string>browzero</string>
</dict>
</plist>
"""
with open(desktop_entry_path, "w") as plist_file:
plist_file.write(plist_content)
print("browzero has been installed successfully")
if __name__ == "__main__":
install()