[feat]: save function

This commit is contained in:
alterNERDtive 2024-06-15 23:50:57 +02:00
parent a9c95b8838
commit 59bbcb140b
Signed by: alterNERDtive
GPG key ID: 547787A4FE6533F1

22
gpgtool
View file

@ -219,6 +219,28 @@ create () {
echo "----- Restoring secret key for further modification …" echo "----- Restoring secret key for further modification …"
ln -sf ${keypath}/${id}/${keygrip}.key ${tempdir}/gpghome/private-keys-v1.d/ ln -sf ${keypath}/${id}/${keygrip}.key ${tempdir}/gpghome/private-keys-v1.d/
echo "----- Remember to import / send & close when done!" 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. # Extends an open key.