From 6ec3d922a48ad6a583315a4433a7170e6850c676 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 17 Apr 2016 05:24:33 +0200 Subject: krebs.backup network-ssh-port -> pkgs.get-ssh-port --- krebs/5pkgs/get-ssh-port/default.nix | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 krebs/5pkgs/get-ssh-port/default.nix (limited to 'krebs/5pkgs/get-ssh-port/default.nix') 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 +'' -- cgit v1.2.3