-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathexoinstall.py
More file actions
1230 lines (1110 loc) · 48 KB
/
exoinstall.py
File metadata and controls
1230 lines (1110 loc) · 48 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
import sys
try:
import termios, tty
except ImportError:
termios = None
tty = None
import os
import sys
import subprocess
import shutil
import hashlib
import tempfile
class ExoInstaller:
class Colors:
HEADER = "\033[95m"
BLUE = "\033[94m"
GREEN = "\033[92m"
YELLOW = "\033[93m"
RED = "\033[91m"
ENDC = "\033[0m"
BOLD = "\033[1m"
REPO_URL = "https://github.com/debuggyo/Exo.git"
def __init__(self):
self.default_config_dir = os.path.expanduser("~/.config/")
self.source_dir = None
self.config_dir = self.default_config_dir
self.aur_helper = None
self.dry_run = False
self.protected_files = [
"user_settings.json",
"colors.scss",
"preview-colors.scss",
]
self.auto_confirm_overwrite = False
self.auto_confirm_delete = False
self.distro = None
self.package_manager = None
def run(self):
self.print_header("Welcome to the Exo Installer")
command_exists = shutil.which("exoupdate") is not None
try:
with tempfile.TemporaryDirectory() as temp_dir:
self.clone_repo(self.REPO_URL, temp_dir)
self.source_dir = temp_dir
self.update_installed_command_if_needed()
print("1: Full Installation")
print("2: Update Existing Installation")
print("3: Run in Test Mode (Dry Run)")
print(f"{self.Colors.RED}4: Uninstall Exo{self.Colors.ENDC}")
print("q: Quit")
options = ["1", "2", "3", "4", "q"]
choice = self.get_user_choice("Select an option: ", options)
if not command_exists and choice in ["1", "2"]:
self.install_as_command()
if choice == "1":
self.full_install()
elif choice == "2":
self.update_install()
elif choice == "3":
self.enter_test_mode()
elif choice == "4":
self.uninstall_exo()
elif choice == "q":
print("Quitting.")
except Exception as e:
print(
f"{self.Colors.RED}An unexpected error occurred: {e}{self.Colors.ENDC}"
)
sys.exit(1)
finally:
print("\nTemporary files have been cleaned up.")
def clone_repo(self, repo_url, dest_dir):
if not shutil.which("git"):
print(
f"{self.Colors.RED}Git command not found. Please install Git to continue.{self.Colors.ENDC}"
)
sys.exit(1)
print(f"Cloning '{repo_url}' into a temporary directory...")
result = subprocess.run(
["git", "clone", "--depth", "1", repo_url, dest_dir],
capture_output=True,
text=True,
check=False,
)
if result.returncode != 0:
print(
f"{self.Colors.RED}Error cloning repository: {result.stderr}{self.Colors.ENDC}"
)
sys.exit(1)
def enter_test_mode(self):
self.dry_run = True
self.config_dir = "/tmp/exo_install_test/"
self.print_header("Entering Test Mode")
print(
f"{self.Colors.YELLOW}All file changes will be applied to: {self.config_dir}{self.Colors.ENDC}"
)
print(
f"{self.Colors.YELLOW}System commands will be simulated.{self.Colors.ENDC}"
)
if os.path.exists(self.config_dir):
shutil.rmtree(self.config_dir)
os.makedirs(self.config_dir)
print("\nWhich workflow would you like to test?")
print("1: Full Installation")
print("2: Update Existing Installation")
print(f"{self.Colors.RED}3: Uninstall Exo{self.Colors.ENDC}")
print("q: Back to Main Menu")
test_choice = self.get_user_choice(
"Select a test option: ", ["1", "2", "3", "q"]
)
if test_choice == "1":
self.full_install()
elif test_choice == "2":
self.update_install()
elif test_choice == "3":
self.uninstall_exo()
elif test_choice == "q":
self.dry_run = False
self.config_dir = self.default_config_dir
self.run()
def run_command(self, cmd, **kwargs):
if self.dry_run:
print(
f"{self.Colors.YELLOW}[DRY RUN] Would execute: {' '.join(cmd)}{self.Colors.ENDC}"
)
return subprocess.CompletedProcess(cmd, 0)
else:
try:
return subprocess.run(cmd, check=True, **kwargs)
except (subprocess.CalledProcessError, FileNotFoundError) as e:
print(
f"{self.Colors.RED}Error executing command: {e}{self.Colors.ENDC}"
)
return None
def print_header(self, title):
print(f"\n{self.Colors.HEADER}{self.Colors.BOLD}{'=' * 50}{self.Colors.ENDC}")
print(f" {self.Colors.HEADER}{self.Colors.BOLD}{title}{self.Colors.ENDC}")
print(f"{self.Colors.HEADER}{self.Colors.BOLD}{'=' * 50}{self.Colors.ENDC}")
def get_user_choice(self, prompt, options):
if (
termios and tty
): # Check if termios and tty were successfully imported at the top
try:
print(
f"{self.Colors.YELLOW}{prompt}{self.Colors.ENDC}",
end="",
flush=True,
)
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(fd)
while True:
char = sys.stdin.read(1)
if char.lower() in options:
print(char)
return char.lower()
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
except (
termios.error
): # Only catch termios.error here; ImportError is handled globally
print(
f"\n{self.Colors.YELLOW}Warning: Immediate input is not supported. Please press 'Enter' after your choice.{self.Colors.ENDC}"
)
while True:
option = input(
f"{self.Colors.YELLOW}{prompt}{self.Colors.ENDC}"
).lower()
if option in options:
return option
print(f"{self.Colors.RED}Invalid input.{self.Colors.ENDC}")
else: # Fallback if termios or tty were not imported (e.g., on non-Unix systems)
print(
f"\n{self.Colors.YELLOW}Warning: Immediate input is not supported. Please press 'Enter' after your choice.{self.Colors.ENDC}"
)
while True:
option = input(
f"{self.Colors.YELLOW}{prompt}{self.Colors.ENDC}"
).lower()
if option in options:
return option
print(f"{self.Colors.RED}Invalid input.{self.Colors.ENDC}")
def get_file_hash(self, file_path):
hasher = hashlib.sha256()
try:
with open(file_path, "rb") as f:
buf = f.read()
hasher.update(buf)
return hasher.hexdigest()
except IOError:
return None
def detect_distro(self):
self.print_header("Distro Check")
if os.path.exists("/etc/arch-release"):
self.distro = "arch"
print(
f"{self.Colors.GREEN}Detected Arch-based distribution.{self.Colors.ENDC}"
)
elif os.path.exists("/etc/fedora-release"):
self.distro = "fedora"
print(
f"{self.Colors.GREEN}Detected Fedora-based distribution.{self.Colors.ENDC}"
)
elif os.path.exists("/etc/lsb-release"):
try:
with open("/etc/lsb-release") as f:
for line in f:
if "Ubuntu" in line or "Debian" in line.capitalize():
self.distro = "ubuntu"
print(
f"{self.Colors.GREEN}Detected Debian/Ubuntu-based distribution.{self.Colors.ENDC}"
)
break
except IOError:
pass
if self.distro:
return True
else:
print(
f"{self.Colors.YELLOW}Unsupported distribution detected.{self.Colors.ENDC}"
)
print("You will need to install the required dependencies manually.")
print(
"Dependencies: python-ignis, ignis-gvc, matugen, swww, gnome-bluetooth, adw-gtk-theme, dart-sass, material-symbols-font"
)
return False
def get_package_manager(self):
if self.distro == "arch":
self.package_manager = "pacman"
elif self.distro == "fedora":
self.package_manager = "dnf"
elif self.distro == "ubuntu":
self.package_manager = "apt"
def check_aur_helper(self):
self.print_header("Checking for AUR Helper")
if shutil.which("paru"):
self.aur_helper = "paru"
elif shutil.which("yay"):
self.aur_helper = "yay"
if self.aur_helper:
print(
f"{self.Colors.GREEN}Found AUR helper: {self.aur_helper}{self.Colors.ENDC}"
)
return True
print(
f"{self.Colors.YELLOW}Neither paru nor yay found. Attempting to install yay...{self.Colors.ENDC}"
)
if self.install_yay():
if shutil.which("yay"):
self.aur_helper = "yay"
return True
print(
f"{self.Colors.RED}Failed to find or install an AUR helper.{self.Colors.ENDC}"
)
return False
def install_yay(self):
print("Installing base-devel and git...")
if not self.run_command(
["sudo", "pacman", "-S", "--needed", "--noconfirm", "git", "base-devel"]
):
return False
yay_bin_dir = "yay-bin"
if os.path.exists(yay_bin_dir):
print(f"Directory '{yay_bin_dir}' already exists. Removing it...")
shutil.rmtree(yay_bin_dir)
print("Cloning yay from the AUR...")
if not self.run_command(
["git", "clone", "https://aur.archlinux.org/yay-bin.git"]
):
return False
try:
os.chdir(yay_bin_dir)
print("Running makepkg to build and install yay...")
result = self.run_command(["makepkg", "-si", "--noconfirm"])
os.chdir("..")
shutil.rmtree(yay_bin_dir)
return result is not None
except Exception as e:
print(
f"{self.Colors.RED}An error occurred during yay installation: {e}{self.Colors.ENDC}"
)
if os.getcwd().endswith(yay_bin_dir):
os.chdir("..")
return False
def install_dependencies(self):
self.print_header("Installing Dependencies")
choice = self.get_user_choice(
"Do you want to automatically install dependencies? (y/n): ", ["y", "n"]
)
if choice == "n":
print(
"Skipping dependency installation. Please ensure all required packages are installed manually."
)
return
dependencies = {
"arch": [
"python-ignis-git",
"ignis-gvc",
"ttf-material-symbols-variable-git",
"matugen-bin",
"swww",
"gnome-bluetooth-3.0",
"adw-gtk-theme",
"dart-sass",
],
"fedora": [
"python3-pip",
"cargo",
"gnome-bluetooth-libs",
"adw-gtk3-theme",
"meson",
"ninja-build",
"pkg-config",
"scdoc",
"nodejs-npm",
"python3-cairo-devel",
"libxkbcommon-devel",
"wayland-devel",
"libdisplay-info-devel",
"libliftoff-devel",
"pulseaudio-libs-devel",
"lz4-devel",
"glib2-devel",
"gobject-introspection-devel",
"libgee-devel",
"vala",
"gcc",
"make",
"wayland-protocols-devel",
"python3-devel",
],
"ubuntu": [
"python3-pip",
"cargo",
"libgnome-bluetooth-3.0-13",
"adw-gtk-theme",
"dart-sass",
"fonts-material-design-icons-iconfont",
"meson",
"ninja-build",
"pkg-config",
"scdoc",
"libxkbcommon-dev",
"wayland-dev",
"libdisplay-info-dev",
"libliftoff-dev",
],
}
if self.distro in dependencies:
packages = dependencies[self.distro]
print(
f"Attempting to install the following packages: {', '.join(packages)}"
)
if self.distro == "arch":
result = self.run_command(
[self.aur_helper, "-S", "--noconfirm"] + packages
)
if result is None or (
hasattr(result, "returncode") and result.returncode != 0
):
print(
f"{self.Colors.RED}Failed to install some packages with AUR helper.{self.Colors.ENDC}"
)
elif self.distro == "fedora":
result = self.run_command(["sudo", "dnf", "install", "-y"] + packages)
if result is None or (
hasattr(result, "returncode") and result.returncode != 0
):
print(
f"{self.Colors.RED}Failed to install some packages with dnf.{self.Colors.ENDC}"
)
print("\nInstalling ignis via pip...")
result = self.run_command(
[
"pip",
"install",
"--user",
"git+https://github.com/ignis-sh/ignis.git",
]
)
if result is None or (
hasattr(result, "returncode") and result.returncode != 0
):
print(
f"{self.Colors.RED}Failed to install ignis via pip.{self.Colors.ENDC}"
)
print("\nInstalling matugen via cargo...")
result = self.run_command(["cargo", "install", "matugen"])
if result is None or (
hasattr(result, "returncode") and result.returncode != 0
):
print(
f"{self.Colors.RED}Failed to install matugen via cargo.{self.Colors.ENDC}"
)
else:
self.run_command(["export", "PATH=\"$PATH:~/.cargo/bin\""])
print("\n Installing required fonts...")
result = self.run_command(["wget", "https://github.com/google/material-design-icons/raw/refs/heads/master/variablefont/MaterialSymbolsOutlined%5BFILL,GRAD,opsz,wght%5D.ttf"])
if result is None or (
hasattr(result, "returncode") and result.returncode != 0
):
print(
f"{self.Colors.RED}Failed to download the font.{self.Colors.ENDC}"
)
else:
result = self.run_command(["sudo", "mkdir", "-p", "/usr/share/fonts/material-symbols-icons"])
if result is None or (
hasattr(result, "returncode") and result.returncode != 0
):
print(
f"{self.Colors.RED}Failed to create the folder for the font.{self.Colors.ENDC}"
)
else:
result = self.run_command(["sudo", "mv", "MaterialSymbolsOutlined[FILL,GRAD,opsz,wght].ttf", "/usr/share/fonts/material-symbols-icons"])
if result is None or (
hasattr(result, "returncode") and result.returncode != 0
):
print(
f"{self.Colors.RED}Failed to install the font.{self.Colors.ENDC}"
)
else:
self.run_command(["fc-cache", "-v"])
elif self.distro == "ubuntu":
result = self.run_command(["sudo", "apt", "update"])
if result is None or (
hasattr(result, "returncode") and result.returncode != 0
):
print(
f"{self.Colors.RED}Failed to update apt repositories.{self.Colors.ENDC}"
)
result = self.run_command(["sudo", "apt", "install", "-y"] + packages)
if result is None or (
hasattr(result, "returncode") and result.returncode != 0
):
print(
f"{self.Colors.RED}Failed to install some packages with apt.{self.Colors.ENDC}"
)
print("\nInstalling ignis via pip...")
result = self.run_command(
[
"pip",
"install",
"--user",
"git+https://github.com/ignis-sh/ignis.git",
]
)
if result is None or (
hasattr(result, "returncode") and result.returncode != 0
):
print(
f"{self.Colors.RED}Failed to install ignis via pip.{self.Colors.ENDC}"
)
print("\nInstalling matugen via cargo...")
result = self.run_command(["cargo", "install", "matugen"])
if result is None or (
hasattr(result, "returncode") and result.returncode != 0
):
print(
f"{self.Colors.RED}Failed to install matugen via cargo.{self.Colors.ENDC}"
)
else:
print(
f"{self.Colors.YELLOW}No automatic dependency installation for your distribution.{self.Colors.ENDC}"
)
if self.distro in ["fedora", "ubuntu"]:
print("\nChecking for dart-sass...")
if not shutil.which("sass"):
print(
"dart-sass is not available as a native package. Attempting to install via npm (user-local)..."
)
if shutil.which("npm"):
result_local = self.run_command(
[
"npm",
"install",
"--prefix",
os.path.expanduser("~/.local"),
"sass",
]
)
if result_local is None or (
hasattr(result_local, "returncode")
and result_local.returncode != 0
):
print(
f"{self.Colors.RED}Failed to install dart-sass via npm. You may need to add ~/.local/bin to your PATH if using user-local install.{self.Colors.ENDC}"
)
else:
print(
f"{self.Colors.GREEN}Installed dart-sass locally via npm. Add ~/.local/bin to your PATH if not already present.{self.Colors.ENDC}"
)
user_local_bin = os.path.expanduser("~/.local/bin")
if user_local_bin not in os.environ.get("PATH", ""):
print(
f"{self.Colors.YELLOW}Reminder: ~/.local/bin is not in your PATH. Add it to use 'sass' globally.{self.Colors.ENDC}"
)
else:
print(
f"{self.Colors.RED}npm is not installed. Please install npm and then run 'npm install --prefix ~/.local sass'.{self.Colors.ENDC}"
)
else:
print("dart-sass (sass) is already installed.")
print("\nInstalling ignis-gvc from source...")
gvc_temp_dir = tempfile.mkdtemp()
gvc_repo_url = "https://github.com/ignis-sh/ignis-gvc.git"
gvc_repo_dir = os.path.join(gvc_temp_dir, "ignis-gvc")
self.run_command(["git", "clone", gvc_repo_url, gvc_repo_dir])
def check_pkgconfig_file(pc_name):
paths = [
"/usr/lib64/pkgconfig",
"/usr/lib/pkgconfig",
"/usr/share/pkgconfig",
]
for path in paths:
if os.path.exists(os.path.join(path, pc_name)):
return path
return None
env = os.environ.copy()
pc_path = check_pkgconfig_file("gobject-introspection-1.0.pc")
if pc_path:
env["PKG_CONFIG_PATH"] = f"{pc_path}:{env.get('PKG_CONFIG_PATH', '')}"
else:
print(
f"{self.Colors.RED}gobject-introspection-1.0.pc not found. Please install gobject-introspection-devel.{self.Colors.ENDC}"
)
result = self.run_command(
["meson", "setup", "build", "--prefix=/usr"], cwd=gvc_repo_dir, env=env
)
if result is None or (hasattr(result, "returncode") and result.returncode != 0):
print(
f"{self.Colors.RED}Failed to run meson setup for ignis-gvc.{self.Colors.ENDC}"
)
else:
result = self.run_command(
["meson", "compile", "-C", "build"], cwd=gvc_repo_dir, env=env
)
if result is None or (
hasattr(result, "returncode") and result.returncode != 0
):
print(
f"{self.Colors.RED}Failed to compile ignis-gvc with meson.{self.Colors.ENDC}"
)
else:
result = self.run_command(
["sudo", "meson", "install", "-C", "build"],
cwd=gvc_repo_dir,
env=env,
)
if result is None or (
hasattr(result, "returncode") and result.returncode != 0
):
print(
f"{self.Colors.RED}Failed to install ignis-gvc with meson.{self.Colors.ENDC}"
)
else:
print(
f"{self.Colors.GREEN}Installed ignis-gvc from source using meson.{self.Colors.ENDC}"
)
shutil.rmtree(gvc_temp_dir)
if not shutil.which("swww"):
print("\nswww not found, attempting to build from source...")
temp_dir = tempfile.mkdtemp()
swww_repo_url = "https://github.com/LGFae/swww.git"
swww_repo_dir = os.path.join(temp_dir, "swww")
print(f"Cloning {swww_repo_url} to {swww_repo_dir}...")
result = self.run_command(
["git", "clone", swww_repo_url, swww_repo_dir], cwd=temp_dir
)
if result and result.returncode == 0:
env = os.environ.copy()
pc_path = check_pkgconfig_file("wayland-protocols.pc")
if pc_path:
env["PKG_CONFIG_PATH"] = (
f"{pc_path}:{env.get('PKG_CONFIG_PATH', '')}"
)
else:
print(
f"{self.Colors.RED}wayland-protocols.pc not found. Please install wayland-protocols-devel.{self.Colors.ENDC}"
)
print("Building swww with cargo...")
result = self.run_command(
["cargo", "build", "--release"], cwd=swww_repo_dir, env=env
)
if result and result.returncode == 0:
for binary in ["swww", "swww-daemon"]:
src = os.path.join(swww_repo_dir, "target", "release", binary)
dest = os.path.join("/usr/local/bin", binary)
if os.path.exists(src):
copy_result = self.run_command(["sudo", "cp", src, dest])
if copy_result and copy_result.returncode == 0:
print(
f"{self.Colors.GREEN}Installed {binary} to /usr/local/bin.{self.Colors.ENDC}"
)
else:
print(
f"{self.Colors.RED}Failed to copy {binary} to /usr/local/bin.{self.Colors.ENDC}"
)
else:
print(
f"{self.Colors.RED}Binary {binary} not found after build.{self.Colors.ENDC}"
)
print(
f"{self.Colors.YELLOW}Optional: Autocompletion scripts are available in the completions directory of the swww repo.{self.Colors.ENDC}"
)
else:
print(
f"{self.Colors.RED}Error building swww with cargo.{self.Colors.ENDC}"
)
else:
print(
f"{self.Colors.RED}Error cloning swww repository.{self.Colors.ENDC}"
)
shutil.rmtree(temp_dir)
else:
print("swww found in PATH.")
def check_desktop(self):
self.print_header("Checking Desktop Environment")
installed_desktops = []
if not self.dry_run:
for desktop in ["niri", "hyprland"]:
if shutil.which(desktop):
installed_desktops.append(desktop)
if len(installed_desktops) == 0:
return self.install_desktop()
elif len(installed_desktops) == 1:
print(f"Found existing desktop: {installed_desktops[0]}")
return installed_desktops[0]
else:
print("Found both Niri and Hyprland.")
return "both"
def install_desktop(self):
self.print_header("Desktop Environment Installation")
print("Neither Niri nor Hyprland found. Would you like to install one?")
print("1: Niri")
print("2: Hyprland")
print("3: Both")
print("q: Quit")
choice = self.get_user_choice("Select an option: ", ["1", "2", "3", "q"])
install_cmd = ["sudo", self.package_manager]
if self.distro == "fedora":
install_cmd.extend(["install", "-y"])
else:
install_cmd.extend(
["-S", "--noconfirm"] if self.distro == "arch" else ["install", "-y"]
)
if choice == "1":
print("Installing Niri...")
if self.run_command(install_cmd + ["niri"]):
return "niri"
elif choice == "2":
print("Installing Hyprland...")
if self.run_command(install_cmd + ["hyprland"]):
return "hyprland"
elif choice == "3":
print("Installing Niri and Hyprland...")
if self.run_command(install_cmd + ["niri", "hyprland"]):
return "both"
elif choice == "q":
print("Quitting.")
sys.exit(0)
print(
f"{self.Colors.RED}Installation failed or cancelled. Cannot proceed.{self.Colors.ENDC}"
)
return None
def install_desktop_configs(self, desktop_env):
if desktop_env in ["niri", "both"]:
print("Copying Niri config...")
niri_config_dir = os.path.join(self.config_dir, "niri")
os.makedirs(niri_config_dir, exist_ok=True)
niri_source = os.path.join(self.source_dir, "exodefaults", "config.kdl")
niri_dest = os.path.join(niri_config_dir, "config.kdl")
if os.path.exists(niri_dest):
print(
f"{self.Colors.YELLOW}Niri config already exists.{self.Colors.ENDC}"
)
choice = self.get_user_choice(
"Backup (b), Overwrite (o), Skip (s)? ", ["b", "o", "s"]
)
if choice == "b":
print(f"Backing up {niri_dest}...")
shutil.copy2(niri_dest, niri_dest + ".bak")
elif choice == "o":
print(f"Overwriting {niri_dest}...")
elif choice == "s":
print(f"Skipping {niri_dest}...")
return
shutil.copy2(niri_source, niri_dest)
if desktop_env in ["hyprland", "both"]:
print("Copying Hyprland config...")
hypr_config_dir = os.path.join(self.config_dir, "hypr")
os.makedirs(hypr_config_dir, exist_ok=True)
hypr_source = os.path.join(self.source_dir, "exodefaults", "hyprland.conf")
hypr_dest = os.path.join(hypr_config_dir, "hyprland.conf")
if os.path.exists(hypr_dest):
print(
f"{self.Colors.YELLOW}Hyprland config already exists.{self.Colors.ENDC}"
)
choice = self.get_user_choice(
"Backup (b), Overwrite (o), Skip (s)? ", ["b", "o", "s"]
)
if choice == "b":
print(f"Backing up {hypr_dest}...")
shutil.copy2(hypr_dest, hypr_dest + ".bak")
elif choice == "o":
print(f"Overwriting {hypr_dest}...")
elif choice == "s":
print(f"Skipping {hypr_dest}...")
return
shutil.copy2(hypr_source, hypr_dest)
def final_setup(self):
self.print_header("Final Setup")
default_wallpaper_path = os.path.join(
self.source_dir, "exodefaults", "default_wallpaper.png"
)
wallpaper_dir = os.path.expanduser("~/Pictures/Wallpapers")
if self.dry_run:
wallpaper_dir = os.path.join(self.config_dir, "Pictures/Wallpapers")
os.makedirs(wallpaper_dir, exist_ok=True)
default_wallpaper_dest = os.path.join(wallpaper_dir, "default.png")
if not os.path.exists(default_wallpaper_dest):
print("Copying default wallpaper...")
shutil.copyfile(default_wallpaper_path, default_wallpaper_dest)
print(
f"{self.Colors.GREEN}Default wallpaper placed in {wallpaper_dir}{self.Colors.ENDC}"
)
print("Wallpaper will be set on first desktop launch.")
ignis_config_dir = os.path.join(self.config_dir, "ignis")
user_settings_path = os.path.join(ignis_config_dir, "user_settings.json")
print("\nGenerating initial color scheme with Matugen...")
if shutil.which("matugen"):
matugen_command = ["matugen", "image", default_wallpaper_dest]
result = self.run_command(matugen_command)
if result is None or (
hasattr(result, "returncode") and result.returncode != 0
):
print(
f"{self.Colors.RED}Failed to generate color scheme with Matugen.{self.Colors.ENDC}"
)
else:
print(
f"{self.Colors.GREEN}Initial color scheme generated.{self.Colors.ENDC}"
)
else:
print(
f"{self.Colors.RED}Matugen is not installed or not in PATH. Skipping color scheme generation. Please install matugen and run manually if desired.{self.Colors.ENDC}"
)
if not os.path.exists(user_settings_path):
print("Creating default user_settings.json...")
os.makedirs(ignis_config_dir, exist_ok=True)
with open(user_settings_path, "w") as f:
f.write("{}")
preview_colors = os.path.join(
self.source_dir, "exodefaults", "preview-colors.scss"
)
preview_colors_dest = os.path.join(
self.config_dir, "ignis", "styles", "preview-colors.scss"
)
if not os.path.exists(preview_colors_dest):
print("Copying default preview-colors.scss...")
shutil.copyfile(preview_colors, preview_colors_dest)
if shutil.which("exoupdate") is None:
self.install_as_command()
def full_install(self):
self.print_header("Starting Full Exo Installation")
if not self.detect_distro():
choice = self.get_user_choice(
"Continue with installation without automatic dependency management? (y/n): ",
["y", "n"],
)
if choice == "n":
return
self.get_package_manager()
if not self.dry_run:
if self.distro == "arch" and not self.check_aur_helper():
return
self.install_dependencies()
else:
print(
f"{self.Colors.YELLOW}[DRY RUN] Skipping AUR helper check and dependency installation.{self.Colors.ENDC}"
)
desktop_env = self.check_desktop()
if not desktop_env:
return
core_folders = ["ignis", "matugen"]
for folder in core_folders:
source = os.path.join(self.source_dir, folder)
destination = os.path.join(self.config_dir, folder)
if os.path.exists(destination):
print(
f"{self.Colors.YELLOW}Warning: '{destination}' already exists.{self.Colors.ENDC}"
)
choice = self.get_user_choice(
"Backup (b), Overwrite (o), or Quit (q)? ", ["b", "o", "q"]
)
if choice == "b":
print(f"Backing up {destination}...")
shutil.move(destination, destination + "-backup")
elif choice == "o":
print(f"Overwriting {destination}...")
shutil.rmtree(destination)
elif choice == "q":
sys.exit(0)
try:
shutil.copytree(source, destination)
print(
f"{self.Colors.GREEN}Copied '{source}' to '{destination}'.{self.Colors.ENDC}"
)
except Exception as e:
print(
f"{self.Colors.RED}Error copying '{source}': {e}{self.Colors.ENDC}"
)
self.install_desktop_configs(desktop_env)
self.final_setup()
print(f"\n{self.Colors.GREEN}Installation complete.{self.Colors.ENDC}")
def update_install(self):
self.print_header("Updating Existing Exo Installation")
overwrite_choice = self.get_user_choice(
"\nHow to handle file overwrites? (y: Yes to all, n: Prompt for each): ",
["y", "n"],
)
if overwrite_choice == "y":
self.auto_confirm_overwrite = True
delete_choice = self.get_user_choice(
"How to handle orphaned files? (y: Yes to all, n: Prompt for each): ",
["y", "n"],
)
if delete_choice == "y":
self.auto_confirm_delete = True
core_folders = ["ignis", "matugen"]
for folder in core_folders:
source_path = os.path.join(self.source_dir, folder)
dest_path = os.path.join(self.config_dir, folder)
if not os.path.isdir(dest_path):
print(
f"{self.Colors.YELLOW}Warning: '{dest_path}' not found. Skipping update for this folder.{self.Colors.ENDC}"
)
continue
print(
f"\n--- Comparing folder: {self.Colors.BLUE}{folder}{self.Colors.ENDC} ---"
)
for root, dirs, files in os.walk(source_path):
dirs[:] = [d for d in dirs if d != "__pycache__"]
for file in files:
if os.path.basename(file) in self.protected_files:
continue
source_file = os.path.join(root, file)
rel_path = os.path.relpath(source_file, source_path)
dest_file = os.path.join(dest_path, rel_path)
self.compare_and_copy(source_file, dest_file)
for root, dirs, files in os.walk(dest_path):
dirs[:] = [d for d in dirs if d != "__pycache__"]
for file in files:
if os.path.basename(file) in self.protected_files:
continue
dest_file = os.path.join(root, file)
rel_path = os.path.relpath(dest_file, dest_path)
source_file = os.path.join(source_path, rel_path)
if not os.path.exists(source_file):
self.prompt_and_delete(dest_file)
preview_colors = os.path.join(
self.source_dir, "exodefaults", "preview-colors.scss"
)
preview_colors_dest = os.path.join(
self.config_dir, "ignis", "styles", "preview-colors.scss"
)
if not os.path.exists(preview_colors_dest):
print("Copying default preview-colors.scss...")
shutil.copyfile(preview_colors, preview_colors_dest)
print(f"\n{self.Colors.GREEN}Update check complete.{self.Colors.ENDC}")
def compare_and_copy(self, source, dest):
source_hash = self.get_file_hash(source)
dest_hash = self.get_file_hash(dest)
if dest_hash is None:
print(
f"{self.Colors.GREEN}New file found: Copying '{os.path.basename(source)}'{self.Colors.ENDC}"
)
os.makedirs(os.path.dirname(dest), exist_ok=True)
shutil.copy2(source, dest)
elif source_hash != dest_hash:
print(
f"{self.Colors.YELLOW}File mismatch: '{os.path.basename(source)}'{self.Colors.ENDC}"
)
if self.auto_confirm_overwrite:
print(f" Updating '{os.path.basename(source)}' (automatic).")
shutil.copy2(source, dest)
else:
choice = self.get_user_choice(
" Overwrite with latest version? (y/n): ", ["y", "n"]
)
if choice == "y":
print(f" Updating '{os.path.basename(source)}'...")
shutil.copy2(source, dest)
def prompt_and_delete(self, file_path):
print(
f"{self.Colors.YELLOW}Orphaned file found: '{os.path.basename(file_path)}' exists in your config but not in the source.{self.Colors.ENDC}"
)
if self.auto_confirm_delete:
print(f" Deleting '{os.path.basename(file_path)}' (automatic).")
os.remove(file_path)
else:
choice = self.get_user_choice(" Delete this file? (y/n): ", ["y", "n"])