shared-assets/pgp-sign.py

22 lines
747 B
Python

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