forked from not-jan/pass-ssh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh.bash
More file actions
executable file
·50 lines (43 loc) · 1.3 KB
/
ssh.bash
File metadata and controls
executable file
·50 lines (43 loc) · 1.3 KB
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
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
shopt -s extglob
ssh_read_data() {
local path="${1%/}"
local passfile="$PREFIX/$path.gpg"
check_sneaky_paths "$path"
[[ ! -f $passfile ]] && die "$path: passfile not found."
contents=$($GPG -d "${GPG_OPTS[@]}" "$passfile")
read -r ssh_password < <(echo "$contents")
while read -r line; do
if [[ "$line" == ssh:* ]]; then
local ssh_address=${line#"ssh:"}
ssh_address=${ssh_address##+([[:space:]])}
fi
if [[ "$line" == sshflags:* ]]; then
local ssh_flags=${line#"sshflags:"}
ssh_flags=${ssh_flags##+([[:space:]])}
fi
if [[ "$line" == user:* ]]; then
local ssh_user=${line#"user:"}
# ssh_user=${ssh_user##+([[:space::]])}
fi
if [[ "$line": == IP:* ]]; then
local ssh_host=${line#"IP:"}
# ssh_host=${ssh_host##+([[:space::]])}
fi
done < <(echo "$contents")
if [[ -z ${ssh_address+x} ]]; then
ssh_address="${ssh_user// /}@${ssh_host// /}"
fi
[[ -z ${ssh_address+x} ]] && die "$path: SSH host not defined."
# Default value for flags
ssh_flags="${ssh_flags:-}"
if [[ "$TERM" == "xterm-kitty" ]]; then
export TERM="xterm-color"
fi
export SSHPASS="$ssh_password"
/usr/bin/sshpass -e -- ssh $ssh_flags "${@:2}" "$ssh_address"
}
ssh_read_data "$@"