-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathharvest-test-data
executable file
·121 lines (108 loc) · 3.54 KB
/
harvest-test-data
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
set -e
set -u
cleanup() {
if [[ -v includes ]] && [[ -n "${includes}" ]] ; then
rm "${includes}"
fi
if [[ -v SUDO_UID ]] && [[ -v SUDO_GID ]] && \
[[ -v target ]] && [[ -d "${target}" ]]
then
chown -R "${SUDO_UID}:${SUDO_GID}" "${target}/"
find "${target}/" -type d -exec chmod 0755 {} \;
find "${target}/" -type f -exec chmod 0644 {} \;
fi
trap - INT TERM EXIT ERR
exit 0
}
trap cleanup INT TERM EXIT ERR
usage_helper() {
echo 'harvest-test-data <target_dir>'
}
show_help() {
echo 'example: sudo harvest-test-data xps13-9380'
}
usage() {
retval=$1 && shift
if [[ ${retval} -gt 0 ]]; then
usage_helper 1>&2
else
usage_helper
show_help
fi
exit ${retval}
}
if [[ $# -ne 1 ]] ; then
usage 1
else
case " ${1} " in
" -h "|" --help "|" -? "|" --usage ")
usage 0
;;
esac
fi
target="${1}" && shift
if [[ $# -gt 0 ]] ; then
usage 1
fi
real_target="$(realpath "${target}")"
cat /proc/mounts | while read dev mountpoint type options extras ; do
if [[ "${mountpoint}" -ef "${real_target}" ]] ; then
echo "Invalid target directory \"${target}\"." 1>&2
exit 1
fi
done
if ! [[ -v EUID ]] || [[ $EUID -ne 0 ]] ; then
echo "This utility must be run as root" >>/dev/stderr
exit 1
fi
#(
#find -H /sys/ -xdev -type d -exec mkdir -p .{} \;
#find -H /sys/ -xdev -type l -exec rsync --exclude-from=rsync-excludes.txt -avSHPl {} .{} \;
#find -H /sys/ -xdev '(' -iname uuid -o -iname guid ')' -exec rsync --exclude-from=rsync-excludes.txt -avSHPl {} .{} \;
#) 2>/dev/null
includes=$(mktemp)
mkdir -p "${target}/"
find -H /sys -xdev '(' -type d -o -type l \
-o '(' -type f \
-a '(' \
-name uuid -o -name guid -o -name wwid -o -name eui -o \
-name host_sas_address -o -name sas_address -o \
-name port_no -o \
-name hid -o -name cid -o -name uid -o \
-name namespace \
-name partition \
-name driver \
')' \
')' \
')' -print | sed 's,^/,,g' > "${includes}"
find -H /sys/firmware/efi/efivars/ -xdev -type f \
'(' \
-iname '*-605dab50-e046-4300-abb6-3dd810dd8b23' \
-o -iname '*-d719b2cb-3d3a-4596-a3bc-dad00e67656f' \
-o -iname 'Audit*-8be4df61-93ca-11d2-aa0d-00e098032b8c' \
-o -iname 'Boot*-8be4df61-93ca-11d2-aa0d-00e098032b8c' \
-o -iname 'Con*-8be4df61-93ca-11d2-aa0d-00e098032b8c' \
-o -iname 'Default*-8be4df61-93ca-11d2-aa0d-00e098032b8c' \
-o -iname 'Deployed*-8be4df61-93ca-11d2-aa0d-00e098032b8c' \
-o -iname 'Driver*-8be4df61-93ca-11d2-aa0d-00e098032b8c' \
-o -iname 'Err*-8be4df61-93ca-11d2-aa0d-00e098032b8c' \
-o -iname 'KEK*-8be4df61-93ca-11d2-aa0d-00e098032b8c' \
-o -iname 'Key*-8be4df61-93ca-11d2-aa0d-00e098032b8c' \
-o -iname '*Lang*-8be4df61-93ca-11d2-aa0d-00e098032b8c' \
-o -iname 'MirrorCurrent-7b9be2e0-e28a-4197-ad3e-32f062f9462c' \
-o -iname 'MirrorRequest-7b9be2e0-e28a-4197-ad3e-32f062f9462c' \
-o -iname 'OsIndications*-8be4df61-93ca-11d2-aa0d-00e098032b8c' \
-o -iname 'PK*-8be4df61-93ca-11d2-aa0d-00e098032b8c' \
-o -iname 'Setup*-8be4df61-93ca-11d2-aa0d-00e098032b8c' \
-o -iname 'SetupMode*-8be4df61-93ca-11d2-aa0d-00e098032b8c' \
-o -iname 'SignatureSupport*-8be4df61-93ca-11d2-aa0d-00e098032b8c' \
-o -iname 'SysPrep*-8be4df61-93ca-11d2-aa0d-00e098032b8c' \
-o -iname 'Timeout*-8be4df61-93ca-11d2-aa0d-00e098032b8c' \
')' >> "${includes}"
find -H /proc/ -xdev -type f \
'(' \
-name partitions \
')' >> "${includes}"
rsync -W -x -d -avSHP --specials --files-from="${includes}" --include-from="${includes}" / "${target}/" 2>/dev/null
# vim:filetype=sh:fenc=utf-8:sw=4:sts=4:ts=8:noet