-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·786 lines (655 loc) · 25.3 KB
/
Copy pathsetup.py
File metadata and controls
executable file
·786 lines (655 loc) · 25.3 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
#!/usr/bin/env python3
"""
Setup and prerequisites check for ct-controller.
Validates system requirements, installs dependencies, and configures the host.
Usage:
./scripts/setup.py # Check prerequisites (no changes)
./scripts/setup.py --install # Install/configure as needed
./scripts/setup.py --fix # Fix permissions and ownership
"""
from __future__ import annotations
import argparse
import grp
import os
import pwd
import shutil
import subprocess
import sys
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any
# Minimum requirements
MIN_PYTHON_VERSION = (3, 10)
REQUIRED_PACKAGES = ["yaml"] # PyYAML imports as 'yaml'
DOCKER_SERVICE_USER = "docker-services"
DOCKER_GROUP = "docker"
DOCKER_ROOT = Path("/opt/docker")
SYSTEMD_SERVICE_PATH = Path("/etc/systemd/system/docker-compose@.service")
SYSTEMD_INFRA_TARGET_PATH = Path("/etc/systemd/system/docker-compose-infra.target")
CRON_FILE_PATH = Path("/etc/cron.d/docker-maintenance")
LOGROTATE_FILE_PATH = Path("/etc/logrotate.d/ct-controller")
# Infrastructure stacks (start first, before apps)
INFRA_STACKS = ["graylog", "fluentbit", "monitoring", "watchtower"]
@dataclass
class CheckResult:
"""Result of a prerequisite check."""
name: str
passed: bool
message: str
fixable: bool = False
fix_command: str | None = None
details: dict[str, Any] = field(default_factory=dict)
@dataclass
class SetupReport:
"""Complete setup check report."""
checks: list[CheckResult] = field(default_factory=list)
@property
def all_passed(self) -> bool:
return all(c.passed for c in self.checks)
@property
def fixable_issues(self) -> list[CheckResult]:
return [c for c in self.checks if not c.passed and c.fixable]
@property
def blocking_issues(self) -> list[CheckResult]:
return [c for c in self.checks if not c.passed and not c.fixable]
def to_dict(self) -> dict:
return {
"all_passed": self.all_passed,
"checks": [
{
"name": c.name,
"passed": c.passed,
"message": c.message,
"fixable": c.fixable,
"fix_command": c.fix_command,
"details": c.details,
}
for c in self.checks
],
"summary": {
"total": len(self.checks),
"passed": sum(1 for c in self.checks if c.passed),
"failed": sum(1 for c in self.checks if not c.passed),
"fixable": len(self.fixable_issues),
},
}
# -----------------------------------------------------------------------------
# Check Functions
# -----------------------------------------------------------------------------
def check_python_version() -> CheckResult:
"""Check Python version meets minimum requirement."""
current = sys.version_info[:2]
passed = current >= MIN_PYTHON_VERSION
return CheckResult(
name="python_version",
passed=passed,
message=(
f"Python {current[0]}.{current[1]}"
if passed
else f"Python {current[0]}.{current[1]} < {MIN_PYTHON_VERSION[0]}.{MIN_PYTHON_VERSION[1]} required"
),
fixable=False,
details={
"current": f"{current[0]}.{current[1]}",
"required": f"{MIN_PYTHON_VERSION[0]}.{MIN_PYTHON_VERSION[1]}",
},
)
def check_python_packages() -> CheckResult:
"""Check required Python packages are installed."""
missing = []
installed = []
for package in REQUIRED_PACKAGES:
try:
__import__(package)
installed.append(package)
except ImportError:
missing.append(package)
passed = len(missing) == 0
# Map import names to pip package names
pip_names = {"yaml": "PyYAML"}
pip_missing = [pip_names.get(p, p) for p in missing]
return CheckResult(
name="python_packages",
passed=passed,
message=(
f"All packages installed: {', '.join(installed)}"
if passed
else f"Missing packages: {', '.join(missing)}"
),
fixable=True,
fix_command=f"pip install {' '.join(pip_missing)}" if missing else None,
details={"installed": installed, "missing": missing},
)
def check_docker_installed() -> CheckResult:
"""Check Docker is installed."""
docker_path = shutil.which("docker")
passed = docker_path is not None
version = None
if passed:
try:
result = subprocess.run(
["docker", "--version"],
capture_output=True,
text=True,
timeout=5,
)
version = result.stdout.strip()
except (subprocess.TimeoutExpired, FileNotFoundError):
pass
return CheckResult(
name="docker_installed",
passed=passed,
message=version or "Docker installed" if passed else "Docker not found",
fixable=False,
details={"path": docker_path, "version": version},
)
def check_docker_running() -> CheckResult:
"""Check Docker daemon is running."""
try:
result = subprocess.run(
["docker", "info"],
capture_output=True,
text=True,
timeout=10,
)
passed = result.returncode == 0
message = "Docker daemon running" if passed else "Docker daemon not running"
except (subprocess.TimeoutExpired, FileNotFoundError):
passed = False
message = "Cannot connect to Docker"
return CheckResult(
name="docker_running",
passed=passed,
message=message,
fixable=True,
fix_command="sudo systemctl start docker",
)
def check_docker_compose() -> CheckResult:
"""Check Docker Compose v2 is available."""
try:
result = subprocess.run(
["docker", "compose", "version"],
capture_output=True,
text=True,
timeout=5,
)
passed = result.returncode == 0
version = result.stdout.strip() if passed else None
message = version or "Docker Compose v2 available"
except (subprocess.TimeoutExpired, FileNotFoundError):
passed = False
version = None
message = "Docker Compose v2 not available"
return CheckResult(
name="docker_compose",
passed=passed,
message=message,
fixable=False,
details={"version": version},
)
def check_service_user() -> CheckResult:
"""Check docker-services user exists and is in docker group."""
try:
user = pwd.getpwnam(DOCKER_SERVICE_USER)
user_exists = True
uid = user.pw_uid
gid = user.pw_gid
except KeyError:
user_exists = False
uid = None
gid = None
in_docker_group = False
if user_exists:
try:
docker_group = grp.getgrnam(DOCKER_GROUP)
in_docker_group = DOCKER_SERVICE_USER in docker_group.gr_mem
except KeyError:
pass
passed = user_exists and in_docker_group
if not user_exists:
message = f"User '{DOCKER_SERVICE_USER}' does not exist"
fix = f"sudo useradd -r -s /usr/sbin/nologin {DOCKER_SERVICE_USER} && sudo usermod -aG docker {DOCKER_SERVICE_USER}"
elif not in_docker_group:
message = f"User '{DOCKER_SERVICE_USER}' not in docker group"
fix = f"sudo usermod -aG docker {DOCKER_SERVICE_USER}"
else:
message = f"User '{DOCKER_SERVICE_USER}' configured correctly"
fix = None
return CheckResult(
name="service_user",
passed=passed,
message=message,
fixable=True,
fix_command=fix,
details={"user_exists": user_exists, "in_docker_group": in_docker_group, "uid": uid},
)
def check_docker_root() -> CheckResult:
"""Check /opt/docker directory exists with correct ownership and permissions."""
exists = DOCKER_ROOT.exists()
correct_owner = False
group_writable = False
has_setgid = False
owner_info = None
mode_info = None
if exists:
try:
stat_result = DOCKER_ROOT.stat()
owner = pwd.getpwuid(stat_result.st_uid).pw_name
group = grp.getgrgid(stat_result.st_gid).gr_name
owner_info = f"{owner}:{group}"
correct_owner = owner == DOCKER_SERVICE_USER and group == DOCKER_SERVICE_USER
# Check group write (0o020) and setgid (0o2000)
mode = stat_result.st_mode
group_writable = bool(mode & 0o020)
has_setgid = bool(mode & 0o2000)
mode_info = oct(mode)[-4:]
except (KeyError, OSError):
pass
passed = exists and correct_owner and group_writable and has_setgid
issues = []
if not exists:
message = f"{DOCKER_ROOT} does not exist"
fix = f"sudo mkdir -p {DOCKER_ROOT} && sudo chown {DOCKER_SERVICE_USER}:{DOCKER_SERVICE_USER} {DOCKER_ROOT} && sudo chmod 2775 {DOCKER_ROOT}"
else:
if not correct_owner:
issues.append(f"ownership is {owner_info}")
if not group_writable:
issues.append("missing group write")
if not has_setgid:
issues.append("missing setgid")
if issues:
message = f"{DOCKER_ROOT}: {', '.join(issues)}"
# Comprehensive fix: ownership, group write, and setgid recursively
fix = (
f"sudo chown -R {DOCKER_SERVICE_USER}:{DOCKER_SERVICE_USER} {DOCKER_ROOT} && "
f"sudo chmod -R g+w {DOCKER_ROOT} && "
f"sudo find {DOCKER_ROOT} -type d -exec chmod g+s {{}} \\;"
)
else:
message = f"{DOCKER_ROOT} exists with correct ownership and permissions"
fix = None
return CheckResult(
name="docker_root",
passed=passed,
message=message,
fixable=True,
fix_command=fix,
details={
"exists": exists,
"owner": owner_info,
"mode": mode_info,
"group_writable": group_writable,
"setgid": has_setgid,
},
)
def check_systemd_service() -> CheckResult:
"""Check systemd service template is installed."""
installed = SYSTEMD_SERVICE_PATH.exists()
# Check if source exists in this repo (now in scripts/templates/)
script_dir = Path(__file__).parent
source_path = script_dir / "templates" / "docker-compose@.service"
source_exists = source_path.exists()
passed = installed
if not installed and source_exists:
message = "Systemd service template not installed"
fix = f"sudo cp {source_path} {SYSTEMD_SERVICE_PATH} && sudo systemctl daemon-reload"
elif not installed:
message = "Systemd service template not installed (source not found)"
fix = None
else:
message = "Systemd service template installed"
fix = None
return CheckResult(
name="systemd_service",
passed=passed,
message=message,
fixable=source_exists,
fix_command=fix,
details={"installed": installed, "path": str(SYSTEMD_SERVICE_PATH)},
)
def check_cron_installed() -> CheckResult:
"""Check maintenance cron jobs are installed."""
installed = CRON_FILE_PATH.exists()
# Check if source exists
script_dir = Path(__file__).parent
source_path = script_dir / "templates" / "docker-maintenance.cron"
source_exists = source_path.exists()
passed = installed
if not installed and source_exists:
message = "Maintenance cron jobs not installed"
fix = f"sudo cp {source_path} {CRON_FILE_PATH} && sudo chmod 644 {CRON_FILE_PATH}"
elif not installed:
message = "Maintenance cron jobs not installed (source not found)"
fix = None
else:
message = "Maintenance cron jobs installed"
fix = None
return CheckResult(
name="cron_jobs",
passed=passed,
message=message,
fixable=source_exists,
fix_command=fix,
details={"installed": installed, "path": str(CRON_FILE_PATH)},
)
def check_logrotate_installed() -> CheckResult:
"""Check logrotate config is installed."""
installed = LOGROTATE_FILE_PATH.exists()
# Check if source exists
script_dir = Path(__file__).parent
source_path = script_dir / "templates" / "ct-controller-logrotate.conf"
source_exists = source_path.exists()
passed = installed
if not installed and source_exists:
message = "Logrotate config not installed"
fix = f"sudo cp {source_path} {LOGROTATE_FILE_PATH} && sudo chmod 644 {LOGROTATE_FILE_PATH}"
elif not installed:
message = "Logrotate config not installed (source not found)"
fix = None
else:
message = "Logrotate config installed"
fix = None
return CheckResult(
name="logrotate",
passed=passed,
message=message,
fixable=source_exists,
fix_command=fix,
details={"installed": installed, "path": str(LOGROTATE_FILE_PATH)},
)
def check_current_user_docker() -> CheckResult:
"""Check if current user can run Docker commands."""
try:
result = subprocess.run(
["docker", "ps"],
capture_output=True,
text=True,
timeout=10,
)
passed = result.returncode == 0
if passed:
message = "Current user can run Docker commands"
else:
message = "Current user cannot run Docker (permission denied?)"
except (subprocess.TimeoutExpired, FileNotFoundError):
passed = False
message = "Cannot run Docker commands"
current_user = os.getenv("USER", "unknown")
return CheckResult(
name="current_user_docker",
passed=passed,
message=message,
fixable=True,
fix_command=f"sudo usermod -aG docker {current_user} && newgrp docker",
details={"user": current_user},
)
def check_boot_ordering() -> CheckResult:
"""Check if boot ordering (infra target + app overrides) is installed."""
script_dir = Path(__file__).parent
# Check if infra target exists
infra_target_installed = SYSTEMD_INFRA_TARGET_PATH.exists()
infra_target_source = script_dir / "templates" / "docker-compose-infra.target"
# Find app stacks that need overrides (non-infra stacks with docker-compose.yml)
# Includes nested stacks like stack/substack
app_stacks = []
if DOCKER_ROOT.exists():
for stack_dir in DOCKER_ROOT.iterdir():
if stack_dir.is_dir() and not stack_dir.name.startswith("."):
# Skip non-stack directories
if stack_dir.name in ("scripts", "tests", "docs", "node_modules"):
continue
compose_file = stack_dir / "docker-compose.yml"
if compose_file.exists() and stack_dir.name not in INFRA_STACKS:
app_stacks.append(stack_dir.name)
# Check for nested stacks (e.g., stack/substack)
for substack_dir in stack_dir.iterdir():
if substack_dir.is_dir() and not substack_dir.name.startswith("."):
substack_compose = substack_dir / "docker-compose.yml"
if substack_compose.exists():
stack_name = f"{stack_dir.name}-{substack_dir.name}"
if stack_name not in app_stacks:
app_stacks.append(stack_name)
# Check which app stacks have overrides installed
missing_overrides = []
for stack in app_stacks:
override_path = Path(f"/etc/systemd/system/docker-compose@{stack}.service.d/after-infra.conf")
if not override_path.exists():
missing_overrides.append(stack)
# Determine status
passed = infra_target_installed and len(missing_overrides) == 0
if not infra_target_installed:
message = "Boot ordering not installed (infra target missing)"
fix = "install_boot_ordering" # Special marker for custom fix function
elif missing_overrides:
message = f"Boot ordering incomplete ({len(missing_overrides)} app stacks missing overrides)"
fix = "install_boot_ordering"
else:
message = "Boot ordering installed (infra target + app overrides)"
fix = None
return CheckResult(
name="boot_ordering",
passed=passed,
message=message,
fixable=infra_target_source.exists(),
fix_command=fix,
details={
"infra_target_installed": infra_target_installed,
"app_stacks": app_stacks,
"missing_overrides": missing_overrides,
},
)
# -----------------------------------------------------------------------------
# Setup Actions
# -----------------------------------------------------------------------------
def run_all_checks() -> SetupReport:
"""Run all prerequisite checks."""
report = SetupReport()
report.checks.append(check_python_version())
report.checks.append(check_python_packages())
report.checks.append(check_docker_installed())
report.checks.append(check_docker_running())
report.checks.append(check_docker_compose())
report.checks.append(check_current_user_docker())
report.checks.append(check_service_user())
report.checks.append(check_docker_root())
report.checks.append(check_systemd_service())
report.checks.append(check_cron_installed())
report.checks.append(check_logrotate_installed())
report.checks.append(check_boot_ordering())
return report
def install_boot_ordering() -> bool:
"""Install boot ordering (infra target + app overrides)."""
script_dir = Path(__file__).parent
infra_target_source = script_dir / "templates" / "docker-compose-infra.target"
override_source = script_dir / "templates" / "docker-compose-app-override.conf"
try:
# Install infra target
if not SYSTEMD_INFRA_TARGET_PATH.exists():
result = subprocess.run(
["sudo", "cp", str(infra_target_source), str(SYSTEMD_INFRA_TARGET_PATH)],
capture_output=True,
text=True,
)
if result.returncode != 0:
print(f" Failed to copy infra target: {result.stderr}")
return False
# Find app stacks (including nested stacks)
app_stacks = []
if DOCKER_ROOT.exists():
for stack_dir in DOCKER_ROOT.iterdir():
if stack_dir.is_dir() and not stack_dir.name.startswith("."):
# Skip non-stack directories
if stack_dir.name in ("scripts", "tests", "docs", "node_modules"):
continue
compose_file = stack_dir / "docker-compose.yml"
if compose_file.exists() and stack_dir.name not in INFRA_STACKS:
app_stacks.append(stack_dir.name)
# Check for nested stacks (e.g., stack/substack)
for substack_dir in stack_dir.iterdir():
if substack_dir.is_dir() and not substack_dir.name.startswith("."):
substack_compose = substack_dir / "docker-compose.yml"
if substack_compose.exists():
stack_name = f"{stack_dir.name}-{substack_dir.name}"
if stack_name not in app_stacks:
app_stacks.append(stack_name)
# Install app overrides
for stack in app_stacks:
override_dir = Path(f"/etc/systemd/system/docker-compose@{stack}.service.d")
override_path = override_dir / "after-infra.conf"
if not override_path.exists():
# Create directory
subprocess.run(["sudo", "mkdir", "-p", str(override_dir)], capture_output=True)
# Copy override
result = subprocess.run(
["sudo", "cp", str(override_source), str(override_path)],
capture_output=True,
text=True,
)
if result.returncode != 0:
print(f" Failed to install override for {stack}: {result.stderr}")
return False
# Reload systemd
result = subprocess.run(
["sudo", "systemctl", "daemon-reload"],
capture_output=True,
text=True,
)
if result.returncode != 0:
print(f" Failed to reload systemd: {result.stderr}")
return False
return True
except Exception as e:
print(f" Error: {e}")
return False
def run_fix(check: CheckResult) -> bool:
"""Attempt to fix a failed check."""
if not check.fix_command:
return False
# Special handling for boot ordering
if check.fix_command == "install_boot_ordering":
print(f" Installing boot ordering (infra target + app overrides)")
return install_boot_ordering()
print(f" Running: {check.fix_command}")
try:
result = subprocess.run(
check.fix_command,
shell=True,
capture_output=True,
text=True,
)
return result.returncode == 0
except Exception as e:
print(f" Error: {e}")
return False
# -----------------------------------------------------------------------------
# Output
# -----------------------------------------------------------------------------
def report_human(report: SetupReport, verbose: bool = False) -> None:
"""Print human-readable report."""
GREEN = "\033[0;32m"
RED = "\033[0;31m"
YELLOW = "\033[1;33m"
CYAN = "\033[0;36m"
BOLD = "\033[1m"
RESET = "\033[0m"
print()
print(f"{BOLD}ct-controller Setup Check{RESET}")
print("=" * 50)
print()
for check in report.checks:
if check.passed:
status = f"{GREEN}[OK]{RESET}"
elif check.fixable:
status = f"{YELLOW}[FIX]{RESET}"
else:
status = f"{RED}[FAIL]{RESET}"
print(f" {status} {check.name}: {check.message}")
if verbose and check.details:
for key, value in check.details.items():
print(f" {key}: {value}")
if not check.passed and check.fix_command:
print(f" {CYAN}Fix: {check.fix_command}{RESET}")
print()
print("=" * 50)
summary = report.to_dict()["summary"]
print(f" Total: {summary['total']}, Passed: {summary['passed']}, Failed: {summary['failed']}")
if report.all_passed:
print(f"\n{GREEN}All checks passed - system ready{RESET}")
elif report.fixable_issues:
print(f"\n{YELLOW}{len(report.fixable_issues)} issue(s) can be fixed automatically{RESET}")
print(f"Run with {BOLD}--install{RESET} to fix")
else:
print(f"\n{RED}Some issues require manual intervention{RESET}")
def report_json(report: SetupReport) -> None:
"""Print JSON report."""
import json
print(json.dumps(report.to_dict(), indent=2))
# -----------------------------------------------------------------------------
# Main
# -----------------------------------------------------------------------------
def main() -> int:
parser = argparse.ArgumentParser(
description="Setup and prerequisites check for ct-controller",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
%(prog)s Check prerequisites (no changes)
%(prog)s --install Install missing packages and configure
%(prog)s --fix Fix permissions only
%(prog)s --json Output JSON report
""",
)
parser.add_argument(
"--install",
action="store_true",
help="Install missing dependencies and configure system",
)
parser.add_argument(
"--fix",
action="store_true",
help="Fix permissions and ownership issues only",
)
parser.add_argument(
"--json",
action="store_true",
help="Output JSON format",
)
parser.add_argument(
"--verbose", "-v",
action="store_true",
help="Show detailed information",
)
args = parser.parse_args()
# Run checks
report = run_all_checks()
# Handle install/fix modes
if args.install or args.fix:
if not args.json:
print("\nAttempting to fix issues...\n")
fixed = 0
for check in report.checks:
if not check.passed and check.fixable and check.fix_command:
if args.fix and check.name not in ("docker_root", "service_user", "systemd_service"):
continue # --fix only does permission-related fixes
if not args.json:
print(f"Fixing: {check.name}")
if run_fix(check):
fixed += 1
if not args.json:
print(f" Success")
else:
if not args.json:
print(f" Failed (may need sudo)")
if not args.json:
print(f"\nFixed {fixed} issue(s)")
print("Re-running checks...\n")
# Re-run checks
report = run_all_checks()
# Output
if args.json:
report_json(report)
else:
report_human(report, verbose=args.verbose)
return 0 if report.all_passed else 1
if __name__ == "__main__":
sys.exit(main())