krebs.backup network-ssh-port -> pkgs.get-ssh-port

This commit is contained in:
tv 2016-04-17 05:24:33 +02:00
parent affb69250d
commit 6ec3d922a4
3 changed files with 42 additions and 25 deletions

View File

@ -113,7 +113,7 @@ let
src=$src_path
dst_user=root
dst_host=$(${fastest-address plan.dst.host})
dst_port=$(${network-ssh-port plan.dst.host "$dst_host"})
dst_port=$(${pkgs.get-ssh-port}/bin/get-ssh-port "$dst_host")
dst_path=${shell.escape plan.dst.path}
dst=$dst_user@$dst_host:$dst_path
echo "update snapshot: current; $src -> $dst" >&2
@ -137,7 +137,7 @@ let
identity=${shell.escape plan.dst.host.ssh.privkey.path}
src_user=root
src_host=$(${fastest-address plan.src.host})
src_port=$(${network-ssh-port plan.src.host "$src_host"})
src_port=$(${pkgs.get-ssh-port}/bin/get-ssh-port "$src_host")
src_path=${shell.escape plan.src.path}
src=$src_user@$src_host:$src_path
dst_path=${shell.escape plan.dst.path}
@ -224,19 +224,6 @@ let
| ${pkgs.coreutils}/bin/head -1; }
'';
# Note that we don't escape word on purpose, so we can deref shell vars.
# TODO type word
network-ssh-port = host: word: ''
case ${word} in
${concatStringsSep ";;\n" (mapAttrsToList
(_: net: "(${head net.aliases}) echo ${toString net.ssh.port}")
host.nets)};;
(*)
echo network-ssh-port: unhandled case: ${word} >&2
exit 1
esac
'';
in out
# TODO ionice
# TODO mail on failed push, pull

View File

@ -14,7 +14,16 @@ with config.krebs.lib;
then trace "Upstream `${upstream.name}' gets overridden by `${override.name}'." override
else override;
in {
in {}
// import ./builders.nix args
// mapAttrs (_: flip callPackage {})
(filterAttrs (_: dir.has-default-nix)
(subdirsOf ./.))
// {
get-ssh-port = callPackage ./get-ssh-port {
inherit config;
};
haskellPackages = pkgs.haskellPackages.override {
overrides = self: super:
mapAttrs (name: path: self.callPackage path {})
@ -29,18 +38,10 @@ with config.krebs.lib;
(builtins.readDir ./haskell-overrides));
};
push = callPackage ./push {
inherit (subdirs) get;
};
ReaktorPlugins = callPackage ./Reaktor/plugins.nix {};
test = {
infest-cac-centos7 = callPackage ./test/infest-cac-centos7 {};
};
}
// import ./builders.nix args
// mapAttrs (_: flip callPackage {})
(filterAttrs (_: dir.has-default-nix)
(subdirsOf ./.));
};
}

View File

@ -0,0 +1,29 @@
{ config, pkgs, ... }: with config.krebs.lib;
pkgs.writeScriptBin "get-ssh-port" ''
#! ${pkgs.dash}/bin/dash
set -efu
if test $# != 1 || test $1 = -h || test $1 = --help; then
echo "usage: get-ssh-port HOSTNAME" >&2
exit 23
fi
case $1 in
${concatMapStringsSep ";;\n"
(host: toString [
"(${shell.escape host.name})"
"echo ${toString host.nets.${config.krebs.search-domain}.ssh.port}"
])
(filter (host: hasAttr config.krebs.search-domain host.nets)
(attrValues config.krebs.hosts))
};;
${concatMapStringsSep ";;\n"
(net: toString [
"(${concatMapStringsSep "|" shell.escape net.aliases})"
"echo ${toString net.ssh.port}"
])
(concatMap (host: attrValues host.nets) (attrValues config.krebs.hosts))
};;
(*) echo "get-ssh-port: don't know ssh port of $1" >&2
exit 1
esac
''