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