aboutsummaryrefslogtreecommitdiff
path: root/lib/subcommands/ssh.bash
blob: 3a781f39be6842acbc9225d0b88b34cef14e0f96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env bash

# SPDX-FileCopyrightText: 2023 Patrick Spek <p.spek@tyil.nl>
#
# SPDX-License-Identifier: AGPL-3.0-or-later

subcommand()
{
	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

		user="$(config_for "$node" "bashtard.ssh.user" "$USER")"
		host="$(config_for "$node" "bashtard.ssh.host")"

		if [[ -z "$host" ]]
		then
			crit "$BASHTARD_NAME/ssh" "bashtard.ssh.host is not configured for $node"
			continue
		fi

		notice "$BASHTARD_NAME/ssh" "$user@$node ($host) > $*"

		# shellcheck disable=SC2029
		ssh "$user@$host" "$@"

		unset user
		unset host
	done
}