shared-assets/pgp-sign.py

17 lines
580 B
Python
Raw Normal View History

2020-09-21 16:35:25 +00:00
import sys
import subprocess
if len(sys.argv) <= 1:
print('Usage: pgp-sign.py [files]')
exit(1)
for file_ in sys.argv[1:]:
print(f'Signing {file_} ...')
proc = subprocess.run(['gpg', '--armor', '--detach-sign', '--output', '-', '--local-user', 'papatutuwawa@polynom.me', file_],
capture_output=True, check=True)
signature = proc.stdout.decode('utf-8')[:-1]
with open(file_, 'r') as fh:
content = fh.read().replace('%%%SIGNED_PAGES_PGP_SIGNATURE%%%', signature)
with open(file_, 'w') as fh:
fh.write(content)