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-10-01 14:38:35 +0100 |
commit | fe4062396a88126d638651805fcb96ce3ee3b90a (patch) | |
tree | f0b94d564da1c42ca58d5b32ae967fc492b1ac84 | |
parent | fac02075e020f5a5a894261fec3940e060312a33 (diff) | |
download | libguestfs-fe4062396a88126d638651805fcb96ce3ee3b90a.tar.gz libguestfs-fe4062396a88126d638651805fcb96ce3ee3b90a.tar.xz libguestfs-fe4062396a88126d638651805fcb96ce3ee3b90a.zip |
sysprep: Create /etc/sysconfig/network file if it doesn't exist (RHBZ#858696).
(cherry picked from commit 88c406feba1390f830c20bfb4c11989a4e877b91)
-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 f832a18a..2452a248 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") -> |