File: test-virt-edit.sh

package info (click to toggle)
libguestfs 1%3A1.18.1-1%2Bdeb7u3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 49,156 kB
  • sloc: ansic: 282,408; ml: 22,707; sh: 16,121; perl: 5,946; java: 5,047; cs: 4,329; makefile: 3,191; haskell: 2,564; erlang: 1,510; python: 1,502; xml: 509; ruby: 217; pascal: 142; cpp: 11
file content (51 lines) | stat: -rwxr-xr-x 1,282 bytes parent folder | download
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
#!/bin/bash -

export LANG=C
set -e

# Make a copy of the Fedora image so we can write to it then
# discard it.
cp ../tests/guests/fedora.img test.img

# Edit interactively.  We have to simulate this by setting $EDITOR.
# The command will be: echo newline >> /tmp/file
export EDITOR='echo newline >>'
./virt-edit -a test.img /etc/test3
if [ "$(../cat/virt-cat -a test.img /etc/test3)" != "a
b
c
d
e
f
newline" ]; then
    echo "$0: error: mismatch in interactive editing of file /etc/test3"
    exit 1
fi
unset EDITOR

# Edit non-interactively, only if we have 'perl' binary.
if perl --version >/dev/null 2>&1; then
    ./virt-edit -a test.img /etc/test3 -e 's/^[a-f]/$lineno/'
    if [ "$(../cat/virt-cat -a test.img /etc/test3)" != "1
2
3
4
5
6
newline" ]; then
        echo "$0: error: mismatch in non-interactive editing of file /etc/test3"
        exit 1
    fi
fi

# Verify the mode of /etc/test3 is still 0600 and the UID:GID is 10:11.
# See tests/guests/guest-aux/make-fedora-img.pl and RHBZ#788641.
if [ "$(../fish/guestfish -i -a test.img --ro lstat /etc/test3 | grep -E '^(mode|uid|gid):' | sort)" != "gid: 11
mode: 33152
uid: 10" ]; then
    echo "$0: error: editing /etc/test3 did not preserve permissions or ownership"
    exit 1
fi

# Discard test image.
rm test.img