From 59bbcb140b92394c8973fac9fbfd5f9b2b4e2d04 Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Sat, 15 Jun 2024 23:50:57 +0200 Subject: [PATCH] [feat]: `save` function --- gpgtool | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/gpgtool b/gpgtool index f6b6439..c3c0142 100755 --- a/gpgtool +++ b/gpgtool @@ -219,6 +219,28 @@ create () { echo "----- Restoring secret key for further modification …" ln -sf ${keypath}/${id}/${keygrip}.key ${tempdir}/gpghome/private-keys-v1.d/ echo "----- Remember to import / send & close when done!" + + # FIXXE: add /info file! +} + +# (Re-)exports an open key after editing. +save () { + _checkinit + + id=${1} + + echo "----- Removing secret key …" + keygrip=$(gpg --homedir "${tempdir}/gpghome" --with-keygrip --list-key ${id} | grep Keygrip | head -n 1 | awk {'print $3'}) + rm ${tempdir}/gpghome/private-keys-v1.d/${keygrip}.key + echo "----- Exporting …" + exdir="${keypath}/${id}/$(date +%F)" + mkdir -p $exdir + gpg --homedir "${tempdir}/gpghome" --armor --export-secret-keys ${id} > ${keypath}/${id}/${id}.private.asc + gpg --homedir "${tempdir}/gpghome" --armor --export ${id} > ${keypath}/${id}/${id}.public.asc + cp ${keypath}/${id}/${id}.*.asc ${exdir} + echo "----- Restoring secret key …" + ln -sf ${keypath}/${id}/${keygrip}.key ${tempdir}/gpghome/private-keys-v1.d/ + echo -e "\nYou probably want to \`gpgtool import ${id}\` to load the updated key into your regular keyring." } # Extends an open key.