import subprocess from pathlib import Path for p in Path('debian/plasma-next-discover/opt/plasma').rglob('*'): if p.is_file() and not p.is_symlink(): with p.open('rb') as f:magic=f.read(4) if magic==bytes([127,69,76,70]): subprocess.run(['patchelf','--set-rpath','/opt/plasma/lib:/opt/plasma/lib/plasma-discover',str(p)],check=True)