compute-file-chksum.py 772 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env python3
  2. import sys,os
  3. import script_init
  4. from mmgen.cfg import Config
  5. from mmgen.util import msg,Msg,make_chksum_6
  6. from mmgen.fileutil import get_lines_from_file
  7. opts_data = {
  8. 'text': {
  9. 'desc': 'Compute checksum for a MMGen data file',
  10. 'usage':'[opts] infile',
  11. 'options': """
  12. -h, --help Print this help message.
  13. -i, --include-first-line Include the first line of the file (you probably don't want this)
  14. """
  15. }
  16. }
  17. cfg = Config(opts_data=opts_data)
  18. lines = get_lines_from_file( cfg, cfg._args[0] )
  19. start = (1,0)[bool(cfg.include_first_line)]
  20. a = make_chksum_6(' '.join(lines[start:]).encode())
  21. if start == 1:
  22. b = lines[0]
  23. msg(
  24. 'Checksum in file OK' if a == b else
  25. f"Checksum in file ({b}) doesn't match computed value!")
  26. Msg(a)