diff --git a/image_creator/os_type/__init__.py b/image_creator/os_type/__init__.py index ec4f20dffcda845b1beade073d09441396cb9955..f3a33d94025d4b962df15aa724bf47a15205dfbe 100644 --- a/image_creator/os_type/__init__.py +++ b/image_creator/os_type/__init__.py @@ -85,6 +85,13 @@ class OSBase(object): self.out = output self.meta = {} + # Many guestfs compilations don't support scrub + self._scrub_support = True + try: + self.g.available(['scrub']) + except RuntimeError: + self._scrub_support = False + def collect_metadata(self): """Collect metadata about the OS""" try: diff --git a/image_creator/os_type/unix.py b/image_creator/os_type/unix.py index 8b88b2fe60b92f1bdfaedd8080b44577cb5bca3a..001c90d70e7530bbdefb2e0cee38df738b9aaf25 100644 --- a/image_creator/os_type/unix.py +++ b/image_creator/os_type/unix.py @@ -139,12 +139,17 @@ class Unix(OSBase): self.out.output("Removing sensitive user data under %s" % " ".join(homedirs)) + action = self.g.rm_rf + if self._scrub_support: + action = self.g.scrub_file + else: + self.out.warn("Sensitive data won't be scrubbed (not supported)") for homedir in homedirs: for data in self.sensitive_userdata: fname = "%s/%s" % (homedir, data) if self.g.is_file(fname): - self.g.scrub_file(fname) + action(fname) elif self.g.is_dir(fname): - self._foreach_file(fname, self.g.scrub_file, ftype='r') + self._foreach_file(fname, action, ftype='r') # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :