git.lirion.de

Of git, get, and gud

summaryrefslogtreecommitdiffstats
path: root/nagios-plugins-contrib-24.20190301~bpo9+1/check_checksums/update_checksums
blob: 2ef376b843f3a095698c77a3bee671b73112bfa7 (plain)
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
#!/bin/bash
#
#    Tool to rebuild all checksums for check_checksums
#
#
#    Copyright (C) 2013 Bernd Zeimetz <b.zeimetz@conova.com>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

set -e
umask 027

for t in md5 sha1 sha224 sha256 sha384 sha512; do
    fname="/etc/nagios/check_checksums.${t}"
    tool="${t}sum"
    if [ -f ${fname} ]; then
        tmp=`mktemp`
        chown root:nagios ${tmp}
        chmod 640 ${tmp}

        trap "rm -f ${tmp}" EXIT

        sed 's,^[^ ]*  ,,' ${fname} | while read f; do
            if [ -f "${f}" ]; then
                ${tool} "${f}" >> ${tmp}
            else
                echo "${f} went missing, ignoring!"
            fi
        done

        ln "${fname}" "${fname}_`date '+%s'`"
        mv "${tmp}" "${fname}"
    fi
done