-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbluekit.py
More file actions
144 lines (107 loc) · 4.35 KB
/
bluekit.py
File metadata and controls
144 lines (107 loc) · 4.35 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
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
# coding:utf-8
import argparse
import ctypes
import json
import os
import sys
import traceback
from pathlib import Path
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication
from app import data, installation_steps, utils
from app.common.config import cfg
from app.view.main_window import MainWindow
try:
import pyi_splash
except ImportError:
pyi_splash = None
parser = argparse.ArgumentParser(
prog='Bluekit',
description='A cybersecurity-focused workstation setup script',
epilog='Have fun!'
)
parser.add_argument('-s', '--silent', action='store_true', help='Run the script without any GUI prompts')
parser.add_argument('-c', '--config', help='Path to the configuration file', type=Path)
parser.add_argument('--bundle', help='Path to the bundled .zip file', type=Path)
parser.add_argument('--keep-cache', action='store_true', help='Keep the cache directory after the script finishes')
parser.add_argument('--ignore-defender', action='store_true', help='Ignore Windows Defender Real-Time Protection')
args = parser.parse_args()
if args and args.keep_cache:
cfg.keep_cache = True
def run_gui():
QApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
# create application
app = QApplication(sys.argv)
app.setAttribute(Qt.AA_DontCreateNativeWidgetSiblings)
if pyi_splash and pyi_splash.is_alive():
pyi_splash.close()
# create main window
w = MainWindow(args)
w.show()
app.exec_()
def ensure_suitable_environment():
# If we are frozen
if getattr(sys, "frozen", False):
# Check if we are running as admin
if not utils.is_admin():
# Not running as admin, try to get admin privileges
ctypes.windll.shell32.ShellExecuteW(
None, "runas", sys.executable, " ".join(sys.argv), None, 1
)
sys.exit()
if not args.ignore_defender and utils.is_defender_real_time_protection_enabled():
if pyi_splash:
pyi_splash.close()
ctypes.windll.user32.MessageBoxW(
0,
"Windows Defender Real-Time Protection is enabled. "
"Please disable it before running this script.",
"Windows Defender Real-Time Protection",
0x10
)
sys.exit(1)
def load_config(config_p: str):
if not os.path.isfile(config_p):
raise FileNotFoundError(f"Config file not found: {config_p}")
with open(config_p, 'r', encoding="utf-8") as config_file:
custom_data = json.loads(config_file.read())
# Perform validation on the custom data
for top_level_keys in custom_data:
if top_level_keys not in data.default_configuration:
raise KeyError(f"Unrecognized key in custom configuration: {top_level_keys}")
data.configuration = data.Configuration(**custom_data)
def main():
ensure_suitable_environment()
if args.config:
if not os.path.isabs(args.config):
args.config = Path.cwd() / args.config
load_config(args.config)
if args.bundle:
if not os.path.isabs(args.bundle):
args.bundle = Path.cwd() / args.bundle
if not os.path.isfile(args.bundle):
raise FileNotFoundError(f"Bundled .zip file not found: {args.bundle}")
cfg.bundledZipFile.value = args.bundle.as_posix()
cfg.saferEnabled.value = data.configuration.settings.enable_windows_safer
cfg.malwareFolders.value = [utils.resolve_path(x) for x in data.configuration.settings.malware_folders]
cfg.installZsh.value = data.configuration.settings.install_zsh_over_git
cfg.makeBindiffAvailable.value = data.configuration.settings.make_bindiff_available
if args and args.keep_cache:
cfg.scoopKeepCache.value = args.keep_cache
if args.silent:
if pyi_splash:
pyi_splash.close()
installation_steps.install_bluekit(data.configuration)
else:
run_gui()
if __name__ == "__main__":
try:
main()
except Exception as e:
if pyi_splash and pyi_splash.is_alive():
pyi_splash.close()
exception_traceback = traceback.format_exc()
ctypes.windll.user32.MessageBoxW(0, exception_traceback, "Error", 0x10)