From db67fb687caa593e0ee5ed3abb3e336f0b1175c8 Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Tue, 29 Oct 2019 16:26:53 +0100 Subject: [PATCH] etc/info: add scripts --- assets/etc-info/restic.sh | 22 +++++++++++++++++++ assets/info_restic.sh | 43 ------------------------------------- system/desktop/packages.nix | 11 ++++++++++ 3 files changed, 33 insertions(+), 43 deletions(-) create mode 100644 assets/etc-info/restic.sh delete mode 100644 assets/info_restic.sh diff --git a/assets/etc-info/restic.sh b/assets/etc-info/restic.sh new file mode 100644 index 0000000..76e60c2 --- /dev/null +++ b/assets/etc-info/restic.sh @@ -0,0 +1,22 @@ + +function only_service(){ + local service=$1 + cat ~/.etc_info/* | jq '.[] | select(has("'${service}'"))' +} + +only_service "restic" \ + | jq '.restic' | jq --slurp . | jq 'group_by(.from)' \ + | jq --raw-output ' +.[] | +.[0].from as $hostname | +.[0].folders as $folders | +[.[] | select(.enable) | .to.server ] as $servers | +" +# \($hostname) +## folders +\( $folders | reduce .[] as $item ( ""; . + "* " + $item + "\n" ) ) +## to +\( $servers | reduce .[] as $item ( ""; . + "* " + $item + "\n") ) +"' | pandoc-from-markdown-to-man | man --local-file - + + diff --git a/assets/info_restic.sh b/assets/info_restic.sh deleted file mode 100644 index b042e57..0000000 --- a/assets/info_restic.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash - -TMPDIR=~/.etc_info -mkdir -p $TMPDIR - -# todo use rsync and make and copy them to a place where -# it is stored for longer -function get_infos(){ - local server=$1 - cd $TMPDIR - scp "${server}:/etc/info/*.json" . -} - -function only_service(){ - local service=$1 - cd $TMPDIR - cat * | jq '.[] | select(has("'${service}'"))' -} - -# main - -get_infos "workhorse.private" -get_infos "porani.private" -get_infos "workout.private" -get_infos "pepe.private" -get_infos "sterni.private" - -only_service "restic" \ - | jq '.restic' | jq --slurp . | jq 'group_by(.from)' \ - | jq --raw-output ' -.[] | -.[0].from as $hostname | -.[0].folders as $folders | -[.[].to.server] | -" -# \($hostname) -## folders -\( $folders | reduce .[] as $item ( ""; . + "*" + $item + "\n" ) ) -## to -\(. | reduce .[] as $item ( ""; . + "* " + $item + "\n") ) -"' | pandoc - -s -t man | man -l - - - diff --git a/system/desktop/packages.nix b/system/desktop/packages.nix index f427bd9..51adfbd 100644 --- a/system/desktop/packages.nix +++ b/system/desktop/packages.nix @@ -295,5 +295,16 @@ in { memo + # etc-info stuff + (pkgs.writers.writeDashBin "etc-info-sync" + (lib.concatStringsSep "\n" + (map + (host: "rsync -avLz ${host}.private:/etc/info/ ~/.etc_info") + (attrNames config.module.cluster.services.tinc."private".hosts)))) + + (pkgs.writers.writeBashBin "etc-info-restic" (lib.fileContents )) + + + ] ++ (lib.crossLists pandocScript [ ["markdown" "mediawiki"] ["mediawiki" "docbook5" "html5" "man"] ]); }