btrfs-progs: tests: add shell quotes to misc test scripts
[platform/upstream/btrfs-progs.git] / tests / misc-tests / 021-image-multi-devices / test.sh
1 #!/bin/bash
2 # Test btrfs-image with multiple devices filesystem and verify that restoring
3 # the created image works against a single device.
4
5 source "$TEST_TOP/common"
6
7 check_prereq btrfs-image
8 check_prereq mkfs.btrfs
9 check_prereq btrfs
10
11 setup_root_helper
12
13 rm -f dev1 dev2
14 run_check truncate -s 2G dev1
15 run_check truncate -s 2G dev2
16 chmod a+w dev1 dev2
17
18 loop1=$(run_check_stdout $SUDO_HELPER losetup --find --show dev1)
19 loop2=$(run_check_stdout $SUDO_HELPER losetup --find --show dev2)
20
21 # Create the test file system.
22
23 run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$loop1" "$loop2"
24 run_check $SUDO_HELPER mount "$loop1" "$TEST_MNT"
25 run_check $SUDO_HELPER dd bs=1M count=1 if=/dev/zero of="$TEST_MNT/foobar"
26 orig_md5=$(run_check_stdout md5sum "$TEST_MNT/foobar" | cut -d ' ' -f 1)
27 run_check $SUDO_HELPER umount "$TEST_MNT"
28
29 # Create the image to restore later.
30 run_check $SUDO_HELPER "$TOP/btrfs-image" "$loop1" "$IMAGE"
31
32 # Wipe out the filesystem from the devices, restore the image on a single
33 # device, check everything works and file foobar is there and with 1Mb of
34 # zeroes.
35 run_check $SUDO_HELPER wipefs -a "$loop1"
36 run_check $SUDO_HELPER wipefs -a "$loop2"
37
38 run_check $SUDO_HELPER "$TOP/btrfs-image" -r "$IMAGE" "$loop1"
39
40 run_check $SUDO_HELPER mount "$loop1" "$TEST_MNT"
41 new_md5=$(run_check_stdout md5sum "$TEST_MNT/foobar" | cut -d ' ' -f 1)
42 run_check $SUDO_HELPER umount "$TEST_MNT"
43
44 # Cleanup loop devices.
45 run_check $SUDO_HELPER losetup -d "$loop1"
46 run_check $SUDO_HELPER losetup -d "$loop2"
47 rm -f dev1 dev2
48
49 # Compare the file digests.
50 [ "$orig_md5" == "$new_md5" ] || _fail "File digests do not match"