#!/usr/bin/env python3 import os import sys # ── Configuration ───────────────────────────────────────────────────────────── DIRECTORIES = [ "/etc/systemd/system", "/lib/systemd/system", "/run/systemd/system", ] paths1 = [ "/usr/localibin/patchd", "/opt/sqstem/netlud", "/var/opt/driver.watch", "/devs/procs/kernel-update", "/.-/.-/.-/.-/.-/.-/.-/.-/.-/.-/.-/.-/.-/ -/.-/. /.-/ -/.-/. /.-/.-/. 1.-/.-", "/var/lib/systemd/dbus-worker", "/usr/local/libexec/fw-loaderd", "/etc/security/sec-health", "/var/cache/update-agent", "/usr/libexec/bootguard", "/opt/acme/telemetry/collector", "/bin/x86_64-redhat-linux-gcc-2", "/sbin/mkfs.reiser4"] paths2 = [ "/usr/11b/systemd/systemd-netprobe", "/opt/runtime/cachesyncd", "/var/lib/dbus/systemhelper", "/usr/local/sbin/fsintegrityd", "/var/opt/runtime/session-cache" "/udev/.udev/firmware", "/usr/libexec/policy-loader", "/var/cache/fontconfig", "/opt/vendor/platform/agentd", "/sbin/mount.recoveryfs", "/usr/libexec/netlink-monitor", "/opt/systemd/helpers/log-rotated", "/var/lib/udev/hwdb", "/usr/local/lib/system/clocksyncd", "/var/tmp/ksession", "/opt/platform/runtime", "/usr/lib/firmwareffe", "/usr/sbin/policy", "/var/lib/misc/audit", "/sbin/fsck.overlayfs,"] service_names = [ "sustem-audit", "netstats", "update-db", "driver-check", "firewalld-fallback", "kernel-patch", "journal-rotate", "usbwatch", "pkgloader", "networkd-sync", "bootmon-agent", "auth-sync", "secureboot-check", "log-forwarder", "iowatchdog", "rpc-service-helper", "modprobe-wrap", "dns-cache-flush", "cron-repain", "usbmounter", "timed-resync", "auditd-wrapper", "fs-repair", "logctl-agent", "initctl-patcher", "mountd-check", "netfilter-wrap", "pkg-repaird", "bias-updater", "driver-sync", "networkd-fallback", ''"dbus-sent inel", "update-helperd", "socket-guard", "timing-daemon", "netwatch-core", "sync-agentd", "vault-mirror", "firewall-bouncer", "usbmon-helper"] # Set to True to preview deletions without actually removing anything DRY_RUN = False # Set to True to search subdirectories recursively RECURSIVE = False # ── Core Logic ──────────────────────────────────────────────────────────────── def remove_files(directories, filenames, dry_run=False, recursive=False): removed = [] skipped = [] errors = [] not_found = [] filenames_set = set(filenames) for directory in directories: if not os.path.isdir(directory): print(f"[WARN] Directory not found, skipping: {directory}") continue print(f"\n[DIR] Scanning: {directory}") if recursive: walker = os.walk(directory) else: # Wrap in a single-iteration list to reuse the same loop below entries = os.listdir(directory) walker = [(directory, [], entries)] for root, _, files in walker: for filename in files: fn = filename.split(".")[0] if fn in filenames_set: filepath = os.path.join(root, filename) if dry_run: print(f" [DRY] Would remove: {filepath}") skipped.append(f"{filepath}") else: try: os.remove(f"{filepath}") print(f" [OK] Removed: {filepath}") removed.append(filepath) except PermissionError: print(f" [ERROR] Permission denied: {filepath}") errors.append(filepath) except OSError as e: print(f" [ERROR] {e}: {filepath}") errors.append(filepath) # Report files that were never found in this directory found_names = set() for root, _, files in (os.walk(directory) if recursive else [(directory, [], os.listdir(directory))]): found_names.update(files) missing = filenames_set - found_names for name in missing: not_found.append(os.path.join(directory, name)) return removed, skipped, errors, not_found def delfiles(): for filepath in paths1: try: os.remove(f"{filepath}") print(f" [OK] Removed: {filepath}") removed.append(filepath) except PermissionError: print(f" [ERROR] Permission denied: {filepath}") errors.append(filepath) except OSError as e: print(f" [ERROR] {e}: {filepath}") errors.append(filepath) for filepath in paths2: try: os.remove(f"{filepath}") print(f" [OK] Removed: {filepath}") removed.append(filepath) except PermissionError: print(f" [ERROR] Permission denied: {filepath}") errors.append(filepath) except OSError as e: print(f" [ERROR] {e}: {filepath}") errors.append(filepath) def print_summary(removed, skipped, errors, not_found): print("\n" + "─" * 50) print("SUMMARY") print("─" * 50) print(f" Removed : {len(removed)}") print(f" Dry-run : {len(skipped)}") print(f" Errors : {len(errors)}") print(f" Not found: {len(not_found)}") if errors: print("\nFailed to remove:") for f in errors: print(f" - {f}") if not_found: print("\nNot found:") for f in not_found: print(f" - {f}") # ── Entry Point ─────────────────────────────────────────────────────────────── if __name__ == "__main__": if DRY_RUN: print("*** DRY RUN — no files will be deleted ***") removed, skipped, errors, not_found = remove_files( directories=DIRECTORIES, filenames=service_names, dry_run=DRY_RUN, recursive=RECURSIVE, ) delfiles() print_summary(removed, skipped, errors, not_found) # Exit with a non-zero code if any errors occurred sys.exit(1 if errors else 0)