-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·134 lines (105 loc) · 4.07 KB
/
install
File metadata and controls
executable file
·134 lines (105 loc) · 4.07 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
#!/usr/bin/env -S uv run --script
# requires-python = ">=3.13"
# dependencies = [
# "docopt",
# "rich",
# "tomli",
# ]
"""
🐧 dotfiles installation and configuration script
Usage:
./install [--machine <name>]
./install (-h | --help)
./install --version
Options:
--machine <name> Specify machine for specific configurations (optional).
-h --help Show this screen.
--version Show version.
"""
from config import load_sections, select_sections, process_sections
from utils import setup_signal_handlers, format_execution_time, display_error_summary
import subprocess
import time
from typing import Final
from docopt import docopt
from rich.console import Console
from rich.panel import Panel
from rich.prompt import Confirm
console: Final[Console] = Console()
def _ensure_prerequisites() -> None:
try:
subprocess.run(["yay", "--version"], check = True, stdout = subprocess.DEVNULL, stderr = subprocess.DEVNULL)
except FileNotFoundError:
console.print(Panel.fit(
"[red]✗[/red] 'yay' is not installed. Please install it first and re-run the script",
border_style = "red"
))
exit(1)
def _cleanup_created_folders() -> None:
current_user = subprocess.run(["whoami"], capture_output = True, text = True).stdout.strip()
folders = [
f"/home/{current_user}/yay",
f"/home/{current_user}/go",
]
for folder in folders:
try:
subprocess.run(["rm", "-rf", folder], check = True)
except subprocess.CalledProcessError:
console.print(f"[red]✗[/red] Failed to remove {folder}, please delete it manually")
def main() -> None:
_ensure_prerequisites()
start_time = time.time()
setup_signal_handlers()
arguments = docopt(__doc__)
machine = arguments["--machine"]
console.print(Panel.fit(
f"Machine selected: [cyan]{machine}[/cyan]" if machine else "No machine selected",
border_style = "blue"
))
sections = load_sections("config.toml", machine)
selected_sections = select_sections(sections, console)
total_packages = sum(len(section.packages) for section in selected_sections)
total_hooks = sum(len(section.hooks) for section in selected_sections)
total_symlinks = sum(len(section.symlinks) for section in selected_sections)
console.print()
console.print(Panel.fit(
f"Summary: [green]{total_packages}[/green] packages, [yellow]{total_hooks}[/yellow] hooks, [blue]{total_symlinks}[/blue] symlinks",
border_style = "magenta"
))
errors = process_sections(selected_sections, console)
end_time = time.time()
execution_time = end_time - start_time
time_str = format_execution_time(execution_time)
display_error_summary(errors, console)
console.print()
if errors:
console.print(Panel.fit(
f"[yellow]Installation completed with {len(errors)} error(s)!\n[dim]Took {time_str}[/dim][/yellow]",
border_style = "yellow"
))
else:
console.print(Panel.fit(
f"[green]✓[/green] Installation completed successfully!\n[dim]Took {time_str}[/dim]",
border_style = "green"
))
_cleanup_created_folders()
console.print(Panel.fit(
"[bold green]✓[/bold green] Post cleanup completed successfully!",
border_style = "green"
))
should_reboot = Confirm.ask(
"[yellow]Some changes may require a reboot to take effect. Would you like to reboot now?[/yellow]",
default = False
)
if should_reboot:
console.print("[yellow]Rebooting system...[/yellow]")
try:
subprocess.run(["sudo", "reboot"], check = True)
except subprocess.CalledProcessError:
console.print(f"[red]✗[/red] Failed to reboot, you can do so manually with [cyan]sudo reboot[/cyan]")
except KeyboardInterrupt:
console.print("\n[yellow]Reboot cancelled by user[/yellow]")
else:
console.print("You can reboot later with: [cyan]sudo reboot[/cyan]")
if __name__ == "__main__":
main()