sha1sum(1) does not exist everywhere, so wrap it in an own function so
the right implementation can be chosen on each OS. Also, wrapping it
avoid using awk everytime.
---
test-data/guestfs-hashsums.sh | 13 +++++++++++++
v2v/test-v2v-i-ova-formats.sh | 4 +++-
v2v/test-v2v-i-ova-gz.sh | 4 +++-
v2v/test-v2v-i-ova-two-disks.sh | 6 ++++--
v2v/test-v2v-i-ova.sh | 6 ++++--
5 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/test-data/guestfs-hashsums.sh b/test-data/guestfs-hashsums.sh
index 79dbd67..96e1238 100755
--- a/test-data/guestfs-hashsums.sh
+++ b/test-data/guestfs-hashsums.sh
@@ -28,3 +28,16 @@ do_md5 ()
;;
esac
}
+
+do_sha1 ()
+{
+ case "$(uname)" in
+ Linux)
+ sha1sum "$1" | awk '{print $1}'
+ ;;
+ *)
+ echo "$0: unknown method to calculate SHA1 of file on $(uname)"
+ exit 1
+ ;;
+ esac
+}
diff --git a/v2v/test-v2v-i-ova-formats.sh b/v2v/test-v2v-i-ova-formats.sh
index 47e57c6..3e2923d 100755
--- a/v2v/test-v2v-i-ova-formats.sh
+++ b/v2v/test-v2v-i-ova-formats.sh
@@ -46,6 +46,8 @@ fi
export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools"
+. $srcdir/../test-data/guestfs-hashsums.sh
+
d=test-v2v-i-ova-formats.d
rm -rf $d
mkdir $d
@@ -55,7 +57,7 @@ pushd $d
# Create a phony OVA. This is only a test of source parsing, not
# conversion, so the contents of the disks doesn't matter.
truncate -s 10k disk1.vmdk
-sha=`sha1sum disk1.vmdk | awk '{print $1}'`
+sha=`do_sha1 disk1.vmdk`
echo -e "SHA1(disk1.vmdk)=$sha\r" > disk1.mf
for format in $formats; do
diff --git a/v2v/test-v2v-i-ova-gz.sh b/v2v/test-v2v-i-ova-gz.sh
index 65071dd..086ff98 100755
--- a/v2v/test-v2v-i-ova-gz.sh
+++ b/v2v/test-v2v-i-ova-gz.sh
@@ -34,6 +34,8 @@ fi
export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools"
+. $srcdir/../test-data/guestfs-hashsums.sh
+
d=test-v2v-i-ova-gz.d
rm -rf $d
mkdir $d
@@ -42,7 +44,7 @@ pushd $d
truncate -s 10k disk1.vmdk
gzip disk1.vmdk
-sha=`sha1sum disk1.vmdk.gz | awk '{print $1}'`
+sha=`do_sha1 disk1.vmdk.gz`
echo -e "SHA1(disk1.vmdk.gz)=$sha\r" > disk1.mf
tar -cf test.ova ../test-v2v-i-ova-gz.ovf disk1.vmdk.gz disk1.mf
diff --git a/v2v/test-v2v-i-ova-two-disks.sh b/v2v/test-v2v-i-ova-two-disks.sh
index 85b23f0..4e7f38b 100755
--- a/v2v/test-v2v-i-ova-two-disks.sh
+++ b/v2v/test-v2v-i-ova-two-disks.sh
@@ -35,6 +35,8 @@ fi
export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools"
export VIRTIO_WIN="$srcdir/../test-data/fake-virtio-win"
+. $srcdir/../test-data/guestfs-hashsums.sh
+
d=test-v2v-i-ova-two-disks.d
rm -rf $d
mkdir $d
@@ -44,10 +46,10 @@ pushd $d
# Create a phony OVA. This is only a test of source parsing, not
# conversion, so the contents of the disks doesn't matter.
truncate -s 10k disk1.vmdk
-sha=`sha1sum disk1.vmdk | awk '{print $1}'`
+sha=`do_sha1 disk1.vmdk`
echo -e "SHA1(disk1.vmdk)=$sha\r" > disk1.mf
truncate -s 100k disk2.vmdk
-sha=`sha1sum disk2.vmdk | awk '{print $1}'`
+sha=`do_sha1 disk2.vmdk`
echo -e "SHA1(disk2.vmdk)=$sha\r" > disk2.mf
tar -cf test.ova ../test-v2v-i-ova-two-disks.ovf disk1.vmdk disk1.mf disk2.vmdk disk2.mf
diff --git a/v2v/test-v2v-i-ova.sh b/v2v/test-v2v-i-ova.sh
index 484e098..ea4f3df 100755
--- a/v2v/test-v2v-i-ova.sh
+++ b/v2v/test-v2v-i-ova.sh
@@ -41,6 +41,8 @@ fi
export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools"
export VIRTIO_WIN="$srcdir/../test-data/fake-virtio-win"
+. $srcdir/../test-data/guestfs-hashsums.sh
+
d=test-v2v-i-ova.d
rm -rf $d
mkdir $d
@@ -53,9 +55,9 @@ raw=TestOva-sda
qemu-img convert $f -O vmdk $d/$vmdk
cp $ovf $d/$ovf
-sha1=`sha1sum $d/$ovf | awk '{print $1}'`
+sha1=`do_sha1 $d/$ovf`
echo "SHA1($ovf)= $sha1" > $d/$mf
-sha1=`sha1sum $d/$vmdk | awk '{print $1}'`
+sha1=`do_sha1 $d/$vmdk`
echo "SHA1($vmdk)= $sha1" >> $d/$mf
pushd .
--
2.5.0