File: update_checksums

package info (click to toggle)
nagios-plugins-contrib 24.20190301
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,944 kB
  • sloc: perl: 36,804; sh: 13,006; python: 2,549; php: 593; lex: 582; makefile: 473; ansic: 281; ruby: 149; awk: 81
file content (47 lines) | stat: -rwxr-xr-x 1,396 bytes parent folder | download | duplicates (9)
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