36 lines
1.5 KiB
Python
36 lines
1.5 KiB
Python
"""Install server source only after verifying it matches the exported baseline."""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import shutil
|
|
from datetime import datetime, timezone
|
|
from pathlib import Path
|
|
|
|
|
|
def install(root, package):
|
|
root,package=Path(root),Path(package)
|
|
manifest=json.loads((package/'manifest.json').read_text(encoding='utf-8'))
|
|
for name,entry in manifest.items():
|
|
incoming=package/'relay'/name
|
|
assert hashlib.sha256(incoming.read_bytes()).hexdigest()==entry['new'], 'Package checksum mismatch'
|
|
target=root/'relay'/name
|
|
current=hashlib.sha256(target.read_bytes()).hexdigest() if target.exists() else None
|
|
if current not in {entry['old'],entry['new']}:
|
|
raise ValueError('Server source differs from reviewed baseline: '+name+'; nothing modified')
|
|
backup=root/'backups'/('before-notifications-'+datetime.now(timezone.utc).strftime('%Y%m%d-%H%M%S-%f'))
|
|
backup.mkdir(parents=True)
|
|
for name in manifest:
|
|
target=root/'relay'/name
|
|
if target.exists():shutil.copy2(target,backup/name)
|
|
shutil.copy2(package/'relay'/name,target)
|
|
print('Server source backup:',backup)
|
|
print('Source updated; running containers are unchanged until image rebuild/recreation.')
|
|
|
|
|
|
if __name__=='__main__':
|
|
parser=argparse.ArgumentParser()
|
|
parser.add_argument('--root',type=Path,required=True)
|
|
parser.add_argument('--package',type=Path,required=True)
|
|
args=parser.parse_args()
|
|
install(args.root,args.package)
|