forked from mar-file-system/GUFI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
verifyknowntree
executable file
·92 lines (75 loc) · 2.98 KB
/
verifyknowntree
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env bash
set -e
ORIGIN="$(realpath $(dirname ${BASH_SOURCE[0]}))"
# go to the root of the GUFI directory
cd "$(dirname ${ORIGIN})"
# check if the executables are here, or in src
if [[ -f src/bfwi && -x src/bfwi ]]; then
SRC="src"
else
SRC=""
fi
# generate a directory
root="$(mktemp -d ${ORIGIN}/XXXXXXXXXX)"
src="${root}/testdir"
dst="${root}/testgufi/"
# always remove root after it is created
function cleanup {
rm -rf "${root}"
}
trap cleanup EXIT
# create the original tree
${ORIGIN}/generatetree -d "${src}"
# read it into GUFI
${ORIGIN}/../${SRC}/bfwi -t "${dst}" "${src}" 2>/dev/null
dst="$(echo ${dst} | tr -s /)" # clean up slashes
dst="${dst%/}" # remove last slash
if [[ "${src}" =~ ^/ ]]; then
dst="${dst}${src}"
else
dst="${dst}/${src}"
fi
# do not exit after first error
set +e
# keep track of errors to use as return code
error=0
# get the uid and gid
GID="$(id -g)"
# compare files
echo "Compare files"
diff <(${ORIGIN}/../scripts/gufi_find --bfq "${ORIGIN}/../${SRC}/bfq" "${root}" -path "${dst}" -type "f" --select "path() || '/' || name as name, type, nlink, uid, gid, size, linkname" | sort) <(
(
echo "${dst}/1KB|f|1|${UID}|${GID}|1024||"
echo "${dst}/1MB|f|1|${UID}|${GID}|1048576||"
echo "${dst}/directory/executable|f|1|${UID}|${GID}|0||"
echo "${dst}/directory/readonly|f|1|${UID}|${GID}|0||"
echo "${dst}/directory/subdirectory/repeat_name|f|1|${UID}|${GID}|0||"
echo "${dst}/directory/writable|f|1|${UID}|${GID}|0||"
echo "${dst}/empty_file|f|1|${UID}|${GID}|0||"
echo "${dst}/.hidden|f|1|${UID}|${GID}|0||"
echo "${dst}/old_file|f|1|${UID}|${GID}|0||"
echo "${dst}/repeat_name|f|1|${UID}|${GID}|0||"
echo "${dst}/unusual, name?#|f|1|${UID}|${GID}|0||"
) | sort) && echo "No Differences"
error=$(($error + $?))
# compare files and symlinks
echo
echo "Compare files and symlinks"
diff <(${ORIGIN}/../scripts/gufi_find --bfq "${ORIGIN}/../${SRC}/bfq" "${root}" -path "${dst}" --select "path() || '/' || name as name, type, nlink, uid, gid, linkname" | sort) <(
(
echo "${dst}/1KB|f|1|${UID}|${GID}||"
echo "${dst}/1MB|f|1|${UID}|${GID}||"
echo "${dst}/directory/executable|f|1|${UID}|${GID}||"
echo "${dst}/directory/readonly|f|1|${UID}|${GID}||"
echo "${dst}/directory/subdirectory/directory_symlink|l|1|${UID}|${GID}|$(realpath ${src})/directory/subdirectory|"
echo "${dst}/directory/subdirectory/repeat_name|f|1|${UID}|${GID}||"
echo "${dst}/directory/writable|f|1|${UID}|${GID}||"
echo "${dst}/empty_file|f|1|${UID}|${GID}||"
echo "${dst}/file_symlink|l|1|${UID}|${GID}|$(realpath ${src})/1KB|"
echo "${dst}/.hidden|f|1|${UID}|${GID}||"
echo "${dst}/old_file|f|1|${UID}|${GID}||"
echo "${dst}/repeat_name|f|1|${UID}|${GID}||"
echo "${dst}/unusual, name?#|f|1|${UID}|${GID}||"
) | sort) && echo "No Differences"
error=$(($error + $?))
exit $error