File: test-put-mount.sh

package info (click to toggle)
augeas 1.8.0-1+deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 13,496 kB
  • ctags: 7,528
  • sloc: ansic: 73,151; sh: 7,434; yacc: 524; makefile: 429; lex: 210; perl: 42; pascal: 27
file content (55 lines) | stat: -rwxr-xr-x 1,213 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#! /bin/bash

# Test that we can write into a bind mount with the copy_if_rename_fails flag.
# This requires that EXDEV or EBUSY is returned from rename(2) to activate the
# code path, so set up a bind mount on Linux.

if [ $UID -ne 0 -o -n "$FAKEROOTKEY" -o "$(uname -s)" != "Linux" ]; then
    echo "Test can only be run as root on Linux to create bind mounts"
    exit 77
fi

ROOT=$abs_top_builddir/build/test-put-mount
LENSES=$abs_top_srcdir/lenses

HOSTS=$ROOT/etc/hosts
TARGET=$ROOT/other/real_hosts

rm -rf $ROOT
mkdir -p $(dirname $HOSTS)
mkdir -p $(dirname $TARGET)

echo 127.0.0.1 localhost > $TARGET
touch $HOSTS

mount --bind $TARGET $HOSTS
Exit() {
    umount $HOSTS
    exit $1
}

HOSTS_SUM=$(sum $HOSTS)

augtool --nostdinc -I $LENSES -r $ROOT <<EOF
set /augeas/save/copy_if_rename_fails 1
set /files/etc/hosts/1/alias myhost
save
print /augeas//error
EOF

if [ ! "x${HOSTS_SUM}" != "x$(sum $HOSTS)" ]; then
    echo "/etc/hosts hasn't changed"
    Exit 1
fi

if [ ! "x${HOSTS_SUM}" != "x$(sum $TARGET)" ]; then
    echo "/other/real_hosts hasn't changed"
    Exit 1
fi

if ! grep myhost $TARGET >/dev/null; then
    echo "/other/real_hosts does not contain the modification"
    Exit 1
fi

Exit 0