-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathsetup_browser.py
More file actions
97 lines (79 loc) · 3.22 KB
/
Copy pathsetup_browser.py
File metadata and controls
97 lines (79 loc) · 3.22 KB
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
import os
import shutil
import zipfile
import stat
import sys
import requests
VERSION = "143.0.7499.169"
BASE_URL = f"https://storage.googleapis.com/chrome-for-testing-public/{VERSION}/linux64"
CHROME_ZIP = "chrome-linux64.zip"
DRIVER_ZIP = "chromedriver-linux64.zip"
CHROME_URL = f"{BASE_URL}/{CHROME_ZIP}"
DRIVER_URL = f"{BASE_URL}/{DRIVER_ZIP}"
def download_file(url, filename):
print(f"[+] Downloading {filename}...")
try:
with requests.get(url, stream=True) as r:
r.raise_for_status()
total_size = int(r.headers.get('content-length', 0))
downloaded = 0
with open(filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
downloaded += len(chunk)
if total_size > 0:
percent = int((downloaded / total_size) * 100)
sys.stdout.write(f"\r Progress: {percent}%")
sys.stdout.flush()
print()
except Exception as e:
print(f"\n[-] Error downloading {url}: {e}")
sys.exit(1)
def set_executable(path):
st = os.stat(path)
os.chmod(path, st.st_mode | stat.S_IEXEC)
def main():
print(f"[*] Setting up Portable Chrome Environment (Version {VERSION})...")
download_file(CHROME_URL, CHROME_ZIP)
download_file(DRIVER_URL, DRIVER_ZIP)
print("[+] Extracting Chrome Browser...")
with zipfile.ZipFile(CHROME_ZIP, 'r') as zip_ref:
zip_ref.extractall(".")
print("[+] Extracting ChromeDriver...")
with zipfile.ZipFile(DRIVER_ZIP, 'r') as zip_ref:
zip_ref.extractall(".")
print("[+] Positioning files...")
source_driver_folder = "chromedriver-linux64"
source_driver_bin = os.path.join(source_driver_folder, "chromedriver")
dest_driver = "chromedriver"
if os.path.exists(source_driver_bin):
if os.path.exists(dest_driver):
os.remove(dest_driver)
shutil.move(source_driver_bin, dest_driver)
else:
print("[-] Error: chromedriver binary not found in extracted folder.")
sys.exit(1)
print("[+] Cleaning up temporary files...")
if os.path.exists(CHROME_ZIP): os.remove(CHROME_ZIP)
if os.path.exists(DRIVER_ZIP): os.remove(DRIVER_ZIP)
if os.path.exists(source_driver_folder): shutil.rmtree(source_driver_folder)
print("[+] Setting recursive executable permissions (755)...")
chrome_dir = "chrome-linux64"
chrome_bin = os.path.join(chrome_dir, "chrome")
try:
if os.path.exists(chrome_dir):
for root, dirs, files in os.walk(chrome_dir):
for momo in dirs:
os.chmod(os.path.join(root, momo), 0o755)
for momo in files:
os.chmod(os.path.join(root, momo), 0o755)
if os.path.exists(dest_driver):
os.chmod(dest_driver, 0o755)
except Exception as e:
print(f"[-] Warning: Could not set all permissions: {e}")
print("-" * 50)
print("[✔] SUCCESS! Environment is ready.")
print(f" - Browser: {os.path.abspath(chrome_bin)}")
print(f" - Driver: {os.path.abspath(dest_driver)}")
if __name__ == "__main__":
main()