diff options
author | tv <tv@krebsco.de> | 2016-04-17 05:24:33 +0200 |
---|---|---|
committer | tv <tv@krebsco.de> | 2016-04-17 05:24:33 +0200 |
commit | 6ec3d922a48ad6a583315a4433a7170e6850c676 (patch) | |
tree | e66cc9279d2524e9b0caf0a963e00f2479f008cb /krebs | |
parent | affb69250d13f64d2be14327c1b47d23cadcb987 (diff) |
krebs.backup network-ssh-port -> pkgs.get-ssh-port
Diffstat (limited to 'krebs')
-rw-r--r-- | krebs/3modules/backup.nix | 17 | ||||
-rw-r--r-- | krebs/5pkgs/default.nix | 21 | ||||
-rw-r--r-- | krebs/5pkgs/get-ssh-port/default.nix | 29 |
3 files changed, 42 insertions, 25 deletions
diff --git a/krebs/3modules/backup.nix b/krebs/3modules/backup.nix index e85a3dfa8..f90081501 100644 --- a/krebs/3modules/backup.nix +++ b/krebs/3modules/backup.nix @@ -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 diff --git a/krebs/5pkgs/default.nix b/krebs/5pkgs/default.nix index 0c39324a7..5ec0d54e9 100644 --- a/krebs/5pkgs/default.nix +++ b/krebs/5pkgs/default.nix @@ -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 ./.)); + }; } diff --git a/krebs/5pkgs/get-ssh-port/default.nix b/krebs/5pkgs/get-ssh-port/default.nix new file mode 100644 index 000000000..2d106b2b6 --- /dev/null +++ b/krebs/5pkgs/get-ssh-port/default.nix @@ -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 +'' |