Skip to content

Commit d00a28e

Browse files
allanmcraeanthraxx
authored andcommitted
Export source PGPs from PKGBUILD on commit
Provide a tool to export keys listed in the PKGBUILDs validpgpkeys to keys/pgp/$fingerprint.asc. The presense of the "keys" directory alongside the PKGBUILD in trunk/ is tested during commitpkg. If the directory is abscent, keys are exported and added to the commit. If the directory is present, a check is made to ensure all valid PGP keys are provided. Signed-off-by: Allan McRae <[email protected]> Signed-off-by: Levente Polyak <[email protected]>
1 parent 5e98478 commit d00a28e

File tree

5 files changed

+114
-0
lines changed

5 files changed

+114
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ bash_completion
77
checkpkg
88
commitpkg
99
diffpkg
10+
export-pkgbuild-keys
1011
finddeps
1112
lddd
1213
makechrootpkg

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ IN_PROGS = \
1313
commitpkg \
1414
crossrepomove\
1515
diffpkg \
16+
export-pkgbuild-keys \
1617
finddeps \
1718
find-libdeps \
1819
lddd \
@@ -74,6 +75,7 @@ BASHCOMPLETION_LINKS = \
7475
MANS = \
7576
doc/archbuild.1 \
7677
doc/arch-nspawn.1 \
78+
doc/export-pkgbuild-keys.1 \
7779
doc/makechrootpkg.1 \
7880
doc/lddd.1 \
7981
doc/checkpkg.1 \

commitpkg.in

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ case "$cmd" in
4848
;;
4949
esac
5050

51+
52+
if (( ${#validpgpkeys[@]} != 0 )); then
53+
if [[ -d keys ]]; then
54+
for key in "${validpgpkeys[@]}"; do
55+
if [[ ! -f keys/pgp/$key.asc ]]; then
56+
export-pkgbuild-keys || die 'Failed to export valid PGP keys for source files'
57+
fi
58+
done
59+
else
60+
export-pkgbuild-keys || die 'Failed to export valid PGP keys for source files'
61+
fi
62+
63+
svn add --parents --force keys/pgp/*
64+
fi
65+
5166
# find files which should be under source control
5267
needsversioning=()
5368
for s in "${source[@]}"; do
@@ -60,6 +75,9 @@ for i in 'changelog' 'install'; do
6075
needsversioning+=("$file")
6176
done < <(sed -n "s/^[[:space:]]*$i=//p" PKGBUILD)
6277
done
78+
for key in "${validpgpkeys[@]}"; do
79+
needsversioning+=("keys/pgp/$key.asc")
80+
done
6381

6482
# assert that they really are controlled by SVN
6583
if (( ${#needsversioning[*]} )); then

doc/export-pkgbuild-keys.asciidoc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export-pkgbuild-keys(1)
2+
=======================
3+
4+
Name
5+
----
6+
export-pkgbuild-keys - Export valid source signing keys from a PKGBUILD
7+
8+
Synopsis
9+
--------
10+
export-pkgbuild-keys
11+
12+
Description
13+
-----------
14+
15+
Export the PGP keys from a PKGBUILDs validpgpkeys array into the keys/pgp/
16+
subdirectory. Useful for distributing packager validated source signing
17+
keys alongside PKGBUILDs.
18+
19+
Options
20+
-------
21+
22+
*-h, --help*::
23+
Show a help text.
24+
25+
include::footer.asciidoc[]

export-pkgbuild-keys.in

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
m4_include(lib/common.sh)
6+
7+
usage() {
8+
cat <<- _EOF_
9+
Usage: ${BASH_SOURCE[0]##*/}
10+
11+
Export the PGP keys from a PKGBUILDs validpgpkeys array into the keys/pgp/
12+
subdirectory. Useful for distributing packager validated source signing
13+
keys alongside PKGBUILDs.
14+
15+
OPTIONS
16+
-h, --help Show this help text
17+
_EOF_
18+
}
19+
20+
# option checking
21+
while (( $# )); do
22+
case $1 in
23+
-h|--help)
24+
usage
25+
exit 0
26+
;;
27+
*)
28+
die "invalid argument: %s" "$1"
29+
;;
30+
esac
31+
done
32+
33+
if [[ ! -f PKGBUILD ]]; then
34+
die "This must be run a directory containing a PKGBUILD."
35+
fi
36+
37+
mapfile -t validpgpkeys < <(
38+
# shellcheck source=PKGBUILD.proto
39+
. ./PKGBUILD
40+
printf "%s\n" "${validpgpkeys[@]}"
41+
)
42+
43+
if (( ${#validpgpkeys[@]} == 0 )); then
44+
exit 0
45+
fi
46+
47+
mkdir -p keys/pgp
48+
error=0
49+
50+
for key in "${validpgpkeys[@]}"; do
51+
gpg --output "keys/pgp/$key.asc.tmp" --armor --export --export-options export-minimal "$key" 2>/dev/null
52+
53+
# gpg does not give a non-zero return value if it fails to export...
54+
if [[ -f keys/pgp/$key.asc.tmp ]]; then
55+
mv "keys/pgp/$key.asc.tmp" "keys/pgp/$key.asc"
56+
else
57+
if [[ -f keys/pgp/$key.asc ]]; then
58+
warning "Failed to update key: $key"
59+
else
60+
error "Key unavailable: $key"
61+
error=1
62+
fi
63+
fi
64+
done
65+
66+
if (( error )); then
67+
die "Failed to export all \'validpgpkeys\' entries."
68+
fi

0 commit comments

Comments
 (0)