| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) 2025 Marc Haber |
| 4 | # This program is free software; you can redistribute it and/or |
| 5 | # modify it under the terms of the GNU General Public License as |
| 6 | # published by the Free Software Foundation; either version 2 of the |
| 7 | # License, or (at your option) any later version. |
| 8 | # |
| 9 | # This program is distributed in the hope that it will be useful, but |
| 10 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | # General Public License for more details. |
| 13 | # |
| 14 | # You should have received a copy of the GNU General Public License |
| 15 | # along with this program; if not, write to the Free Software |
| 16 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | |
| 18 | |
| 19 | set -e |
| 20 | set -C |
| 21 | |
| 22 | # this helper program gets run (as root) before the less privileged |
| 23 | # dailyaidecheck gets started. It currently just calls one executable rule |
| 24 | # to generate a cache file containing LVM run time data that cannot |
| 25 | # be obtained as non-root. |
| 26 | # |
| 27 | # If this construct is needed more often, this helper should be extended |
| 28 | # to iterate over all executable files that end in _needsroot. |
| 29 | |
| 30 | #!/bin/sh |
| 31 | |
| 32 | # TODO: parse DIR from configuration file |
| 33 | DIR="/var/lib/aide" |
| 34 | AIDEUSER="_aide" |
| 35 | mkdir -p "$DIR" |
| 36 | TEMPFILE=$(mktemp "$DIR/tmp.XXXXXX") |
| 37 | CACHEFILE="$DIR/10_aide_rootrules_cache" |
| 38 | |
| 39 | NOW="$(date --iso-8601=seconds)" |
| 40 | SCRIPT="/etc/aide/aide.conf.d/10_aide_lvm_needsroot" |
| 41 | |
| 42 | printf >> "${TEMPFILE}" "# output from %s on %s at %s:\n" "${SCRIPT}" "$(hostname --fqdn)" "${NOW}" |
| 43 | >> "${TEMPFILE}" "${SCRIPT}" |
| 44 | |
| 45 | if [ ! -f "${CACHEFILE}" ] || ! cmp -s "${TEMPFILE}" "${CACHEFILE}"; then |
| 46 | mv "${TEMPFILE}" "${CACHEFILE}" |
| 47 | fi |
| 48 | rm -f "${TEMPFILE}" |
| 49 | chown "${AIDEUSER}" "${CACHEFILE}" |
| 50 | |
| 51 | # vim: tabstop=4 shiftwidth=4 expandtab |
| 52 | # end of file |