import pathlib, subprocess, sys
source=pathlib.Path(sys.argv[1]).resolve()
version=sys.argv[2]
work=source.parent/('version-'+version)
subprocess.run(['dpkg-deb','-R',str(source),str(work)],check=True)
control=work/'DEBIAN/control'
lines=control.read_text().splitlines()
control.write_text('\n'.join('Version: '+version if line.startswith('Version: ') else line for line in lines)+'\n')
# Only the package version changes; payload and maintainer scripts remain the exact build output.
subprocess.run(['dpkg-deb','--root-owner-group','-Zzstd','-b',str(work),str(source.parent/('upgrade-'+version+'.deb'))],check=True)
