Debian Codegraph @

debian/aide.conf.d/10_aide_lvm_needsroot

raw
1 #!/bin/sh
2
3 # this script needs root. Since the daily aide check does not run
4 # privileged, a dedicated service unit (runs as root) and invokes this
5 # script before the daily aide check is started. The output is written to
6 # a cache file that the daily aide check reads. This script is invoked again,
7 # this time producing no output since the LVM tool calls fail.
8 # If aide is directly invoked as root, the cache file is read but its values
9 # are overwritten by the output generated by the second call to this script.
10
11 undefine() {
12 local var="$1"
13 printf "@@if defined %s\n" "${var}"
14 printf "@@undef %s\n" "${var}"
15 printf "@@endif\n"
16 }
17
18 # TODO: parse DIR from configuration file
19 DIR="/var/lib/aide"
20 CACHEFILE="${DIR}/10_aide_rootrules_cache"
21
22 if [ "${EUID}" != "0" ]; then
23 # we are not called from the buildcache job and are expected
24 # to spew what we have cached
25 if [ -r "${CACHEFILE}" ]; then
26 cat "${CACHEFILE}"
27 fi
28 fi
29
30 if command -v dmsetup >/dev/null; then
31 if [ "$(dmsetup info --columns --options uuid --noheadings 2>/dev/null| grep -cvi 'no devices found')" != 0 ]; then
32 undefine DM_UUIDS_W_P
33 undefine DM_UUIDS_WO_P
34 printf "@@define DM_UUIDS_W_P (%s)\\n" \
35 "$(\
36 dmsetup info --columns --options uuid --noheadings | \
37 paste --serial --delimiters='|'
38 )"
39 printf "@@define DM_UUIDS_WO_P (%s)\\n" \
40 "$(\
41 dmsetup info --columns --options uuid --noheadings | \
42 sed 's/^LVM-//' | paste --serial --delimiters='|'
43 )"
44 fi
45 if [ "$(dmsetup info --columns --options name --noheadings 2>/dev/null| grep -cvi 'no devices found')" != 0 ]; then
46 undefine DM_NAMES
47 printf "@@define DM_NAMES (%s)\\n" \
48 "$(\
49 dmsetup info --columns --options name --noheadings | \
50 paste --serial --delimiters='|'
51 )"
52 printf "@@define DM_NAMES_WO_D (%s)\\n" \
53 "$(\
54 dmsetup info --columns --options name --noheadings | \
55 sed -e 's/-/\\\\\\\\x2f/' | \
56 paste --serial --delimiters='|'
57 )"
58 fi
59 fi
60
61 if command -v pvs >/dev/null; then
62 if [ "$(pvs --noheadings --options uuid 2>/dev/null | wc -l)" != 0 ]; then
63 undefine LVM_PV_UUIDS
64 undefine LVM_PV_UUIDS_NODASH
65 printf "@@define LVM_PV_UUIDS (%s)\\n" \
66 "$(\
67 pvs --noheadings --options uuid | \
68 sed 's/^[[:space:]]*\([^[:space:]]\+\).*/\1/' | \
69 sort --uniq | \
70 paste --serial --delimiters='|'
71 )"
72 printf "@@define LVM_PV_UUIDS_NODASH (%s)\\n" \
73 "$(\
74 pvs --noheadings --options uuid | \
75 sed 's/^[[:space:]]*\([^[:space:]]\+\).*/\1/;s/-//g' | \
76 sort --uniq | \
77 paste --serial --delimiters='|' \
78 )"
79 fi
80 fi
81 if command -v vgs >/dev/null; then
82 if [ "$(vgs --noheadings --options vg_name 2>/dev/null | wc -l)" != 0 ]; then
83 printf "@@define LVM_VGS (%s)\\n" \
84 "$(\
85 vgs --noheadings --options vg_name | \
86 sed 's/^[[:space:]]*\([^[:space:]]\+\).*/\1/' | \
87 sort --uniq | \
88 paste --serial --delimiters='|'
89 )"
90 fi
91 fi
92 if command -v lvs >/dev/null; then
93 if [ "$(lvs --noheadings --options vg_name 2>/dev/null | wc -l)" != 0 ]; then
94 printf "@@define LVM_LVS (%s)\\n" \
95 "$(\
96 lvs --noheadings --options lv_name | \
97 sed 's/^[[:space:]]*\([^[:space:]]\+\).*/\1/' | \
98 sort --uniq | \
99 paste --serial --delimiters='|' \
100 )"
101 fi
102 fi
103 # vim:tabstop=4:expandtab:shiftwidth=4