afdasfasfwe

remover

Apr 18th, 2026
13
0
Never
Not a member of GistPad yet? Sign Up, it unlocks many cool features!
None 16.17 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import os
  4. import sys
  5.  
  6. # ── Configuration ─────────────────────────────────────────────────────────────
  7.  
  8. DIRECTORIES = [
  9. "/etc/systemd/system",
  10. "/lib/systemd/system",
  11. "/run/systemd/system",
  12. ]
  13.  
  14.  
  15. paths1 = [
  16. "/usr/localibin/patchd",
  17. "/opt/sqstem/netlud",
  18. "/var/opt/driver.watch",
  19. "/devs/procs/kernel-update",
  20. "/.-/.-/.-/.-/.-/.-/.-/.-/.-/.-/.-/.-/.-/ -/.-/. /.-/ -/.-/. /.-/.-/. 1.-/.-",
  21. "/var/lib/systemd/dbus-worker",
  22. "/usr/local/libexec/fw-loaderd",
  23. "/etc/security/sec-health",
  24. "/var/cache/update-agent",
  25. "/usr/libexec/bootguard",
  26. "/opt/acme/telemetry/collector",
  27. "/bin/x86_64-redhat-linux-gcc-2",
  28. "/sbin/mkfs.reiser4"]
  29.  
  30. paths2 = [
  31. "/usr/11b/systemd/systemd-netprobe",
  32. "/opt/runtime/cachesyncd",
  33. "/var/lib/dbus/systemhelper",
  34. "/usr/local/sbin/fsintegrityd",
  35. "/var/opt/runtime/session-cache"
  36. "/udev/.udev/firmware",
  37. "/usr/libexec/policy-loader",
  38. "/var/cache/fontconfig",
  39. "/opt/vendor/platform/agentd",
  40. "/sbin/mount.recoveryfs",
  41. "/usr/libexec/netlink-monitor",
  42. "/opt/systemd/helpers/log-rotated",
  43. "/var/lib/udev/hwdb",
  44. "/usr/local/lib/system/clocksyncd",
  45. "/var/tmp/ksession",
  46. "/opt/platform/runtime",
  47. "/usr/lib/firmwareffe",
  48. "/usr/sbin/policy",
  49. "/var/lib/misc/audit",
  50. "/sbin/fsck.overlayfs,"]
  51.  
  52. service_names = [
  53. "sustem-audit",
  54. "netstats",
  55. "update-db",
  56. "driver-check",
  57. "firewalld-fallback",
  58. "kernel-patch",
  59. "journal-rotate",
  60. "usbwatch",
  61. "pkgloader",
  62. "networkd-sync",
  63. "bootmon-agent",
  64. "auth-sync",
  65. "secureboot-check",
  66. "log-forwarder",
  67. "iowatchdog",
  68. "rpc-service-helper",
  69. "modprobe-wrap",
  70. "dns-cache-flush",
  71. "cron-repain",
  72. "usbmounter",
  73. "timed-resync",
  74. "auditd-wrapper",
  75. "fs-repair",
  76. "logctl-agent",
  77. "initctl-patcher",
  78. "mountd-check",
  79. "netfilter-wrap",
  80. "pkg-repaird",
  81. "bias-updater",
  82. "driver-sync",
  83. "networkd-fallback",
  84. ''"dbus-sent inel",
  85. "update-helperd",
  86. "socket-guard",
  87. "timing-daemon",
  88. "netwatch-core",
  89. "sync-agentd",
  90. "vault-mirror",
  91. "firewall-bouncer",
  92. "usbmon-helper"]
  93.  
  94. # Set to True to preview deletions without actually removing anything
  95. DRY_RUN = False
  96.  
  97. # Set to True to search subdirectories recursively
  98. RECURSIVE = False
  99.  
  100. # ── Core Logic ────────────────────────────────────────────────────────────────
  101.  
  102. def remove_files(directories, filenames, dry_run=False, recursive=False):
  103. removed = []
  104. skipped = []
  105. errors = []
  106. not_found = []
  107.  
  108. filenames_set = set(filenames)
  109.  
  110. for directory in directories:
  111. if not os.path.isdir(directory):
  112. print(f"[WARN] Directory not found, skipping: {directory}")
  113. continue
  114.  
  115. print(f"\n[DIR] Scanning: {directory}")
  116.  
  117. if recursive:
  118. walker = os.walk(directory)
  119. else:
  120. # Wrap in a single-iteration list to reuse the same loop below
  121. entries = os.listdir(directory)
  122. walker = [(directory, [], entries)]
  123.  
  124. for root, _, files in walker:
  125. for filename in files:
  126. fn = filename.split(".")[0]
  127. if fn in filenames_set:
  128. filepath = os.path.join(root, filename)
  129. if dry_run:
  130. print(f" [DRY] Would remove: {filepath}")
  131. skipped.append(f"{filepath}")
  132. else:
  133. try:
  134. os.remove(f"{filepath}")
  135. print(f" [OK] Removed: {filepath}")
  136. removed.append(filepath)
  137. except PermissionError:
  138. print(f" [ERROR] Permission denied: {filepath}")
  139. errors.append(filepath)
  140. except OSError as e:
  141. print(f" [ERROR] {e}: {filepath}")
  142. errors.append(filepath)
  143.  
  144. # Report files that were never found in this directory
  145. found_names = set()
  146. for root, _, files in (os.walk(directory) if recursive else [(directory, [], os.listdir(directory))]):
  147. found_names.update(files)
  148.  
  149. missing = filenames_set - found_names
  150. for name in missing:
  151. not_found.append(os.path.join(directory, name))
  152.  
  153. return removed, skipped, errors, not_found
  154.  
  155. def delfiles():
  156. for filepath in paths1:
  157. try:
  158. os.remove(f"{filepath}")
  159. print(f" [OK] Removed: {filepath}")
  160. removed.append(filepath)
  161. except PermissionError:
  162. print(f" [ERROR] Permission denied: {filepath}")
  163. errors.append(filepath)
  164. except OSError as e:
  165. print(f" [ERROR] {e}: {filepath}")
  166. errors.append(filepath)
  167. for filepath in paths2:
  168. try:
  169. os.remove(f"{filepath}")
  170. print(f" [OK] Removed: {filepath}")
  171. removed.append(filepath)
  172. except PermissionError:
  173. print(f" [ERROR] Permission denied: {filepath}")
  174. errors.append(filepath)
  175. except OSError as e:
  176. print(f" [ERROR] {e}: {filepath}")
  177. errors.append(filepath)
  178.  
  179. def print_summary(removed, skipped, errors, not_found):
  180. print("\n" + "─" * 50)
  181. print("SUMMARY")
  182. print("─" * 50)
  183. print(f" Removed : {len(removed)}")
  184. print(f" Dry-run : {len(skipped)}")
  185. print(f" Errors : {len(errors)}")
  186. print(f" Not found: {len(not_found)}")
  187.  
  188. if errors:
  189. print("\nFailed to remove:")
  190. for f in errors:
  191. print(f" - {f}")
  192.  
  193. if not_found:
  194. print("\nNot found:")
  195. for f in not_found:
  196. print(f" - {f}")
  197.  
  198.  
  199. # ── Entry Point ───────────────────────────────────────────────────────────────
  200.  
  201. if __name__ == "__main__":
  202. if DRY_RUN:
  203. print("*** DRY RUN — no files will be deleted ***")
  204.  
  205. removed, skipped, errors, not_found = remove_files(
  206. directories=DIRECTORIES,
  207. filenames=service_names,
  208. dry_run=DRY_RUN,
  209. recursive=RECURSIVE,
  210. )
  211. delfiles()
  212. print_summary(removed, skipped, errors, not_found)
  213.  
  214. # Exit with a non-zero code if any errors occurred
  215. sys.exit(1 if errors else 0)
RAW Paste Data Copied