28 lines
1.2 KiB
Python
28 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Install the pinned official Godot RE Tools Linux bundle inside the workspace."""
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import stat
|
|
import zipfile
|
|
from install_local_tools import ROOT, TOOLS, DOWNLOADS, download
|
|
|
|
|
|
def main():
|
|
pin=json.loads((ROOT/'docs/toolchain.lock.json').read_text())['godot_re_tools']
|
|
DOWNLOADS.mkdir(parents=True,exist_ok=True)
|
|
archive,_=download(pin['url'],pin['url'].rsplit('/',1)[1],pin['sha256'])
|
|
destination=TOOLS/pin['directory'];destination.mkdir(exist_ok=True)
|
|
with zipfile.ZipFile(archive) as z:
|
|
for name,expected in pin['files'].items():
|
|
if Path(name).name!=name:raise ValueError('Invalid pinned tool filename')
|
|
entry=z.getinfo(name)
|
|
if stat.S_ISLNK(entry.external_attr>>16):raise ValueError('Tool archive contains a symlink')
|
|
data=z.read(entry)
|
|
if hashlib.sha256(data).hexdigest()!=expected:raise ValueError('Tool file differs from pin')
|
|
target=destination/name;target.write_bytes(data);target.chmod(0o755 if name==pin['executable'] else 0o644)
|
|
print(f"Installed Godot RE Tools {pin['version']} in {destination}")
|
|
|
|
|
|
if __name__=='__main__':main()
|