96 lines
2.1 KiB
Python
Executable file
96 lines
2.1 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
import json, sys, tarfile, os
|
|
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
from urllib.parse import urlparse
|
|
from urllib.request import Request, urlopen, urlretrieve
|
|
|
|
|
|
url = 'https://api.github.com/repos/GloriousEggroll/proton-ge-custom/releases/latest'
|
|
compatdirs = [
|
|
'~/.steam/compatibilitytools.d',
|
|
'~/.steam/debian-installation/compatibilitytools.d',
|
|
'~/.steam/steam/compatibilitytools.d'
|
|
]
|
|
|
|
|
|
for directory in compatdirs:
|
|
protondir = Path(directory).expanduser()
|
|
|
|
if protondir.exists():
|
|
break
|
|
|
|
if not protondir.exists():
|
|
protondir.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
def dl_progress(count, bsize, size):
|
|
progress = count * bsize / size
|
|
term_width = os.get_terminal_size().columns
|
|
status = ""
|
|
|
|
if progress >= 1:
|
|
progress = 1
|
|
status = "Done...\r\n"
|
|
|
|
text1 = f'\rDownloading {filename}: ['
|
|
text2 = f'] {int(round(progress, 2)*100)}% {status}'
|
|
|
|
bar_length = term_width - len(text1 + text2)
|
|
block = int(round(bar_length*progress))
|
|
bar_progress = '#'*block + '-'*(bar_length - block)
|
|
|
|
sys.stdout.write(text1 + bar_progress + text2)
|
|
sys.stdout.flush()
|
|
|
|
|
|
def dl_progress_old(count, bsize, size):
|
|
progress = count * bsize
|
|
percent = progress / size
|
|
|
|
print(percent)
|
|
|
|
|
|
with urlopen(Request(url, headers={'Accept': 'application/vnd.github.v3+json'})) as resp:
|
|
data = json.loads(resp.read())
|
|
release = None
|
|
|
|
builds = data['assets']
|
|
|
|
for build in builds:
|
|
if not build['browser_download_url'].endswith('.tar.gz'):
|
|
continue
|
|
|
|
release = {
|
|
'name': build['name'],
|
|
'size': build['size'],
|
|
'date:': build['created_at'],
|
|
'url': build['browser_download_url']
|
|
}
|
|
|
|
break
|
|
|
|
if not release:
|
|
print('Failed to get build info:', e)
|
|
sys.exit()
|
|
|
|
|
|
filename = Path(urlparse(release['url']).path).name
|
|
tarname = Path(f'/tmp/{filename}')
|
|
extpath = protondir.joinpath(filename.replace('.tar.gz', ''))
|
|
|
|
|
|
if not tarname.exists() and not extpath.exists():
|
|
urlretrieve(release['url'], tarname, dl_progress)
|
|
|
|
|
|
if not extpath.exists():
|
|
print(f'Extracting {filename} to {extpath}')
|
|
tar = tarfile.open(tarname)
|
|
tar.extractall(protondir)
|
|
print('Installed latest version of proton-ge')
|
|
|
|
else:
|
|
print('Latest version of proton-ge already installed')
|