diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-09-19 17:34:11 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-09-19 17:34:58 +0100 |
commit | 88c406feba1390f830c20bfb4c11989a4e877b91 (patch) | |
tree | 1ff106967fd5e8579baccd9768a19233623df476 | |
parent | aeb2f76a585afdca07691771ab4d3d50cab2cbd0 (diff) | |
download | libguestfs-88c406feba1390f830c20bfb4c11989a4e877b91.tar.gz libguestfs-88c406feba1390f830c20bfb4c11989a4e877b91.tar.xz libguestfs-88c406feba1390f830c20bfb4c11989a4e877b91.zip |
sysprep: Create /etc/sysconfig/network file if it doesn't exist (RHBZ#858696).
-rw-r--r-- | sysprep/sysprep_operation_hostname.ml | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/sysprep/sysprep_operation_hostname.ml b/sysprep/sysprep_operation_hostname.ml index 3fc8800b..4b9d6d17 100644 --- a/sysprep/sysprep_operation_hostname.ml +++ b/sysprep/sysprep_operation_hostname.ml @@ -31,18 +31,27 @@ let hostname_perform g root = let distro = g#inspect_get_distro root in match typ, distro with | "linux", ("fedora"|"rhel"|"centos"|"scientificlinux"|"redhat-based") -> - (* Replace HOSTNAME=... entry. The code assumes it's a small, - * plain text file. + (* Fedora 18 anaconda can create guests without + * /etc/sysconfig/network file. If this happens then we may need + * to create this file (RHBZ#858696). *) let filename = "/etc/sysconfig/network" in - let lines = Array.to_list (g#read_lines filename) in - let lines = List.filter ( - fun line -> not (string_prefix line "HOSTNAME=") - ) lines in - let file = - String.concat "\n" lines ^ - sprintf "\nHOSTNAME=%s\n" !hostname in - g#write filename file; + if g#is_file filename then ( + (* Replace HOSTNAME=... entry. The code assumes it's a small, + * plain text file. + *) + let lines = Array.to_list (g#read_lines filename) in + let lines = List.filter ( + fun line -> not (string_prefix line "HOSTNAME=") + ) lines in + let file = + String.concat "\n" lines ^ + sprintf "\nHOSTNAME=%s\n" !hostname in + g#write filename file; + ) else ( + let file = sprintf "HOSTNAME=%s\n" !hostname in + g#write filename file; + ); [ `Created_files ] | "linux", ("debian"|"ubuntu") -> |