blob: cb81efe005351b45b43dc0b02694dc06d9da15cd (
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#!/bin/sh
# For when script calls itself
if [ -n "$PASSWORD" ]
then
pass show "$PASSWORD" &&
exit
exit 1
fi
if [ "$MENUCMD" = "tofi" ]
then
menucmd="tofi --matching-algorithm=normal"
else
menucmd="$MENUCMD"
fi
die ()
{
echo "$1" >&2
}
notify ()
{
notify-send -t 1000 "keyadd" "$1"
die "$1"
}
SSHFOLDER="$HOME/.ssh"
# Test if can connect to ssh-agent
ssh-add -l > /dev/null 2>&1
if [ $? -gt 1 ] # ignore if there are no identities
then
notify "Could not connect to agent."
exit 1
fi
if [ -z "${key:=$1}" ]
then
key="$(find "$SSHFOLDER" -iname "*.pub" |
sed "s,$SSHFOLDER/,," | # Clean
sed 's/\.pub$//' |
$menucmd)"
else
shift
fi
die "key: $key"
[ ! -f "$SSHFOLDER/$key" ] && exit 1
HOST=$(hostnamectl hostname)
die "host: $HOST"
if [ "$1" = "-d" ]
then
if ssh-add -q -d - < "$SSHFOLDER"/"$key".pub 2> /dev/null
then
notify "Deleted <b>$key</b>"
else
notify "Could not delete."
fi
# check if key is already added
elif ssh-add -l | grep -q "$(ssh-keygen -lf "$SSHFOLDER"/"$key")"
then
notify "Key already added."
else
export PASSWORD="keys/$HOST/ssh/$key"
export SSH_ASKPASS="$0"
ssh-add -q - < "$SSHFOLDER"/"$key" &&
notify "Added <b>$key</b>."
fi
|