mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 13:55:58 +00:00
Prepare isolated Play bundle builds and distribution safeguards
This commit is contained in:
1 parent
773d37ff21
commit
2f6e43e3d1
102 files changed
+3070
-182
No files matched your search
@@ -1,5 +1,8 @@
|
||||
#!/bin/bash
|
||||
set -u
|
||||
if compgen -G '/opt/droiddeck-bundles/*/*.apk' >/dev/null; then
|
||||
exit 2
|
||||
fi
|
||||
export FLATPAK_BWRAP=/usr/local/bin/droiddeck-bwrap
|
||||
cores="libretro-core-info libretro-beetle-pce-fast libretro-beetle-psx libretro-beetle-vb libretro-beetle-wswan
|
||||
libretro-bsnes-mercury-performance libretro-desmume libretro-gambatte libretro-genesisplusgx libretro-mgba
|
||||
|
||||
@@ -16,7 +16,11 @@ fex_install() {
|
||||
local tag=$1 sha=$2 urls=$3 dst=/ tmp u f
|
||||
tmp=$(mktemp -d)
|
||||
for u in $urls; do
|
||||
curl -fsSL --retry 2 --connect-timeout 20 --speed-limit 1024 --speed-time 60 "$u" -o "$tmp/fex.tzst" && echo "$sha $tmp/fex.tzst" | sha256sum -c --quiet >/dev/null 2>&1 && break
|
||||
if compgen -G '/opt/droiddeck-bundles/*/*.apk' >/dev/null; then
|
||||
python3 /usr/local/lib/droiddeck/component_delivery.py fetch "$u" "$tmp/fex.tzst" --sha256 "$sha" && break
|
||||
else
|
||||
curl -fsSL --retry 2 --connect-timeout 20 --speed-limit 1024 --speed-time 60 "$u" -o "$tmp/fex.tzst" && echo "$sha $tmp/fex.tzst" | sha256sum -c --quiet >/dev/null 2>&1 && break
|
||||
fi
|
||||
rm -f "$tmp/fex.tzst"
|
||||
done
|
||||
if [ ! -s "$tmp/fex.tzst" ]; then
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/python3
|
||||
import hashlib
|
||||
import glob
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
@@ -17,6 +18,11 @@ SOURCES = {
|
||||
}
|
||||
USER_AGENT = "droiddeck-proton-extra"
|
||||
NEED_BYTES = 4 * 1024 * 1024 * 1024
|
||||
PLAY_BUNDLES = bool(glob.glob('/opt/droiddeck-bundles/*/*.apk'))
|
||||
if PLAY_BUNDLES:
|
||||
SOURCES = {"droiddeck": (SOURCES["droiddeck"][0], re.compile(r"aarch64\.tar\.(gz|xz|zst)$"))}
|
||||
sys.path.insert(0, '/usr/local/lib/droiddeck')
|
||||
import component_delivery
|
||||
|
||||
|
||||
def log(*args):
|
||||
@@ -24,6 +30,9 @@ def log(*args):
|
||||
|
||||
|
||||
def fetch_json(url):
|
||||
if PLAY_BUNDLES:
|
||||
with component_delivery.BundleReader() as reader:
|
||||
return json.loads(reader.read(url))
|
||||
req = urllib.request.Request(url, headers={
|
||||
"User-Agent": USER_AGENT, "Accept": "application/vnd.github+json"})
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
@@ -58,6 +67,10 @@ def release_asset(source, tag):
|
||||
|
||||
def download(url, path):
|
||||
log("downloading %s" % os.path.basename(path))
|
||||
if PLAY_BUNDLES:
|
||||
with component_delivery.BundleReader() as reader:
|
||||
reader.fetch(url, path)
|
||||
return
|
||||
rc = subprocess.call([
|
||||
"curl", "-fL", "--retry", "5", "--retry-delay", "3", "--retry-connrefused",
|
||||
"-C", "-", "-A", USER_AGENT, "-o", path, url])
|
||||
@@ -71,10 +84,16 @@ def verify(path, sums_url):
|
||||
log("no checksum published; skipping verification")
|
||||
return
|
||||
try:
|
||||
req = urllib.request.Request(sums_url, headers={"User-Agent": USER_AGENT})
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
want = r.read().decode("utf-8", "replace").split()[0].lower()
|
||||
if PLAY_BUNDLES:
|
||||
with component_delivery.BundleReader() as reader:
|
||||
want = reader.read(sums_url).decode('utf-8').split()[0].lower()
|
||||
else:
|
||||
req = urllib.request.Request(sums_url, headers={"User-Agent": USER_AGENT})
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
want = r.read().decode("utf-8", "replace").split()[0].lower()
|
||||
except (urllib.error.URLError, IndexError, OSError) as e:
|
||||
if PLAY_BUNDLES:
|
||||
raise
|
||||
log("could not read the checksum (%s); skipping verification" % e)
|
||||
return
|
||||
h = hashlib.sha512()
|
||||
@@ -138,7 +157,7 @@ def main():
|
||||
if not url:
|
||||
raise SystemExit("droiddeck-proton-extra: no ARM64 build published for %s" % what)
|
||||
log("%s -> %s" % (what, tag))
|
||||
elif what.startswith("http"):
|
||||
elif what.startswith("http") or PLAY_BUNDLES and what.startswith("droiddeck-bundle://"):
|
||||
url, sums = what, None
|
||||
elif os.path.isfile(what):
|
||||
local, url, sums = what, None, None
|
||||
|
||||
@@ -507,6 +507,10 @@ case $mode in
|
||||
_bl_got_proton=0
|
||||
while read -r _bl_extra || [ -n "$_bl_extra" ]; do
|
||||
case ${_bl_extra# } in ""|"#"*) continue ;; esac
|
||||
if compgen -G '/opt/droiddeck-bundles/*/*.apk' >/dev/null && [ "${_bl_extra%% *}" != droiddeck ]; then
|
||||
echo "$_bl_extra" >> "$_bl_left"
|
||||
continue
|
||||
fi
|
||||
step "installing Proton '$_bl_extra' (large download, several minutes)"
|
||||
if droiddeck-proton-extra "$_bl_proton_root" $_bl_extra; then
|
||||
_bl_got_proton=1
|
||||
|
||||
@@ -21,7 +21,13 @@ x64_default_dir() {
|
||||
while IFS= read -r d; do
|
||||
[ -f "$d/.droiddeck-arm64-proton" ] && { echo "$d"; return; }
|
||||
done < <(ls -d "$STEAM_X64"/compatibilitytools.d/DroidDeck-Proton* 2>/dev/null | sort -V -r
|
||||
ls -d "$STEAM_X64"/compatibilitytools.d/GE-Proton*-aarch64 2>/dev/null | sort -V -r)
|
||||
if ! compgen -G '/opt/droiddeck-bundles/*/*.apk' >/dev/null; then
|
||||
ls -d "$STEAM_X64"/compatibilitytools.d/GE-Proton*-aarch64 2>/dev/null | sort -V -r
|
||||
fi)
|
||||
if compgen -G '/opt/droiddeck-bundles/*/*.apk' >/dev/null; then
|
||||
echo "$STEAM_X64/compatibilitytools.d/DroidDeck-Proton"
|
||||
return
|
||||
fi
|
||||
echo "$STEAM_X64/compatibilitytools.d/droiddeck-proton-arm64"
|
||||
}
|
||||
x64_default_tool() {
|
||||
@@ -321,6 +327,10 @@ PY
|
||||
|
||||
x64_fetch() {
|
||||
local url=$1 out=$2 label=$3 total pid rc=0 last=-1 pct
|
||||
if compgen -G '/opt/droiddeck-bundles/*/*.apk' >/dev/null; then
|
||||
python3 /usr/local/lib/droiddeck/component_delivery.py fetch "$url" "$out" --sha256 "$ROOTFS_SHA256"
|
||||
return $?
|
||||
fi
|
||||
total=$(curl -fsSIL "$url" 2>/dev/null | tr -d '\r' | awk 'tolower($1) == "content-length:" { v = $2 } END { print v + 0 }')
|
||||
curl -fL -sS -C - "$url" -o "$out" &
|
||||
pid=$!
|
||||
|
||||
@@ -102,7 +102,15 @@ install)
|
||||
mkdir -p "$cache"
|
||||
pkg=$cache/steamvr.pkg.tar.zst
|
||||
echo "downloading SteamVR (571 MB) from Valve's package server"
|
||||
curl -fsSL --retry 5 -C - -o "$pkg" "$PKG_URL" || { echo "download failed"; exit 1; }
|
||||
play_bundle=
|
||||
for apk in /opt/droiddeck-bundles/*/*.apk; do
|
||||
if [ -f "$apk" ]; then play_bundle=1; break; fi
|
||||
done
|
||||
if [ -n "$play_bundle" ]; then
|
||||
python3 /usr/local/lib/droiddeck/component_delivery.py fetch "$PKG_URL" "$pkg" --sha256 "$PKG_SHA256" || exit 1
|
||||
else
|
||||
curl -fsSL --retry 5 -C - -o "$pkg" "$PKG_URL" || { echo "download failed"; exit 1; }
|
||||
fi
|
||||
echo "$PKG_SHA256 $pkg" | sha256sum -c - >/dev/null 2>&1 || { echo "checksum mismatch: removing the download"; rm -f "$pkg"; exit 1; }
|
||||
tmp=$cache/extract
|
||||
rm -rf "$tmp" && mkdir -p "$tmp"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/python3
|
||||
import json
|
||||
import glob
|
||||
import os
|
||||
import re
|
||||
import runpy
|
||||
@@ -13,6 +14,7 @@ LABEL_FILE = "/etc/steam-compatibility-label"
|
||||
PROTON_ARM64_APPID = "4427310"
|
||||
LAUNCHER = "droiddeck-proton"
|
||||
LEGACY_LAUNCHER = "bannerlator-proton"
|
||||
PLAY_BUNDLES = bool(glob.glob('/opt/droiddeck-bundles/*/*.apk'))
|
||||
LIBRARY = "/mnt/droiddeck"
|
||||
SOURCES = ("Proton Experimental (ARM64)", "Proton 11.0 (ARM64)")
|
||||
OWN_TOOLS = ((TOOL, SOURCES), (TOOL_11, ("Proton 11.0 (ARM64)",)))
|
||||
@@ -1131,7 +1133,7 @@ def tool_catalog(steam_root, extras=None):
|
||||
extras[first_key(os.path.join(tool_dir, "compatibilitytool.vdf"), ["compatibilitytools", "compat_tools"]) or entry] = entry
|
||||
for name, entry in sorted(extras.items()):
|
||||
catalog.append(tool_entry(name, display_name(entry), os.path.join(tools, entry), False))
|
||||
return catalog
|
||||
return own_builds(catalog) if PLAY_BUNDLES else catalog
|
||||
|
||||
|
||||
def requested_tool(request, catalog):
|
||||
@@ -1141,6 +1143,8 @@ def requested_tool(request, catalog):
|
||||
for tool in catalog:
|
||||
if tool["dir"] and tool["dir"] == request.get("dir") and tool["valve"] == bool(request.get("valve")):
|
||||
return tool["name"]
|
||||
if PLAY_BUNDLES:
|
||||
return own_proton_moves({}, catalog)[0]
|
||||
return None
|
||||
|
||||
|
||||
@@ -1298,7 +1302,7 @@ def choose_default(steam_default, state, request, catalog, adopt_steam=True, app
|
||||
elif adopt_steam and steam_default in names and steam_default != state.get("default"):
|
||||
state.update(default=steam_default, seq=now or now_ms(), source="steam")
|
||||
if state.get("default") not in names:
|
||||
state["default"] = TOOL
|
||||
state["default"] = (own_proton_moves({}, catalog)[0] or TOOL) if PLAY_BUNDLES else TOOL
|
||||
return state["default"], state
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
import argparse
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import sys
|
||||
import tempfile
|
||||
import zipfile
|
||||
|
||||
|
||||
DIRECTORY = Path('/opt/droiddeck-bundles')
|
||||
INDEX = 'assets/play-components/index.json'
|
||||
INDEX_LIMIT = 16 * 1024 * 1024
|
||||
SHA256 = re.compile(r'[0-9a-f]{64}')
|
||||
ASSET = re.compile(r'play-components/[0-9a-f]{64}/[0-9]{4,}')
|
||||
|
||||
|
||||
def enabled(directory=DIRECTORY):
|
||||
return any(directory.glob('*/*.apk'))
|
||||
|
||||
|
||||
class BundleReader:
|
||||
def __init__(self, directory=DIRECTORY):
|
||||
self.archives = []
|
||||
self.assets = {}
|
||||
try:
|
||||
paths = sorted(directory.glob('*/*.apk'))
|
||||
if not paths or len(paths) > 128:
|
||||
raise ValueError('Installed component bundles are unavailable')
|
||||
for path in paths:
|
||||
archive = zipfile.ZipFile(path)
|
||||
self.archives.append(archive)
|
||||
for entry in archive.infolist():
|
||||
if not entry.filename.startswith('assets/play-components/'):
|
||||
continue
|
||||
if entry.filename in self.assets:
|
||||
raise ValueError('Duplicate component asset: ' + entry.filename)
|
||||
self.assets[entry.filename] = (archive, entry)
|
||||
index = self.read_object(INDEX, 2 * 1024 * 1024)
|
||||
if index.get('schema') != 1 or not isinstance(index.get('entries'), dict):
|
||||
raise ValueError('Unsupported component index')
|
||||
self.entries = index['entries']
|
||||
except BaseException:
|
||||
self.close()
|
||||
raise
|
||||
|
||||
def close(self):
|
||||
for archive in self.archives:
|
||||
archive.close()
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, *args):
|
||||
self.close()
|
||||
|
||||
def read_object(self, path, limit=INDEX_LIMIT):
|
||||
archive, entry = self.assets[path]
|
||||
if entry.file_size > limit:
|
||||
raise ValueError('Component metadata exceeds its size limit')
|
||||
with archive.open(entry) as source:
|
||||
return json.load(source)
|
||||
|
||||
def copy(self, url, output, limit, expected_sha256=None):
|
||||
entry = self.entries.get(url)
|
||||
if entry is None:
|
||||
raise ValueError('Component is absent from this build: ' + url)
|
||||
size, digest = entry['size'], entry['sha256']
|
||||
if type(size) is not int or size <= 0 or size > limit or not SHA256.fullmatch(digest):
|
||||
raise ValueError('Invalid component metadata')
|
||||
if expected_sha256 is not None and digest != expected_sha256.lower():
|
||||
raise ValueError('Component version does not match this build')
|
||||
recipe = 'play-components/recipes/' + digest + '.json'
|
||||
if entry.get('recipe') != recipe:
|
||||
raise ValueError('Invalid component recipe path')
|
||||
chunks = self.read_object('assets/' + recipe)['chunks']
|
||||
if not chunks:
|
||||
raise ValueError('Component contains no payload')
|
||||
full_digest = hashlib.sha256()
|
||||
total = 0
|
||||
for chunk in chunks:
|
||||
path, chunk_size, chunk_sha256 = chunk['asset'], chunk['size'], chunk['sha256']
|
||||
if not ASSET.fullmatch(path) or type(chunk_size) is not int or not 0 < chunk_size <= size - total:
|
||||
raise ValueError('Invalid component chunk metadata')
|
||||
if not SHA256.fullmatch(chunk_sha256):
|
||||
raise ValueError('Invalid component chunk digest')
|
||||
archive, asset = self.assets['assets/' + path]
|
||||
if asset.file_size != chunk_size:
|
||||
raise ValueError('Component chunk size mismatch')
|
||||
chunk_digest = hashlib.sha256()
|
||||
copied = 0
|
||||
with archive.open(asset) as source:
|
||||
for block in iter(lambda: source.read(65536), b''):
|
||||
copied += len(block)
|
||||
total += len(block)
|
||||
if copied > chunk_size:
|
||||
raise ValueError('Component chunk exceeds pinned size')
|
||||
chunk_digest.update(block)
|
||||
full_digest.update(block)
|
||||
output.write(block)
|
||||
if copied != chunk_size or chunk_digest.hexdigest() != chunk_sha256:
|
||||
raise ValueError('Component chunk failed verification')
|
||||
if total != size or full_digest.hexdigest() != digest:
|
||||
raise ValueError('Component failed verification')
|
||||
return total
|
||||
|
||||
def read(self, url):
|
||||
output = io.BytesIO()
|
||||
self.copy(url, output, INDEX_LIMIT)
|
||||
return output.getvalue()
|
||||
|
||||
def fetch(self, url, destination, expected_sha256=None):
|
||||
destination = Path(destination)
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
descriptor, temporary = tempfile.mkstemp(prefix=destination.name + '.', suffix='.component-part', dir=destination.parent)
|
||||
try:
|
||||
with os.fdopen(descriptor, 'wb') as output:
|
||||
self.copy(url, output, sys.maxsize, expected_sha256)
|
||||
os.replace(temporary, destination)
|
||||
finally:
|
||||
if os.path.exists(temporary):
|
||||
os.unlink(temporary)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('command', choices=['enabled', 'read', 'fetch'])
|
||||
parser.add_argument('url', nargs='?')
|
||||
parser.add_argument('destination', nargs='?', type=Path)
|
||||
parser.add_argument('--sha256')
|
||||
arguments = parser.parse_args()
|
||||
if arguments.command == 'enabled':
|
||||
return 0 if enabled() else 1
|
||||
if not arguments.url or arguments.command == 'fetch' and arguments.destination is None:
|
||||
parser.error('Component URL and fetch destination are required')
|
||||
with BundleReader() as reader:
|
||||
if arguments.command == 'read':
|
||||
sys.stdout.buffer.write(reader.read(arguments.url))
|
||||
else:
|
||||
reader.fetch(arguments.url, arguments.destination, arguments.sha256)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
sys.exit(main())
|
||||
except (OSError, ValueError, KeyError, TypeError, zipfile.BadZipFile) as error:
|
||||
print('Bundled component unavailable: ' + str(error), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
Reference in new issue
Block a user