diff options
author | makefu <github@syntax-fehler.de> | 2014-07-15 15:22:03 +0200 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2014-07-15 15:22:03 +0200 |
commit | bae95b3f9e926e381fe429a182f232e9a6c0b857 (patch) | |
tree | 4a36affc350be40c933272110c2c9ebe94d0cc06 /Reaktor/commands/nag | |
parent | 058d1fcf51ad6cf7c6b334ac2cac4408b168d0d7 (diff) | |
parent | de8c7b0950103fed60ce15e8474a270e96c688ad (diff) |
Merge branch 'master' of ssh://github.com/krebscode/painload
Diffstat (limited to 'Reaktor/commands/nag')
-rwxr-xr-x | Reaktor/commands/nag | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/Reaktor/commands/nag b/Reaktor/commands/nag index 68035831..24414dd3 100755 --- a/Reaktor/commands/nag +++ b/Reaktor/commands/nag @@ -1,22 +1,41 @@ #! /bin/sh set -euf -cd "$workdir" - -if test -e nag.hosts; then +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 nag.services nag.patch' EXIT INT QUIT +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' +} -(cd "$hostsdir" && ls | sort) > nag.hosts -(cd "$servicesdir" && ls | sort) > nag.services -diff -u nag.hosts nag.services > nag.patch || : +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' ' ') -superfluous_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' ' ') + # # output @@ -24,9 +43,6 @@ superfluous_services=$(sed -n '1d;2d;s/^+\(.*\)/\1/p' nag.patch | tr '\n' ' ') if test -n "$missing_services"; then echo missing services: $missing_services fi -if test -n "$superfluous_services"; then - echo superfluous services: $superfluous_services -fi -if test -z "$missing_services$superfluous_services"; then - echo hosts and services are in sync +if test -n "$obsolete_services"; then + echo obsolete services: $obsolete_services fi |