aboutsummaryrefslogtreecommitdiffstats
path: root/commands/nag
blob: fabeec8dec52682f54e332dab4911c46ff659e69 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#! /bin/sh
set -euf
if test -e nag.hosts.ls; then
  echo "nag seems to run already... if not, then delete $workdir/nag.*, please"
  exit 23
fi

trap 'rm -f nag.hosts.ls nag.services.ls nag.patch' EXIT INT QUIT


# usage: git_pull_output_filter REPO_NAME
git_pull_output_filter() {
  sed -n 's/^ [0-9]\+ file change/'"$1"': &/p'
}


if ! test -d nag.hosts; then
    git clone "$hosts_repo" nag.hosts
else
    (cd nag.hosts && git pull) | git_pull_output_filter hosts
fi

if ! test -d nag.services; then
    git clone "$services_repo" nag.services
else
    (cd nag.services && git pull) | git_pull_output_filter services
fi


(cd nag.hosts && ls | sort) > nag.hosts.ls
(cd nag.services && ls | sort) > nag.services.ls

diff -u nag.hosts.ls nag.services.ls > nag.patch || :

missing_services=$(sed -n '1d;2d;s/^-\(.*\)/\1/p' nag.patch | tr '\n' ' ')
obsolete_services=$(sed -n '1d;2d;s/^+\(.*\)/\1/p' nag.patch | tr '\n' ' ')

if test "${inspect_services-false}" = true; then
  missing_owners=$(set +f; cd nag.services && grep '^owner:$' * | cut -d: -f1)
  missing_mailtos=$(set +f; cd nag.services && grep '^mailto:$' * | cut -d: -f1)
fi

#
# output
#
did_nag=false
if test -n "$missing_services"; then
  echo missing services: $missing_services
  did_nag=true
fi
if test -n "$obsolete_services"; then
  echo obsolete services: $obsolete_services
  did_nag=true
fi
if test -n "${missing_owners-}"; then
  echo services with missing owner entry: $missing_owners
  did_nag=true
fi
if test -n "${missing_mailtos-}"; then
  echo services with missing mailto entry: $missing_mailtos
  did_nag=true
fi
# if asked directly, answer if there is nothing to nag about
if test $did_nag = false -a -n "${_from:-}";then
  echo "nothing to nag about"
fi