From 8d41470b6fc81b742896996393812b274514bca2 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Sat, 21 Apr 2012 22:27:39 +0100 Subject: [PATCH] sysprep: Don't enable every option by default. All current operations are enabled by default. Also: * The POD description is split into a heading and the description body. * An 'enabled_by_default' flag is added to the structure. --- sysprep/sysprep_operation.ml | 70 +++++++++++++++------- sysprep/sysprep_operation.mli | 11 +++- sysprep/sysprep_operation_bash_history.ml | 6 +- sysprep/sysprep_operation_cron_spool.ml | 4 +- sysprep/sysprep_operation_dhcp_client_state.ml | 4 +- sysprep/sysprep_operation_dhcp_server_state.ml | 4 +- sysprep/sysprep_operation_hostname.ml | 8 ++- sysprep/sysprep_operation_logfiles.ml | 9 ++- sysprep/sysprep_operation_mail_spool.ml | 4 +- sysprep/sysprep_operation_net_hwaddr.ml | 8 ++- sysprep/sysprep_operation_random_seed.ml | 4 +- sysprep/sysprep_operation_rhn_systemid.ml | 4 +- sysprep/sysprep_operation_script.ml | 4 +- sysprep/sysprep_operation_smolt_uuid.ml | 4 +- sysprep/sysprep_operation_ssh_hostkeys.ml | 6 +- sysprep/sysprep_operation_ssh_userdir.ml | 6 +- sysprep/sysprep_operation_udev_persistent_net.ml | 4 +- sysprep/sysprep_operation_utmp.ml | 6 +- sysprep/sysprep_operation_yum_uuid.ml | 6 +- sysprep/virt-sysprep.pod | 40 ++++++++++--- 20 files changed, 148 insertions(+), 64 deletions(-) diff --git a/sysprep/sysprep_operation.ml b/sysprep/sysprep_operation.ml index b48d8f8..d3a12fe 100644 --- a/sysprep/sysprep_operation.ml +++ b/sysprep/sysprep_operation.ml @@ -24,12 +24,15 @@ type flag = [ `Created_files ] type operation = { name : string; - pod_description : string; + enabled_by_default : bool; + heading : string; + pod_description : string option; extra_args : ((Arg.key * Arg.spec * Arg.doc) * string) list; perform : Guestfs.guestfs -> string -> flag list; } -let ops = ref [] +let all_operations = ref [] +let enabled_by_default_operations = ref [] module OperationSet = Set.Make ( struct @@ -42,17 +45,21 @@ type set = OperationSet.t let empty_set = OperationSet.empty let add_to_set name set = - let op = List.find (fun { name = n } -> name = n) !ops in + let op = List.find (fun { name = n } -> name = n) !all_operations in OperationSet.add op set -let register_operation op = ops := op :: !ops +let register_operation op = + all_operations := op :: !all_operations; + if op.enabled_by_default then + enabled_by_default_operations := op :: !enabled_by_default_operations let baked = ref false let rec bake () = - let ops' = List.sort (fun { name = a } { name = b } -> compare a b) !ops in - check_no_dupes ops'; - List.iter check ops'; - ops := ops'; + let ops = + List.sort (fun { name = a } { name = b } -> compare a b) !all_operations in + check_no_dupes ops; + List.iter check ops; + all_operations := ops; baked := true and check_no_dupes ops = ignore ( @@ -78,14 +85,28 @@ and check op = eprintf "virt-sysprep: disallowed character (%c) in operation name\n" c; exit 1 done; - let n = String.length op.pod_description in + let n = String.length op.heading in if n = 0 then ( - eprintf "virt-sysprep: operation %s has no POD\n" op.name; + eprintf "virt-sysprep: operation %s has no heading\n" op.name; exit 1 ); - if op.pod_description.[n-1] = '\n' then ( - eprintf "virt-sysprep: POD for %s must not end with newline\n" op.name; + if op.heading.[n-1] = '\n' || op.heading.[n-1] = '.' then ( + eprintf "virt-sysprep: heading for %s must not end with newline or period\n" + op.name; exit 1 + ); + (match op.pod_description with + | None -> () + | Some description -> + let n = String.length description in + if n = 0 then ( + eprintf "virt-sysprep: operation %s has no POD\n" op.name; + exit 1 + ); + if description.[n-1] = '\n' then ( + eprintf "virt-sysprep: POD for %s must not end with newline\n" op.name; + exit 1 + ) ) let extra_args () = @@ -94,7 +115,7 @@ let extra_args () = List.flatten ( List.map (fun { extra_args = extra_args } -> List.map fst extra_args - ) !ops + ) !all_operations ) (* These internal functions are used to generate the man page. *) @@ -104,9 +125,14 @@ let dump_pod () = List.iter ( fun op -> printf "=head2 B<%s>\n" op.name; + if op.enabled_by_default then printf "*\n"; printf "\n"; - printf "%s\n\n" op.pod_description - ) !ops + printf "%s.\n\n" op.heading; + (match op.pod_description with + | None -> () + | Some description -> printf "%s\n\n" description + ) + ) !all_operations let dump_pod_options () = assert !baked; @@ -114,7 +140,7 @@ let dump_pod_options () = let args = List.map ( fun { name = op_name; extra_args = extra_args } -> List.map (fun ea -> op_name, ea) extra_args - ) !ops in + ) !all_operations in let args = List.flatten args in let args = List.map ( fun (op_name, ((arg_name, spec, _), pod)) -> @@ -152,17 +178,19 @@ let dump_pod_options () = let list_operations () = assert !baked; - (* For compatibility with old shell version, list just the operation - * names, sorted. - *) - List.iter (fun op -> print_endline op.name ) !ops + List.iter ( + fun op -> + printf "%s %s %s\n" op.name + (if op.enabled_by_default then "*" else " ") + op.heading + ) !all_operations let perform_operations ?operations ?(quiet = false) g root = assert !baked; let ops = match operations with - | None -> !ops (* all operations *) + | None -> !enabled_by_default_operations | Some opset -> (* just the operation names listed *) OperationSet.elements opset in diff --git a/sysprep/sysprep_operation.mli b/sysprep/sysprep_operation.mli index 0f58510..ab7da93 100644 --- a/sysprep/sysprep_operation.mli +++ b/sysprep/sysprep_operation.mli @@ -26,8 +26,15 @@ type operation = { line. Must contain only alphanumeric and '-' (dash) character. *) - pod_description : string; - (** POD-format description, used for the man page. *) + enabled_by_default : bool; + (** If true, then enabled by default when no [--enable] option is + given on the command line. *) + + heading : string; + (** One-line description, NO trailing period. *) + + pod_description : string option; + (** POD-format long description, used for the man page. *) extra_args : ((Arg.key * Arg.spec * Arg.doc) * string) list; (** Extra command-line arguments, if any. eg. The [hostname] diff --git a/sysprep/sysprep_operation_bash_history.ml b/sysprep/sysprep_operation_bash_history.ml index 4367973..dbd6c50 100644 --- a/sysprep/sysprep_operation_bash_history.ml +++ b/sysprep/sysprep_operation_bash_history.ml @@ -34,9 +34,9 @@ let bash_history_perform g root = let bash_history_op = { name = "bash-history"; - pod_description = "\ -Remove the bash history in the guest. - + enabled_by_default = true; + heading = "Remove the bash history in the guest"; + pod_description = Some "\ Remove the bash history of user \"root\" and any other users who have a C<.bash_history> file in their home directory."; extra_args = []; diff --git a/sysprep/sysprep_operation_cron_spool.ml b/sysprep/sysprep_operation_cron_spool.ml index e67688b..daa3c68 100644 --- a/sysprep/sysprep_operation_cron_spool.ml +++ b/sysprep/sysprep_operation_cron_spool.ml @@ -26,7 +26,9 @@ let cron_spool_perform g root = let cron_spool_op = { name = "cron-spool"; - pod_description = "Remove user at-jobs and cron-jobs."; + enabled_by_default = true; + heading = "Remove user at-jobs and cron-jobs"; + pod_description = None; extra_args = []; perform = cron_spool_perform; } diff --git a/sysprep/sysprep_operation_dhcp_client_state.ml b/sysprep/sysprep_operation_dhcp_client_state.ml index e3e87cb..279893d 100644 --- a/sysprep/sysprep_operation_dhcp_client_state.ml +++ b/sysprep/sysprep_operation_dhcp_client_state.ml @@ -31,7 +31,9 @@ let dhcp_client_state_perform g root = let dhcp_client_state_op = { name = "dhcp-client-state"; - pod_description = "Remove DHCP client leases."; + enabled_by_default = true; + heading = "Remove DHCP client leases"; + pod_description = None; extra_args = []; perform = dhcp_client_state_perform; } diff --git a/sysprep/sysprep_operation_dhcp_server_state.ml b/sysprep/sysprep_operation_dhcp_server_state.ml index c5251ce..b28aa69 100644 --- a/sysprep/sysprep_operation_dhcp_server_state.ml +++ b/sysprep/sysprep_operation_dhcp_server_state.ml @@ -26,7 +26,9 @@ let dhcp_server_state_perform g root = let dhcp_server_state_op = { name = "dhcp-server-state"; - pod_description = "Remove DHCP server leases."; + enabled_by_default = true; + heading = "Remove DHCP server leases"; + pod_description = None; extra_args = []; perform = dhcp_server_state_perform; } diff --git a/sysprep/sysprep_operation_hostname.ml b/sysprep/sysprep_operation_hostname.ml index 51f9386..395691c 100644 --- a/sysprep/sysprep_operation_hostname.ml +++ b/sysprep/sysprep_operation_hostname.ml @@ -52,9 +52,11 @@ let hostname_perform g root = let hostname_op = { name = "hostname"; - pod_description = "\ -Changes the hostname of the guest to the value given in the I<--hostname> -parameter. + enabled_by_default = true; + heading = "Change the hostname of the guest"; + pod_description = Some "\ +This operation changes the hostname of the guest to the value +given in the I<--hostname> parameter. If the I<--hostname> parameter is not given, then the hostname is changed to C."; diff --git a/sysprep/sysprep_operation_logfiles.ml b/sysprep/sysprep_operation_logfiles.ml index b4c6ea9..2ad3726 100644 --- a/sysprep/sysprep_operation_logfiles.ml +++ b/sysprep/sysprep_operation_logfiles.ml @@ -59,10 +59,13 @@ let logfiles_perform g root = let logfiles_op = { name = "logfiles"; - pod_description = sprintf "\ -Remove many log files. On Linux the following files are removed: + enabled_by_default = true; + heading = "Remove many log files from the guest"; + pod_description = Some ( + sprintf "\ +On Linux the following files are removed: -%s" globs_as_pod; +%s" globs_as_pod); extra_args = []; perform = logfiles_perform; } diff --git a/sysprep/sysprep_operation_mail_spool.ml b/sysprep/sysprep_operation_mail_spool.ml index 74f2d94..25f4272 100644 --- a/sysprep/sysprep_operation_mail_spool.ml +++ b/sysprep/sysprep_operation_mail_spool.ml @@ -31,7 +31,9 @@ let mail_spool_perform g root = let mail_spool_op = { name = "mail-spool"; - pod_description = "Remove email from the local mail spool directory."; + enabled_by_default = true; + heading = "Remove email from the local mail spool directory"; + pod_description = None; extra_args = []; perform = mail_spool_perform; } diff --git a/sysprep/sysprep_operation_net_hwaddr.ml b/sysprep/sysprep_operation_net_hwaddr.ml index 02e3b5e..57ca2b9 100644 --- a/sysprep/sysprep_operation_net_hwaddr.ml +++ b/sysprep/sysprep_operation_net_hwaddr.ml @@ -44,9 +44,11 @@ let net_hwaddr_perform g root = let net_hwaddr_op = { name = "net-hwaddr"; - pod_description = "\ -Remove HWADDR (hard-coded MAC address) configuration. For Fedora and -Red Hat Enterprise Linux, this is removed from C files."; + enabled_by_default = true; + heading = "Remove HWADDR (hard-coded MAC address) configuration"; + pod_description = Some "\ +For Fedora and Red Hat Enterprise Linux, +this is removed from C files."; extra_args = []; perform = net_hwaddr_perform; } diff --git a/sysprep/sysprep_operation_random_seed.ml b/sysprep/sysprep_operation_random_seed.ml index 989ffe8..c6e8d85 100644 --- a/sysprep/sysprep_operation_random_seed.ml +++ b/sysprep/sysprep_operation_random_seed.ml @@ -45,7 +45,9 @@ let random_seed_perform g root = let random_seed_op = { name = "random-seed"; - pod_description = "\ + enabled_by_default = true; + heading = "Generate random seed for guest"; + pod_description = Some "\ Write some random bytes from the host into the random seed file of the guest. diff --git a/sysprep/sysprep_operation_rhn_systemid.ml b/sysprep/sysprep_operation_rhn_systemid.ml index 35849e4..9d9f2f8 100644 --- a/sysprep/sysprep_operation_rhn_systemid.ml +++ b/sysprep/sysprep_operation_rhn_systemid.ml @@ -32,7 +32,9 @@ let rhn_systemid_perform g root = let rhn_systemid_op = { name = "rhn-systemid"; - pod_description = "Remove the RHN system ID."; + enabled_by_default = true; + heading = "Remove the RHN system ID"; + pod_description = None; extra_args = []; perform = rhn_systemid_perform; } diff --git a/sysprep/sysprep_operation_script.ml b/sysprep/sysprep_operation_script.ml index 977d41f..bcbba73 100644 --- a/sysprep/sysprep_operation_script.ml +++ b/sysprep/sysprep_operation_script.ml @@ -113,7 +113,9 @@ trap cleanup INT TERM QUIT EXIT ERR\n" let script_op = { name = "script"; - pod_description = "\ + enabled_by_default = true; + heading = "Run arbitrary scripts against the guest"; + pod_description = Some "\ The C