@@ -7,48 +7,49 @@ set -euo pipefail
7
7
# $ get_ssh_key "Personal" "git commit signing key"
8
8
9
9
vault_name=" ${1:- } "
10
- key_name =" ${2:- } "
10
+ item_name =" ${2:- } "
11
11
12
12
if [ -z " $vault_name " ]; then
13
13
echo " vault_name not passed as 1st argument. Nothing was done."
14
14
exit 1
15
15
fi
16
16
17
- if [ -z " $key_name " ]; then
18
- echo " key_name not passed as 2nd argument. Nothing was done."
17
+ if [ -z " $item_name " ]; then
18
+ echo " item_name not passed as 2nd argument. Nothing was done."
19
19
exit 1
20
20
fi
21
21
22
- private_key_path=" id_ed25519"
23
- public_key_path=" id_ed25519.pub"
22
+ # First try to get custom key name.
23
+ private_key_name=" $( op read " op://$vault_name /$item_name /name" 2> /dev/null || printf " id_ed25519" ) "
24
+ public_key_name=" $private_key_name .pub"
24
25
25
- if [ -f " $private_key_path " ]; then
26
- echo " $private_key_path already exists. Nothing was done."
26
+ if [ -f " $private_key_name " ]; then
27
+ echo " $private_key_name already exists. Nothing was done."
27
28
exit 2
28
29
fi
29
30
30
- if [ -f " public_key_path " ]; then
31
- echo " public_key_path already exists. Nothing was done."
31
+ if [ -f " $public_key_name " ]; then
32
+ echo " $public_key_name already exists. Nothing was done."
32
33
exit 2
33
34
fi
34
35
35
36
op read \
36
- --out-file " $private_key_path " \
37
- " op://$vault_name /$key_name /private key?ssh-format=openssh"
37
+ --out-file " $private_key_name " \
38
+ " op://$vault_name /$item_name /private key?ssh-format=openssh"
38
39
39
40
# Apply workaround for:
40
41
# https://1password.community/discussion/142733/bad-characters-when-exporting-ssh-private-key-via-cli
41
- private_key_content=" $( cat " $private_key_path " ) "
42
- printf " %s " " $private_key_content " | tr -d ' \r' > " $private_key_path "
42
+ private_key_content=" $( cat " $private_key_name " ) "
43
+ echo " $private_key_content " | tr -d ' \r' > " $private_key_name "
43
44
44
45
op read \
45
- --out-file " $public_key_path " \
46
- " op://$vault_name /$key_name /public key"
46
+ --out-file " $public_key_name " \
47
+ " op://$vault_name /$item_name /public key"
47
48
48
49
# Add a comment (if it exists)
49
- comment=" $( op read " op://Personal/git commit signing key /comment" 2> /dev/null || true) "
50
+ comment=" $( op read " op://$vault_name / $item_name /comment" 2> /dev/null || true) "
50
51
if [ -n " $comment " ]; then
51
- pubkey_content=" $( tr -d ' \n' < " $public_key_path " ) "
52
- true > " $public_key_path "
53
- printf " %s %s\n" " $pubkey_content " " $comment " > " $public_key_path "
52
+ pubkey_content=" $( tr -d ' \n' < " $public_key_name " ) "
53
+ true > " $public_key_name "
54
+ printf " %s %s\n" " $pubkey_content " " $comment " > " $public_key_name "
54
55
fi
0 commit comments