git.annexia.org
/
libguestfs.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
2135ec2
)
virt-sysprep: Simplify calls to guestfish --remote.
author
Richard W.M. Jones
<rjones@redhat.com>
Thu, 13 Oct 2011 10:09:31 +0000
(11:09 +0100)
committer
Richard W.M. Jones
<rjones@redhat.com>
Thu, 13 Oct 2011 14:25:12 +0000
(15:25 +0100)
clone/virt-sysprep.in
patch
|
blob
|
history
diff --git
a/clone/virt-sysprep.in
b/clone/virt-sysprep.in
index
b73acfb
..
4448860
100644
(file)
--- a/
clone/virt-sysprep.in
+++ b/
clone/virt-sysprep.in
@@
-182,9
+182,12
@@
cleanup ()
}
trap cleanup EXIT
}
trap cleanup EXIT
+# Helper.
+gf="guestfish --remote --"
+
# Launch back-end, inspect for operating systems, and get the guest
# root disk.
# Launch back-end, inspect for operating systems, and get the guest
# root disk.
-root=$(
guestfish --remote
inspect-get-roots)
+root=$(
$gf
inspect-get-roots)
if [ "$root" = "" ]; then
echo "$program: no operating system was found on this disk"
if [ "$root" = "" ]; then
echo "$program: no operating system was found on this disk"
@@
-196,14
+199,14
@@
if [ "$verbose" = "yes" ]; then
fi
# Get the guest type.
fi
# Get the guest type.
-type="$(
guestfish --remote --
-inspect-get-type $root)"
+type="$(
$gf
-inspect-get-type $root)"
if [ "$type" = "linux" ]; then
if [ "$type" = "linux" ]; then
- distro="$(
guestfish --remote --
-inspect-get-distro $root)"
+ distro="$(
$gf
-inspect-get-distro $root)"
fi
if [ "$type" = "windows" ]; then
fi
if [ "$type" = "windows" ]; then
- systemroot="$(
guestfish --remote --
-inspect-get-windows-systemroot $root)"
+ systemroot="$(
$gf
-inspect-get-windows-systemroot $root)"
fi
#----------------------------------------------------------------------
fi
#----------------------------------------------------------------------
@@
-214,9
+217,9
@@
fi
# Erase line(s) in a file that match the given regex.
erase_line ()
{
# Erase line(s) in a file that match the given regex.
erase_line ()
{
-
guestfish --remote --
download "$1" "$tmpdir/file"
+
$gf
download "$1" "$tmpdir/file"
sed "/$2/d" < "$tmpdir/file" > "$tmpdir/file.1"
sed "/$2/d" < "$tmpdir/file" > "$tmpdir/file.1"
-
guestfish --remote --
upload "$tmpdir/file.1" "$1"
+
$gf
upload "$tmpdir/file.1" "$1"
}
# rm_files wildcard
}
# rm_files wildcard
@@
-226,9
+229,9
@@
erase_line ()
# quoting.
rm_files ()
{
# quoting.
rm_files ()
{
- files=$(
guestfish --remote --
glob-expand "$1")
+ files=$(
$gf
glob-expand "$1")
for f in $files; do
for f in $files; do
-
guestfish --remote --
rm "$f"
+
$gf
rm "$f"
done
}
done
}
@@
-238,9
+241,9
@@
rm_files ()
# a file.
rm_file ()
{
# a file.
rm_file ()
{
- t=$(
guestfish --remote --
is-file "$1")
+ t=$(
$gf
is-file "$1")
if [ "$t" = "true" ]; then
if [ "$t" = "true" ]; then
-
guestfish --remote --
rm "$1"
+
$gf
rm "$1"
fi
}
fi
}
@@
-250,14
+253,12
@@
rm_file ()
if [ "$hostname" = "yes" ]; then
case "$type/$distro" in
linux/fedora)
if [ "$hostname" = "yes" ]; then
case "$type/$distro" in
linux/fedora)
- guestfish --remote -- \
- download /etc/sysconfig/network "$tmpdir/network"
+ $gf download /etc/sysconfig/network "$tmpdir/network"
echo "HOSTNAME=$hostname_param" > "$tmpdir/network.1"
sed '/^HOSTNAME=/d' < "$tmpdir/network" >> "$tmpdir/network.1"
echo "HOSTNAME=$hostname_param" > "$tmpdir/network.1"
sed '/^HOSTNAME=/d' < "$tmpdir/network" >> "$tmpdir/network.1"
- guestfish --remote -- \
- upload "$tmpdir/network.1" /etc/sysconfig/network ;;
+ $gf upload "$tmpdir/network.1" /etc/sysconfig/network ;;
linux/debian|linux/ubuntu)
linux/debian|linux/ubuntu)
-
guestfish --remote --
write /etc/hostname "$hostname_param"
+
$gf
write /etc/hostname "$hostname_param"
esac
fi
esac
fi
@@
-265,7
+266,7
@@
if [ "$net_hwaddr" = "yes" ]; then
case "$type/$distro" in
linux/fedora)
# XXX these filenames can have spaces and untrusted chars in them!
case "$type/$distro" in
linux/fedora)
# XXX these filenames can have spaces and untrusted chars in them!
- files=$(
guestfish --remote --
glob-expand '/etc/sysconfig/network-scripts/ifcfg-*')
+ files=$(
$gf
glob-expand '/etc/sysconfig/network-scripts/ifcfg-*')
for f in $files; do
erase_line "$f" "^HWADDR="
done
for f in $files; do
erase_line "$f" "^HWADDR="
done
@@
-282,8
+283,8
@@
fi
# Clean up and close down.
# Clean up and close down.
-
guestfish --remote
umount-all
-
guestfish --remote
sync
-
guestfish --remote
exit
+
$gf
umount-all
+
$gf
sync
+
$gf
exit
exit 0
exit 0