Bump to 1.14.1
[platform/upstream/augeas.git] / tests / test-put-mount.sh
1 #!/bin/sh
2
3 # Test that we can write into a bind mount with the copy_if_rename_fails flag.
4 # This requires that EXDEV or EBUSY is returned from rename(2) to activate the
5 # code path, so set up a bind mount on Linux.
6
7 if [ "$UID" != 0 -o "$(uname -s)" != "Linux" ]; then
8     echo "Test can only be run as root on Linux to create bind mounts"
9     exit 77
10 fi
11
12 ROOT=$abs_top_builddir/build/test-put-mount
13 LENSES=$abs_top_srcdir/lenses
14
15 HOSTS=$ROOT/etc/hosts
16 TARGET=$ROOT/other/real_hosts
17
18 rm -rf $ROOT
19 mkdir -p $(dirname $HOSTS)
20 mkdir -p $(dirname $TARGET)
21
22 echo 127.0.0.1 localhost > $TARGET
23 touch $HOSTS
24
25 mount --bind $TARGET $HOSTS
26 Exit() {
27     umount $HOSTS
28     exit $1
29 }
30
31 HOSTS_SUM=$(sum $HOSTS)
32
33 augtool --nostdinc -I $LENSES -r $ROOT <<EOF
34 set /augeas/save/copy_if_rename_fails 1
35 set /files/etc/hosts/1/alias myhost
36 save
37 print /augeas//error
38 EOF
39
40 if [ ! "x${HOSTS_SUM}" != "x$(sum $HOSTS)" ]; then
41     echo "/etc/hosts hasn't changed"
42     Exit 1
43 fi
44
45 if [ ! "x${HOSTS_SUM}" != "x$(sum $TARGET)" ]; then
46     echo "/other/real_hosts hasn't changed"
47     Exit 1
48 fi
49
50 if ! grep myhost $TARGET >/dev/null; then
51     echo "/other/real_hosts does not contain the modification"
52     Exit 1
53 fi
54
55 Exit 0