shared-assets/pgp-sign.py

22 lines
747 B
Python
Raw Normal View History

2020-09-21 20:23:46 +00:00
import re
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_} ...')
2020-09-21 20:23:46 +00:00
with open(file_, 'r') as fh:
content = fh.read()
content = re.sub(r'^\s*<!doctype[^>]*>', '', content)
2020-09-21 16:35:25 +00:00
proc = subprocess.run(['gpg', '--armor', '--detach-sign', '--output', '-', '--local-user', 'papatutuwawa@polynom.me', file_],
2020-09-21 20:23:46 +00:00
capture_output=True, check=True, input=content, encoding='utf-8')
signature = proc.stdout[:-1]
print(signature)
2020-09-21 16:35:25 +00:00
with open(file_, 'r') as fh:
content = fh.read().replace('%%%SIGNED_PAGES_PGP_SIGNATURE%%%', signature)
with open(file_, 'w') as fh:
fh.write(content)