builder: templates: Add a can_sysprep_os function.

Does virt-sysprep know how to sysprep this disk image?  Add a function
to find out.

Just refactoring.
This commit is contained in:
Richard W.M. Jones
2018-09-11 15:51:20 +01:00
parent 112880e61b
commit d0ff42dfa2

View File

@@ -234,16 +234,14 @@ let rec main () =
| _ -> ()
);
(match os with
| FreeBSD _ -> () (* virt-sysprep doesn't work on FreeBSD. *)
| _ ->
(* Sysprep. Relabel SELinux-using guests. *)
printf "Sysprepping ...\n%!";
let cmd =
sprintf "virt-sysprep --quiet -a %s%s"
(quote tmpout)
(if is_selinux_os os then " --selinux-relabel" else "") in
if Sys.command cmd <> 0 then exit 1
if can_sysprep_os os then (
(* Sysprep. Relabel SELinux-using guests. *)
printf "Sysprepping ...\n%!";
let cmd =
sprintf "virt-sysprep --quiet -a %s%s"
(quote tmpout)
(if is_selinux_os os then " --selinux-relabel" else "") in
if Sys.command cmd <> 0 then exit 1
);
(* Sparsify and copy to output name. *)
@@ -418,6 +416,11 @@ and string_of_os_noarch = function
| Ubuntu (ver, _) -> sprintf "ubuntu-%s" ver
| FreeBSD (major, minor) -> sprintf "freebsd-%d.%d" major minor
(* Does virt-sysprep know how to sysprep this OS? *)
and can_sysprep_os = function
| RHEL _ | CentOS _ | Fedora _ | Debian _ | Ubuntu _ -> true
| FreeBSD _ -> false
and is_selinux_os = function
| RHEL _ | CentOS _ | Fedora _ -> true
| Debian _ | Ubuntu _