File: test-put-mount-augnew.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 (69 lines) | stat: -rwxr-xr-x 1,543 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#! /bin/bash

# Test that we can write into a bind mount placed at PATH.augnew 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-augnew
LENSES=$abs_top_srcdir/lenses

HOSTS=$ROOT/etc/hosts
HOSTS_AUGNEW=${HOSTS}.augnew
TARGET=$ROOT/other/real_hosts

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

echo 127.0.0.1 localhost > $HOSTS
touch $TARGET $HOSTS_AUGNEW

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

HOSTS_SUM=$(sum $HOSTS)

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

if [ ! -f $HOSTS ] ; then
    echo "/etc/hosts is no longer a regular file"
    Exit 1
fi
if [ ! "x${HOSTS_SUM}" = "x$(sum $HOSTS)" ]; then
    echo "/etc/hosts has changed"
    Exit 1
fi
if [ ! "x${HOSTS_SUM}" = "x$(sum $HOSTS)" ]; then
    echo "/etc/hosts has changed"
    Exit 1
fi

if [ ! -s $HOSTS_AUGNEW ]; then
    echo "/etc/hosts.augnew is empty"
    Exit 1
fi
if [ ! -s $TARGET ]; then
    echo "/other/real_hosts is empty"
    Exit 1
fi

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

Exit 0