Remove the bash history of users in home directory,
and history of root.
Signed-off-by: Wanlong Gao <gaowanlong(a)cn.fujitsu.com>
---
sysprep/Makefile.am | 2 ++
sysprep/sysprep_operation_bash_history.ml | 46 +++++++++++++++++++++++++++++
2 files changed, 48 insertions(+)
create mode 100644 sysprep/sysprep_operation_bash_history.ml
diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am
index 8730bc0..3a48702 100644
--- a/sysprep/Makefile.am
+++ b/sysprep/Makefile.am
@@ -33,6 +33,7 @@ SOURCES = \
main.ml \
sysprep_operation.ml \
sysprep_operation.mli \
+ sysprep_operation_bash_history.ml \
sysprep_operation_cron_spool.ml \
sysprep_operation_dhcp_client_state.ml \
sysprep_operation_dhcp_server_state.ml \
@@ -56,6 +57,7 @@ if HAVE_OCAML
OBJECTS = \
utils.cmx \
sysprep_operation.cmx \
+ sysprep_operation_bash_history.cmx \
sysprep_operation_cron_spool.cmx \
sysprep_operation_dhcp_client_state.cmx \
sysprep_operation_dhcp_server_state.cmx \
diff --git a/sysprep/sysprep_operation_bash_history.ml
b/sysprep/sysprep_operation_bash_history.ml
new file mode 100644
index 0000000..9065b9f
--- /dev/null
+++ b/sysprep/sysprep_operation_bash_history.ml
@@ -0,0 +1,46 @@
+(* virt-sysprep
+ * Copyright (C) 2012 Fujitsu Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+open Sysprep_operation
+
+module G = Guestfs
+
+let bash_history_perform g root =
+ let typ = g#inspect_get_type root in
+ if typ <> "windows" then (
+ let files = g#glob_expand "/home/*/.bash_history" in
+ Array.iter (
+ fun file -> try g#rm file with G.Error _ -> ();
+ ) files;
+ (try g#rm "/root/.bash_history" with G.Error _ -> ());
+ []
+ )
+ else []
+
+let bash_history_op = {
+ name = "bash-history";
+ pod_description = "\
+Remove the bash history in the guest.
+
+Remove the bash history of user root and any other users
+who have a bash history file in his home directory.";
+ extra_args = [];
+ perform = bash_history_perform;
+}
+
+let () = register_operation bash_history_op
--
1.7.10.rc3