summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2011-10-13 15:07:41 +0100
committerRichard W.M. Jones <rjones@redhat.com>2011-10-13 15:25:13 +0100
commit189c3d6ac1e3fbd4f8ffbaafdc36b8ad00961284 (patch)
tree83b33c1c97b207a5dc4c1f61f3dfae29b7c1a64d
parent17b26be2325348da1c7f6edf28397b8e45e9e499 (diff)
downloadlibguestfs-189c3d6ac1e3fbd4f8ffbaafdc36b8ad00961284.tar.gz
libguestfs-189c3d6ac1e3fbd4f8ffbaafdc36b8ad00961284.tar.xz
libguestfs-189c3d6ac1e3fbd4f8ffbaafdc36b8ad00961284.zip
virt-sysprep: Use Augeas for config file manipulation.
-rw-r--r--clone/virt-sysprep.in29
1 files changed, 24 insertions, 5 deletions
diff --git a/clone/virt-sysprep.in b/clone/virt-sysprep.in
index b98e4b06..cf4ad969 100644
--- a/clone/virt-sysprep.in
+++ b/clone/virt-sysprep.in
@@ -167,6 +167,11 @@ fi
# Create a temporary directory for general purpose use during operations.
tmpdir="$(mktemp -d)"
+# Increase the amount of memory allocated to the appliance because
+# we're using augeas. The user can override this by setting
+# $LIBGUESTFS_MEMSIZE before running the script.
+export LIBGUESTFS_MEMSIZE=${LIBGUESTFS_MEMSIZE:-2048}
+
# Call guestfish.
GUESTFISH_PID=
eval $("${guestfish[@]}")
@@ -209,6 +214,12 @@ if [ "$type" = "windows" ]; then
systemroot="$($gf -inspect-get-windows-systemroot $root)"
fi
+# Start Augeas if it's a Linux guest.
+if [ "$type" = "linux" ]; then
+ $gf aug-init / 0
+ using_augeas=yes
+fi
+
#----------------------------------------------------------------------
# Useful functions.
@@ -265,8 +276,8 @@ rm_file ()
if [ "$hostname" = "yes" ]; then
case "$type/$distro" in
linux/fedora)
- erase_line /etc/sysconfig/network "^HOSTNAME="
- prepend_line /etc/sysconfig/network "HOSTNAME=$hostname_param"
+ $gf aug-set /files/etc/sysconfig/network/HOSTNAME "$hostname_param"
+ augeas_save_needed=yes
;;
linux/debian|linux/ubuntu)
$gf write /etc/hostname "$hostname_param"
@@ -278,9 +289,11 @@ if [ "$net_hwaddr" = "yes" ]; then
case "$type/$distro" in
linux/fedora)
# XXX these filenames can have spaces and untrusted chars in them!
- files=$($gf glob-expand '/etc/sysconfig/network-scripts/ifcfg-*')
- for f in $files; do
- erase_line "$f" "^HWADDR="
+ nodes=$( $gf aug-ls /files/etc/sysconfig/network-scripts |
+ grep /files/etc/sysconfig/network-scripts/ifcfg- )
+ for node in $nodes; do
+ $gf -aug-rm "$node/HWADDR" >/dev/null
+ augeas_save_needed=yes
done
;;
esac
@@ -294,8 +307,14 @@ if [ "$udev_persistent_net" = "yes" -a "$type" = "linux" ]; then
rm_file /etc/udev/rules.d/70-persistent-net.rules
fi
+#----------------------------------------------------------------------
# Clean up and close down.
+if [ "$using_augeas" = "yes" -a "$augeas_save_needed" = "yes" ]; then
+ $gf aug-save
+ $gf aug-close
+fi
+
$gf umount-all
$gf sync
$gf exit