Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

sysprep: Create /etc/sysconfig/network file if it doesn't exist (RHBZ…

…#858696).
  • Loading branch information...
commit 88c406feba1390f830c20bfb4c11989a4e877b91 1 parent aeb2f76
rwmjones rwmjones authored

Showing 1 changed file with 19 additions and 10 deletions. Show diff stats Hide diff stats

  1. +19 10 sysprep/sysprep_operation_hostname.ml
29 sysprep/sysprep_operation_hostname.ml
@@ -31,18 +31,27 @@ let hostname_perform g root =
31 31 let distro = g#inspect_get_distro root in
32 32 match typ, distro with
33 33 | "linux", ("fedora"|"rhel"|"centos"|"scientificlinux"|"redhat-based") ->
34   - (* Replace HOSTNAME=... entry. The code assumes it's a small,
35   - * plain text file.
  34 + (* Fedora 18 anaconda can create guests without
  35 + * /etc/sysconfig/network file. If this happens then we may need
  36 + * to create this file (RHBZ#858696).
36 37 *)
37 38 let filename = "/etc/sysconfig/network" in
38   - let lines = Array.to_list (g#read_lines filename) in
39   - let lines = List.filter (
40   - fun line -> not (string_prefix line "HOSTNAME=")
41   - ) lines in
42   - let file =
43   - String.concat "\n" lines ^
44   - sprintf "\nHOSTNAME=%s\n" !hostname in
45   - g#write filename file;
  39 + if g#is_file filename then (
  40 + (* Replace HOSTNAME=... entry. The code assumes it's a small,
  41 + * plain text file.
  42 + *)
  43 + let lines = Array.to_list (g#read_lines filename) in
  44 + let lines = List.filter (
  45 + fun line -> not (string_prefix line "HOSTNAME=")
  46 + ) lines in
  47 + let file =
  48 + String.concat "\n" lines ^
  49 + sprintf "\nHOSTNAME=%s\n" !hostname in
  50 + g#write filename file;
  51 + ) else (
  52 + let file = sprintf "HOSTNAME=%s\n" !hostname in
  53 + g#write filename file;
  54 + );
46 55 [ `Created_files ]
47 56
48 57 | "linux", ("debian"|"ubuntu") ->

0 comments on commit 88c406f

Please sign in to comment.
Something went wrong with that request. Please try again.