diff options
author | Patrick Spek <p.spek@tyil.nl> | 2022-04-15 16:32:43 +0200 |
---|---|---|
committer | Patrick Spek <p.spek@tyil.nl> | 2022-04-15 16:32:43 +0200 |
commit | d8a2f732b300cdbb892e0878fe87dbb7a0ef6d03 (patch) | |
tree | d364845506af8f3080c79df9a91bb3e32cc4b4d8 /lib/subcommands/ssh.bash |
Initial commit
Diffstat (limited to 'lib/subcommands/ssh.bash')
-rw-r--r-- | lib/subcommands/ssh.bash | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/subcommands/ssh.bash b/lib/subcommands/ssh.bash new file mode 100644 index 0000000..19ead9a --- /dev/null +++ b/lib/subcommands/ssh.bash @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +subcommand() +{ + local ssh="$(config app.ssh)" + + if [[ ! -d "$BASHTARD_ETCDIR/hosts.d" ]] + then + crit "$BASHTARD_NAME/ssh" "Could not find hosts file at $BASHTARD_ETCDIR/hosts.d" + return 3 + fi + + chgdir "$BASHTARD_ETCDIR/hosts.d" + + for node in * + do + local user + local host + local ip + + user="$(config_for "$node" "ssh.user" "root")" + + # Try IPv6 first + host="$(config_for "$node" "ssh.host" "$(config_for "$node" "vpn.ipv6")")" + + if [[ -z "$host" ]] + then + # Otherwise try IPv4 + host="$(config_for "$node" "ssh.host" "$(config_for "$node" "vpn.ipv4")")" + fi + + notice "ssh" "$user@$node ($host) > $*" + + $ssh "$user@$host" "$@" + + unset user + unset host + done +} |