forked from ravendevteam/talon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathraven_software_install.py
147 lines (119 loc) · 4.45 KB
/
raven_software_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
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
import os
import sys
import json
import logging
import platform
import subprocess
import ssl
import urllib.request
from pathlib import Path
from tqdm import tqdm
def log(message):
logging.info(message)
def get_packages_json():
url = "https://raw.githubusercontent.com/ravendevteam/toolbox/refs/heads/main/packages.json"
try:
context = ssl._create_unverified_context()
response = urllib.request.urlopen(url, context=context)
return json.loads(response.read().decode())
except Exception as e:
log(f"Error downloading packages.json: {e}")
return None
def add_defender_exclusion(path):
try:
subprocess.run(
['powershell', '-Command',
f'Add-MpPreference -ExclusionPath "{path}"'],
check=True,
capture_output=True
)
log(f"Added Windows Defender exclusion for: {path}")
return True
except Exception as e:
log(f"Failed to add Windows Defender exclusion: {e}")
return False
def get_installation_path():
if platform.system() == "Windows":
install_path = Path(os.getenv('APPDATA')) / "ravendevteam"
install_path.mkdir(parents=True, exist_ok=True)
# Windows Defender istisnası ekle
add_defender_exclusion(str(install_path))
return install_path
else:
return Path.home() / "Library" / "Application Support" / "ravendevteam"
def download_file(url, destination, desc="Downloading"):
try:
context = ssl._create_unverified_context()
with tqdm(unit='B', unit_scale=True, desc=desc) as pbar:
def report_hook(count, block_size, total_size):
if total_size > 0:
pbar.total = total_size
pbar.update(block_size)
opener = urllib.request.build_opener(urllib.request.HTTPSHandler(context=context))
urllib.request.install_opener(opener)
urllib.request.urlretrieve(url, destination, reporthook=report_hook)
return True
except Exception as e:
log(f"Download error: {e}")
return False
def create_shortcut(target_path, shortcut_name):
try:
desktop = os.path.join(os.path.expanduser("~"), "Desktop")
shortcut_path = os.path.join(desktop, f"{shortcut_name}.lnk")
os.system(f'cmd /c mklink "{shortcut_path}" "{target_path}"')
log(f"Created shortcut for {shortcut_name}")
return True
except Exception as e:
log(f"Failed to create shortcut: {e}")
return False
def install_package(package, install_dir):
platform_name = platform.system()
if platform_name not in package["os"]:
log(f"Package {package['name']} is not available for {platform_name}")
return False
package_dir = install_dir / package["name"]
package_dir.mkdir(parents=True, exist_ok=True)
url = package["url"][platform_name]
file_name = url.split("/")[-1]
download_path = package_dir / file_name
log(f"Installing {package['name']} v{package['version']}...")
if not download_file(url, download_path, f"Downloading {package['name']}"):
return False
if package["shortcut"] and platform_name == "Windows":
create_shortcut(str(download_path), package["name"])
log(f"Successfully installed {package['name']}")
return True
def run_toolbox():
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
log("Fetching package list...")
packages_data = get_packages_json()
if not packages_data:
log("Failed to fetch packages data")
return False
install_dir = get_installation_path()
install_dir.mkdir(parents=True, exist_ok=True)
success = True
for package in packages_data["packages"]:
if not install_package(package, install_dir):
success = False
log(f"Failed to install {package['name']}")
else:
log(f"Successfully installed {package['name']}")
log("Installation process completed" + (" successfully" if success else " with some failures"))
return success
def main():
try:
success = run_toolbox()
return success
except KeyboardInterrupt:
log("\nInstallation cancelled by user")
return False
except Exception as e:
log(f"Unexpected error: {e}")
return False
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)