69 lines
3.1 KiB
Python
69 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Install the pinned syly2 build toolchain in the current UAT user's home."""
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import tarfile
|
|
import urllib.request
|
|
|
|
os.umask(0o077)
|
|
base = Path.home() / '.local/opt/syly2-build'
|
|
base.mkdir(parents=True, exist_ok=True)
|
|
downloads = base / 'downloads'
|
|
downloads.mkdir(exist_ok=True)
|
|
packages = [
|
|
{
|
|
'name': 'corretto-8.512.09.1',
|
|
'url': 'https://corretto.aws/downloads/resources/8.512.09.1/amazon-corretto-8.512.09.1-linux-x64.tar.gz',
|
|
'algorithm': 'sha256',
|
|
'checksum': '2f2df938886e61c80010ed5af0ea6504ca685280a3b807c5c59ed3ca4fb95be4',
|
|
'checksum_source': 'https://corretto.aws/downloads/latest_sha256/amazon-corretto-8-x64-linux-jdk.tar.gz',
|
|
'executable': 'bin/java',
|
|
},
|
|
{
|
|
'name': 'apache-maven-3.9.11',
|
|
'url': 'https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.tar.gz',
|
|
'algorithm': 'sha512',
|
|
'checksum': 'bcfe4fe305c962ace56ac7b5fc7a08b87d5abd8b7e89027ab251069faebee516b0ded8961445d6d91ec1985dfe30f8153268843c89aa392733d1a3ec956c9978',
|
|
'checksum_source': 'https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.tar.gz.sha512',
|
|
'executable': 'bin/mvn',
|
|
},
|
|
]
|
|
for package in packages:
|
|
archive = downloads / (package['name'] + '.tar.gz')
|
|
if not archive.exists():
|
|
print('Downloading', package['name'], flush=True)
|
|
partial = archive.with_suffix('.part')
|
|
with urllib.request.urlopen(package['url'], timeout=90) as response, partial.open('wb') as output:
|
|
while chunk := response.read(1024 * 1024):
|
|
output.write(chunk)
|
|
partial.rename(archive)
|
|
digest = hashlib.new(package['algorithm'], archive.read_bytes()).hexdigest()
|
|
if digest != package['checksum']:
|
|
raise RuntimeError('Checksum mismatch: ' + package['name'])
|
|
dest = base / package['name']
|
|
if not dest.exists():
|
|
staging = base / (package['name'] + '.extract')
|
|
staging.mkdir(exist_ok=False)
|
|
with tarfile.open(archive) as tar:
|
|
tar.extractall(staging, filter='data')
|
|
children = list(staging.iterdir())
|
|
if len(children) != 1 or not children[0].is_dir():
|
|
raise RuntimeError('Unexpected archive layout')
|
|
children[0].rename(dest)
|
|
staging.rmdir()
|
|
if not (dest / package['executable']).is_file():
|
|
raise RuntimeError('Incomplete installation: ' + str(dest))
|
|
print('Verified and installed', dest, flush=True)
|
|
|
|
jdk = base / packages[0]['name']
|
|
maven = base / packages[1]['name']
|
|
env_text = f'export JAVA_HOME="{jdk}"\nexport PATH="{jdk}/bin:{maven}/bin:$PATH"\nexport MAVEN_OPTS="-Xmx1536m -Djava.awt.headless=true"\n'
|
|
(base / 'env.sh').write_text(env_text)
|
|
(base / 'manifest.json').write_text(json.dumps(packages, indent=2) + '\n')
|
|
env = dict(os.environ, JAVA_HOME=str(jdk), PATH=f'{jdk}/bin:{maven}/bin:' + os.environ['PATH'])
|
|
subprocess.run([str(jdk / 'bin/java'), '-version'], env=env, check=True)
|
|
subprocess.run([str(maven / 'bin/mvn'), '-version'], env=env, check=True)
|