DNS zonefiles for the `cosi.clarkson.edu`, `cslabs.clarkson.edu`, and `csprojects.clarkson.edu` subdomains
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.6 KiB

  1. #!/usr/bin/env python3
  2. import re, sys, os
  3. prop_serial = None
  4. if len(sys.argv) > 1:
  5. try:
  6. prop_serial = int(sys.argv[1])
  7. except ValueError:
  8. print(f'Usage: {sys.argv[0]} <serialnum>')
  9. exit(1)
  10. FILES = [
  11. 'db.cosi',
  12. 'db.cslabs',
  13. 'db.csprojects',
  14. #'db.cslabs.rvs',
  15. 'db.cslabs.rvs.144',
  16. 'db.cslabs.rvs.145',
  17. 'db.cslabs.rvs.146',
  18. 'db.cslabs.rvs.c051',
  19. ]
  20. SERPAT = re.compile(r'(\d+)(\s*;\s*serial)')
  21. maxser = None
  22. data = {}
  23. for fname in FILES:
  24. content = open(fname).read()
  25. data[fname] = content
  26. match = SERPAT.search(content)
  27. if not match:
  28. print(f'Could not find pattern in file {fname}; abort.')
  29. exit(1)
  30. ser = int(match.group(1))
  31. print(f'Ser for {fname}: {ser}')
  32. if maxser is None:
  33. maxser = ser
  34. else:
  35. maxser = max((maxser, ser))
  36. print(f'Detected maximum serial: {maxser}')
  37. if prop_serial is None:
  38. prop_serial = maxser + 1
  39. elif prop_serial <= maxser:
  40. print(f'Warning: proposed serial {prop_serial} <= {maxser}')
  41. while True:
  42. resp = input(f'Proposing serial {prop_serial}; update [y/n]? ')
  43. if resp.lower() == 'y':
  44. print('Ok, editing...')
  45. break
  46. elif resp.lower() == 'n':
  47. print('Abort.')
  48. exit(1)
  49. else:
  50. print('Please enter "y" or "n".')
  51. for fname in FILES:
  52. bakname = fname + '.bak'
  53. print(f'Writing backup of {fname} to {bakname}...')
  54. open(bakname, 'w').write(data[fname])
  55. for fname in FILES:
  56. print(f'Writing {fname}...')
  57. open(fname, 'w').write(SERPAT.sub(f'{prop_serial}\\2', data[fname]))
  58. print('Done.')