forked from jwilk/sshpg2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssh-add
executable file
·48 lines (40 loc) · 1007 Bytes
/
ssh-add
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
#!/bin/sh
# Copyright © 2016-2020 Jakub Wilk <[email protected]>
# Copyright © 2024 Christopher Bock <[email protected]>
# SPDX-License-Identifier: MIT
set -e -u
orig_ssh_add=$(command -v -p ssh-add) || {
printf 'ssh-add: command not found\n' >&2
exit 127
}
GPGD=$HOME/.ssh/gpg.d
if [ $# -eq 1 ]; then
if [ -z "${1%%*.gpg}" ] && [ -r "$1" ]; then
F="$1";
elif [ -z "${1%%*.pub}" ] && [ -r "$1" ]; then
F="$GPGD/${1##*/}"; F="${F%.*}.gpg";
else
F="$GPGD/${1##*/}.ed25519.gpg";
fi
if ! [ -r "$F" ]; then
echo "Could not read file $F"
exit 66
else
gpg -q -d < "$F" | "$orig_ssh_add" -
exit 0
fi
fi
if [ $# != 0 ]
then
exec "$orig_ssh_add" "$@"
fi
START=$(date -u +%s)
for pubkey in ~/.ssh/gpg.d/*.pub
do
seckey="${pubkey%.pub}.gpg"
[ -e "$seckey" ] || continue
gpg -q -d < "$seckey" | "$orig_ssh_add" -
done
STOP=$(date -u +%s)
echo "ssh-add: $(( STOP - START ))s"
# vim:ts=4 sts=4 sw=4 et