diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2011-10-13 14:30:35 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2011-10-13 15:25:13 +0100 |
commit | 17b26be2325348da1c7f6edf28397b8e45e9e499 (patch) | |
tree | afa744cbe53f9dcffb7075320baefc715067f7b7 /clone/virt-sysprep.in | |
parent | 11be7d8eee16e6249ed2868b5bd552f29508ec02 (diff) | |
download | libguestfs-17b26be2325348da1c7f6edf28397b8e45e9e499.tar.gz libguestfs-17b26be2325348da1c7f6edf28397b8e45e9e499.tar.xz libguestfs-17b26be2325348da1c7f6edf28397b8e45e9e499.zip |
virt-sysprep: Add prepend_line utility function.
Diffstat (limited to 'clone/virt-sysprep.in')
-rw-r--r-- | clone/virt-sysprep.in | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/clone/virt-sysprep.in b/clone/virt-sysprep.in index 792282c7..b98e4b06 100644 --- a/clone/virt-sysprep.in +++ b/clone/virt-sysprep.in @@ -222,6 +222,18 @@ erase_line () $gf upload "$tmpdir/file.1" "$1" } +# prepend_line filename line +# +# Prepend a line to a file (this is better than appending, because it +# works even when the original file isn't terminated with a newline). +prepend_line () +{ + $gf download "$1" "$tmpdir/file" + echo "$2" > "$tmpdir/file.1" + cat "$tmpdir/file.1" "$tmpdir/file" >> "$tmpdir/file.2" + $gf upload "$tmpdir/file.2" "$1" +} + # rm_files wildcard # # Remove files. Doesn't fail if no files exist. Note the wildcard @@ -253,12 +265,12 @@ rm_file () if [ "$hostname" = "yes" ]; then case "$type/$distro" in linux/fedora) - $gf download /etc/sysconfig/network "$tmpdir/network" - echo "HOSTNAME=$hostname_param" > "$tmpdir/network.1" - sed '/^HOSTNAME=/d' < "$tmpdir/network" >> "$tmpdir/network.1" - $gf upload "$tmpdir/network.1" /etc/sysconfig/network ;; + erase_line /etc/sysconfig/network "^HOSTNAME=" + prepend_line /etc/sysconfig/network "HOSTNAME=$hostname_param" + ;; linux/debian|linux/ubuntu) $gf write /etc/hostname "$hostname_param" + ;; esac fi @@ -270,6 +282,7 @@ if [ "$net_hwaddr" = "yes" ]; then for f in $files; do erase_line "$f" "^HWADDR=" done + ;; esac fi |