#!/bin/bash - # libguestfs # Copyright (C) 2009 Red Hat Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. unset CDPATH set -e #set -v if [ -z "$top_builddir" ]; then echo "$0: error: environment variable \$top_builddir must be set" exit 1 fi nr_stages=$(grep "^stage " $0 | wc -l) # Allow top_builddir to be a relative path, but also make it absolute, # and move to that directory for the initial phase of the script. top_builddir=$(cd "$top_builddir" > /dev/null; pwd) # Set libguestfs up for running locally. export LIBGUESTFS_PATH="$top_builddir/appliance" # Paths to the other programs and files. NB: Must be absolute paths. guestfish="$top_builddir/fish/guestfish" guestmount="$top_builddir/fuse/guestmount" image="$top_builddir/fuse/test.img" mp="$top_builddir/fuse/test-mp" if [ ! -x "$guestfish" -o ! -x "$guestmount" ]; then echo "$0: error: guestfish or guestmount are not available" exit 1 fi # Ensure everything is cleaned up on exit. rm -f "$image" mkdir -p "$mp" fusermount -u "$mp" >/dev/null 2>&1 ||: function cleanup () { status=$? set +e [ $status = 0 ] || echo "*** FAILED ***" echo "Unmounting filesystem and cleaning up." # Move out of the mountpoint (otherwise our cwd will prevent the # mountpoint from being unmounted). cd "$top_builddir" # Who's using this? Should be no one, but see below. if [ -x /sbin/fuser ]; then /sbin/fuser "$mp"; fi # If you run this and you have GNOME running at the same time, # then randomly /usr/libexec/gvfs-gdu-volume-monitor will decide # to do whatever it does in the mountpoint directory, preventing # you from unmounting it! Hence the need for this loop. count=10 while ! fusermount -u "$mp" && [ $count -gt 0 ]; do sleep 1 ((count--)) done rm -f "$image" rm -rf "$mp" exit $status } trap cleanup INT TERM QUIT EXIT s=1 function stage () { echo "test-fuse: $s/$nr_stages:" "$@" "..." ((s++)) } stage Create filesystem with some initial content $guestfish <> copy.txt echo world >> copy.txt echo bigger >> copy.txt echo biggest >> copy.txt [ "$(cat copy.txt)" = "hello world bigger biggest" ] # These ones are not yet tested by the current script: #stage XXX statfs/statvfs #stage XXX xattr operations # These ones cannot easily be tested by the current script, eg because # this script doesn't run as root: #stage XXX fsync #stage XXX chown #stage XXX mknod