fix(configure): gracefully handle missing ufw dirs and skip redundant apt calls
This commit is contained in:
3 files changed
+32
-25
No files matched your search
@@ -11,12 +11,16 @@ def run(ctx, args):
|
||||
log.info("Starting base system initialization...")
|
||||
if not os.path.isfile("/etc/debian_version"):
|
||||
log.error("Requires a Debian-based system (Debian/Ubuntu)."); raise SystemExit(1)
|
||||
log.info("Updating package lists..."); s.sudo(["apt-get", "update", "-y"])
|
||||
log.info("Installing essential packages...")
|
||||
s.sudo(["apt-get", "install", "-y", "curl", "wget", "git", "rsyslog"])
|
||||
needed = [p for p in ["curl", "wget", "git", "rsyslog"] if not shutil.which(p)]
|
||||
if needed:
|
||||
log.info("Updating package lists..."); s.sudo(["apt-get", "update", "-y"])
|
||||
log.info(f"Installing missing essential packages: {', '.join(needed)}...")
|
||||
s.sudo(["apt-get", "install", "-y", "-o", "DPkg::Lock::Timeout=60", *needed])
|
||||
else:
|
||||
log.info("Essential packages already installed.")
|
||||
s.ensure_running("rsyslog")
|
||||
if not shutil.which("ufw"):
|
||||
log.info("Installing UFW..."); s.sudo(["apt-get", "install", "-y", "ufw"])
|
||||
log.info("Installing UFW..."); s.sudo(["apt-get", "install", "-y", "-o", "DPkg::Lock::Timeout=60", "ufw"])
|
||||
else:
|
||||
log.info("UFW already installed.")
|
||||
from engine.lib.ufw import resolve_ufw_docker_bin
|
||||
|
||||
@@ -13,12 +13,12 @@ def run(ctx, args):
|
||||
docker_dir = os.path.join(cfg, "docker")
|
||||
host_dir = os.path.join(cfg, "host")
|
||||
ctx.log.info("Configuring UFW rules...")
|
||||
# Mirrors the bash branch structure: host dir is passed unconditionally (a missing
|
||||
# one exits 66 inside apply); both dirs missing = warn + success, like bash.
|
||||
if os.path.isdir(docker_dir):
|
||||
ctx.ufw.apply(docker_dir, host_dir, dry_run=args.dry_run)
|
||||
else:
|
||||
has_docker = os.path.isdir(docker_dir)
|
||||
has_host = os.path.isdir(host_dir)
|
||||
if not has_docker:
|
||||
ctx.log.warn(f"Docker rules dir not found at {docker_dir}. Skipping ufw-docker rules.")
|
||||
if os.path.isdir(host_dir):
|
||||
ctx.ufw.apply(docker_dir, host_dir, dry_run=args.dry_run)
|
||||
if not has_host:
|
||||
ctx.log.warn(f"Host rules dir not found at {host_dir}. Skipping host rules.")
|
||||
if has_docker or has_host:
|
||||
ctx.ufw.apply(docker_dir if has_docker else None, host_dir if has_host else None, dry_run=args.dry_run)
|
||||
ctx.log.success("Configured ufw.")
|
||||
Reference in new issue
Block a user