export-pkgbuild-keys: use TEMPDIR while exporting key

This avoids the possibility to pollute the keys directory with temporary
files if the script is aborted in between.

Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
This commit is contained in:
Levente Polyak 2022-06-09 21:02:56 +02:00
parent 8d4c46d368
commit 01b6196883
No known key found for this signature in database
GPG Key ID: FC1B547C8D8172C8
1 changed files with 6 additions and 3 deletions

View File

@ -45,16 +45,19 @@ if (( ${#validpgpkeys[@]} == 0 )); then
exit 0
fi
trap 'rm -rf $TEMPDIR' EXIT INT TERM QUIT
TEMPDIR=$(mktemp -d --tmpdir export-pkgbuild-keys.XXXXXXXXXX)
mkdir -p keys/pgp
error=0
for key in "${validpgpkeys[@]}"; do
gpg --output "keys/pgp/$key.asc.tmp" --armor --export --export-options export-minimal "$key" 2>/dev/null
gpg --output "$TEMPDIR/$key.asc" --armor --export --export-options export-minimal "$key" 2>/dev/null
# gpg does not give a non-zero return value if it fails to export...
if [[ -f keys/pgp/$key.asc.tmp ]]; then
if [[ -f $TEMPDIR/$key.asc ]]; then
msg2 "Exported $key"
mv "keys/pgp/$key.asc.tmp" "keys/pgp/$key.asc"
mv "$TEMPDIR/$key.asc" "keys/pgp/$key.asc"
else
if [[ -f keys/pgp/$key.asc ]]; then
warning "Failed to update key: $key"