diff --git a/.github/scripts/publish-preview-index.py b/.github/scripts/publish-preview-index.py new file mode 100644 index 00000000..76eeb348 --- /dev/null +++ b/.github/scripts/publish-preview-index.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python3 + +import datetime +import json +import os +import re +import subprocess +from pathlib import Path + + +IMAGE_KEY = re.compile(r"preview/armada-\d{8}(?:\.[0-9a-f]{7,40})?\.img\.gz") +KEEP_IMAGES = 5 + + +def expired_keys(objects, current_key): + if not IMAGE_KEY.fullmatch(current_key): + raise ValueError("Current image is not a Preview disk image under preview/") + + images = [] + keys = {obj["Key"] for obj in objects} + nonempty_keys = {obj["Key"] for obj in objects if obj["Size"] > 0} + for obj in objects: + if IMAGE_KEY.fullmatch(obj["Key"]): + modified = datetime.datetime.fromisoformat(obj["LastModified"].replace("Z", "+00:00")) + images.append((modified, obj["Key"])) + if current_key not in nonempty_keys or current_key + ".sha256" not in nonempty_keys: + raise ValueError("Current image and checksum must exist before pruning") + + images.sort(reverse=True) + retained = {current_key} + for _, key in images: + if key not in nonempty_keys or key + ".sha256" not in nonempty_keys: + continue + if len(retained) < KEEP_IMAGES: + retained.add(key) + + expired = [] + for _, key in images: + if key not in retained: + if key + ".sha256" in keys: + expired.append(key + ".sha256") + expired.append(key) + return expired + + +def main(): + if os.environ.get("R2_PREFIX", "preview").strip("/") != "preview": + raise ValueError("Preview pruning is restricted to preview/") + endpoint = os.environ["R2_ENDPOINT_URL"] + bucket = os.environ["R2_BUCKET"] + current = json.loads(Path("output/current-build.json").read_text()) + current_key = current["image"]["key"] + aws = ["aws", "--endpoint-url", endpoint, "s3api"] + listing = subprocess.check_output( + aws + ["list-objects-v2", "--bucket", bucket, "--prefix", "preview/", "--output", "json"], + text=True, + ) + objects = json.loads(listing).get("Contents", []) + managed_keys = set() + for obj in objects: + key = obj["Key"] + if not IMAGE_KEY.fullmatch(key): + continue + details = json.loads(subprocess.check_output( + aws + ["head-object", "--bucket", bucket, "--key", key, "--output", "json"], + text=True, + )) + if details.get("Metadata", {}).get("armada-preview") == "true": + managed_keys.update((key, key + ".sha256")) + managed_objects = [obj for obj in objects if obj["Key"] in managed_keys] + expired = expired_keys(managed_objects, current_key) + + def read_object(key): + return subprocess.check_output( + ["aws", "s3", "cp", f"s3://{bucket}/{key}", "-", + "--endpoint-url", endpoint, "--only-show-errors"], text=True, + ) + + keys = {obj["Key"] for obj in objects} + previous = [] + if "preview/builds.json" in keys: + previous = json.loads(read_object("preview/builds.json"))["builds"] + known = {build["image"]["key"]: build for build in previous} + builds = [current] + for obj in sorted(managed_objects, key=lambda obj: obj["LastModified"], reverse=True): + key = obj["Key"] + if key not in known or key == current_key or key in expired: + continue + sha256 = read_object(key + ".sha256").split()[0] + if not re.fullmatch(r"[a-f0-9]{64}", sha256): + raise ValueError(f"Invalid checksum for {key}") + build = dict(known[key]) + if build["image"]["sha256"] != sha256: + build["published_at"] = obj["LastModified"] + build["published_at"] = build["published_at"].replace("+00:00", "Z") + build["image"] = {**build["image"], "size": obj["Size"], "sha256": sha256} + builds.append(build) + index = {"channel": "preview", "latest": current["version"], "builds": builds} + Path("output/builds.json").write_text(json.dumps(index, indent=2) + "\n") + for key in expired: + subprocess.run(aws + ["delete-object", "--bucket", bucket, "--key", key], check=True) + print(f"Deleted s3://{bucket}/{key}") + + subprocess.run( + ["aws", "s3", "cp", "output/builds.json", f"s3://{bucket}/preview/builds.json", + "--endpoint-url", endpoint, "--content-type", "application/json", + "--cache-control", "no-store", "--only-show-errors"], check=True, + ) + + summary = os.environ.get("GITHUB_STEP_SUMMARY") + if summary: + with open(summary, "a") as output: + output.write(f"\nPreview retention: keep {KEEP_IMAGES} images; deleted {len(expired)} older objects.\n") + + +if __name__ == "__main__": + main() diff --git a/.github/workflows/build-disk.yml b/.github/workflows/build-disk.yml index de5d491e..1a0c8fc6 100644 --- a/.github/workflows/build-disk.yml +++ b/.github/workflows/build-disk.yml @@ -13,14 +13,37 @@ on: description: "Optional custom container tag. Overrides the dropdown when set." type: string default: "" + workflow_call: + inputs: + tag: + type: string + default: testing + publish_r2: + type: boolean + default: false + image_digest: + type: string + default: "" + source_ref: + type: string + default: "" + secrets: + R2_ACCESS_KEY_ID: + required: false + R2_SECRET_ACCESS_KEY: + required: false env: IMAGE_NAME: ${{ github.event.repository.name }} IMAGE_REGISTRY: "ghcr.io/${{ github.repository_owner }}" BIB_IMAGE: "quay.io/centos-bootc/bootc-image-builder:latest" + R2_ENDPOINT_URL: ${{ vars.R2_ENDPOINT_URL }} + R2_BUCKET: ${{ vars.R2_BUCKET }} + R2_PREFIX: preview + R2_PUBLIC_URL: ${{ vars.R2_PUBLIC_URL }} concurrency: - group: ${{ github.workflow }}-${{ github.ref || github.run_id }} + group: ${{ inputs.publish_r2 && 'preview-disk' || format('build-disk-{0}', github.ref || github.run_id) }} cancel-in-progress: false jobs: @@ -33,6 +56,20 @@ jobs: packages: read steps: + - name: Check R2 configuration + if: inputs.publish_r2 + env: + R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }} + R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} + run: | + set -euo pipefail + for setting in R2_ENDPOINT_URL R2_BUCKET R2_ACCESS_KEY_ID R2_SECRET_ACCESS_KEY; do + if [ -z "${!setting}" ]; then + echo "::error::${setting} is not configured. Set it in repository Settings > Secrets and variables > Actions." + exit 1 + fi + done + - name: Maximize build space uses: ublue-os/remove-unwanted-software@cc0becac701cf642c8f0a6613bbdaf5dc36b259e # v9 with: @@ -40,6 +77,8 @@ jobs: - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ inputs.source_ref || github.sha }} - name: Install dependencies run: | @@ -47,12 +86,7 @@ jobs: echo "IMAGE_NAME=${IMAGE_NAME,,}" >> "${GITHUB_ENV}" echo "IMAGE_REGISTRY=${IMAGE_REGISTRY,,}" >> "${GITHUB_ENV}" sudo apt-get update - sudo apt-get install -y --no-install-recommends \ - containernetworking-plugins \ - curl \ - jq \ - pigz \ - python3 + sudo apt-get install -y --no-install-recommends containernetworking-plugins - name: Check build recipes uses: ublue-os/just-action@30ab4659369934b65b655bf8d2fa4ddd6547d384 # v3 @@ -78,6 +112,8 @@ jobs: echo "tag=${tag}" >> "${GITHUB_OUTPUT}" - name: Build Armada image + env: + ARMADA_IMAGE_DIGEST: ${{ inputs.image_digest }} run: | set -euxo pipefail JUST_BIN=$(command -v just) @@ -85,13 +121,50 @@ jobs: # Build the disk FROM the published container so the disk and the ghcr # image are identical content and the installed system's bootc origin # points at ghcr (so OTA works). The Justfile pulls the ref for BIB. - sudo "${JUST_BIN}" build-armada-image "${IMAGE_REGISTRY}/${IMAGE_NAME}" "${{ steps.tag.outputs.tag }}" + sudo env PATH="${PATH}" ARMADA_IMAGE_DIGEST="${ARMADA_IMAGE_DIGEST}" \ + "${JUST_BIN}" build-armada-image "${IMAGE_REGISTRY}/${IMAGE_NAME}" "${{ steps.tag.outputs.tag }}" sudo chown -R "$(id -u):$(id -g)" output - IMG=$(find output -maxdepth 1 -name 'armada-*.img.gz' -type f -print -quit) - sha256sum "${IMG}" > "${IMG}.sha256" - ls -lh "${IMG}" "${IMG}.sha256" + + - name: Inspect disk source image + id: built_image + env: + EXPECTED_DIGEST: ${{ inputs.image_digest }} + CONTAINER_TAG: ${{ steps.tag.outputs.tag }} + PUBLISH_R2: ${{ inputs.publish_r2 }} + run: | + set -euo pipefail + inspection=$(sudo podman image inspect "${IMAGE_REGISTRY}/${IMAGE_NAME}:${CONTAINER_TAG}") + digest=$(jq -er '.[0].Digest' <<< "${inspection}") + if [ -n "${EXPECTED_DIGEST}" ] && [ "${digest}" != "${EXPECTED_DIGEST}" ]; then + echo "::error::Built image digest ${digest} does not match requested digest ${EXPECTED_DIGEST}." + exit 1 + fi + revision=$(jq -r '.[0].Config.Labels["org.opencontainers.image.revision"] // empty' <<< "${inspection}") + if [ "${PUBLISH_R2}" = true ] && ! [[ "${revision}" =~ ^[a-f0-9]{40}$ ]]; then + echo "::error::Preview container has no valid source revision label." + exit 1 + fi + echo "digest=${digest}" >> "${GITHUB_OUTPUT}" + echo "revision=${revision}" >> "${GITHUB_OUTPUT}" + + - name: Prepare disk image upload + id: disk + run: | + set -euo pipefail + shopt -s nullglob + images=(output/armada-*.img.gz) + if [ "${#images[@]}" -ne 1 ] || [ ! -s "${images[0]}" ]; then + echo "::error::Expected exactly one nonempty disk image in output/." + exit 1 + fi + image="${images[0]}" + filename="${image##*/}" + # Use the basename so sha256sum -c works beside the downloaded image. + (cd output && sha256sum "${filename}" > "${filename}.sha256") + echo "image=${image}" >> "${GITHUB_OUTPUT}" - name: Upload disk image + if: ${{ !inputs.publish_r2 }} uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: armada-disk-image @@ -102,3 +175,93 @@ jobs: retention-days: 1 compression-level: 0 overwrite: true + + - name: Publish disk image to R2 + id: publish + if: inputs.publish_r2 + env: + AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: auto + AWS_EC2_METADATA_DISABLED: "true" + AWS_REQUEST_CHECKSUM_CALCULATION: when_required + AWS_RESPONSE_CHECKSUM_VALIDATION: when_required + CONTAINER_TAG: ${{ steps.tag.outputs.tag }} + CONTAINER_DIGEST: ${{ steps.built_image.outputs.digest }} + BUILD_COMMIT: ${{ steps.built_image.outputs.revision }} + DISK_IMAGE: ${{ steps.disk.outputs.image }} + run: | + set -euo pipefail + image="${DISK_IMAGE}" + filename="${image##*/}" + prefix="${R2_PREFIX#/}" + prefix="${prefix%/}" + + require_current_preview() { + current=$(skopeo inspect --no-creds --override-arch arm64 --format '{{.Digest}}' \ + "docker://${IMAGE_REGISTRY}/${IMAGE_NAME}:testing") + if [ "${current}" != "${CONTAINER_DIGEST}" ]; then + echo "::error::Preview has advanced to ${current}; refusing to publish stale disk ${CONTAINER_DIGEST}." + exit 1 + fi + } + require_current_preview + + commit_title=$(git show -s --format=%s "${BUILD_COMMIT}") + # The high-level S3 command handles multipart uploads for large images. + aws configure set default.s3.multipart_chunksize 64MB + for file in "${image}" "${image}.sha256"; do + key="${prefix}/${file##*/}" + aws s3 cp "${file}" "s3://${R2_BUCKET}/${key}" \ + --endpoint-url "${R2_ENDPOINT_URL}" \ + --metadata armada-preview=true --cache-control no-store --only-show-errors + uploaded_size=$(aws s3api head-object \ + --endpoint-url "${R2_ENDPOINT_URL}" \ + --bucket "${R2_BUCKET}" --key "${key}" \ + --query ContentLength --output text) + if [ "${uploaded_size}" != "$(stat -c %s "${file}")" ]; then + echo "::error::Uploaded size does not match ${file##*/}." + exit 1 + fi + done + + require_current_preview + version="${filename#armada-}" + version="${version%.img.gz}" + read -r image_sha256 checksum_filename < "${image}.sha256" + jq -n \ + --arg version "${version}" \ + --arg published_at "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ + --arg build_commit "${BUILD_COMMIT}" \ + --arg build_commit_title "${commit_title}" \ + --arg container "${IMAGE_REGISTRY}/${IMAGE_NAME}:${CONTAINER_TAG}" \ + --arg digest "${CONTAINER_DIGEST}" \ + --arg filename "${filename}" \ + --arg key "${prefix}/${filename}" \ + --arg public_url "${R2_PUBLIC_URL%/}" \ + --arg sha256 "${image_sha256}" \ + --argjson size "$(stat -c %s "${image}")" \ + '{version: $version, + published_at: $published_at, build_commit: $build_commit, build_commit_title: $build_commit_title, + container: {reference: $container, digest: $digest}, + image: {filename: $filename, key: $key, url: ($public_url + "/" + $key), + size: $size, sha256: $sha256}, + checksum: {key: ($key + ".sha256"), url: ($public_url + "/" + $key + ".sha256")}}' \ + > output/current-build.json + python3 .github/scripts/publish-preview-index.py + + # Only advertise the download after both objects have been uploaded. + echo "image_key=${prefix}/${filename}" >> "${GITHUB_OUTPUT}" + echo "checksum_key=${prefix}/${filename}.sha256" >> "${GITHUB_OUTPUT}" + { + printf '### Disk image uploaded to R2\n\n' + printf 'Container: `%s/%s:%s`\n\n' "${IMAGE_REGISTRY}" "${IMAGE_NAME}" "${CONTAINER_TAG}" + printf 'Image: `s3://%s/%s/%s`\n\n' "${R2_BUCKET}" "${prefix}" "${filename}" + printf 'Checksum: `s3://%s/%s/%s.sha256`\n\n' "${R2_BUCKET}" "${prefix}" "${filename}" + if [ -n "${R2_PUBLIC_URL}" ]; then + printf '[Download image](%s/%s/%s) · [SHA-256](%s/%s/%s.sha256)\n' \ + "${R2_PUBLIC_URL%/}" "${prefix}" "${filename}" \ + "${R2_PUBLIC_URL%/}" "${prefix}" "${filename}" + printf '\n[Preview builds](%s/%s/builds.json)\n' "${R2_PUBLIC_URL%/}" "${prefix}" + fi + } >> "${GITHUB_STEP_SUMMARY}" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..ff5f9782 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,308 @@ +--- +name: Build container image +on: + pull_request: + branches: + - main + push: + branches: + - main + paths-ignore: + - '**/README.md' + workflow_dispatch: + inputs: + branch: + description: "Branch to build. Leave empty to use the workflow ref." + type: string + default: "" + +env: + ARMADA_CANONICAL_IMAGE: "ghcr.io/armada-os/armada" + ARMADA_LEGACY_IMAGE: "ghcr.io/virtudude/armada" + BASE_IMAGE: "quay.io/fedora/fedora-bootc:44" + IMAGE_DESC: "Armada: a gaming-focused, SteamOS-like Fedora bootc image for ARM64 handhelds" + IMAGE_NAME: "${{ github.event.repository.name }}" + IMAGE_REGISTRY: "ghcr.io/${{ github.repository_owner }}" + # Every merge to main publishes the "testing" channel; beta/stable are made by + # promoting (retagging) a testing build via promote.yml — no rebuild. + DEFAULT_TAG: "testing" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref || github.run_id }}-${{ inputs.branch }} + cancel-in-progress: false + +jobs: + build_push: + name: Build and push image + runs-on: ubuntu-24.04-arm + + permissions: + contents: read + packages: write + id-token: write + + steps: + - name: Prepare environment + run: | + echo "IMAGE_REGISTRY=${IMAGE_REGISTRY,,}" >> ${GITHUB_ENV} + echo "IMAGE_NAME=${IMAGE_NAME,,}" >> ${GITHUB_ENV} + + - name: Resolve manual build ref + id: manual + if: github.event_name == 'workflow_dispatch' + env: + INPUT_BRANCH: ${{ inputs.branch }} + run: | + set -euo pipefail + branch="${INPUT_BRANCH}" + if [ -z "${branch}" ]; then + exit 0 + fi + branch="${branch#refs/heads/}" + if ! [[ "${branch}" =~ ^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$ ]]; then + echo "::error::Branch '${branch}' cannot be used as a matching container tag. Use letters, numbers, dots, underscores, or dashes." + exit 1 + fi + + echo "branch=${branch}" >> "${GITHUB_OUTPUT}" + + - name: Require main for Preview publication + if: github.event_name != 'pull_request' + env: + PUBLISH_TAG: ${{ steps.manual.outputs.branch || env.DEFAULT_TAG }} + BUILD_BRANCH: ${{ steps.manual.outputs.branch || github.ref_name }} + run: | + if [ "${PUBLISH_TAG}" = testing ] && [ "${BUILD_BRANCH}" != main ]; then + echo "::error::Preview must be built from main. Use an explicit branch tag for other builds." + exit 1 + fi + + - name: Ensure container tools + run: | + set -euxo pipefail + # ubuntu-24.04 dropped these from the runner image; the build action, + # validation, and push all need them. + need="" + for t in buildah jq skopeo; do + command -v "$t" >/dev/null || need="$need $t" + done + [ -z "$need" ] || { sudo apt-get update && sudo apt-get install -y $need; } + + - name: Require signing key before publishing a channel + if: github.event_name != 'pull_request' + run: | + if [ -z "${{ secrets.SIGNING_SECRET }}" ]; then + echo "::error::SIGNING_SECRET is not set — refusing to publish an unsigned image (devices verify ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }})." + exit 1 + fi + + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ steps.manual.outputs.branch || github.ref }} + + - name: Check build recipes + uses: ublue-os/just-action@30ab4659369934b65b655bf8d2fa4ddd6547d384 # v3 + + - name: Get image version + id: version + run: | + echo "created=$(date -u +%Y\-%m\-%d\T%H\:%M\:%S\Z)" >> $GITHUB_OUTPUT + echo "version=$(TZ=America/New_York date +%Y%m%d).$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + - name: Image Metadata + uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0 + id: metadata + with: + tags: | + type=raw,value=${{ steps.manual.outputs.branch || env.DEFAULT_TAG }} + type=sha,enable=${{ github.event_name == 'pull_request' }} + type=ref,event=pr + labels: | + org.opencontainers.image.created=${{ steps.version.outputs.created }} + org.opencontainers.image.description=${{ env.IMAGE_DESC }} + org.opencontainers.image.documentation=https://raw.githubusercontent.com/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}/${{ github.sha }}/README.md + org.opencontainers.image.licenses=GPL-2.0-or-later + org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}/blob/${{ github.sha }}/Containerfile + org.opencontainers.image.title=${{ env.IMAGE_NAME }} + org.opencontainers.image.url=https://github.com/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}/tree/${{ github.sha }} + org.opencontainers.image.vendor=${{ github.repository_owner }} + org.opencontainers.image.version=${{ steps.version.outputs.version }} + containers.bootc=1 + sep-tags: " " + sep-annotations: " " + + - name: Prepare Chunkah config + id: chunkah_config + env: + METADATA_JSON: ${{ steps.metadata.outputs.json }} + run: | + set -euo pipefail + base_digest=$(skopeo inspect --override-arch arm64 --format '{{.Digest}}' \ + "docker://${BASE_IMAGE}") + base_image="${BASE_IMAGE%:*}@${base_digest}" + config=$(skopeo inspect --override-arch arm64 --config \ + "docker://${base_image}" | + jq -c --argjson metadata "${METADATA_JSON}" ' + .config | + .Labels = ((.Labels // {}) + ($metadata.labels // {})) | + del(.Labels["ostree.commit"]) | + del(.Labels["ostree.final-diffid"])') + printf '%s\n' "${config}" > "${RUNNER_TEMP}/chunkah-config.json" + echo "base_image=${base_image}" >> "${GITHUB_OUTPUT}" + echo "config=${config}" >> "${GITHUB_OUTPUT}" + + - name: Require native OverlayFS + run: | + set -euxo pipefail + buildah info --storage-opt=overlay.mount_program= | + jq -e '.store.GraphStatus["Native Overlay Diff"] == "true"' + + - name: Build Image + id: build_image + uses: redhat-actions/buildah-build@5d8479758cc72ed82df28daba521d27e20ff8c8a # v3.0.0 + with: + containerfiles: | + ./Containerfile + image: ${{ env.IMAGE_NAME }} + tags: build-output + labels: ${{ steps.metadata.outputs.labels }} + build-args: | + ARMADA_VERSION=${{ steps.version.outputs.version }} + BASE_IMAGE=${{ steps.chunkah_config.outputs.base_image }} + CHUNKAH_CONFIG_STR=${{ steps.chunkah_config.outputs.config }} + # armada-rootfs is consumed through RUN --mount, so retain otherwise-unused stages. + extra-args: | + --skip-unused-stages=false + --target=chunkah + --volume=${{ runner.temp }}:/run/src + --security-opt=label=disable + --storage-opt=overlay.mount_program= + oci: false + + - name: Validate Chunkah output + id: chunkah_output + run: | + set -euxo pipefail + CHUNKAH_LOG_FILE="${RUNNER_TEMP}/chunkah.log" + CHUNKAH_MANIFEST_FILE="${RUNNER_TEMP}/chunkah-manifest.json" + CHUNKAH_IMAGE_CONFIG_FILE="${RUNNER_TEMP}/chunkah-image-config.json" + for component in steam proton fex-rootfs; do + if ! grep -Eq "creating tar layer .*\"xattr/${component}\"" "${CHUNKAH_LOG_FILE}"; then + echo "::error::Chunkah did not emit an xattr/${component} component layer" + exit 1 + fi + done + + CHUNKED_REF="oci:${RUNNER_TEMP}/chunked" + skopeo inspect --raw "${CHUNKED_REF}" > "${CHUNKAH_MANIFEST_FILE}" + jq -e '(.layers | length) > 1 and (.layers | length) <= 128' \ + "${CHUNKAH_MANIFEST_FILE}" || { + echo "::error::Chunkah output has an invalid layer count" + exit 1 + } + jq -e '((.annotations // {}) | has("ostree.commit") | not) and + ((.annotations // {}) | has("ostree.final-diffid") | not)' \ + "${CHUNKAH_MANIFEST_FILE}" || { + echo "::error::Chunkah output retained OSTree manifest annotations" + exit 1 + } + skopeo inspect --config "${CHUNKED_REF}" > "${CHUNKAH_IMAGE_CONFIG_FILE}" + jq -e --slurpfile expected "${RUNNER_TEMP}/chunkah-config.json" \ + '.config == $expected[0]' "${CHUNKAH_IMAGE_CONFIG_FILE}" || { + echo "::error::Chunkah output did not preserve the prepared runtime config" + exit 1 + } + jq -e '.architecture == "arm64" and .os == "linux" and + .config.Cmd == ["/sbin/init"] and + .config.Labels["containers.bootc"] == "1" and + .config.Labels["ostree.bootable"] == "true" and + (.config.Labels | has("ostree.commit") | not) and + (.config.Labels | has("ostree.final-diffid") | not)' \ + "${CHUNKAH_IMAGE_CONFIG_FILE}" + python3 build_files/verify-steam-bootstrap.py --oci "${RUNNER_TEMP}/chunked" + echo "Steam bootstrap manifest verified in Chunkah output" + jq '{layers: (.layers | length), compressed_bytes: ([.layers[].size] | add)}' \ + "${CHUNKAH_MANIFEST_FILE}" + echo "ref=${CHUNKED_REF}" >> "${GITHUB_OUTPUT}" + + - name: Push to GHCR + id: push + if: github.event_name != 'pull_request' + run: | + set -euxo pipefail + echo "${{ secrets.GITHUB_TOKEN }}" | skopeo login ghcr.io -u "${{ github.actor }}" --password-stdin + IMAGE_FULL="${IMAGE_REGISTRY}/${IMAGE_NAME}" + BUILD_TAG="build-${{ steps.version.outputs.version }}-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}" + n=0 + until skopeo copy --all \ + "${{ steps.chunkah_output.outputs.ref }}" "docker://${IMAGE_FULL}:${BUILD_TAG}"; do + n=$((n + 1)); [ "${n}" -ge 3 ] && exit 1; sleep 15 + done + digest=$(skopeo inspect --format '{{.Digest}}' "docker://${IMAGE_FULL}:${BUILD_TAG}") + echo "digest=${digest}" >> "${GITHUB_OUTPUT}" + + - name: Install Cosign + uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2 + if: github.event_name != 'pull_request' && env.HAVE_SIGNING_SECRET == 'true' + env: + HAVE_SIGNING_SECRET: ${{ secrets.SIGNING_SECRET != '' }} + with: + cosign-release: 'v2.6.3' + + - name: Sign container image + if: github.event_name != 'pull_request' && env.HAVE_SIGNING_SECRET == 'true' + run: | + set -euo pipefail + IMAGE_FULL="${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}" + IMAGE_REF="${IMAGE_FULL}@${{ steps.push.outputs.digest }}" + # Cosign and Skopeo use separate registry auth stores. + echo "${{ secrets.GITHUB_TOKEN }}" | cosign login ghcr.io -u "${{ github.actor }}" --password-stdin + # Sign the digest, not a tag (a concurrent run could re-point the tag). + # --new-bundle-format=false: bootc's verifier expects the legacy .sig; the + # default flips in cosign v3. + cosign sign -y --new-bundle-format=false --key env://COSIGN_PRIVATE_KEY "${IMAGE_REF}" + + # Legacy-hosted images also need the canonical identity required by bridge policy. + if [ "${IMAGE_FULL}" = "${ARMADA_LEGACY_IMAGE}" ]; then + cosign sign -y --new-bundle-format=false \ + --key env://COSIGN_PRIVATE_KEY \ + --sign-container-identity "${ARMADA_CANONICAL_IMAGE}" \ + "${IMAGE_REF}" + fi + + if [ "${{ github.event.repository.fork }}" != "true" ]; then + cosign verify --key system_files/etc/pki/containers/armada.pub "${IMAGE_REF}" + if [ "${IMAGE_FULL}" = "${ARMADA_LEGACY_IMAGE}" ]; then + cosign verify --check-claims=false \ + --key system_files/etc/pki/containers/armada.pub \ + "${IMAGE_REF}" | + jq -s -e --arg identity "${ARMADA_CANONICAL_IMAGE}" \ + 'any(.. | objects; .critical?.identity?["docker-reference"]? == $identity)' + fi + fi + env: + HAVE_SIGNING_SECRET: ${{ secrets.SIGNING_SECRET != '' }} + TAGS: ${{ steps.push.outputs.digest }} + COSIGN_EXPERIMENTAL: false + COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }} + + - name: Publish channel tags + if: github.event_name != 'pull_request' && env.HAVE_SIGNING_SECRET == 'true' + run: | + set -euo pipefail + IMAGE_FULL="${IMAGE_REGISTRY}/${IMAGE_NAME}" + SRC="docker://${IMAGE_FULL}@${{ steps.push.outputs.digest }}" + for tag in ${{ steps.metadata.outputs.tags }}; do + n=0 + until skopeo copy --all "${SRC}" "docker://${IMAGE_FULL}:${tag}"; do + n=$((n + 1)); [ "${n}" -ge 3 ] && exit 1; sleep 15 + done + tag_digest=$(skopeo inspect --format '{{.Digest}}' "docker://${IMAGE_FULL}:${tag}") + if [ "${tag_digest}" != "${{ steps.push.outputs.digest }}" ]; then + echo "::error::${tag} resolved to ${tag_digest}, not the signed digest ${{ steps.push.outputs.digest }}" + exit 1 + fi + done + env: + HAVE_SIGNING_SECRET: ${{ secrets.SIGNING_SECRET != '' }} diff --git a/.github/workflows/publish-preview-disk.yml b/.github/workflows/publish-preview-disk.yml new file mode 100644 index 00000000..16360d99 --- /dev/null +++ b/.github/workflows/publish-preview-disk.yml @@ -0,0 +1,54 @@ +--- +name: Publish Preview disk image + +on: + workflow_dispatch: + workflow_run: + workflows: [Build container image] + types: [completed] + branches: [main] + +permissions: + contents: read + packages: read + +jobs: + resolve: + name: Resolve Preview container + if: >- + (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main') || + (github.event.workflow_run.conclusion == 'success' && + github.event.workflow_run.head_repository.full_name == github.repository && + contains(fromJSON('["push", "workflow_dispatch"]'), github.event.workflow_run.event)) + runs-on: ubuntu-24.04-arm + outputs: + image_digest: ${{ steps.source.outputs.image_digest }} + source_ref: ${{ steps.source.outputs.source_ref }} + steps: + - name: Resolve Preview source + id: source + run: | + set -euo pipefail + image="ghcr.io/${GITHUB_REPOSITORY,,}:testing" + inspection=$(skopeo inspect --override-arch arm64 "docker://${image}") + digest=$(jq -er '.Digest' <<< "${inspection}") + revision=$(jq -er '.Labels["org.opencontainers.image.revision"]' <<< "${inspection}") + if ! [[ "${digest}" =~ ^sha256:[a-f0-9]{64}$ && "${revision}" =~ ^[a-f0-9]{40}$ ]]; then + echo "::error::Preview container has an invalid digest or source revision." + exit 1 + fi + echo "image_digest=${digest}" >> "${GITHUB_OUTPUT}" + echo "source_ref=${revision}" >> "${GITHUB_OUTPUT}" + + publish: + name: Publish preview image + needs: resolve + uses: ./.github/workflows/build-disk.yml + with: + tag: testing + publish_r2: true + image_digest: ${{ needs.resolve.outputs.image_digest }} + source_ref: ${{ needs.resolve.outputs.source_ref }} + secrets: + R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }} + R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} diff --git a/Containerfile b/Containerfile index 542e4f59..eebb2414 100644 --- a/Containerfile +++ b/Containerfile @@ -1,25 +1,27 @@ +ARG STEAM_BOOTSTRAP_PKG=ghcr.io/armada-os/armada-packages/steam-bootstrap@sha256:58609299e384dfea2ef1ed3a000c323145dd74c2c9c15051007d7b5522bf1d43 ARG FEX_PKG=ghcr.io/armada-os/armada-packages/fex@sha256:277a25328499761e570bfb1f7fdce44b29dee074d76462402b0d8c361dacdffc -ARG MESA_PKG=ghcr.io/armada-os/armada-packages/mesa@sha256:559c976d78bcc771f574c18d8fed5debcc3b8856a0ff448e968940480bca1165 -ARG MESA_ANDROID_PKG=ghcr.io/armada-os/armada-packages/mesa-android@sha256:1e7d5f5e692c38b7545e0c0774bbee45ab1b634309d9240f0e08b407b3fcc526 -ARG MESA_X86_PKG=ghcr.io/armada-os/armada-packages/mesa-x86@sha256:f891d7fc16daf816d68c602655336e5cae1aae8b0aa3e1ef47a6215e4c4b11e5 +ARG MESA_PKG=ghcr.io/armada-os/armada-packages/mesa@sha256:c86f49047950fa64167f1fe48431559ad90f9f69d2c275feffdcaf1ae15e5ee3 +ARG MESA_ANDROID_PKG=ghcr.io/armada-os/armada-packages/mesa-android@sha256:32f59a5a2d65ee6b65a968c1e579012c2262cc436b1d94cd6491bf2d7bdb5de3 +ARG MESA_X86_PKG=ghcr.io/armada-os/armada-packages/mesa-x86@sha256:e73a26770a56d8ca8249640f50358f6f0d23fa4a8c6562ac2c2eb5bc091e1a5f ARG MANGOHUD_PKG=ghcr.io/armada-os/armada-packages/mangohud@sha256:c68472ba185d91c25ef0d0cb7046058cedf5a86203ab5e073c6f21ec43694c7b ARG GAMESCOPE_PKG=ghcr.io/armada-os/armada-packages/gamescope@sha256:9550a0d0ed0034303c1dff1f6ca4e11bf88f7b3449acd2ed9a05cfd5fc87e9fd -ARG GAMESCOPE_SESSION_PKG=ghcr.io/armada-os/armada-packages/gamescope-session@sha256:f75cfa6fefd69ba9f8496fa0e528aee3bf489e71bde53acef8d02c3bd311f396 +ARG GAMESCOPE_SESSION_PKG=ghcr.io/armada-os/armada-packages/gamescope-session@sha256:2d789621b7fdf625fdb56c38b6705827503b7e6eb176aa065db466fd12399623 ARG GAMESCOPE_SESSION_STEAM_PKG=ghcr.io/armada-os/armada-packages/gamescope-session-steam@sha256:bd9abba8a51c5aad9dd8fb8b1ed4ecf55b7fd26268772658603d73953231a2cf ARG KWIN_PKG=ghcr.io/armada-os/armada-packages/kwin@sha256:515e14f78f19d2abd3f3b73915e260f4b26cf9a0f84dbe55a06bbcb5f9e8ddce ARG PLASMA_MOBILE_PKG=ghcr.io/armada-os/armada-packages/plasma-mobile@sha256:81c08a4ac34f1ffabdd59b89934cc858e47cf6dfe1f0390c0650e397b0919a30 ARG POWERDEVIL_PKG=ghcr.io/armada-os/armada-packages/powerdevil@sha256:86ad5666a0af470793f480895fb2cef49dc1184800e8445a64d475d0f0d9fe4a -ARG KERNEL_PKG=ghcr.io/armada-os/armada-packages/kernel@sha256:f1ecae210946e48924b7afffde2048d28c0e5c9f138d9e2f1cb2a1f940639b2a -ARG INPUTPLUMBER_PKG=ghcr.io/armada-os/armada-packages/inputplumber@sha256:894bcb70919f6182c1b1c3ada40c7389d0ffee4b92d9b7a7088a62f540503f6b +ARG KERNEL_PKG=ghcr.io/armada-os/armada-packages/kernel@sha256:2561854d1420c1ffe8f76d8dd8b7f1c73f85192437c46d28cb26cd2b878e9f71 +ARG INPUTPLUMBER_PKG=ghcr.io/armada-os/armada-packages/inputplumber@sha256:e0db9a76befc2c421446951aba0bfc902f22b1e32564e81cb5b7ac3085e4e949 ARG EXTEST_PKG=ghcr.io/armada-os/armada-packages/extest@sha256:13aee022b77eb9212be1debb74cd1d5a5c6ed94aa42bdac7e6b3a6e72e38101b ARG NETWORKMANAGER_PKG=ghcr.io/armada-os/armada-packages/networkmanager@sha256:cea22dd25c2d033ec14bc9154a87153ef8331ba725bde036dd7a05ad1430747d ARG JUPITER_HW_SUPPORT_PKG=ghcr.io/armada-os/armada-packages/jupiter-hw-support@sha256:efc0739700ede36ed08c894445973ce2b594c70a0ee487fd5cf209bc07c955ee ARG ARMADA_SPLASH_PKG=ghcr.io/armada-os/armada-packages/armada-splash@sha256:6b018ab61218ad5b760fc93b27f7f6af4af4fb6301cb1ed4711cd33ded8c0ea0 -ARG ARMADA_RGB_PKG=ghcr.io/armada-os/armada-packages/armada-rgb@sha256:a7b66324d7bf8030e260d5f2fc9074ad9ced7c47852187783f5e3e082d0ebc25 +ARG ARMADA_RGB_PKG=ghcr.io/armada-os/armada-packages/armada-rgb@sha256:269a0b19aee60cf6c0b31b2cee60e996115e912cd605f5e6204813eccfd57fe7 ARG UMTP_RESPONDER_PKG=ghcr.io/armada-os/armada-packages/umtp-responder@sha256:0e7f962145b72de85c2a3563d947c6357fc3a1a34797b7106cbff1c8832078ea ARG CHUNKAH_IMAGE=quay.io/coreos/chunkah@sha256:ff8b8b466a942ec6000445d4001fc661e2fc5a952ad9ee29b4de9ab09d1d1708 ARG BASE_IMAGE=quay.io/fedora/fedora-bootc:44 +FROM ${STEAM_BOOTSTRAP_PKG} AS steam-bootstrap FROM ${FEX_PKG} AS fex FROM ${MESA_PKG} AS mesa FROM ${MANGOHUD_PKG} AS mangohud @@ -63,6 +65,7 @@ ARG ARMADA_VERSION=unknown LABEL org.opencontainers.image.version="${ARMADA_VERSION}" RUN --mount=type=bind,from=ctx,source=/,target=/ctx \ + --mount=type=bind,from=steam-bootstrap,source=/steam-bootstrap,target=/packages/steam-bootstrap \ --mount=type=bind,from=fex,source=/rpms,target=/packages/fex \ --mount=type=bind,from=mesa,source=/rpms,target=/packages/mesa \ --mount=type=bind,from=mangohud,source=/rpms,target=/packages/mangohud \ diff --git a/Justfile b/Justfile index 1fd613f7..82b8b33a 100644 --- a/Justfile +++ b/Justfile @@ -128,6 +128,17 @@ _rootful_load_image $target_image=image_name $tag=default_tag: #!/usr/bin/bash set -eoux pipefail + if [[ -n "${ARMADA_IMAGE_DIGEST:-}" ]]; then + if ! [[ "${ARMADA_IMAGE_DIGEST}" =~ ^sha256:[a-f0-9]{64}$ ]]; then + echo "Invalid ARMADA_IMAGE_DIGEST: expected sha256 followed by 64 lowercase hex digits" >&2 + exit 1 + fi + just sudoif podman pull "${target_image}@${ARMADA_IMAGE_DIGEST}" + # Pin build content while keeping the installed system on its channel. + just sudoif podman tag "${target_image}@${ARMADA_IMAGE_DIGEST}" "${target_image}:${tag}" + exit 0 + fi + if [[ -n "${SUDO_USER:-}" || "${UID}" -eq "0" ]]; then # Always re-pull a remote tag so the disk uses the freshly published # image, not a stale cached one; localhost builds are already loaded. diff --git a/abl/README b/abl/README index a59e11fd..8ff356ca 100644 --- a/abl/README +++ b/abl/README @@ -5,9 +5,10 @@ From ROCKNIX (https://github.com/ROCKNIX/abl), GPL-2.0, (c) ROCKNIX contributors 2. Identify the SoC for your device (flashing the wrong ABL can brick the device, so match it carefully): - SM8250 - Retroid Pocket 5, Pocket Flip 2, Pocket Mini, Pocket Mini V2 + SM8250 - AYN Thor Lite + Retroid Pocket 5, Pocket Flip 2, Pocket Mini, Pocket Mini V2 SM8550 - AYN Odin 2, Odin 2 Mini, Odin 2 Portal, Thor - AYANEO Pocket EVO, ACE, DMG, DS, S 2K + AYANEO Pocket EVO, ACE, DMG, DS, S 1K/2K Retroid Pocket 6, Pocket Nova SM8650 - AYANEO Pocket S2 KONKR Pocket FIT (G3 Gen 3) diff --git a/audio_topology/README.md b/audio_topology/README.md new file mode 100644 index 00000000..53dd262b --- /dev/null +++ b/audio_topology/README.md @@ -0,0 +1,19 @@ +# Audio Topology + +Source files for Armada's Qualcomm AudioReach topology blobs. + +Only the generated topology blobs under the following directory are copied into +the firmware image; the `.m4` sources remain in this directory. + +```text +system_files/usr/lib/firmware/qcom/sm8750/ +``` + +To regenerate a topology using [audioreach-topology](https://git.codelinaro.org/linaro/qcomlt/audioreach-topology): + +```sh +m4 -I sm8750/SM8750-AYN.m4 > SM8750-AYN.conf +alsatplg -c SM8750-AYN.conf -o SM8750-AYN-tplg.bin +``` + +Replace the corresponding `-tplg.bin` in `system_files` after regeneration. diff --git a/audio_topology/sm8750/SM8750-AYN.m4 b/audio_topology/sm8750/SM8750-AYN.m4 new file mode 100644 index 00000000..596f40f4 --- /dev/null +++ b/audio_topology/sm8750/SM8750-AYN.m4 @@ -0,0 +1,59 @@ +# SPDX-License-Identifier: BSD-3-Clause +# AudioReach topology source for the AYN Odin 3 (SM8750). +# MultiMedia1-4 provide speakers, headphones, headset capture, and DisplayPort. +# DisplayPort uses a dedicated PCM so all outputs remain in one card profile. +include(`audioreach/audioreach.m4') +include(`audioreach/stream-subgraph.m4') +include(`audioreach/device-subgraph.m4') +include(`util/route.m4') +include(`util/mixer.m4') +include(`audioreach/tokens.m4') +dnl Playback MultiMedia1 +STREAM_SG_PCM_ADD(audioreach/subgraph-stream-vol-playback.m4, FRONTEND_DAI_MULTIMEDIA1, + `S16_LE', 48000, 48000, 2, 2, + 0x00004001, 0x00004001, 0x00006001, `110000') +dnl Playback MultiMedia2 +STREAM_SG_PCM_ADD(audioreach/subgraph-stream-vol-playback.m4, FRONTEND_DAI_MULTIMEDIA2, + `S16_LE', 48000, 48000, 2, 2, + 0x00004002, 0x00004002, 0x00006010, `110000') +dnl Capture MultiMedia3 +STREAM_SG_PCM_ADD(audioreach/subgraph-stream-capture.m4, FRONTEND_DAI_MULTIMEDIA3, + `S16_LE', 48000, 48000, 1, 2, + 0x00004003, 0x00004003, 0x00006020, `110000') +dnl Playback MultiMedia4, feeds the DisplayPort backend only +STREAM_SG_PCM_ADD(audioreach/subgraph-stream-vol-playback.m4, FRONTEND_DAI_MULTIMEDIA4, + `S16_LE', 48000, 48000, 2, 2, + 0x00004004, 0x00004004, 0x00006030, `110000') +dnl Speaker amps: 2x AW88261 on SECONDARY MI2S. +DEVICE_SG_ADD(audioreach/subgraph-device-i2s-playback.m4, `Secondary', SECONDARY_MI2S_RX, + `S16_LE', 48000, 48000, 2, 2, + LPAIF_INTF_TYPE_LPAIF, I2S_INTF_TYPE_SECONDARY, SD_LINE_IDX_I2S_SD0, DATA_FORMAT_FIXED_POINT, + 0x00004005, 0x00004005, 0x00006050, `SECONDARY_MI2S_RX') +dnl WCD939x playback (headphones) +DEVICE_SG_ADD(audioreach/subgraph-device-codec-dma-playback.m4, `RX_CODEC_DMA_RX_0', RX_CODEC_DMA_RX_0, + `S16_LE', 48000, 48000, 2, 2, + LPAIF_INTF_TYPE_RXTX, CODEC_INTF_IDX_RX0, 0, DATA_FORMAT_FIXED_POINT, + 0x00004007, 0x00004007, 0x00006070) +dnl WCD939x capture (headset mic) +DEVICE_SG_ADD(audioreach/subgraph-device-codec-dma-capture.m4, `TX_CODEC_DMA_TX_3', TX_CODEC_DMA_TX_3, + `S16_LE', 48000, 48000, 1, 2, + LPAIF_INTF_TYPE_RXTX, CODEC_INTF_IDX_TX3, 0, DATA_FORMAT_FIXED_POINT, + 0x00004009, 0x00004009, 0x00006090) +dnl DisplayPort over USB-C, fed from MultiMedia4. The DP sink module needs no +dnl interface index, the stream picks its DPTX from the dai id +dnl (DISPLAY_PORT_RX_0 = dai 104). +DEVICE_SG_ADD(audioreach/subgraph-device-display-port-playback.m4, `DISPLAY_PORT_RX_0', DISPLAY_PORT_RX_0, + `S16_LE', 48000, 48000, 2, 2, + 0, 0, 0, DATA_FORMAT_FIXED_POINT, + 0x00004008, 0x00004008, 0x00006080, `DISPLAY_PORT_RX_0') + +STREAM_DEVICE_PLAYBACK_MIXER(SECONDARY_MI2S_RX, ``SECONDARY_MI2S_RX'', ``MultiMedia1'', ``MultiMedia2'') +STREAM_DEVICE_PLAYBACK_MIXER(RX_CODEC_DMA_RX_0, ``RX_CODEC_DMA_RX_0'', ``MultiMedia1'', ``MultiMedia2'') +STREAM_DEVICE_PLAYBACK_MIXER(DISPLAY_PORT_RX_0, ``DISPLAY_PORT_RX_0'', ``MultiMedia4'') + +STREAM_DEVICE_PLAYBACK_ROUTE(SECONDARY_MI2S_RX, ``SECONDARY_MI2S_RX Audio Mixer'', ``MultiMedia1, stream0.logger1'', ``MultiMedia2, stream1.logger1'') +STREAM_DEVICE_PLAYBACK_ROUTE(RX_CODEC_DMA_RX_0, ``RX_CODEC_DMA_RX_0 Audio Mixer'', ``MultiMedia1, stream0.logger1'', ``MultiMedia2, stream1.logger1'') +STREAM_DEVICE_PLAYBACK_ROUTE(DISPLAY_PORT_RX_0, ``DISPLAY_PORT_RX_0 Audio Mixer'', ``MultiMedia4, stream3.logger1'') + +STREAM_DEVICE_CAPTURE_MIXER(FRONTEND_DAI_MULTIMEDIA3, ``TX_CODEC_DMA_TX_3'') +STREAM_DEVICE_CAPTURE_ROUTE(FRONTEND_DAI_MULTIMEDIA3, ``MultiMedia3 Mixer'', ``TX_CODEC_DMA_TX_3, device120.logger1'') diff --git a/audio_topology/sm8750/SM8750-KONKR.m4 b/audio_topology/sm8750/SM8750-KONKR.m4 new file mode 100644 index 00000000..796cee34 --- /dev/null +++ b/audio_topology/sm8750/SM8750-KONKR.m4 @@ -0,0 +1,60 @@ +# SPDX-License-Identifier: BSD-3-Clause +# AudioReach topology source for the KONKR Pocket FIT Elite (SM8750). +# MultiMedia1-4 provide speakers, headphones, headset capture, and DisplayPort. +# DisplayPort uses a dedicated PCM so all outputs remain in one card profile. +include(`audioreach/audioreach.m4') +include(`audioreach/stream-subgraph.m4') +include(`audioreach/device-subgraph.m4') +include(`util/route.m4') +include(`util/mixer.m4') +include(`audioreach/tokens.m4') +dnl Playback MultiMedia1 +STREAM_SG_PCM_ADD(audioreach/subgraph-stream-vol-playback.m4, FRONTEND_DAI_MULTIMEDIA1, + `S16_LE', 48000, 48000, 2, 2, + 0x00004001, 0x00004001, 0x00006001, `110000') +dnl Playback MultiMedia2 +STREAM_SG_PCM_ADD(audioreach/subgraph-stream-vol-playback.m4, FRONTEND_DAI_MULTIMEDIA2, + `S16_LE', 48000, 48000, 2, 2, + 0x00004002, 0x00004002, 0x00006010, `110000') +dnl Capture MultiMedia3 +STREAM_SG_PCM_ADD(audioreach/subgraph-stream-capture.m4, FRONTEND_DAI_MULTIMEDIA3, + `S16_LE', 48000, 48000, 1, 2, + 0x00004003, 0x00004003, 0x00006020, `110000') +dnl Playback MultiMedia4, feeds the DisplayPort backend only +STREAM_SG_PCM_ADD(audioreach/subgraph-stream-vol-playback.m4, FRONTEND_DAI_MULTIMEDIA4, + `S16_LE', 48000, 48000, 2, 2, + 0x00004004, 0x00004004, 0x00006030, `110000') +dnl Speaker amps: 2x AW88261 on SECONDARY MI2S. The populated amps are the +dnl stock quad-design's ch2/ch3, so the DSP has to drive data1 = SD1. +DEVICE_SG_ADD(audioreach/subgraph-device-i2s-playback.m4, `Secondary', SECONDARY_MI2S_RX, + `S16_LE', 48000, 48000, 2, 2, + LPAIF_INTF_TYPE_LPAIF, I2S_INTF_TYPE_SECONDARY, SD_LINE_IDX_I2S_SD1, DATA_FORMAT_FIXED_POINT, + 0x00004005, 0x00004005, 0x00006050, `SECONDARY_MI2S_RX') +dnl WCD939x playback (headphones) +DEVICE_SG_ADD(audioreach/subgraph-device-codec-dma-playback.m4, `RX_CODEC_DMA_RX_0', RX_CODEC_DMA_RX_0, + `S16_LE', 48000, 48000, 2, 2, + LPAIF_INTF_TYPE_RXTX, CODEC_INTF_IDX_RX0, 0, DATA_FORMAT_FIXED_POINT, + 0x00004007, 0x00004007, 0x00006070) +dnl WCD939x capture (headset mic) +DEVICE_SG_ADD(audioreach/subgraph-device-codec-dma-capture.m4, `TX_CODEC_DMA_TX_3', TX_CODEC_DMA_TX_3, + `S16_LE', 48000, 48000, 1, 2, + LPAIF_INTF_TYPE_RXTX, CODEC_INTF_IDX_TX3, 0, DATA_FORMAT_FIXED_POINT, + 0x00004009, 0x00004009, 0x00006090) +dnl DisplayPort over USB-C, fed from MultiMedia4. The DP sink module needs no +dnl interface index, the stream picks its DPTX from the dai id +dnl (DISPLAY_PORT_RX_0 = dai 104). +DEVICE_SG_ADD(audioreach/subgraph-device-display-port-playback.m4, `DISPLAY_PORT_RX_0', DISPLAY_PORT_RX_0, + `S16_LE', 48000, 48000, 2, 2, + 0, 0, 0, DATA_FORMAT_FIXED_POINT, + 0x00004008, 0x00004008, 0x00006080, `DISPLAY_PORT_RX_0') + +STREAM_DEVICE_PLAYBACK_MIXER(SECONDARY_MI2S_RX, ``SECONDARY_MI2S_RX'', ``MultiMedia1'', ``MultiMedia2'') +STREAM_DEVICE_PLAYBACK_MIXER(RX_CODEC_DMA_RX_0, ``RX_CODEC_DMA_RX_0'', ``MultiMedia1'', ``MultiMedia2'') +STREAM_DEVICE_PLAYBACK_MIXER(DISPLAY_PORT_RX_0, ``DISPLAY_PORT_RX_0'', ``MultiMedia4'') + +STREAM_DEVICE_PLAYBACK_ROUTE(SECONDARY_MI2S_RX, ``SECONDARY_MI2S_RX Audio Mixer'', ``MultiMedia1, stream0.logger1'', ``MultiMedia2, stream1.logger1'') +STREAM_DEVICE_PLAYBACK_ROUTE(RX_CODEC_DMA_RX_0, ``RX_CODEC_DMA_RX_0 Audio Mixer'', ``MultiMedia1, stream0.logger1'', ``MultiMedia2, stream1.logger1'') +STREAM_DEVICE_PLAYBACK_ROUTE(DISPLAY_PORT_RX_0, ``DISPLAY_PORT_RX_0 Audio Mixer'', ``MultiMedia4, stream3.logger1'') + +STREAM_DEVICE_CAPTURE_MIXER(FRONTEND_DAI_MULTIMEDIA3, ``TX_CODEC_DMA_TX_3'') +STREAM_DEVICE_CAPTURE_ROUTE(FRONTEND_DAI_MULTIMEDIA3, ``MultiMedia3 Mixer'', ``TX_CODEC_DMA_TX_3, device120.logger1'') diff --git a/build_files/30-install-steam-session.sh b/build_files/30-install-steam-session.sh index 58d4d0d2..dacf2008 100755 --- a/build_files/30-install-steam-session.sh +++ b/build_files/30-install-steam-session.sh @@ -15,8 +15,7 @@ dnf5 -y install --setopt=install_weak_deps=False \ gamemode \ gtk2 \ openal-soft \ - xorg-x11-server-Xwayland \ - xorg-x11-server-Xvfb + xorg-x11-server-Xwayland # Patched InputPlumber: dpad signed-axis fix dnf5 -y install --setopt=install_weak_deps=False /packages/inputplumber/inputplumber-*.rpm @@ -95,7 +94,12 @@ EOF STEAM_BOOTSTRAP_HOME=/var/home/armada STEAM_HOME="${STEAM_BOOTSTRAP_HOME}/.local/share/Steam" -STEAM_BOOTSTRAP_HOME="${STEAM_BOOTSTRAP_HOME}" bash /ctx/build_files/generate-steam-bootstrap.sh +(cd /packages/steam-bootstrap && sha256sum -c steam-bootstrap.tar.zst.sha256) +rm -rf "${STEAM_BOOTSTRAP_HOME}" +mkdir -p "${STEAM_BOOTSTRAP_HOME}" +tar --zstd -xf /packages/steam-bootstrap/steam-bootstrap.tar.zst -C "${STEAM_BOOTSTRAP_HOME}" +python3 /ctx/build_files/verify-steam-bootstrap.py \ + "${STEAM_HOME}/package/steam_client_steamdeck_publicbeta_linuxarm64.installed" "${STEAM_HOME}" rm -f /etc/steamos-oobe-image PROTON_VER="11.0-20260703-slr" diff --git a/build_files/40-vendor-system-files.sh b/build_files/40-vendor-system-files.sh index 45a5b654..4606ae3a 100755 --- a/build_files/40-vendor-system-files.sh +++ b/build_files/40-vendor-system-files.sh @@ -105,6 +105,7 @@ systemctl enable armada-steamos-manager.service systemctl --global enable armada-steamos-manager.service systemctl enable armada-bootimg-sync.service systemctl enable armada-esp-rename.service +systemctl enable armada-boot-hotkeys.service systemctl enable armada-flatpak-setup.service systemctl enable armada-waydroid-input.path systemctl enable armada-splash-stall.service diff --git a/build_files/generate-steam-bootstrap.sh b/build_files/generate-steam-bootstrap.sh deleted file mode 100755 index 4c80f153..00000000 --- a/build_files/generate-steam-bootstrap.sh +++ /dev/null @@ -1,197 +0,0 @@ -#!/bin/bash -set -euxo pipefail - -if [[ "$(uname -m)" != "aarch64" ]]; then - echo "ERROR: ARM Steam bootstrap must be generated on aarch64" >&2 - exit 1 -fi - -STEAM_BOOTSTRAP_HOME="${STEAM_BOOTSTRAP_HOME:-/var/lib/armada/steam-bootstrap-home}" -STEAM="${STEAM_BOOTSTRAP_HOME}/.local/share/Steam" -DOT_STEAM="${STEAM_BOOTSTRAP_HOME}/.steam" -STEAM_ARM_RUNTIME_BASE="https://repo.steampowered.com/steamrt3c/images" -STEAM_ARM_RUNTIME_CHANNEL="${STEAM_ARM_RUNTIME_CHANNEL:-latest-public-beta}" -STEAM_ARM_RUNTIME_SNAPSHOT="${STEAM_ARM_RUNTIME_SNAPSHOT:-$(curl -fsSL "${STEAM_ARM_RUNTIME_BASE}/${STEAM_ARM_RUNTIME_CHANNEL}.txt" | tr -d '[:space:]')}" -[[ -n "${STEAM_ARM_RUNTIME_SNAPSHOT}" ]] || { echo "ERROR: could not resolve ${STEAM_ARM_RUNTIME_CHANNEL} to a steamrt3c snapshot" >&2; exit 1; } -STEAM_ARM_RUNTIME_URL="${STEAM_ARM_RUNTIME_BASE}/${STEAM_ARM_RUNTIME_SNAPSHOT}/steam-runtime-steamrt-arm64.tar.xz" -STEAM_ARM_CHANNEL="steamdeck_publicbeta" -STEAM_ARM_CDN="https://client-update.steamstatic.com" -STEAM_ARM_MANIFEST_NAME="steam_client_${STEAM_ARM_CHANNEL}_linuxarm64" -STEAM_ARM_MANIFEST_URL="${STEAM_ARM_CDN}/${STEAM_ARM_MANIFEST_NAME}" -STEAM_BOOTSTRAP_TIMEOUT="${STEAM_BOOTSTRAP_TIMEOUT:-900}" -script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" - -rm -rf "${STEAM_BOOTSTRAP_HOME}" -mkdir -p "${STEAM}/package" "${DOT_STEAM}" - -echo "${STEAM_ARM_CHANNEL}" > "${STEAM}/package/beta" -ln -sfn ../.local/share/Steam "${DOT_STEAM}/steam" -ln -sfn ../.local/share/Steam "${DOT_STEAM}/root" -ln -sfn ../.local/share/Steam/linux32 "${DOT_STEAM}/sdk32" -ln -sfn ../.local/share/Steam/linux64 "${DOT_STEAM}/sdk64" -ln -sfn ../.local/share/Steam/linuxarm64 "${DOT_STEAM}/sdkarm64" -ln -sfn ../.local/share/Steam/ubuntu12_32 "${DOT_STEAM}/bin32" -ln -sfn ../.local/share/Steam/ubuntu12_64 "${DOT_STEAM}/bin64" - -steam_manifest="${STEAM}/package/${STEAM_ARM_MANIFEST_NAME}.manifest" -curl -fsSL -o "${steam_manifest}" "${STEAM_ARM_MANIFEST_URL}" - -steam_seed_package=$( - python3 - "${steam_manifest}" <<'PY' -import pathlib -import re -import sys - -manifest = pathlib.Path(sys.argv[1]).read_text(errors="ignore") -match = re.search(r'bins_linuxarm64_linuxarm64\.zip\.(?!vz\.)[^"\s]+', manifest) -if not match: - raise SystemExit("failed to find ARM64 Steam seed package") -print(match.group(0)) -PY -) - -curl -fsSL -o "${STEAM}/package/${steam_seed_package}" \ - "${STEAM_ARM_CDN}/${steam_seed_package}" -unzip -q -o "${STEAM}/package/${steam_seed_package}" -d "${STEAM}" - -python3 - "${STEAM}/package/${steam_seed_package}" "${STEAM}" <<'PY' -import os -import pathlib -import stat -import subprocess -import sys -import zipfile - -archive = pathlib.Path(sys.argv[1]) -steam = pathlib.Path(sys.argv[2]) - -with zipfile.ZipFile(archive) as zf: - names = [info.filename for info in zf.infolist() if not info.is_dir()] - -for name in names: - path = (steam / name).resolve() - if not path.is_relative_to(steam.resolve()) or not path.is_file(): - continue - result = subprocess.run( - ["file", "-b", str(path)], - check=False, - text=True, - stdout=subprocess.PIPE, - ) - if "interpreter /lib/ld-linux" not in result.stdout and not result.stdout.startswith( - ("POSIX shell script", "Python script") - ): - continue - mode = path.stat().st_mode - os.chmod(path, mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) -PY - -curl -fsSL -o /tmp/steam-runtime-steamrt-arm64.tar.xz "${STEAM_ARM_RUNTIME_URL}" -tar -xJf /tmp/steam-runtime-steamrt-arm64.tar.xz -C "${STEAM}" -rm -f /tmp/steam-runtime-steamrt-arm64.tar.xz - -steam_arm_ibus=$( - find "${STEAM}/steam-runtime-steamrt-arm64" \ - -path '*/files/lib/aarch64-linux-gnu/libibus-1.0.so.5.*' \ - -type f | - sort | - tail -n1 -) -if [[ -z "${steam_arm_ibus}" ]]; then - echo "ERROR: failed to find ARM64 Steam runtime libibus shim" >&2 - exit 1 -fi -mkdir -p "${STEAM}/lib/aarch64-linux-gnu" -ln -sfn \ - "../../${steam_arm_ibus#"${STEAM}/"}" \ - "${STEAM}/lib/aarch64-linux-gnu/libibus-1.0.so.5" - -if [[ ! -f "${STEAM}/steamrtarm64/steam" ]]; then - echo "ERROR: ARM64 Steam seed did not install steamrtarm64/steam" >&2 - exit 1 -fi - -Xvfb :99 -screen 0 1280x800x24 >/tmp/armada-steam-bootstrap-xvfb.log 2>&1 & -xvfb_pid=$! -trap 'kill "${xvfb_pid}" 2>/dev/null || true' EXIT -sleep 1 - -export HOME="${STEAM_BOOTSTRAP_HOME}" -export DISPLAY=:99 -export LD_LIBRARY_PATH="${STEAM}/steamrtarm64:${STEAM}/lib/aarch64-linux-gnu" - -installed_manifest="${STEAM}/package/${STEAM_ARM_MANIFEST_NAME}.installed" - -verify_installed_manifest() { - python3 "${script_dir}/verify-steam-bootstrap.py" \ - "${installed_manifest}" "${STEAM}" -} - -steam_verified=false -bootstrap_deadline=$((SECONDS + STEAM_BOOTSTRAP_TIMEOUT)) -for attempt in {1..3}; do - remaining_timeout=$((bootstrap_deadline - SECONDS)) - if ((remaining_timeout <= 0)); then - break - fi - set +e - timeout "${remaining_timeout}" \ - "${STEAM}/steamrtarm64/steam" \ - -steamdeck \ - -exitsteam \ - >/tmp/armada-steam-bootstrap.stdout \ - 2>/tmp/armada-steam-bootstrap.stderr - steam_rc=$? - set -e - - if [[ "${steam_rc}" == "124" ]]; then - echo "ERROR: Steam bootstrap exhausted its ${STEAM_BOOTSTRAP_TIMEOUT}-second timeout" >&2 - break - fi - - if [[ -x "${STEAM}/steamrtarm64/steam" \ - && -f "${STEAM}/steamrtarm64/steamui.so" \ - && -f "${installed_manifest}" ]] \ - && verify_installed_manifest; then - steam_verified=true - break - fi - echo "Steam bootstrap attempt ${attempt} was incomplete (rc ${steam_rc})" >&2 -done - -if [[ "${steam_verified}" != "true" ]]; then - echo "ERROR: Steam bootstrap did not produce a complete ARM64 Steam tree" >&2 - echo "--- last bootstrap stdout (tail) ---" >&2 - tail -n 30 /tmp/armada-steam-bootstrap.stdout >&2 || true - echo "--- last bootstrap stderr (tail) ---" >&2 - tail -n 30 /tmp/armada-steam-bootstrap.stderr >&2 || true - exit 1 -fi - -rm -rf \ - "${STEAM}/logs" \ - "${STEAM}/appcache/httpcache" \ - "${STEAM}/appcache/cefdata" \ - "${STEAM}/config/htmlcache" -find "${STEAM_BOOTSTRAP_HOME}" \ - \( -name '*.log' -o -name '*.pid' -o -name '*.token' -o -name '*.crash' \) \ - -delete -find "${STEAM_BOOTSTRAP_HOME}" \( -type s -o -type p \) -delete -rm -f \ - "${STEAM}/package/steam_client_metrics.bin" \ - "${STEAM}/registry.vdf" \ - "${STEAM}/ssfn"* \ - "${DOT_STEAM}/registry.vdf" \ - "${DOT_STEAM}/steam.pid" \ - "${DOT_STEAM}/steam.token" - -# Steam opens Decky's localhost CEF debugger only when this marker exists. -touch "${STEAM}/.cef-enable-remote-debugging" -if ! verify_installed_manifest; then - echo "ERROR: Steam bootstrap cleanup removed manifest content" >&2 - exit 1 -fi - -package_count=$(find "${STEAM}/package" -maxdepth 1 -type f | wc -l) -zipvz_count=$(find "${STEAM}/package" -maxdepth 1 -type f -name '*.zip.vz.*' | wc -l) -echo "Generated ARM64 Steam bootstrap: ${package_count} package files, ${zipvz_count} compressed payloads, updater rc ${steam_rc}, manifest verified" diff --git a/decky/armada-control/py_modules/armada_control/config.py b/decky/armada-control/py_modules/armada_control/config.py index 906329e3..1296d80d 100644 --- a/decky/armada-control/py_modules/armada_control/config.py +++ b/decky/armada-control/py_modules/armada_control/config.py @@ -1,5 +1,6 @@ -from .controller import CONTROLLER_TYPES, controller_type +from .controller import CONTROLLER_TYPES, controller_type, inputplumber_targets from .power import factory_power_defaults, parse_power +from .rgb import rgb_supported from .steam import installed_games from .system import ( abl_auto_enabled, @@ -30,7 +31,7 @@ def build_config(include_games=True): "fexProfiles": fex_profile_labels(fex_contract), "perf": perf_info(), "cpuDeviceClass": env.get("ARMADA_SOC_CLASS", ""), - "rgbSupported": bool(env.get("ARMADA_RGB_BACKEND")), + "rgbSupported": rgb_supported(), "protonDefaults": [ default.strip() for default in env.get("ARMADA_PROTON_DEFAULTS", "").split(":") @@ -52,5 +53,7 @@ def build_config(include_games=True): "sleepMode": env.get("ARMADA_SUSPEND_MODE", "s2idle"), "sleepModes": sleep_modes(), "controllerType": controller_type(), - "controllerTypes": [{"data": key, "label": label} for key, label in CONTROLLER_TYPES.items()], + "controllerTypes": [ + {"data": key, "label": CONTROLLER_TYPES[key]} for key in inputplumber_targets(env) + ], } diff --git a/decky/armada-control/py_modules/armada_control/controller.py b/decky/armada-control/py_modules/armada_control/controller.py index ab492583..3f261970 100644 --- a/decky/armada-control/py_modules/armada_control/controller.py +++ b/decky/armada-control/py_modules/armada_control/controller.py @@ -6,6 +6,7 @@ DEFAULT_TYPE = "deck-uhid" CONTROLLER_TYPES = { "deck-uhid": "Steam Deck", + "xbox-series": "Xbox Series", "xb360": "Xbox 360", "ds5": "DualSense", } @@ -29,3 +30,13 @@ def set_controller_type(value): if value not in CONTROLLER_TYPES: raise ValueError("invalid controller type") return str(call("set_controller_type", value=value).get("value") or controller_type()) + + +def inputplumber_targets(env): + raw = env.get("ARMADA_IP_TARGETS", "") + targets = [] + for item in raw.split(","): + item = item.strip() + if item in CONTROLLER_TYPES and item not in targets: + targets.append(item) + return targets or list(CONTROLLER_TYPES) diff --git a/decky/armada-control/py_modules/armada_control/rgb.py b/decky/armada-control/py_modules/armada_control/rgb.py index 9e5baf23..325fe941 100644 --- a/decky/armada-control/py_modules/armada_control/rgb.py +++ b/decky/armada-control/py_modules/armada_control/rgb.py @@ -1,6 +1,13 @@ from .privileged import call +def rgb_supported(): + try: + return get_rgb() is not None + except Exception: + return False + + def get_rgb(): return call("get_rgb") diff --git a/decky/armada-control/src/index.tsx b/decky/armada-control/src/index.tsx index 65fa44ab..d143576c 100644 --- a/decky/armada-control/src/index.tsx +++ b/decky/armada-control/src/index.tsx @@ -23,6 +23,7 @@ export default definePlugin(() => { .catch(() => ({ state: { appids: [] as string[], protonDefault: "" }, loaded: false })); Promise.all([getConfig(), getInstalledGames(), handledRequest]) .then(async ([config, games, handled]) => { + await (window as any).App.WaitForServicesInitialized(); if (cancelled) return; const explicitTool = config.tweaks?.global?.windowsCompatTool; configureCompatPolicy( diff --git a/decky/armada-control/src/lib/compatManager.ts b/decky/armada-control/src/lib/compatManager.ts new file mode 100644 index 00000000..bc428910 --- /dev/null +++ b/decky/armada-control/src/lib/compatManager.ts @@ -0,0 +1,99 @@ +import { findModuleExport } from "@decky/ui"; + +export class CompatToolsRequest { + appid?: number; + + serializeBinary(): Uint8Array { + if (this.appid === undefined) return new Uint8Array(); + let value = this.appid >>> 0; + const bytes = [8]; // appid: uint32, field 1 + while (value > 127) { + bytes.push((value & 127) | 128); + value >>>= 7; + } + bytes.push(value); + return new Uint8Array(bytes); + } +} + +export class CompatToolsResponse { + tools: Array<{ name?: string; display_name?: string; is_incompatible?: boolean }> = []; + + static deserializeBinaryFromReader(message: CompatToolsResponse, reader: any): void { + while (reader.nextField()) { + if (reader.isEndGroup()) break; + if (reader.getFieldNumber() !== 1) { + // Armada's default policy requires concrete tool IDs, not Steam aliases. + reader.skipField(); + continue; + } + const tool: CompatToolsResponse["tools"][number] = {}; + reader.readMessage(tool, (entry: typeof tool, fields: any) => { + while (fields.nextField()) { + if (fields.isEndGroup()) break; + switch (fields.getFieldNumber()) { + case 1: entry.name = fields.readString(); break; + case 2: entry.display_name = fields.readString(); break; + case 6: entry.is_incompatible = fields.readBool(); break; + default: fields.skipField(); + } + } + }); + message.tools.push(tool); + } + } +} + +let transportStore: any; +let messageClass: any; + +function compatTransport(): any { + if (!transportStore) { + // The minified getter has no stable signature; the module's diagnostic does. + let require: any; + window.webpackChunksteamui?.push([ + [Symbol("armada-compat-transport")], {}, (loader: any) => { require = loader; }, + ]); + const id = Object.keys(require?.m || {}).find((key) => + require.m[key].toString().includes("Multiple attempts to set a default WebUI transport"), + ); + if (id) { + for (const value of Object.values(require(id))) { + if (typeof value !== "function") continue; + let candidate; + try { candidate = value(); } catch { continue; } + if (typeof candidate?.GetDefaultTransport === "function") { + transportStore = candidate; + break; + } + } + } + } + messageClass ||= findModuleExport((value: any) => + typeof value?.Init === "function" + && typeof value?.InitFromObject === "function" + && typeof value?.prototype?.SetBodyFields === "function", + ); + const transport = transportStore?.GetDefaultTransport(); + if (!transport?.SendMsg || !messageClass) { + throw new Error("Steam compatibility tool discovery is unavailable"); + } + return transport; +} + +export async function getCompatManagerTools(appid?: number): Promise { + // Steam can dereference a missing Proton alias before its post-login services initialize. + await (window as any).App.WaitForServicesInitialized(); + const transport = compatTransport(); + const request = messageClass.Init(CompatToolsRequest); + request.Body().appid = appid; + const response = await transport.SendMsg( + "CompatManager.GetCompatTools#1", request, CompatToolsResponse, + // Steam's CompatManager privilege level (1), executing in clientdll (2). + { ePrivilege: 1, eClientExecutionSite: 2 }, + ); + if (!response.BSuccess()) { + throw new Error(`Steam compatibility tool discovery failed (${response.GetEResult()})`); + } + return response.Body(); +} diff --git a/decky/armada-control/src/lib/compatTools.ts b/decky/armada-control/src/lib/compatTools.ts new file mode 100644 index 00000000..6f19bb59 --- /dev/null +++ b/decky/armada-control/src/lib/compatTools.ts @@ -0,0 +1,31 @@ +import type { CompatTool } from "./protonPolicy"; + +export function mapCompatTools(raw: any): CompatTool[] { + const tools = Array.isArray(raw) ? raw : raw?.tools; + if (!Array.isArray(tools)) return []; + return tools + .filter((tool: any) => !tool?.is_incompatible) + .map((tool: any) => { + const id = String(tool?.strToolName ?? tool?.strName ?? tool?.name ?? ""); + return { + id, + label: String(tool?.strDisplayName || tool?.display_name || id), + }; + }) + .filter((tool: CompatTool) => tool.id); +} + +// An empty tool list is valid on older clients and must not trigger fallback. +export async function readCompatTools( + client: any, + getCompatTools: (appid?: number) => Promise, + appid?: number, +): Promise { + if (appid === undefined && client?.Settings?.GetGlobalCompatTools) { + return mapCompatTools(await client.Settings.GetGlobalCompatTools()); + } + if (appid !== undefined && client?.Apps?.GetAvailableCompatTools) { + return mapCompatTools(await client.Apps.GetAvailableCompatTools(appid)); + } + return mapCompatTools(await getCompatTools(appid)); +} diff --git a/decky/armada-control/src/lib/steamCompat.ts b/decky/armada-control/src/lib/steamCompat.ts index 05ac1c23..d9f9ca06 100644 --- a/decky/armada-control/src/lib/steamCompat.ts +++ b/decky/armada-control/src/lib/steamCompat.ts @@ -2,6 +2,8 @@ import { defaultWindowsCompatTool, type CompatTool, } from "./protonPolicy"; +import { readCompatTools } from "./compatTools"; +import { getCompatManagerTools } from "./compatManager"; export { defaultWindowsCompatTool, } from "./protonPolicy"; @@ -24,7 +26,6 @@ function isManagedType(type: number | null): boolean { } const apps = () => window.SteamClient?.Apps; -const settings = () => window.SteamClient?.Settings; export const USE_DEFAULT_COMPAT = "__armada_default__"; export const FOLLOW_STEAM_COMPAT = "__steam_default__"; @@ -42,6 +43,7 @@ export function setWindowsCompatTool(toolName: string | undefined): void { // A saved default can name a tool a later release stopped shipping. async function effectiveWindowsCompatTool(): Promise { + if (windowsCompatTool === FOLLOW_STEAM_COMPAT) return FOLLOW_STEAM_COMPAT; const tools = await getProtonTools(); if (!tools.length) return ""; if (windowsCompatTool && tools.some((tool) => tool.id === windowsCompatTool)) return windowsCompatTool; @@ -90,23 +92,13 @@ export function markCompatHandled(appid: string): boolean { return handledAppids.size !== size; } -function mapCompatTools(raw: any): CompatTool[] { - if (!Array.isArray(raw)) return []; - return raw - .map((tool: any) => ({ - id: String(tool?.strToolName ?? tool?.strName ?? tool?.name ?? ""), - label: String(tool?.strDisplayName ?? tool?.strToolName ?? tool?.strName ?? ""), - })) - .filter((tool: CompatTool) => tool.id); -} - export async function getProtonTools(refresh = false): Promise { if (!refresh && protonToolsCache.length && Date.now() - protonToolsCachedAt < 5000) return protonToolsCache; if (protonToolsRequest) return protonToolsRequest; protonToolsRequest = (async () => { try { // Steam exposes Proton globally; per-app Linux runtimes only appear in available tools. - const tools = mapCompatTools(await settings()?.GetGlobalCompatTools?.()); + const tools = await readCompatTools(window.SteamClient, getCompatManagerTools); if (tools.length) { protonToolsCache = tools; protonToolsCachedAt = Date.now(); @@ -124,7 +116,7 @@ export async function getProtonTools(refresh = false): Promise { // A game's supported tools per Steam's OS filtering (Proton, plus SLR for a Linux depot); for the per-game picker. export async function getAppCompatTools(appid: string): Promise { try { - return mapCompatTools(await apps()?.GetAvailableCompatTools?.(Number(appid))); + return await readCompatTools(window.SteamClient, getCompatManagerTools, Number(appid)); } catch (error) { return []; } @@ -155,7 +147,7 @@ export function compatSelection(state: CompatState | null, defaultTool?: string) export async function specifyCompatTool(appid: string, toolName: string): Promise { const store = apps(); if (!store?.SpecifyCompatTool) throw new Error("Steam compatibility settings are unavailable"); - await store.SpecifyCompatTool(Number(appid), toolName); + await store.SpecifyCompatTool(Number(appid), toolName === FOLLOW_STEAM_COMPAT ? "" : toolName); } const delay = (ms: number) => new Promise((resolve) => window.setTimeout(resolve, ms)); @@ -306,6 +298,7 @@ async function clearCompatToolAndResolveRoute(appid: string): Promise { + if (windowsCompatTool === FOLLOW_STEAM_COMPAT) return repinToTool(appid, ""); if (route === null) return false; if (route === "linux") { markCompatHandled(appid); @@ -377,7 +370,7 @@ async function applyWindowsCompatDefault(appid: string): Promise { if (handledAppids.has(appid)) return true; const details = await resolveSettledCompatDetails(appid); if (!details) return false; - if (!autoApplyCompat || Number(details.nCompatToolPriority || 0) >= 250) { + if (!autoApplyCompat || windowsCompatTool === FOLLOW_STEAM_COMPAT || Number(details.nCompatToolPriority || 0) >= 250) { markCompatHandled(appid); return true; } @@ -411,8 +404,10 @@ export async function migrateWindowsCompatTool( pinnedAppids?: string[] | null, ): Promise { if (!oldTool || oldTool === newTool) return; - const protonTools = await getProtonTools(); - if (!protonTools.some((tool) => tool.id === newTool)) return; + if (newTool !== FOLLOW_STEAM_COMPAT) { + const protonTools = await getProtonTools(); + if (!protonTools.some((tool) => tool.id === newTool)) return; + } setWindowsCompatTool(newTool); const pinned = pinnedAppids ? new Set(pinnedAppids.map(String)) : null; let next = 0; @@ -431,7 +426,12 @@ export async function migrateWindowsCompatTool( await repinToTool(appid, newTool); continue; } - if (priority < 250 || String(details.strCompatToolName || "") !== oldTool) continue; + const currentTool = String(details.strCompatToolName || ""); + if (oldTool === FOLLOW_STEAM_COMPAT) { + if (priority >= 250 || await resolveCompatRoute(currentTool) !== "windows") continue; + } else if (priority < 250 || currentTool !== oldTool) { + continue; + } for (let attempt = 0; attempt < 3; attempt++) { if (await applyCompatDefaultForRoute(appid, "windows")) break; } @@ -448,6 +448,11 @@ export async function resetCompatToolToDefault(appid: string, pinnedAppids?: str } if (!isManagedType(type)) return ""; const tool = await effectiveWindowsCompatTool(); + if (tool === FOLLOW_STEAM_COMPAT) { + await specifyCompatTool(appid, ""); + markCompatHandled(appid); + return ""; + } // Clearing first needs a default to put back and a known pin state; null is unknown. if (!tool || pinnedAppids === null) { const state = await resolveCompatState(appid); @@ -479,7 +484,9 @@ export async function resetAllGamePolicies(appids: string[], pinnedAppids?: stri continue; } if (!isManagedType(type)) continue; - if (canResetCompat && pinned?.has(appid)) { + if (tool === FOLLOW_STEAM_COMPAT) { + await repinToTool(appid, ""); + } else if (canResetCompat && pinned?.has(appid)) { await repinToTool(appid, tool); } else if (canResetCompat) { await applyCompatDefaultForRoute(appid, await clearCompatToolAndResolveRoute(appid)); diff --git a/decky/armada-control/src/tabs/Compatibility.tsx b/decky/armada-control/src/tabs/Compatibility.tsx index 4ff10123..cedeacf4 100644 --- a/decky/armada-control/src/tabs/Compatibility.tsx +++ b/decky/armada-control/src/tabs/Compatibility.tsx @@ -233,7 +233,7 @@ export function Compatibility({ config, setConfig }: { config: Config; setConfig compatTools, config.protonDefaults, ); // The setting is kept rather than rewritten: reinstalling the tool restores the choice. - const globalToolMissing = !!globalTool && compatTools.length > 0 + const globalToolMissing = !!globalTool && globalTool !== FOLLOW_STEAM_COMPAT && compatTools.length > 0 && !compatTools.some((tool) => tool.id === globalTool); const activeGlobalTool = !globalTool || globalToolMissing ? resolvedDefaultTool : globalTool; const runtimeGame = config.game; @@ -483,7 +483,10 @@ export function Compatibility({ config, setConfig }: { config: Config; setConfig setConfig((current) => (current ? { ...current, selectedGame: saved || null } : current)); }; - const toolOptions = compatTools.map((tool) => ({ data: tool.id, label: tool.label })); + const toolOptions = [ + { data: FOLLOW_STEAM_COMPAT, label: "Follow Steam" }, + ...compatTools.map((tool) => ({ data: tool.id, label: tool.label })), + ]; const onSelectGlobalDefault = async (choice: any) => { if (switchingDefault) return; const name = String(choice); @@ -805,14 +808,18 @@ export function Compatibility({ config, setConfig }: { config: Config; setConfig {globalTool} is no longer installed. Choose a new default for your games. ) : null} - { - setAutoApplyCompat(enabled); - patchSettings({ autoApplyCompat: enabled }); - }} - /> + {activeGlobalTool === FOLLOW_STEAM_COMPAT ? ( +
Steam chooses the compatibility tool for each game.
+ ) : ( + { + setAutoApplyCompat(enabled); + patchSettings({ autoApplyCompat: enabled }); + }} + /> + )} ) : ( diff --git a/decky/armada-control/test/compatManager.test.ts b/decky/armada-control/test/compatManager.test.ts new file mode 100644 index 00000000..e4ac06cb --- /dev/null +++ b/decky/armada-control/test/compatManager.test.ts @@ -0,0 +1,66 @@ +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import test from "node:test"; +import { runInNewContext } from "node:vm"; +import ts from "typescript"; + +const source = readFileSync(new URL("../src/lib/compatManager.ts", import.meta.url), "utf8"); +const compiled = ts.transpileModule(source, { + compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, +}).outputText; + +function setup(ready: Promise) { + const requests: Array = []; + const body: { appid?: number } = {}; + const messageClass = { + Init: () => ({ Body: () => body }), + InitFromObject: () => {}, + prototype: { SetBodyFields: () => {} }, + }; + const transport = { + SendMsg: async (method: string, request: any) => { + assert.equal(method, "CompatManager.GetCompatTools#1"); + requests.push(request.Body().appid); + return { BSuccess: () => true, Body: () => ({ tools: [] }) }; + }, + }; + const webpack = Object.assign( + () => ({ getStore: () => ({ GetDefaultTransport: () => transport }) }), + { m: { transport: () => "Multiple attempts to set a default WebUI transport" } }, + ); + const exports: any = {}; + runInNewContext(compiled, { + exports, + require: () => ({ findModuleExport: () => messageClass }), + window: { + App: { WaitForServicesInitialized: () => ready }, + webpackChunksteamui: { push: (chunk: any) => chunk[2](webpack) }, + }, + }); + return { requests, getTools: exports.getCompatManagerTools }; +} + +test("does not send a compatibility request before Steam services initialize", async () => { + let finish!: (value: boolean) => void; + const ready = new Promise((resolve) => { finish = resolve; }); + const { requests, getTools } = setup(ready); + const result = getTools(); + await new Promise((resolve) => setImmediate(resolve)); + assert.deepEqual(requests, []); + finish(true); + await result; + assert.deepEqual(requests, [undefined]); +}); + +test("allows per-app requests once Steam services are initialized", async () => { + const { requests, getTools } = setup(Promise.resolve(true)); + await getTools(391220); + assert.deepEqual(requests, [391220]); +}); + +test("does not send a request when Steam initialization fails", async () => { + const error = new Error("Steam initialization failed"); + const { requests, getTools } = setup(Promise.reject(error)); + await assert.rejects(getTools(), error); + assert.deepEqual(requests, []); +}); diff --git a/decky/armada-control/test/compatTools.test.ts b/decky/armada-control/test/compatTools.test.ts new file mode 100644 index 00000000..0d039e4c --- /dev/null +++ b/decky/armada-control/test/compatTools.test.ts @@ -0,0 +1,63 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { mapCompatTools, readCompatTools } from "../src/lib/compatTools.ts"; + +const id = "proton-experimental-arm64"; +const label = "Proton Experimental (ARM64)"; +const expected = [{ id, label }]; +const modern = { + tools: [{ name: id, display_name: label, is_incompatible: false }], + aliases: [{ alias: "proton-stable", current_tool_name: "proton_11-arm64" }], + selected_tool_identifier: "", + default_tool_identifier: "proton-stable", +}; + +test("maps the CompatManager response, keeping concrete tool IDs and labels", () => { + assert.deepEqual(mapCompatTools(modern), expected); +}); + +test("maps legacy native response fields and falls back to the tool ID for empty labels", () => { + assert.deepEqual(mapCompatTools([{ strToolName: id, strDisplayName: label }]), expected); + assert.deepEqual(mapCompatTools([{ strName: id, strDisplayName: "" }]), [{ id, label: id }]); + assert.deepEqual(mapCompatTools([{ name: id }]), [{ id, label: id }]); +}); + +test("ignores malformed entries and incompatible tools", () => { + assert.deepEqual(mapCompatTools({ tools: [null, {}, { name: id, is_incompatible: true }] }), []); + for (const raw of [null, undefined, {}, { tools: {} }]) assert.deepEqual(mapCompatTools(raw), []); +}); + +test("uses CompatManager when the beta removes the native methods", async () => { + const requests: Array = []; + const fetch = async (appid?: number) => { requests.push(appid); return modern; }; + assert.deepEqual(await readCompatTools({ Settings: {}, Apps: {} }, fetch), expected); + assert.deepEqual(await readCompatTools({ Settings: {}, Apps: {} }, fetch, 391220), expected); + assert.deepEqual(requests, [undefined, 391220]); +}); + +test("preserves native methods and their receiver on older clients", async () => { + const fallback = async () => { assert.fail("must use the native API"); }; + const settings = { + async GetGlobalCompatTools() { assert.equal(this, settings); return [{ strToolName: id, strDisplayName: label }]; }, + }; + const apps = { + async GetAvailableCompatTools(appid: number) { + assert.equal(this, apps); + assert.equal(appid, 391220); + return [{ strToolName: id, strDisplayName: label }]; + }, + }; + const client = { Settings: settings, Apps: apps }; + assert.deepEqual(await readCompatTools(client, fallback), expected); + assert.deepEqual(await readCompatTools(client, fallback, 391220), expected); +}); + +test("does not switch APIs on a legitimate empty native response", async () => { + const client = { Settings: { GetGlobalCompatTools: async () => [] } }; + assert.deepEqual(await readCompatTools(client, async () => { assert.fail(); }), []); +}); + +test("propagates discovery failures to the caller's existing cache/error handling", async () => { + const error = new Error("transport unavailable"); + await assert.rejects(readCompatTools({}, async () => { throw error; }), error); +}); diff --git a/decky/armada-control/test/steamCompat.test.ts b/decky/armada-control/test/steamCompat.test.ts new file mode 100644 index 00000000..b59f7a51 --- /dev/null +++ b/decky/armada-control/test/steamCompat.test.ts @@ -0,0 +1,151 @@ +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import test from "node:test"; +import { runInNewContext } from "node:vm"; +import ts from "typescript"; + +import * as protonPolicy from "../src/lib/protonPolicy.ts"; +import * as compatTools from "../src/lib/compatTools.ts"; + +const experimental = "proton-experimental-arm64"; +const stable = "proton_11-arm64"; +const source = readFileSync(new URL("../src/lib/steamCompat.ts", import.meta.url), "utf8"); +const compiled = ts.transpileModule(source, { + compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, +}).outputText; + +function setup(tools = [experimental, stable]) { + const details = new Map(); + const types = new Map(); + const listeners = new Map void>>(); + const writes: Array<[number, string]> = []; + const launchWrites: number[] = []; + const exports: any = {}; + runInNewContext(compiled, { + exports, + require: (id: string) => { + if (id === "./protonPolicy") return protonPolicy; + if (id === "./compatTools") return compatTools; + if (id === "./compatManager") return { + getCompatManagerTools: async () => { throw new Error("Discovery unavailable"); }, + }; + throw new Error(`Unexpected import: ${id}`); + }, + window: { + setTimeout, clearTimeout, setInterval, clearInterval, + appStore: { GetAppOverviewByAppID: (appid: number) => ({ app_type: types.get(appid) ?? 1 }) }, + SteamClient: { + Settings: { GetGlobalCompatTools: async () => tools.map((name) => ({ name })) }, + Apps: { + RegisterForAppDetails: (appid: number, callback: (value: any) => void) => { + const callbacks = listeners.get(appid) || new Set(); + listeners.set(appid, callbacks); + callbacks.add(callback); + callback(details.get(appid)); + return { unregister: () => callbacks.delete(callback) }; + }, + SpecifyCompatTool: async (appid: number, name: string) => { + writes.push([appid, name]); + const current = details.get(appid); + current.strCompatToolName = name || stable; + current.nCompatToolPriority = name ? 250 : 0; + for (const callback of listeners.get(appid) || []) callback(current); + }, + SetAppLaunchOptions: async (appid: number) => { launchWrites.push(appid); }, + }, + }, + }, + }); + function game(appid: number, tool = stable, priority = 0, type = 1) { + types.set(appid, type); + details.set(appid, { strCompatToolName: tool, nCompatToolPriority: priority }); + return { appid: String(appid) }; + } + return { api: exports as typeof import("../src/lib/steamCompat.ts"), game, writes, launchWrites }; +} + +test("global Follow Steam leaves new games and existing overrides alone, while adding the launch wrapper", async () => { + const { api, game, writes, launchWrites } = setup(); + api.configureCompatPolicy(api.FOLLOW_STEAM_COMPAT, true, [], [experimental]); + await api.sweepInstalledGames([game(1), game(2, experimental, 250), game(3, "steamlinuxruntime")]); + assert.deepEqual(writes, []); + assert.deepEqual(launchWrites.sort(), [1, 2, 3]); + assert.deepEqual(Array.from(api.handledGameAppids()), ["1", "2", "3"]); + assert.equal(protonPolicy.factoryDefaultTransition(api.FOLLOW_STEAM_COMPAT, true, stable, experimental), null); +}); + +test("changing a named default to Follow Steam clears only matching game pins", async () => { + const { api, game, writes } = setup(); + game(1, experimental, 250); + game(2, stable, 250); + game(3, experimental, 0); + game(4, experimental, 250, 4); + api.configureCompatPolicy(experimental, true, [], [experimental]); + await api.migrateWindowsCompatTool(["1", "2", "3", "4"], experimental, api.FOLLOW_STEAM_COMPAT); + assert.deepEqual(writes, [[1, ""]]); +}); + +test("Follow Steam can clear known pins to a missing default without tool discovery", async () => { + const { api, game, writes } = setup([]); + game(1, "", 0); + game(2, stable, 250); + game(3, "", 0); + await api.migrateWindowsCompatTool(["1", "2", "3"], "removed-proton", api.FOLLOW_STEAM_COMPAT, ["1", "2"]); + assert.deepEqual(writes, [[1, ""]]); +}); + +test("Use Default clears the mapping when the global choice is Follow Steam", async () => { + const { api, game, writes } = setup(); + game(1, experimental, 250); + await api.specifyCompatTool("1", api.FOLLOW_STEAM_COMPAT); + assert.deepEqual(writes, [[1, ""]]); + assert.equal(api.compatSelection({ tool: stable, priority: 0 }, api.FOLLOW_STEAM_COMPAT), api.FOLLOW_STEAM_COMPAT); +}); + +test("resetting a game under Follow Steam clears its pin without discovery or a known pin state", async () => { + const { api, game, writes } = setup([]); + game(1, experimental, 250); + api.configureCompatPolicy(api.FOLLOW_STEAM_COMPAT, true, [], [experimental]); + assert.equal(await api.resetCompatToolToDefault("1", null), ""); + assert.deepEqual(writes, [[1, ""]]); +}); + +test("reset all under Follow Steam clears game pins and preserves tool apps", async () => { + const { api, game, writes, launchWrites } = setup([]); + game(1, experimental, 250); + game(2, stable, 250); + game(3, experimental, 250, 4); + api.configureCompatPolicy(api.FOLLOW_STEAM_COMPAT, true, [], [experimental]); + await api.resetAllGamePolicies(["1", "2", "3"], null); + assert.deepEqual(writes, [[1, ""], [2, ""]]); + assert.deepEqual(launchWrites.sort(), [1, 2]); +}); + +test("switching away from Follow Steam migrates handled Windows games and preserves pins and Linux routes", async () => { + const { api, game, writes } = setup(); + const games = [game(1), game(2, stable, 250), game(3, "steamlinuxruntime"), game(4, ""), game(5, stable, 0, 4)]; + api.configureCompatPolicy(api.FOLLOW_STEAM_COMPAT, false, games.map(g => g.appid), [experimental]); + await api.migrateWindowsCompatTool(games.map(g => g.appid), api.FOLLOW_STEAM_COMPAT, experimental); + assert.deepEqual(writes, [[1, experimental]]); + api.setAutoApplyCompat(true); + await api.sweepInstalledGames([...games, game(6)]); + assert.deepEqual(writes, [[1, experimental], [6, experimental]]); +}); + +test("a named default round trip through Follow Steam restores its game pins", async () => { + const { api, game, writes } = setup(); + const games = [game(1, experimental, 250), game(2, stable, 250)]; + api.configureCompatPolicy(experimental, true, games.map(g => g.appid), [experimental]); + await api.migrateWindowsCompatTool(["1", "2"], experimental, api.FOLLOW_STEAM_COMPAT); + await api.migrateWindowsCompatTool(["1", "2"], api.FOLLOW_STEAM_COMPAT, experimental); + assert.deepEqual(writes, [[1, ""], [1, experimental]]); +}); + +test("named defaults still migrate matching pins and honor Apply to New Games", async () => { + const { api, game, writes } = setup(); + game(1, stable, 250); + api.configureCompatPolicy(stable, false, [], [experimental]); + await api.migrateWindowsCompatTool(["1"], stable, experimental); + await api.sweepInstalledGames([game(2)]); + assert.deepEqual(writes, [[1, experimental]]); +}); diff --git a/decky/armada-store/catalog.json b/decky/armada-store/catalog.json index 42a64b3c..e3523921 100644 --- a/decky/armada-store/catalog.json +++ b/decky/armada-store/catalog.json @@ -199,6 +199,50 @@ "ref": "org.scummvm.ScummVM" } }, + { + "id": "bigpemu", + "name": "BigPEmu", + "summary": "Atari Jaguar", + "category": "emulators", + "icon": "https://dl.flathub.org/media/com/richwhitehouse/BigPEmu/451d43de33ac9e5fdc84e96beea46c14/icons/128x128/com.richwhitehouse.BigPEmu.png", + "install": { + "type": "flatpak", + "ref": "com.richwhitehouse.BigPEmu" + } + }, + { + "id": "mame", + "name": "MAME", + "summary": "Multiple Arcade Machine Emulator", + "category": "emulators", + "icon": "https://dl.flathub.org/media/org/mamedev/MAME/2f148eb3399537f36adeb744dddcb778/icons/128x128/org.mamedev.MAME.png", + "install": { + "type": "flatpak", + "ref": "org.mamedev.MAME" + } + }, + { + "id": "primehack", + "name": "PrimeHack", + "summary": "Dolphin fork for the Metroid Prime trilogy", + "category": "emulators", + "icon": "https://dl.flathub.org/media/io/github/shiiion.primehack/228ebb798795e052dab61f4e1db8c469/icons/128x128/io.github.shiiion.primehack.png", + "install": { + "type": "flatpak", + "ref": "io.github.shiiion.primehack" + } + }, + { + "id": "ymir", + "name": "Ymir", + "summary": "Sega Saturn", + "category": "emulators", + "icon": "https://dl.flathub.org/media/io/github/strikerx3.ymir/436dc7a579f0d1fa0060245e6770bd81/icons/128x128/io.github.strikerx3.ymir.png", + "install": { + "type": "flatpak", + "ref": "io.github.strikerx3.ymir" + } + }, { "id": "moonlight", "name": "Moonlight", diff --git a/decky/armada-store/py_modules/armada_store/installers.py b/decky/armada-store/py_modules/armada_store/installers.py index 2221ad05..951d0124 100644 --- a/decky/armada-store/py_modules/armada_store/installers.py +++ b/decky/armada-store/py_modules/armada_store/installers.py @@ -210,7 +210,7 @@ def install_flatpak(ref, cancel, on_percent): # Emulator manifests rarely grant removable media, and DuckStation's grants no # filesystem access at all. Armada mounts cards under /run/media. -BASE_OVERRIDES = ("--filesystem=/run/media", "--filesystem=/media") +BASE_OVERRIDES = ("--filesystem=/var/home/armada", "--filesystem=/home/armada", "--filesystem=/run/media", "--filesystem=/media") # Persistent rather than a `flatpak run` argument: ES-DE launches the flatpak diff --git a/decky/armada-store/templates/es-de/es_find_rules.xml b/decky/armada-store/templates/es-de/es_find_rules.xml index b63d6449..801a1dc5 100644 --- a/decky/armada-store/templates/es-de/es_find_rules.xml +++ b/decky/armada-store/templates/es-de/es_find_rules.xml @@ -13,6 +13,20 @@ ~/bin/ARMSX2*.AppImage + + + bigpemu + com.richwhitehouse.BigPEmu + + + ~/Applications/bigpemu/bigpemu + ~/.local/share/applications/bigpemu/bigpemu + ~/.local/bin/bigpemu/bigpemu + ~/bin/bigpemu/bigpemu + /var/lib/flatpak/exports/bin/com.richwhitehouse.BigPEmu + ~/.local/share/flatpak/exports/bin/com.richwhitehouse.BigPEmu + + cemu diff --git a/system_files/usr/lib/armada/devices/ayaneo-pocket-ds.conf b/system_files/usr/lib/armada/devices/ayaneo-pocket-ds.conf index 2249a29a..0a0ee470 100644 --- a/system_files/usr/lib/armada/devices/ayaneo-pocket-ds.conf +++ b/system_files/usr/lib/armada/devices/ayaneo-pocket-ds.conf @@ -13,5 +13,5 @@ ARMADA_SECONDARY_BACKLIGHT=sy7758-backlight ARMADA_SECONDARY_TOUCHSCREEN='bottom_touchscreen' ARMADA_VIRTUAL_KEYBOARD_CONNECTOR=DSI-2 ARMADA_PANEL_ORIENTATION=left -ARMADA_GAMEPAD_QUIRK=ayaneo-xbox +ARMADA_GAMEPAD_QUIRK=ayaneo-default ARMADA_SYNC_SUSPEND=1 diff --git a/system_files/usr/lib/armada/devices/ayaneo-pocket-s1k.conf b/system_files/usr/lib/armada/devices/ayaneo-pocket-s1k.conf new file mode 100644 index 00000000..f32fb5ee --- /dev/null +++ b/system_files/usr/lib/armada/devices/ayaneo-pocket-s1k.conf @@ -0,0 +1,11 @@ +ARMADA_DEVICE_ID=ayaneo-pocket-s1k +ARMADA_DEVICE_NAME='AYANEO Pocket S 1K' +ARMADA_SOC_CLASS=SM8550 + +ARMADA_PRIMARY_CONNECTOR=DSI-1 +ARMADA_PANEL_ORIENTATION=right +ARMADA_PANEL_NATIVE_WIDTH=1080 +ARMADA_PANEL_NATIVE_HEIGHT=1920 +ARMADA_PANEL_REFRESH_RATES=60 +ARMADA_GAMESCOPE_USE_ROTATION_SHADER=1 +ARMADA_GAMEPAD_QUIRK=ayaneo-xbox diff --git a/system_files/usr/lib/armada/devices/ayaneo-pocket-s2.conf b/system_files/usr/lib/armada/devices/ayaneo-pocket-s2.conf index f8460981..06b537e9 100644 --- a/system_files/usr/lib/armada/devices/ayaneo-pocket-s2.conf +++ b/system_files/usr/lib/armada/devices/ayaneo-pocket-s2.conf @@ -3,4 +3,4 @@ ARMADA_DEVICE_NAME='AYANEO Pocket S2' ARMADA_SOC_CLASS=SM8650 ARMADA_PANEL_ORIENTATION=right -ARMADA_GAMEPAD_QUIRK=ayaneo-xbox +ARMADA_GAMEPAD_QUIRK=ayaneo-default diff --git a/system_files/usr/lib/armada/devices/ayn-odin-2-portal.conf b/system_files/usr/lib/armada/devices/ayn-odin-2-portal.conf index 31cc3e6f..70003860 100644 --- a/system_files/usr/lib/armada/devices/ayn-odin-2-portal.conf +++ b/system_files/usr/lib/armada/devices/ayn-odin-2-portal.conf @@ -1,7 +1,5 @@ ARMADA_DEVICE_ID=ayn-odin-2-portal ARMADA_DEVICE_NAME='AYN Odin 2 Portal' ARMADA_SOC_CLASS=SM8550 -ARMADA_RGB_BACKEND=multicolor -ARMADA_RGB_TARGETS='rgb:l1 rgb:l2 rgb:l3 rgb:l4 rgb:r1 rgb:r2 rgb:r3 rgb:r4' ARMADA_PANEL_ORIENTATION=left diff --git a/system_files/usr/lib/armada/devices/ayn-odin-3.conf b/system_files/usr/lib/armada/devices/ayn-odin-3.conf index 47af37c3..4da3e737 100644 --- a/system_files/usr/lib/armada/devices/ayn-odin-3.conf +++ b/system_files/usr/lib/armada/devices/ayn-odin-3.conf @@ -1,8 +1,6 @@ ARMADA_DEVICE_ID=ayn-odin-3 ARMADA_DEVICE_NAME='AYN Odin 3' ARMADA_SOC_CLASS=SM8750 -ARMADA_RGB_BACKEND=channels -ARMADA_RGB_TARGETS='red=l:r1 red=l:r2 red=l:r3 red=l:r4 red=r:r1 red=r:r2 red=r:r3 red=r:r4 green=l:g1 green=l:g2 green=l:g3 green=l:g4 green=r:g1 green=r:g2 green=r:g3 green=r:g4 blue=l:b1 blue=l:b2 blue=l:b3 blue=l:b4 blue=r:b1 blue=r:b2 blue=r:b3 blue=r:b4' ARMADA_PANEL_ORIENTATION=right ARMADA_HDR_NITS=650 diff --git a/system_files/usr/lib/armada/devices/ayn-thor-lite.conf b/system_files/usr/lib/armada/devices/ayn-thor-lite.conf new file mode 100644 index 00000000..65f0ce86 --- /dev/null +++ b/system_files/usr/lib/armada/devices/ayn-thor-lite.conf @@ -0,0 +1,15 @@ +ARMADA_DEVICE_ID=ayn-thor-lite +ARMADA_DEVICE_NAME='AYN Thor Lite' +ARMADA_SOC_CLASS=SM8250 + +# Dual screen: top panel is DSI-1 (mdss_dsi0), bottom panel is DSI-2 +# (mdss_dsi1). Gamescope drives only the top panel; the desktop session +# uses both (see desktop-bootstrap). +ARMADA_PRIMARY_CONNECTOR=DSI-1 +ARMADA_PRIMARY_BACKLIGHT=ae94000.dsi.0 +ARMADA_PRIMARY_TOUCHSCREEN=top_touchscreen +ARMADA_SECONDARY_CONNECTOR=DSI-2 +ARMADA_SECONDARY_BACKLIGHT=ae96000.dsi.0 +ARMADA_SECONDARY_TOUCHSCREEN=bottom_touchscreen +ARMADA_VIRTUAL_KEYBOARD_CONNECTOR=DSI-2 +ARMADA_PANEL_ORIENTATION=right diff --git a/system_files/usr/lib/armada/devices/ayn-thor.conf b/system_files/usr/lib/armada/devices/ayn-thor.conf index 5c737123..ce75a0a1 100644 --- a/system_files/usr/lib/armada/devices/ayn-thor.conf +++ b/system_files/usr/lib/armada/devices/ayn-thor.conf @@ -1,8 +1,6 @@ ARMADA_DEVICE_ID=ayn-thor ARMADA_DEVICE_NAME='AYN Thor' ARMADA_SOC_CLASS=SM8550 -ARMADA_RGB_BACKEND=multicolor -ARMADA_RGB_TARGETS='rgb:l1 rgb:l2 rgb:l3 rgb:l4 rgb:r1 rgb:r2 rgb:r3 rgb:r4' # Dual screen: top panel is DSI-2 (mdss_dsi1), bottom panel is DSI-1 # (mdss_dsi0). Gamescope drives only the top panel; the desktop session diff --git a/system_files/usr/lib/armada/devices/defaults.conf b/system_files/usr/lib/armada/devices/defaults.conf index a39aeff4..ce2ba0ba 100644 --- a/system_files/usr/lib/armada/devices/defaults.conf +++ b/system_files/usr/lib/armada/devices/defaults.conf @@ -21,6 +21,10 @@ ARMADA_PANEL_TYPE=internal ARMADA_PANEL_ORIENTATION=normal ARMADA_GAMESCOPE_FORCE_COMPOSITION_ROTATION=0 ARMADA_GAMEPAD_QUIRK=none +# Controller targets InputPlumber can emulate on this device, comma +# separated, in menu order. The first entry is the default. Explicit user +# choice in /etc/armada/controller.conf overrides this when present. +ARMADA_IP_TARGETS=deck-uhid,xbox-series,xb360,ds5 # s2idle or fake ARMADA_SUSPEND_MODE=s2idle ARMADA_HDR_NITS=0 diff --git a/system_files/usr/lib/armada/devices/konkr-pocket-fit-elite.conf b/system_files/usr/lib/armada/devices/konkr-pocket-fit-elite.conf index af1f7e22..ac54798b 100644 --- a/system_files/usr/lib/armada/devices/konkr-pocket-fit-elite.conf +++ b/system_files/usr/lib/armada/devices/konkr-pocket-fit-elite.conf @@ -1,8 +1,6 @@ ARMADA_DEVICE_ID=konkr-pocket-fit-elite ARMADA_DEVICE_NAME='KONKR Pocket FIT Elite' ARMADA_SOC_CLASS=SM8750 -ARMADA_RGB_BACKEND=multicolor -ARMADA_RGB_TARGETS='konkr:rgb:joysticks' -ARMADA_RGB_CORRECTION='red:0,20,20' ARMADA_PANEL_ORIENTATION=right +ARMADA_GAMEPAD_QUIRK=ayaneo-default diff --git a/system_files/usr/lib/armada/devices/konkr-pocket-fit.conf b/system_files/usr/lib/armada/devices/konkr-pocket-fit.conf index 540eb20b..cb36c181 100644 --- a/system_files/usr/lib/armada/devices/konkr-pocket-fit.conf +++ b/system_files/usr/lib/armada/devices/konkr-pocket-fit.conf @@ -3,3 +3,4 @@ ARMADA_DEVICE_NAME='KONKR Pocket FIT' ARMADA_SOC_CLASS=SM8650 ARMADA_PANEL_ORIENTATION=right +ARMADA_GAMEPAD_QUIRK=ayaneo-default diff --git a/system_files/usr/lib/armada/devices/retroid-pocket-5.conf b/system_files/usr/lib/armada/devices/retroid-pocket-5.conf index 73a7203e..5aefa99d 100644 --- a/system_files/usr/lib/armada/devices/retroid-pocket-5.conf +++ b/system_files/usr/lib/armada/devices/retroid-pocket-5.conf @@ -1,7 +1,5 @@ ARMADA_DEVICE_ID=retroid-pocket-5 ARMADA_DEVICE_NAME='Retroid Pocket 5' ARMADA_SOC_CLASS=SM8250 -ARMADA_RGB_BACKEND=multicolor -ARMADA_RGB_TARGETS='rgb:l1 rgb:l2 rgb:l3 rgb:l4 rgb:r1 rgb:r2 rgb:r3 rgb:r4' ARMADA_PANEL_ORIENTATION=left diff --git a/system_files/usr/lib/armada/devices/retroid-pocket-6.conf b/system_files/usr/lib/armada/devices/retroid-pocket-6.conf index 1b938788..933681a9 100644 --- a/system_files/usr/lib/armada/devices/retroid-pocket-6.conf +++ b/system_files/usr/lib/armada/devices/retroid-pocket-6.conf @@ -1,7 +1,5 @@ ARMADA_DEVICE_ID=retroid-pocket-6 ARMADA_DEVICE_NAME='Retroid Pocket 6' ARMADA_SOC_CLASS=SM8550 -ARMADA_RGB_BACKEND=multicolor -ARMADA_RGB_TARGETS='rgb:l1 rgb:l2 rgb:l3 rgb:l4 rgb:r1 rgb:r2 rgb:r3 rgb:r4' ARMADA_PANEL_ORIENTATION=left diff --git a/system_files/usr/lib/armada/devices/retroid-pocket-flip2.conf b/system_files/usr/lib/armada/devices/retroid-pocket-flip2.conf index 6dcb473a..f9a5b330 100644 --- a/system_files/usr/lib/armada/devices/retroid-pocket-flip2.conf +++ b/system_files/usr/lib/armada/devices/retroid-pocket-flip2.conf @@ -1,7 +1,6 @@ ARMADA_DEVICE_ID=retroid-pocket-flip2 ARMADA_DEVICE_NAME='Retroid Pocket Flip2' ARMADA_SOC_CLASS=SM8250 -ARMADA_RGB_BACKEND=multicolor -ARMADA_RGB_TARGETS='rgb:l1 rgb:l2 rgb:l3 rgb:l4 rgb:r1 rgb:r2 rgb:r3 rgb:r4' ARMADA_PANEL_ORIENTATION=left +ARMADA_IP_TARGETS=xbox-series,xb360,ds5 diff --git a/system_files/usr/lib/armada/devices/retroid-pocket-nova.conf b/system_files/usr/lib/armada/devices/retroid-pocket-nova.conf index 50d4e626..dfef23d4 100644 --- a/system_files/usr/lib/armada/devices/retroid-pocket-nova.conf +++ b/system_files/usr/lib/armada/devices/retroid-pocket-nova.conf @@ -1,7 +1,5 @@ ARMADA_DEVICE_ID=retroid-pocket-nova ARMADA_DEVICE_NAME='Retroid Pocket Nova' ARMADA_SOC_CLASS=SM8550 -ARMADA_RGB_BACKEND=multicolor -ARMADA_RGB_TARGETS='rgb:l1 rgb:l2 rgb:l3 rgb:l4 rgb:r1 rgb:r2 rgb:r3 rgb:r4' ARMADA_PANEL_ORIENTATION=normal diff --git a/system_files/usr/lib/armada/input-lib b/system_files/usr/lib/armada/input-lib index b4750e20..d6ee34b4 100644 --- a/system_files/usr/lib/armada/input-lib +++ b/system_files/usr/lib/armada/input-lib @@ -29,3 +29,19 @@ armada_lid_closed() { evtest --query "$dev" EV_SW SW_LID >/dev/null 2>&1; rc=$? [[ "$rc" -eq 10 ]] } + +# True if $1 (a /dev/input/eventN path) reports key code $2 in its EV_KEY +# capability bitmap. The bitmap prints 64-bit groups, most significant first. +armada_dev_has_key() { + local input_class="${ARMADA_INPUT_CLASS:-/sys/class/input}" + local cap line words idx + + cap="${input_class}/$(basename "$1")/device/capabilities/key" + [[ -r "$cap" ]] || return 1 + read -r line < "$cap" || return 1 + read -r -a words <<<"$line" + idx=$(( ${#words[@]} - 1 - $2 / 64 )) + (( idx >= 0 )) || return 1 + [[ "${words[idx]}" =~ ^[0-9a-fA-F]+$ ]] || return 1 + (( 0x${words[idx]} >> ($2 % 64) & 1 )) +} diff --git a/system_files/usr/lib/armada/supported-dtbs b/system_files/usr/lib/armada/supported-dtbs index f6672483..351d72e1 100644 --- a/system_files/usr/lib/armada/supported-dtbs +++ b/system_files/usr/lib/armada/supported-dtbs @@ -3,8 +3,11 @@ qcs8550-ayn-odin2portal qcs8550-ayn-odin2 qcs8550-ayn-odin2mini qcs8550-ayn-thor +sm8250-ayn-thorlite sm8250-retroidpocket-rp5 +sm8250-retroidpocket-rp5-visionox sm8250-retroidpocket-flip2 +sm8250-retroidpocket-flip2-visionox sm8250-retroidpocket-rpmini sm8250-retroidpocket-rpminiv2 qcs8550-retroidpocket-rp6 @@ -17,4 +20,5 @@ qcs8550-ayaneo-pocketace qcs8550-ayaneo-pocketdmg qcs8550-ayaneo-pocketds qcs8550-ayaneo-pocketevo +qcs8550-ayaneo-pockets1k qcs8550-ayaneo-pockets2k diff --git a/system_files/usr/lib/firmware/qcom/sm8250/ayn/thor/aw883xx_acf.bin b/system_files/usr/lib/firmware/qcom/sm8250/ayn/thor/aw883xx_acf.bin new file mode 120000 index 00000000..4c67e8b8 --- /dev/null +++ b/system_files/usr/lib/firmware/qcom/sm8250/ayn/thor/aw883xx_acf.bin @@ -0,0 +1 @@ +../../../sm8550/ayn/thor/aw883xx_acf.bin \ No newline at end of file diff --git a/system_files/usr/lib/firmware/qcom/sm8750/SM8750-AYN-tplg.bin b/system_files/usr/lib/firmware/qcom/sm8750/SM8750-AYN-tplg.bin index a5c032dc..b03148ce 100644 Binary files a/system_files/usr/lib/firmware/qcom/sm8750/SM8750-AYN-tplg.bin and b/system_files/usr/lib/firmware/qcom/sm8750/SM8750-AYN-tplg.bin differ diff --git a/system_files/usr/lib/firmware/qcom/sm8750/SM8750-KONKR-tplg.bin b/system_files/usr/lib/firmware/qcom/sm8750/SM8750-KONKR-tplg.bin index fc968670..95f3c653 100644 Binary files a/system_files/usr/lib/firmware/qcom/sm8750/SM8750-KONKR-tplg.bin and b/system_files/usr/lib/firmware/qcom/sm8750/SM8750-KONKR-tplg.bin differ diff --git a/system_files/usr/lib/systemd/system/armada-boot-hotkeys.service b/system_files/usr/lib/systemd/system/armada-boot-hotkeys.service new file mode 100644 index 00000000..08d7fe34 --- /dev/null +++ b/system_files/usr/lib/systemd/system/armada-boot-hotkeys.service @@ -0,0 +1,16 @@ +[Unit] +Description=Boot-time hotkeys (hold Select for Desktop Mode) +DefaultDependencies=no +After=local-fs.target +Before=display-manager.service +Conflicts=shutdown.target +ConditionPathExists=/usr/libexec/armada/armada-boot-hotkeys +ConditionPathExists=!/etc/armada/boot-hotkeys-disabled + +[Service] +Type=simple +ExecStart=/usr/libexec/armada/armada-boot-hotkeys +TimeoutStopSec=5 + +[Install] +WantedBy=sysinit.target diff --git a/system_files/usr/lib/systemd/system/armada-controller-type.service b/system_files/usr/lib/systemd/system/armada-controller-type.service index e638cb5e..05c823c7 100644 --- a/system_files/usr/lib/systemd/system/armada-controller-type.service +++ b/system_files/usr/lib/systemd/system/armada-controller-type.service @@ -1,6 +1,5 @@ [Unit] Description=Apply Armada controller type -ConditionPathExists=/etc/armada/controller.conf After=inputplumber.service Requires=inputplumber.service Before=display-manager.service diff --git a/system_files/usr/libexec/armada/armada-boot-hotkeys b/system_files/usr/libexec/armada/armada-boot-hotkeys new file mode 100755 index 00000000..d87b2d64 --- /dev/null +++ b/system_files/usr/libexec/armada/armada-boot-hotkeys @@ -0,0 +1,125 @@ +#!/usr/bin/bash +# Hold a key during the boot splash to change what the device boots into. +# EVIOCGKEY state, not an event stream: reads through InputPlumber's grab. +set -uo pipefail + +source "${ARMADA_INPUT_LIB:-/usr/lib/armada/input-lib}" + +HOLD_MS="${ARMADA_BOOT_HOTKEY_HOLD_MS:-3000}" +POLL_MS="${ARMADA_BOOT_HOTKEY_POLL_MS:-500}" +MAX_SECS="${ARMADA_BOOT_HOTKEY_MAX:-600}" +RESCAN_MS="${ARMADA_BOOT_HOTKEY_RESCAN_MS:-5000}" +CEF_PORT="${ARMADA_SPLASH_CEF_PORT:-8080}" +SESSION_CONTROL="${ARMADA_SESSION_CONTROL:-/usr/libexec/armada/session-control}" +STATUS="${ARMADA_SPLASH_STATUS:-/run/armada/splash/status}" +PROGRESS="${ARMADA_SPLASH_PROGRESS:-/usr/libexec/armada/armada-splash-progress}" +RECOVERY_MARKER="${ARMADA_RECOVERY_MARKER:-/run/armada/recovery-mode}" +INPUT_DEV_DIR="${ARMADA_INPUT_DEV_DIR:-/dev/input}" + +log() { logger -t armada-boot-hotkeys -- "$*" 2>/dev/null; return 0; } + +announce() { [[ -x "$PROGRESS" ]] && ARMADA_SPLASH_STATUS="$STATUS" "$PROGRESS" "$@"; return 0; } + +action_desktop() { + announce "Starting Desktop" + # Runtime marker distinguishing a hotkey boot from a chosen one. + : > "$RECOVERY_MARKER" 2>/dev/null + # The per-boot gamemode reset must land before this override does. + systemctl start armada-session-default.service 2>/dev/null + if systemctl is-active --quiet display-manager.service 2>/dev/null; then + "$SESSION_CONTROL" switch-desktop + return + fi + # session-control clears the failure state, so a failed sddm has to be + # started here; checked before that reset, not after. + local was_failed=0 + systemctl is-failed --quiet display-manager.service 2>/dev/null && was_failed=1 + "$SESSION_CONTROL" default-desktop + (( was_failed )) && systemctl --no-block start display-manager.service + return 0 +} + +# code:evdev name:label:action. Select because no capability map translates it, +# so it reaches the raw node unchanged. +hotkeys=( + "314:BTN_SELECT:Desktop Mode:action_desktop" +) + +(( POLL_MS > 0 )) || POLL_MS=500 +hold_polls=$(( HOLD_MS / POLL_MS )) +(( hold_polls > 0 )) || hold_polls=1 +rescan_polls=$(( RESCAN_MS / POLL_MS )) +(( rescan_polls > 0 )) || rescan_polls=1 +sleep_arg=$(printf '%d.%03d' $(( POLL_MS / 1000 )) $(( POLL_MS % 1000 ))) + +declare -A hotkey_devices=() +have_devices=0 + +scan_devices() { + local entry code devs dev + have_devices=0 + for entry in "${hotkeys[@]}"; do + IFS=: read -r code _ _ _ <<<"$entry" + devs="" + for dev in "$INPUT_DEV_DIR"/event*; do + [[ -e "$dev" ]] || continue + armada_dev_has_key "$dev" "$code" && devs+=" $dev" + done + hotkey_devices[$code]="${devs# }" + [[ -n "$devs" ]] && have_devices=1 + done +} + +held_hotkey() { + local entry code name dev rc + for entry in "${hotkeys[@]}"; do + IFS=: read -r code name _ _ <<<"$entry" + for dev in ${hotkey_devices[$code]}; do + evtest --query "$dev" EV_KEY "$name" >/dev/null 2>&1; rc=$? + (( rc == 10 )) && { printf '%s\n' "$entry"; return 0; } + done + done + return 1 +} + +# Steam owns this button once up; the gamescope unit goes active too early. +steam_up() { + (exec 3<>"/dev/tcp/127.0.0.1/${CEF_PORT}") 2>/dev/null +} + +current="" +held=0 +waited=0 +polls=0 +max_ms=$(( MAX_SECS * 1000 )) + +while (( waited < max_ms )); do + steam_up && exit 0 + if (( have_devices == 0 || polls % rescan_polls == 0 )); then + scan_devices + fi + polls=$(( polls + 1 )) + + entry=$(held_hotkey) || entry="" + if [[ -n "$entry" ]]; then + IFS=: read -r _ _ label action <<<"$entry" + if [[ "$entry" != "$current" ]]; then + current="$entry" + held=0 + log "holding ${label}" + fi + held=$(( held + 1 )) + if (( held > hold_polls )); then + log "triggering ${label}" + "$action" + exit 0 + fi + elif [[ -n "$current" ]]; then + log "released before the hold completed" + current="" + held=0 + fi + + sleep "$sleep_arg" + waited=$(( waited + POLL_MS )) +done diff --git a/system_files/usr/libexec/armada/armada-control b/system_files/usr/libexec/armada/armada-control index b9a9a1bb..1c07f106 100755 --- a/system_files/usr/libexec/armada/armada-control +++ b/system_files/usr/libexec/armada/armada-control @@ -29,7 +29,7 @@ ABL_PARTITIONS = ( ) MAX_REQUEST = 1024 * 1024 CLIENT_TIMEOUT = 5 -CONTROLLER_TYPES = {"deck-uhid", "xb360", "ds5"} +CONTROLLER_TYPES = {"deck-uhid", "xbox-series", "xb360", "ds5"} INTERCEPT_MODES = {"overlay", "reset"} SLEEP_CONFIG = Path("/etc/armada/sleep.conf") SUSPEND_MODE_KEY = "suspend_mode" @@ -456,6 +456,20 @@ def action_get_abl_version(request): return {"version": abl_version()} +def rgb_supported(): + try: + result = subprocess.run( + [RGB_TOOL, "supported"], + check=False, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + timeout=5, + ) + except (OSError, subprocess.SubprocessError): + return False + return result.returncode == 0 + + def run_rgb(command): output = subprocess.check_output([RGB_TOOL, *command], text=True, timeout=5) config = json.loads(output) @@ -465,13 +479,13 @@ def run_rgb(command): def action_get_rgb(request): - if not device_env().get("ARMADA_RGB_BACKEND"): + if not rgb_supported(): return None return run_rgb(["get"]) def action_set_rgb(request): - if not device_env().get("ARMADA_RGB_BACKEND"): + if not rgb_supported(): raise RuntimeError("RGB lighting is not supported on this device") enabled = request.get("enabled") diff --git a/system_files/usr/libexec/armada/armada-installer b/system_files/usr/libexec/armada/armada-installer index 8286f5b6..4a87ecd0 100644 --- a/system_files/usr/libexec/armada/armada-installer +++ b/system_files/usr/libexec/armada/armada-installer @@ -1,986 +1,840 @@ -#!/usr/bin/bash -set -euo pipefail -source /usr/lib/armada/bootimg-args -source /usr/lib/armada/storage-lib -source /usr/lib/armada/update-lib - -DEVICE="${ARMADA_INTERNAL_DEVICE:-$(armada_internal_device || true)}" -ESP_GUID="c12a7328-f81f-11d2-ba4b-00a0c93ec93b" -ESP_PARTLABEL="ARMADA" -ESP_MIB=512 -BOOT_MIB=1024 -# Floor, not target: enough for two bootc deployments plus OTA staging headroom. -ROOT_MIN_MIB=$((32 * 1024)) -ANDROID_MIN_MIB=$((8 * 1024)) -destructive=0 -TARGET="" -BTRFS_OPTS="noatime,compress=zstd:1,discard=async" -ASSUME_YES=0 -UD_GIB="" -OPERATION=install -INHIBIT_PID="" -SELF=/usr/libexec/armada/armada-installer - -# Installed before any destructive step (repartition, mkfs, or reset), so a -# failure after internal storage is modified surfaces the recovery instructions -# rather than leaving the user with an unbootable device and no guidance. -cleanup() { - local rc=$? - [[ -n "$INHIBIT_PID" ]] && kill "$INHIBIT_PID" 2>/dev/null || true - [[ -n "$TARGET" ]] && { umount -R "$TARGET" 2>/dev/null || true; rmdir "$TARGET" 2>/dev/null || true; } - # A half-done operation is recoverable from the SD card (re-run the installer); - # UNINSTALL CFW in ABL is the fallback. On a replace, Android was never touched, - # so it's safe to say so. - if (( rc != 0 && destructive == 1 )); then - case $OPERATION in - reset) - echo "ERROR: reset did not finish after internal storage was modified. To finish the removal, select UNINSTALL CFW in ABL." >&2 - ;; - replace) - echo "ERROR: install did not finish after internal storage was modified, but Android is unchanged. Do NOT boot internal storage; re-run the installer from the SD card to finish, or select UNINSTALL CFW in ABL to abandon the installation." >&2 - ;; - *) - echo "ERROR: install did not finish after internal storage was modified. Do NOT boot internal storage. Re-run the installer from the SD card to finish, or select UNINSTALL CFW in ABL to abandon the installation." >&2 - ;; - esac - fi - exit $rc -} - -# Hold a logind lock for the run so an idle timeout or the power button can't suspend -# the device mid-write; a suspend during repartition or deploy could brick internal -# storage. Released by cleanup. -inhibit_sleep() { - command -v systemd-inhibit >/dev/null 2>&1 || return 0 - systemd-inhibit --what=sleep:idle --who="Armada Installer" \ - --why="writing internal storage" --mode=block sleep infinity & - INHIBIT_PID=$! -} - -need_root() { - if [[ $EUID -ne 0 ]]; then - echo "ERROR: must run as root" >&2 - exit 1 - fi -} - -need_cmds() { - local missing=0 - for cmd in blkid btrfs findmnt jq lsblk mkfs.btrfs mkfs.ext4 mkfs.vfat ostree parted partprobe realpath sfdisk sgdisk udevadm; do - if ! command -v "$cmd" >/dev/null 2>&1; then - echo "ERROR: missing required command: $cmd" >&2 - missing=1 - fi - done - (( missing == 0 )) || exit 1 -} - -check_device() { - if [[ -z $DEVICE ]]; then - echo "ERROR: could not determine internal storage; set ARMADA_INTERNAL_DEVICE=/dev/sdX" >&2 - exit 1 - fi - if [[ ! -b $DEVICE ]]; then - echo "ERROR: internal storage device $DEVICE not found; set ARMADA_INTERNAL_DEVICE" >&2 - exit 1 - fi -} - -refuse_self() { - local src - src=$(root_source) - if [[ -z $src ]]; then - echo "ERROR: cannot determine the boot device; refusing to modify $DEVICE" >&2 - exit 1 - fi - case "$src" in - "$DEVICE"*) - echo "ERROR: booted from $DEVICE; refusing to modify the disk you're running from" >&2 - exit 1 - ;; - esac -} - -confirm() { - (( ASSUME_YES )) && return 0 - local prompt="$1" - local answer - read -rp "$prompt [y/N]: " answer - [[ $answer =~ ^[Yy]$ ]] -} - -root_source() { - local source - source=$(findmnt -no SOURCE /sysroot 2>/dev/null || findmnt -no SOURCE /) - # findmnt reports a btrfs root as /dev/sdaN[/subvol]; strip it so readlink - # resolves the node (else refuse_self fails open on an internal boot). - source=${source%%\[*} - readlink -f "$source" -} - -resolve_partlabel() { - local label="$1" - local matches=() - # Restrict to $DEVICE: a duplicate label on another disk must not match. - mapfile -t matches < <(blkid -t "PARTLABEL=${label}" -o device 2>/dev/null \ - | grep -E "^${DEVICE}p?[0-9]+$" || true) - if [[ ${#matches[@]} -ne 1 || ! -b ${matches[0]} ]]; then - echo "ERROR: expected exactly one partition with PARTLABEL=${label} on ${DEVICE}" >&2 - exit 1 - fi - printf '%s\n' "${matches[0]}" -} - -part_node() { - # /dev/sda + 5 → /dev/sda5, but /dev/mmcblk0 / /dev/nvme0n1 need a 'p': …0p5. - local dev="$1" num="$2" - [[ $dev =~ [0-9]$ ]] && echo "${dev}p${num}" || echo "${dev}${num}" -} - -# One TSV row per partition: NUM START_BYTE END_BYTE(inclusive) NAME. -# END is the inclusive last byte (start+size-1). Parsed by key from sfdisk --json -# rather than splitting columns: a ':' in a partition name or a stray warning line -# would otherwise shift a field or drop a row, and a row missed after userdata is -# silent data loss. -list_partitions() { - sfdisk --json "$DEVICE" 2>/dev/null | jq -r ' - .partitiontable as $t - | ($t.sectorsize // 512) as $ss - | ($t.partitions // [])[] - | [ (.node | match("[0-9]+$").string), - (.start * $ss), - ((.start + .size) * $ss - 1), - (.name // "") ] - | @tsv' -} - -partition_names() { - list_partitions | cut -f4 -} - -detect_mode() { - local name - has_rocknix=0 - has_armada=0 - has_armada_boot=0 - has_armada_root=0 - has_storage=0 - - while IFS= read -r name; do - case "$name" in - ROCKNIX) has_rocknix=1 ;; - ARMADA) has_armada=1 ;; - ARMADA_BOOT) has_armada_boot=1 ;; - ARMADA_ROOT) has_armada_root=1 ;; - STORAGE) has_storage=1 ;; - esac - done < <(partition_names) - - if (( has_rocknix || has_armada || has_armada_boot || has_armada_root || has_storage )); then - mode=occupied - else - mode=fresh - fi -} - -find_userdata() { - mapfile -t ud_line < <(list_partitions | awk -F'\t' '$4=="userdata"') - if [[ ${#ud_line[@]} -ne 1 ]]; then - echo "ERROR: could not uniquely find userdata partition on $DEVICE" >&2 - parted -s "$DEVICE" print >&2 - exit 1 - fi - - IFS=$'\t' read -r UD_NUM UD_START UD_END _ <<< "${ud_line[0]}" - UD_PART=$(part_node "$DEVICE" "$UD_NUM") - UD_START_MIB=$(( (UD_START + 1048575) / 1048576 )) - UD_END_MIB=$(( UD_END / 1048576 )) - UD_ORIG_GIB=$(( (UD_END_MIB - UD_START_MIB) / 1024 )) -} - -require_userdata_last() { - # The fresh layout claims the freed window and partition numbers UD_NUM+1..+3, - # both of which assume userdata is the LAST partition. Refuse if anything lies - # after it (e.g. trailing Android partitions on some Odin 3 layouts) rather than - # mislabel or overwrite it. - local num start_b end_b name - while IFS=$'\t' read -r num start_b end_b name; do - (( num == UD_NUM )) && continue - if (( end_b > UD_END )); then - echo "ERROR: partition #${num} lies after userdata on ${DEVICE}; refusing" >&2 - echo " (a fresh install assumes userdata is the last partition)." >&2 - parted -s "$DEVICE" print >&2 - exit 1 - fi - done < <(list_partitions) -} - -collect_our_tail() { - local num start_b end_b name - OUR_NUMS=() - OUR_LABELS=() - OUR_MAX_END=$UD_END - LINUX_BYTES=0 - OUR_FOREIGN_AFTER=0 - while IFS=$'\t' read -r num start_b end_b name; do - (( num == UD_NUM )) && continue - case "$name" in - ROCKNIX|ARMADA|ARMADA_BOOT|ARMADA_ROOT|STORAGE) - OUR_NUMS+=("$num") - OUR_LABELS+=("$name") - LINUX_BYTES=$((LINUX_BYTES + end_b - start_b)) - (( end_b > OUR_MAX_END )) && OUR_MAX_END=$end_b - ;; - *) - (( end_b > UD_END )) && OUR_FOREIGN_AFTER=1 - ;; - esac - done < <(list_partitions) -} - -compute_ud_bounds() { - RESERVE_MIB=$((ESP_MIB + BOOT_MIB + ROOT_MIN_MIB + 64)) - MAX_NEW_UD_MIB=$((UD_END_MIB - UD_START_MIB - RESERVE_MIB)) - MIN_NEW_UD_MIB=$ANDROID_MIN_MIB - (( MAX_NEW_UD_MIB >= MIN_NEW_UD_MIB )) -} - -choose_userdata_size() { - local max_gib min_gib - if ! compute_ud_bounds; then - echo "ERROR: not enough free space; armada needs about $((RESERVE_MIB / 1024)) GiB" >&2 - exit 1 - fi - min_gib=$((MIN_NEW_UD_MIB / 1024)) - max_gib=$((MAX_NEW_UD_MIB / 1024)) - - if [[ -n $UD_GIB ]]; then - [[ $UD_GIB =~ ^[0-9]+$ ]] || { echo "ERROR: --userdata-gib must be an integer" >&2; exit 2; } - ud_gib=$UD_GIB - ud_mib=$((ud_gib * 1024)) - if (( ud_mib < MIN_NEW_UD_MIB || ud_mib > MAX_NEW_UD_MIB )); then - echo "ERROR: --userdata-gib ${ud_gib} out of range (${min_gib} .. ${max_gib} GiB)" >&2 - exit 2 - fi +#!/usr/bin/python3 +"""Install the running Armada image alongside Android on internal storage.""" + +import argparse +from contextlib import contextmanager +from dataclasses import asdict, dataclass, replace +import fcntl +import hashlib +import html +import json +import os +from pathlib import Path +import platform +import re +import select +import shlex +import shutil +import signal +import subprocess +import sys +import tempfile +import time +import tomllib + +MIB = 1024**2 +GIB = 1024**3 +ESP_SIZE, BOOT_SIZE, ROOT_MIN, ANDROID_MIN = 512 * MIB, GIB, 32 * GIB, 8 * GIB +RESERVE = ESP_SIZE + BOOT_SIZE + ROOT_MIN + 64 * MIB +ESP_TYPE = "c12a7328-f81f-11d2-ba4b-00a0c93ec93b" +LINUX_TYPE = "0fc63daf-8483-4772-8e79-3d69d8477de4" +BTRFS_OPTS = "noatime,compress=zstd:1,discard=async" +SELF = "/usr/libexec/armada/armada-installer" +BOOTIMG = "/usr/libexec/armada/armada-bootimg-update" +RECOVERY = ("To retry from SD, select SD as the boot source in ABL and re-run the installer. " + "To abandon the internal installation, select UNINSTALL CFW in ABL.") + + +class Error(Exception): + pass + + +class Cancelled(Exception): + pass + + +class Interrupted(Error): + def __init__(self, signum): + self.signum = signum + super().__init__(f"operation interrupted by signal {signum}") + + +def run(*args, capture=False, check=True, input=None, **kwargs): + args = [str(arg) for arg in args] + kwargs.setdefault("stdout", subprocess.PIPE if capture else None) + kwargs.setdefault("stderr", subprocess.PIPE if capture else None) + if input is not None: + kwargs["stdin"] = subprocess.PIPE + child = subprocess.Popen(args, text=True, **kwargs) + previous, interrupted = {}, [] + + def forward(signum, _frame): + interrupted.append(signum) + child.send_signal(signum) + + try: + for signum in (signal.SIGHUP, signal.SIGINT, signal.SIGTERM): + previous[signum] = signal.signal(signum, forward) + out, err = child.communicate(input) + finally: + for signum, handler in previous.items(): + signal.signal(signum, handler) + if interrupted: + raise Interrupted(interrupted[0]) + if check and child.returncode: + raise Error(f"{shlex.join(args)} failed ({child.returncode})" + (f": {err.strip()}" if err else "")) + return subprocess.CompletedProcess(args, child.returncode, out, err) + + +def output(*args): + return run(*args, capture=True).stdout.strip() + + +def ostree_api(): + import gi + gi.require_version("OSTree", "1.0") + from gi.repository import Gio, OSTree + return Gio, OSTree + + +def repo_path(repo): + # Libostree may return a /proc/self/fd path that child processes cannot use. + return str(Path(repo.get_path().get_path()).resolve(strict=True)) + + +def part_node(device, number): + return f"{device}{'p' if device[-1].isdigit() else ''}{number}" + + +@dataclass(frozen=True) +class Partition: + number: int + start: int + end: int + name: str + type: str + uuid: str = "" + attrs: str = "" + + +@dataclass(frozen=True) +class Table: + device: str + sector_size: int + first: int + last: int + disk_id: str + parts: tuple + entry_count: int = 128 + unused: tuple = () + + @classmethod + def parse(cls, device, data): + try: + t = data["partitiontable"] + sector = t["sectorsize"] + if (t["label"] != "gpt" or t["unit"] != "sectors" or t["device"] != device + or type(sector) is not int or sector not in (512, 4096)): + raise ValueError("expected a GPT disk with 512 or 4096 byte sectors") + first, last = t["firstlba"], t["lastlba"] + if type(first) is not int or type(last) is not int or not 0 < first < last: + raise ValueError("invalid usable disk bounds") + count = t.get("table-length", 128) + if not re.fullmatch(r"[1-9][0-9]*", str(count)) or int(count) > 2**32 - 1: + raise ValueError("invalid GPT entry count") + count = int(count) + parts, unused = [], [] + for p in t["partitions"]: + node = p["node"] + match = re.fullmatch(re.escape(device) + ("p" if device[-1].isdigit() else "") + r"([1-9][0-9]*)", node) + if not match or int(match[1]) > count: + raise ValueError("invalid partition number") + if p["type"] == "00000000-0000-0000-0000-000000000000": + unused.append(int(match[1])) + continue + if type(p["start"]) is not int or type(p["size"]) is not int or p["size"] <= 0: + raise ValueError("invalid partition extent or device node") + if not isinstance(p.get("name", ""), str): + raise ValueError("invalid partition name") + parts.append(Partition(int(match[1]), p["start"], p["start"] + p["size"], + p.get("name", ""), p["type"].lower(), p["uuid"].lower(), p.get("attrs", ""))) + ordered = sorted(parts, key=lambda p: p.start) + if (len({p.number for p in parts} | set(unused)) != len(parts) + len(unused) + or any(p.start < first or p.end > last + 1 for p in parts) + or any(a.end > b.start for a, b in zip(ordered, ordered[1:]))): + raise ValueError("overlapping or out-of-bounds partitions") + return cls(device, sector, first, last, t["id"].lower(), tuple(sorted(parts, key=lambda p: p.number)), count, tuple(sorted(unused))) + except (KeyError, TypeError, ValueError, AttributeError) as error: + raise Error(f"Could not validate the partition table: {error}") from error + + def layout(self): + userdata = [p for p in self.parts if p.name == "userdata"] + if len(userdata) != 1: + raise Error("Expected exactly one Android userdata partition") + userdata = userdata[0] + tail = tuple(sorted((p for p in self.parts if p.start >= userdata.end), key=lambda p: p.start)) + return userdata, tail + + def info(self): + userdata, tail = self.layout() + android_gib = (userdata.end - userdata.start) * self.sector_size // GIB + if tail: + return dict(mode="occupied", partition_names=", ".join( + f"{part_node(self.device, p.number)} ({p.name or 'unnamed'})" for p in tail), + android_gib=android_gib, linux_gib=sum(p.end - p.start for p in tail) * self.sector_size // GIB) + maximum = ((userdata.end * self.sector_size // MIB * MIB) + - align_up(userdata.start * self.sector_size) - RESERVE) // GIB + if maximum < ANDROID_MIN // GIB: + return dict(mode="toosmall", needed_gib=RESERVE // GIB, android_current_gib=android_gib) + return dict(mode="fresh", android_min_gib=ANDROID_MIN // GIB, android_max_gib=maximum, + android_current_gib=android_gib) + + +def align_up(value): + return (value + MIB - 1) // MIB * MIB + + +def read_table(device): + try: + return Table.parse(device, json.loads(output("sfdisk", "--json", device))) + except ValueError as error: + raise Error(f"Invalid partition table output: {error}") from error + + +def table_fingerprint(table): + ident = os.stat(table.device).st_rdev + diskseq = (Path("/sys/dev/block") / f"{os.major(ident)}:{os.minor(ident)}" / "diskseq").read_text().strip() + data = dict(table=asdict(table), device_id=ident, disk_sequence=diskseq) + return hashlib.sha256(json.dumps(data, sort_keys=True).encode()).hexdigest() + + +@dataclass(frozen=True) +class Plan: + table: Table + operation: str + userdata: Partition + userdata_end: int + remove: tuple + create: tuple + + @classmethod + def make(cls, table, userdata_gib=None): + userdata, tail = table.layout() + sector = table.sector_size + end = max(p.end for p in (userdata, *tail)) + if tail: + if userdata_gib is not None: + raise Error("--userdata-gib only applies to a fresh install") + operation, ud_end = "replace", userdata.end + start = align_up(ud_end * sector) // sector + else: + info = table.info() + if info["mode"] == "toosmall": + raise Error("Not enough space for Android and Armada") + if type(userdata_gib) is not int or not info["android_min_gib"] <= userdata_gib <= info["android_max_gib"]: + raise Error(f"Android size must be {info['android_min_gib']}..{info['android_max_gib']} GiB") + operation = "fresh" + ud_end = (align_up(userdata.start * sector) + userdata_gib * GIB) // sector + start = ud_end + end = end * sector // MIB * MIB // sector + if (end - start) * sector < ESP_SIZE + BOOT_SIZE + ROOT_MIN: + raise Error("Space after userdata is too small; use UNINSTALL CFW in ABL, then install with a smaller Android size") + used = {p.number for p in table.parts if p not in tail} + preferred = [userdata.number + offset for offset in (1, 2, 3)] + free = [number for number in range(1, table.entry_count + 1) if number not in used] + numbers = preferred if all(number in free for number in preferred) else free[:3] + if len(numbers) != 3: + raise Error("Not enough free GPT partition slots") + esp_end, boot_end = start + ESP_SIZE // sector, start + (ESP_SIZE + BOOT_SIZE) // sector + create = (Partition(numbers[0], start, esp_end, "ARMADA", ESP_TYPE), + Partition(numbers[1], esp_end, boot_end, "ARMADA_BOOT", LINUX_TYPE), + Partition(numbers[2], boot_end, end, "ARMADA_ROOT", LINUX_TYPE)) + return cls(table, operation, userdata, ud_end, tail, create) + + def describe(self): + if self.operation == "replace": + names = ", ".join(f"{part_node(self.table.device, p.number)} ({p.name or 'unnamed'})" for p in self.remove) + return f"Erase ALL partitions after Android userdata on {self.table.device} ({names}) and install the running Armada image? All data in these partitions will be lost. Userdata and earlier partitions stay unchanged." + size = (self.userdata_end - self.userdata.start) * self.table.sector_size // GIB + return f"Install the running Armada image and resize Android to {size} GiB? All Android user data will be erased." + + def script(self): + table = self.table + lines = ["label: gpt", f"label-id: {table.disk_id}", "unit: sectors", + f"first-lba: {table.first}", f"last-lba: {table.last}", + f"sector-size: {table.sector_size}", f"table-length: {table.entry_count}"] + parts = [replace(p, end=self.userdata_end) if p == self.userdata else p + for p in table.parts if p not in self.remove] + list(self.create) + for p in sorted(parts, key=lambda p: p.number): + name = re.sub(r'["\\\x00-\x1f]', lambda m: f"\\x{ord(m[0]):02x}", p.name) + fields = [f"start={p.start}", f"size={p.end - p.start}", f"type={p.type}", + f'name="{name}"'] + if p.uuid: + fields.append("uuid=" + p.uuid) + if p.attrs: + fields.append("attrs=" + json.dumps(p.attrs)) + lines.append(part_node(table.device, p.number) + ": " + ", ".join(fields)) + return "\n".join(lines) + "\n" + + def write(self): + run("sfdisk", "--no-reread", "--no-tell-kernel", "--wipe=never", "--wipe-partitions=never", + self.table.device, input=self.script()) + + def verify(self, actual): + expected = {p.number: p for p in self.table.parts if p not in self.remove} + expected[self.userdata.number] = replace(self.userdata, end=self.userdata_end) + new = {p.number: p for p in self.create} + if ((actual.device, actual.sector_size, actual.first, actual.last, actual.disk_id, actual.entry_count) + != (self.table.device, self.table.sector_size, self.table.first, self.table.last, self.table.disk_id, self.table.entry_count) + or actual.unused or {p.number for p in actual.parts} != expected.keys() | new.keys()): + raise Error("Partition table does not match the installation plan") + for p in actual.parts: + wanted = new.get(p.number) + if (wanted and replace(p, uuid="", attrs="") != wanted) or (not wanted and p != expected[p.number]): + raise Error(f"Partition {p.number} does not match the installation plan") + + + def verify_kernel(self): + for p in (replace(self.userdata, end=self.userdata_end), *self.create): + node = part_node(self.table.device, p.number) + path = Path("/sys/class/block") / Path(self.table.device).name / Path(node).name + try: + ident = os.stat(node).st_rdev + device_id = (path / "dev").read_text().strip() + # Sysfs uses 512-byte sectors even on 4Kn disks. + start = int((path / "start").read_text()) * 512 + size = int((path / "size").read_text()) * 512 + except (OSError, ValueError) as error: + raise Error(f"Could not verify the kernel partition mapping for {node}: {error}") from error + if (device_id != f"{os.major(ident)}:{os.minor(ident)}" + or start != p.start * self.table.sector_size + or size != (p.end - p.start) * self.table.sector_size): + raise Error(f"Kernel partition mapping for {node} does not match the installation plan") + + +def discover_device(override=None): + if override: + device = str(Path(override).resolve(strict=True)) + else: + disks = json.loads(output("lsblk", "--json", "--paths", "--output", "NAME,TYPE,PARTLABEL"))["blockdevices"] + candidates = [d["name"] for d in disks if d["type"] == "disk" + and any(p.get("partlabel") == "userdata" for p in d.get("children", []))] + if len(candidates) != 1: + raise Error("Could not uniquely identify internal storage; use --device or ARMADA_INTERNAL_DEVICE") + device = candidates[0] + if not Path(device).is_block_device() or output("lsblk", "-dnro", "TYPE", device) != "disk": + raise Error(f"{device} is not a whole block device") + return device + + +def refuse_boot_disk(device): + mount = "/sysroot" if Path("/sysroot").is_mount() else "/" + source = output("findmnt", "--noheadings", "--output", "SOURCE", "--target", mount).split("[", 1)[0] + if not Path(source).is_block_device(): + raise Error("Cannot determine the boot disk; refusing to modify internal storage") + ancestors = output("lsblk", "--inverse", "--noheadings", "--raw", "--output", "MAJ:MIN", source).splitlines() + ident = os.stat(device).st_rdev + if not ancestors or f"{os.major(ident)}:{os.minor(ident)}" in ancestors: + raise Error("Refusing to modify the disk the running system booted from") + + +def require_idle(plan): + parts = list(plan.remove) + if plan.operation != "replace": + parts.append(plan.userdata) + mounted = {line.split()[2] for path in ("/proc/1/mountinfo", "/proc/self/mountinfo") + for line in Path(path).read_text().splitlines()} + swaps = {os.stat(line.split()[0]).st_rdev for line in Path("/proc/swaps").read_text().splitlines()[1:]} + for p in parts: + node = part_node(plan.table.device, p.number) + ident = os.stat(node).st_rdev + key = f"{os.major(ident)}:{os.minor(ident)}" + if key in mounted or ident in swaps or any((Path("/sys/dev/block") / key / "holders").iterdir()): + raise Error(f"{node} is in use; unmount it and disable its swap or device mappings before continuing") + + +@dataclass +class SourceImage: + repo: object + checksum: str + origin: object + refs: dict + + @classmethod + def read(cls, repo, deployment): + _, OSTree = ostree_api() + from gi.repository import GLib + if deployment is None or deployment.get_unlocked() != OSTree.DeploymentUnlockedState.NONE: + raise Error("A locked, booted OSTree deployment is required") + origin = deployment.get_origin() + if origin is None or any(origin.has_group(g) for g in ("rpmostree", "packages", "overrides", "modules")): + raise Error("Missing update origin or unsupported local package modifications") + data, length = origin.to_data() + origin = type(origin).new() + origin.load_from_data(data, length, 0) + ref = origin.get_string("origin", "container-image-reference") + if not re.fullmatch(r"(?:ostree-image-signed:docker://|ostree-unverified-registry:|ostree-unverified-image:)[A-Za-z0-9_./:@+-]+", ref): + raise Error("Unsupported container update origin") + registry_ref = re.sub(r"^(?:ostree-image-signed:docker://|ostree-unverified-registry:(?:docker://)?|ostree-unverified-image:docker://)", "", ref) + if re.fullmatch(r"ghcr\.io/(?:armada-os|virtudude)/armada(?::[A-Za-z0-9_.-]+)?(?:@sha256:[0-9a-f]{64})?", registry_ref): + origin.set_string("origin", "container-image-reference", "ostree-image-signed:docker://" + registry_ref) + checksum = deployment.get_csum() + try: + metadata = cls.metadata(repo, checksum) + manifest = json.loads(metadata["ostree.manifest"]) + config = json.loads(metadata["ostree.container.image-config"]) + if (not isinstance(config, dict) or not re.fullmatch(r"sha256:[0-9a-f]{64}", metadata["ostree.manifest-digest"]) + or manifest["schemaVersion"] != 2 or not isinstance(manifest["layers"], list) or not manifest["layers"]): + raise ValueError("invalid image metadata") + refs = {checksum: checksum} + for layer in manifest["layers"]: + digest = layer["digest"] + if not re.fullmatch(r"sha256:[0-9a-f]{64}", digest): + raise ValueError("invalid layer digest") + layer_ref = "ostree/container/blob/" + digest.replace(":", "_3A_") + _, layer_commit = repo.resolve_rev(layer_ref, False) + cls.metadata(repo, layer_commit) + refs[layer_ref] = layer_commit + except (KeyError, TypeError, ValueError, GLib.Error) as error: + raise Error(f"The selected deployment has no supported complete container image: {error}") from error + return cls(repo, checksum, origin, refs) + + @staticmethod + def metadata(repo, checksum): + _, commit, state = repo.load_commit(checksum) + if state: + raise Error(f"Incomplete source commit: {checksum}") + return commit.unpack()[0] + + def copy(self, target): + repo = Path(target) / "ostree/repo" + run("ostree", "pull-local", "--untrusted", "--disable-verify-bindings", f"--repo={repo}", + repo_path(self.repo), *self.refs) + for ref, expected in self.refs.items(): + if output("ostree", "rev-parse", f"--repo={repo}", ref) != expected: + raise Error(f"Copied image reference does not match the source: {ref}") + run("ostree", "fsck", f"--repo={repo}") + + +@contextmanager +def locked_source(): + _, OSTree = ostree_api() + sysroot = OSTree.Sysroot.new_default() + sysroot.initialize_with_mount_namespace(None) + if not sysroot.is_booted(): + raise Error("The installer must run from a booted OSTree system") + run("mount", "--make-rprivate", "/") + print("Waiting for the OSTree source lock...", flush=True) + sysroot.lock() + try: + sysroot.load(None) + _, repo = sysroot.get_repo(None) + path = repo_path(repo) + # fsck can mark damaged commits partial, even without repair options. + run("mount", "--bind", path, path) + try: + run("mount", "-o", "remount,bind,ro", path) + yield SourceImage.read(repo, sysroot.get_booted_deployment()) + finally: + run("umount", path) + finally: + sysroot.unlock() + + +def base_kargs(directory=Path("/usr/lib/bootc/kargs.d")): + args = [] + for path in sorted(directory.glob("*.toml")): + with path.open("rb") as stream: + data = tomllib.load(stream) + if "match-architectures" in data and platform.machine() not in data["match-architectures"]: + continue + values = data.get("kargs", []) + if not isinstance(values, list) or any(not isinstance(v, str) or any(c.isspace() for c in v) for v in values): + raise Error(f"Invalid kernel arguments in {path}") + args.extend(v for v in values if not v.startswith(("root=", "boot=", "rootflags=", "ostree="))) + return args + + +def configure_deployment(target, source, uuids, kargs): + Gio, OSTree = ostree_api() + sysroot = OSTree.Sysroot.new(Gio.File.new_for_path(str(target))) + sysroot.load(None) + deployments = sysroot.get_deployments() + if len(deployments) != 1 or deployments[0].get_csum() != source.checksum: + raise Error("Target does not contain exactly the selected deployment") + deployment = deployments[0] + if deployment.get_origin().get_string("origin", "container-image-reference") != source.origin.get_string("origin", "container-image-reference"): + raise Error("Target update origin does not match the selected image") + root = target / "ostree/deploy" / deployment.get_osname() / "deploy" / f"{source.checksum}.{deployment.get_deployserial()}" + (root / "etc/fstab").write_text( + f"UUID={uuids['boot']} /boot auto ro 0 0\n" + f"UUID={uuids['esp']} /boot/efi vfat umask=0077,shortname=winnt 0 2\n" + f"UUID={uuids['root']} /var btrfs {BTRFS_OPTS},subvol=var 0 0\n" + f"UUID={uuids['root']} /var/home btrfs {BTRFS_OPTS},subvol=home 0 0\n") + entries = list((target / "boot/loader/entries").glob("*.conf")) + if len(entries) != 1: + raise Error("Expected one boot entry for the new installation") + entry = entries[0] + fields = dict(line.split(None, 1) for line in entry.read_text().splitlines() if line.strip()) + pointers = [arg for arg in fields.get("options", "").split() if arg.startswith("ostree=")] + if len(pointers) != 1 or not fields.get("linux") or not fields.get("initrd"): + raise Error("Incomplete boot entry") + if (target / pointers[0].split("=", 1)[1].lstrip("/")).resolve(strict=True) != root.resolve(): + raise Error("Boot entry does not reference the selected deployment") + linux, initrd = (fields[key] if fields[key].startswith("/boot/") else "/boot" + fields[key] for key in ("linux", "initrd")) + options = [f"root=UUID={uuids['root']}", "rw", f"boot=UUID={uuids['boot']}", *kargs, + f"rootflags=subvol=root,{BTRFS_OPTS}", pointers[0]] + entry.write_text(f"title Armada\nversion {fields.get('version', '1')}\noptions {' '.join(options)}\n" + f"linux {linux}\ninitrd {initrd}\nfdtdir {Path(linux).parent}/dtb\n") + + +class Installation: + def __init__(self, plan): + self.plan = plan + self.changed = False + self.mounts = [] + self.work = None + + def mount(self, source, target, options=None): + target.mkdir(parents=True, exist_ok=True) + self.mounts.append(target) + try: + run("mount", *(["-o", options] if options else []), source, target) + except BaseException: + if not target.is_mount(): + self.mounts.remove(target) + raise + + def close(self): + failed = False + for target in reversed(self.mounts): + try: + run("umount", target) + except (Error, OSError) as error: + failed = True + print(f"ERROR: cleanup: {error}", file=sys.stderr) + if self.work and not failed: + shutil.rmtree(self.work) + if failed: + raise Error("Could not unmount the installation filesystems; do not remove storage") + + def partition(self): + plan = self.plan + refuse_boot_disk(plan.table.device) + if read_table(plan.table.device) != plan.table: + raise Error("The partition table changed after inspection; start the installer again") + require_idle(plan) + self.changed = True + plan.write() + run("partprobe", plan.table.device) + run("udevadm", "settle") + plan.verify(read_table(plan.table.device)) + plan.verify_kernel() + if plan.operation != "replace": + run("dd", "if=/dev/zero", f"of={part_node(plan.table.device, plan.userdata.number)}", + "bs=1M", "count=8", "conv=fsync", "status=none") + + def deploy(self, source, kargs): + plan = self.plan + esp, boot, root = [part_node(plan.table.device, p.number) for p in plan.create] + self.work = Path(tempfile.mkdtemp(prefix="armada-install.", dir="/run")) + target, top = self.work / "target", self.work / "top" + print("Preparing the internal filesystems...", flush=True) + run("mkfs.btrfs", "-f", "-L", "root", root) + self.mount(root, top) + for name in ("root", "var", "home"): + run("btrfs", "subvolume", "create", top / name) + run("umount", top) + self.mounts.remove(top) + self.mount(root, target, BTRFS_OPTS + ",subvol=root") + self.mount(root, target / "var", BTRFS_OPTS + ",subvol=var") + self.mount(root, target / "var/home", BTRFS_OPTS + ",subvol=home") + run("ostree", "admin", "init-fs", "--modern", target) + run("mkfs.vfat", "-F", "16", "-S", plan.table.sector_size, "-s", 16384 // plan.table.sector_size, "-n", "ARMADA", esp) + run("mkfs.ext4", "-F", "-L", "boot", boot) + self.mount(boot, target / "boot") + self.mount(esp, target / "boot/efi") + uuids = {name: output("blkid", "-s", "UUID", "-o", "value", node) + for name, node in (("root", root), ("boot", boot), ("esp", esp))} + if not all(re.fullmatch(r"[A-Za-z0-9-]+", value) for value in uuids.values()): + raise Error("Could not determine filesystem UUIDs") + repo = target / "ostree/repo" + run("ostree", "config", f"--repo={repo}", "set", "sysroot.bootloader", "none") + run("ostree", "config", f"--repo={repo}", "set", "sysroot.bootprefix", "true") + run("ostree", "config", f"--repo={repo}", "set", "sysroot.readonly", "true") + run("ostree", "admin", "os-init", f"--sysroot={target}", "default") + print("Copying and verifying the selected image...", flush=True) + source.copy(target) + origin = self.work / "origin" + origin.write_text(source.origin.to_data()[0]) + run("ostree", "admin", "deploy", "--no-merge", f"--origin-file={origin}", f"--sysroot={target}", "--os=default", source.checksum) + seed = target / ".armada-var-seed" + run("ostree", "checkout", f"--repo={repo}", "--subpath=/var", source.checksum, seed) + run("cp", "-a", f"{seed}/.", f"{target}/var/") + shutil.rmtree(seed) + configure_deployment(target, source, uuids, kargs) + print("Writing the internal boot image...", flush=True) + with tempfile.TemporaryDirectory(prefix=".armada-bootimg.", dir=target) as scratch: + run(BOOTIMG, env=dict(os.environ, TMPDIR=scratch, ESP=str(target / "boot/efi"), + BOOTROOT=str(target / "boot"), SYSROOT=str(target))) + if not (target / "boot/efi/KERNEL").is_file() or not (target / "boot/efi/KERNEL").stat().st_size: + raise Error("The internal boot image was not created") + + def recovery(self): + android = " Android userdata and earlier partitions are unchanged." if self.plan.operation == "replace" else "" + return "Internal storage was modified." + android + " Do not boot internal storage. " + RECOVERY + + +@contextmanager +def operation(plan): + job = Installation(plan) + failure = None + try: + yield job + except BaseException as error: + failure = error + raise + finally: + try: + job.close() + except (Error, OSError) as error: + if failure is None: + failure = error + raise + finally: + if failure is not None and job.changed: + print("ERROR: " + job.recovery(), file=sys.stderr) + + +@contextmanager +def inhibit_sleep(): + # Starting systemd-inhibit does not mean logind has granted the lock. + child = subprocess.Popen(["systemd-inhibit", "--what=sleep:idle:shutdown", "--who=Armada Installer", + "--why=installer operation in progress", "--mode=block", sys.executable, "-c", + "import time; print('ready', flush=True); time.sleep(2147483647)"], + stdout=subprocess.PIPE, start_new_session=True) + try: + if not select.select([child.stdout], [], [], 10)[0] or child.stdout.readline() != b"ready\n": + raise Error("Could not inhibit sleep and shutdown; installation was not started") + yield + finally: + if child.poll() is None: + os.killpg(child.pid, signal.SIGTERM) + child.wait() + child.stdout.close() + + +def require_commands(): + needed = ["sfdisk", "lsblk", "findmnt", "partprobe", "udevadm", "dd", "systemd-inhibit", "mount"] + needed += ["btrfs", "mkfs.btrfs", "mkfs.ext4", "mkfs.vfat", "umount", "ostree", "blkid", "cp", BOOTIMG] + missing = [name for name in needed if not shutil.which(name)] + if missing: + raise Error("Missing required tools: " + ", ".join(missing)) + + +def execute(args): + if os.geteuid() != 0: + raise Error("This command must run as root") + if args.command == "preflight": + started = time.monotonic() + with inhibit_sleep(), locked_source() as source: + print("Checking the complete source repository...", flush=True) + run("ostree", "fsck", f"--repo={repo_path(source.repo)}") + print(f"Validated source commit: {source.checksum}", flush=True) + print(f"Source preflight completed in {time.monotonic() - started:.1f} seconds; internal storage was not touched.", flush=True) return - fi - - while :; do - read -rp "New Android userdata size in GiB [min ${min_gib}, max ${max_gib}]: " ud_gib - ud_gib=${ud_gib:-$min_gib} - if ! [[ $ud_gib =~ ^[0-9]+$ ]]; then echo " enter an integer"; continue; fi - ud_mib=$((ud_gib * 1024)) - if (( ud_mib < MIN_NEW_UD_MIB || ud_mib > MAX_NEW_UD_MIB )); then - echo " out of range: ${min_gib} .. ${max_gib} GiB"; continue - fi - break - done -} - -# Fills [esp_start_mib .. region_end_mib] with ARMADA/ARMADA_BOOT/ARMADA_ROOT and -# resolves them by label. userdata is the last existing partition either way (fresh -# recreates it, replace leaves it), so the three claim slots UD_NUM+1..+3. -create_linux_partitions() { - local esp_start_mib="$1" region_end_mib="$2" - local esp_end_mib boot_start_mib boot_end_mib root_start_mib esp_num boot_num root_num part - esp_end_mib=$((esp_start_mib + ESP_MIB)) - boot_start_mib=$esp_end_mib - boot_end_mib=$((boot_start_mib + BOOT_MIB)) - root_start_mib=$boot_end_mib - esp_num=$((UD_NUM + 1)) - boot_num=$((UD_NUM + 2)) - root_num=$((UD_NUM + 3)) - - parted -a optimal -s "$DEVICE" mkpart primary fat32 "${esp_start_mib}MiB" "${esp_end_mib}MiB" - parted -s "$DEVICE" name "$esp_num" "$ESP_PARTLABEL" - parted -s "$DEVICE" set "$esp_num" boot on - sgdisk --typecode="${esp_num}:${ESP_GUID}" "$DEVICE" >/dev/null - - parted -a optimal -s "$DEVICE" mkpart primary ext4 "${boot_start_mib}MiB" "${boot_end_mib}MiB" - parted -s "$DEVICE" name "$boot_num" ARMADA_BOOT - - # End the btrfs at region_end_mib, never 100%: that bound stays inside the window - # actually owned (the freed userdata window on fresh, the freed Linux window on - # replace) and never spans a trailing partition. - parted -a optimal -s "$DEVICE" mkpart primary btrfs "${root_start_mib}MiB" "${region_end_mib}MiB" - parted -s "$DEVICE" name "$root_num" ARMADA_ROOT - - partprobe "$DEVICE" || true - udevadm settle - - # Resolve by the labels just set, not by assumed device-node numbers. - ESP_PART=$(resolve_partlabel "$ESP_PARTLABEL") - BOOT_PART=$(resolve_partlabel ARMADA_BOOT) - ROOT_PART=$(resolve_partlabel ARMADA_ROOT) - for part in "$ESP_PART" "$BOOT_PART" "$ROOT_PART"; do - [[ -b $part ]] || { echo "ERROR: $part did not appear after partitioning" >&2; exit 1; } - done -} - -# Fresh device: shrink Android userdata to the chosen size, then fill the freed -# space with Armada. Android is reset (superblock zeroed). -install_fresh() { - local new_ud_end_mib=$((UD_START_MIB + ud_mib)) - - cat </dev/null 2>&1; then - umount "$UD_PART" - fi - - # Past this point the original Android userdata partition is gone; a failure - # leaves no bootable internal layout, so arm the recovery message. - destructive=1 - parted -s "$DEVICE" rm "$UD_NUM" - parted -a optimal -s "$DEVICE" mkpart primary ext4 "${UD_START_MIB}MiB" "${new_ud_end_mib}MiB" - parted -s "$DEVICE" name "$UD_NUM" userdata - - create_linux_partitions "$new_ud_end_mib" "$UD_END_MIB" - [[ -b $UD_PART ]] || { echo "ERROR: $UD_PART did not appear after partitioning" >&2; exit 1; } - dd if=/dev/zero of="$UD_PART" bs=1M count=8 status=none -} - -# Existing install: delete only its Linux partitions and put Armada in that freed -# space. Android userdata is left exactly as-is: no resize, no wipe. -install_replace() { - local esp_start_mib region_end_mib win_mib installed n p - OPERATION=replace - # First MiB boundary after the untouched userdata, out to the end of the freed - # Linux region (OUR_MAX_END, the original userdata extent). - esp_start_mib=$(( (UD_END + 1048576) / 1048576 )) - region_end_mib=$(( OUR_MAX_END / 1048576 )) - win_mib=$(( region_end_mib - esp_start_mib )) - if (( win_mib < ESP_MIB + BOOT_MIB + ROOT_MIN_MIB )); then - echo "ERROR: the freed Linux space (~$((win_mib / 1024)) GiB) is too small for Armada (needs ~$(( (ESP_MIB + BOOT_MIB + ROOT_MIN_MIB) / 1024 )) GiB)." >&2 - echo " Use 'armada-installer reset' to return the disk to Android, then install fresh." >&2 - exit 1 - fi - if (( has_armada || has_armada_boot || has_armada_root )); then installed="Armada"; else installed="ROCKNIX"; fi - - cat </dev/null 2>&1; then - umount "$p" || { echo "ERROR: $p is mounted and could not be unmounted; aborting before any change." >&2; exit 1; } - fi - done - - # Past this point the old Linux install is being torn down; a failure leaves no - # bootable internal layout, so arm the recovery message. Android is untouched. - destructive=1 - for n in $(printf '%s\n' "${OUR_NUMS[@]}" | sort -rn); do - parted -s "$DEVICE" rm "$n" - done - create_linux_partitions "$esp_start_mib" "$region_end_mib" -} - -base_kargs() { - local file - for file in /usr/lib/bootc/kargs.d/*.toml; do - [[ -f $file ]] || continue - sed -n '/^kargs = \[/,/^\]/{s/^[[:space:]]*"\([^"]*\)",\?/\1/p}' "$file" - done -} - -set_origin() { - # A raw `ostree admin deploy` leaves no container origin (bootc upgrade no-ops); - # copy the booted origin so the internal install tracks the same ghcr ref. - local src dst ref registry bare - # || true: an empty glob makes ls exit nonzero, which set -e would treat as fatal. - src=$(ls /ostree/deploy/*/deploy/"${commit}".*.origin 2>/dev/null | head -n1) || true - dst=$(ls "$TARGET"/ostree/deploy/*/deploy/"${commit}".*.origin 2>/dev/null | head -n1) || true - if [[ -z $src || -z $dst ]]; then - echo "WARNING: could not set bootc origin; internal install will NOT receive OTA updates" >&2 + device = discover_device(args.device) + table = read_table(device) + if args.command == "detect": + info = table.info() + info.update(device=device, table_fingerprint=table_fingerprint(table)) + print(json.dumps(info) if args.json else "\n".join(f"{k}={v}" for k, v in info.items())) return - fi - cp -f "$src" "$dst" - ref=$(sed -n 's/^container-image-reference=//p' "$dst" | head -1) - # Preserve unknown origins; signed Armada rewrites would make bootc reject them. - registry=$(armada_registry_from_ref "$ref") - if [[ -z $registry ]]; then - echo "WARNING: bootc origin is '${ref:-}', not a signed Armada repository; OTA updates will NOT work on this install (expected for a locally-built image)." >&2 - return - fi - # Anchor at the repository so transport-prefixed and digest refs normalize safely. - bare="${registry}${ref##*${registry}}" - sed -i "s|^container-image-reference=.*|container-image-reference=ostree-image-signed:docker://${bare}|" "$dst" -} - -copy_bootc_ref() { - local ref="$1" - ostree pull-local --repo="$TARGET/ostree/repo" /sysroot/ostree/repo "$ref" -} - -copy_current_bootc_deployment() { - local parent ref target_commit manifest blob_refs image_refs - local image_ref_count=0 - local -a required_refs=("$commit") - - copy_bootc_ref "$commit" || { - echo "ERROR: could not copy booted deployment commit $commit" >&2 - return 1 - } - - parent=$(ostree show --repo=/sysroot/ostree/repo "$commit" | - sed -n 's/^Parent:[[:space:]]*//p' | head -n1) - if [[ -n $parent ]]; then - copy_bootc_ref "$parent" || { - echo "ERROR: could not copy container-image parent commit $parent" >&2 - return 1 - } - required_refs+=("$parent") - fi - - # Generic OCI layers are cached as independent commits. The final image commit - # does not reference them through OSTree history, but bootc still requires each - # manifest layer's blob ref to read deployment metadata and reuse cached layers. - if ! manifest=$(ostree show --repo=/sysroot/ostree/repo \ - --print-metadata-key=ostree.manifest "$commit" 2>/dev/null); then - [[ -n $parent ]] || { - echo "ERROR: booted commit has no container manifest" >&2 - return 1 - } - manifest=$(ostree show --repo=/sysroot/ostree/repo \ - --print-metadata-key=ostree.manifest "$parent") || { - echo "ERROR: container-image parent has no manifest" >&2 - return 1 - } - fi - # ostree prints string metadata in GVariant form, including outer quotes. - manifest=${manifest#\'} - manifest=${manifest%\'} - blob_refs=$(jq -er ' - .layers as $layers - | if ($layers | type) != "array" or ($layers | length) == 0 then - error("container manifest has no layers") - else - $layers - | map( - .digest - | if type == "string" and test("^sha256:[0-9a-f]{64}$") then - "ostree/container/blob/" + sub(":"; "_3A_") - else - error("invalid container layer digest") - end - ) - | unique[] - end - ' <<<"$manifest") || { - echo "ERROR: could not read container layer refs from booted commit" >&2 - return 1 - } - while IFS= read -r ref; do - copy_bootc_ref "$ref" || { - echo "ERROR: could not copy bootc layer ref $ref" >&2 - return 1 - } - required_refs+=("$ref") - done <<<"$blob_refs" - - # A source with a staged update may have image refs for multiple commits. Copy - # only refs for the deployment being installed (or its container-image parent). - image_refs=$(ostree refs --repo=/sysroot/ostree/repo | - sed -n 's#^\(ostree/container/image/.*\)#\1#p') || { - echo "ERROR: could not list container image refs" >&2 - return 1 - } - while IFS= read -r ref; do - [[ -n $ref ]] || continue - target_commit=$(ostree rev-parse --repo=/sysroot/ostree/repo "$ref" 2>/dev/null || true) - if [[ $target_commit == "$commit" || ( -n $parent && $target_commit == "$parent" ) ]]; then - copy_bootc_ref "$ref" || { - echo "ERROR: could not copy bootc image ref $ref" >&2 - return 1 - } - required_refs+=("$ref") - image_ref_count=$((image_ref_count + 1)) - fi - done <<<"$image_refs" - - if (( image_ref_count == 0 )); then - echo "ERROR: no container image ref matches the booted deployment" >&2 - return 1 - fi - - # Do not create a boot entry for a partial copy. In particular, a deployment - # can boot without these layer refs while `bootc status` and upgrades are broken. - for ref in "${required_refs[@]}"; do - ostree rev-parse --repo="$TARGET/ostree/repo" "$ref" >/dev/null 2>&1 || { - echo "ERROR: copied bootc ref is missing from target repository: $ref" >&2 - return 1 - } - done -} - -seed_kernel() { - # SYSROOT must be the target: the ostree= karg comes from the target's BLS - # entry and only resolves against the filesystem that generated it. - ESP="$TARGET/boot/efi" BOOTROOT="$TARGET/boot" SYSROOT="$TARGET" \ - /usr/libexec/armada/armada-bootimg-update || - { echo "ERROR: no /KERNEL written; the internal install is complete but not bootable" >&2; exit 1; } -} - -write_fstab() { - local deploy_dir - deploy_dir=$(find "$TARGET/ostree/deploy/default/deploy" -mindepth 1 -maxdepth 1 -type d -name "${commit}.*" | sort | tail -n1) - [[ -n $deploy_dir ]] || { echo "ERROR: could not find ostree deploy dir" >&2; exit 1; } - mkdir -p "$deploy_dir/etc" - printf 'UUID=%s /boot auto ro 0 0\n' "$BOOT_UUID" > "$deploy_dir/etc/fstab" - # Mount the ESP so /KERNEL regen lands on the FAT the ABL reads, not a /boot dir. - printf 'UUID=%s /boot/efi vfat umask=0077,shortname=winnt 0 2\n' "$ESP_UUID" >> "$deploy_dir/etc/fstab" - printf 'UUID=%s /var btrfs %s,subvol=var 0 0\n' "$ROOT_UUID" "$BTRFS_OPTS" >> "$deploy_dir/etc/fstab" - printf 'UUID=%s /var/home btrfs %s,subvol=home 0 0\n' "$ROOT_UUID" "$BTRFS_OPTS" >> "$deploy_dir/etc/fstab" -} - -rewrite_bls() { - local entry version linux initrd ostree_arg options karg bootdir - # Just-deployed = default = highest BLS version (same helper armada-bootimg-update uses). - entry=$(armada_default_bls_entry "$TARGET/boot") - [[ -n $entry ]] || { echo "ERROR: no BLS entry created" >&2; exit 1; } - - version=$(sed -n 's/^version //p' "$entry" | head -1) - linux=$(sed -n 's/^linux //p' "$entry" | head -1) - initrd=$(sed -n 's/^initrd //p' "$entry" | head -1) - ostree_arg=$(grep -o 'ostree=[^ ]*' "$entry" | head -n1 || true) - [[ -n $linux && -n $initrd && -n $ostree_arg ]] || { echo "ERROR: BLS entry incomplete" >&2; exit 1; } - [[ $linux == /boot/* ]] || linux="/boot${linux}" - [[ $initrd == /boot/* ]] || initrd="/boot${initrd}" - - options="root=UUID=${ROOT_UUID} rw boot=UUID=${BOOT_UUID}" - while IFS= read -r karg; do - # Armada always uses the btrfs subvol layout, so these rootflags replace kargs.d's. - [[ $karg == rootflags=* ]] && continue - options="${options} ${karg}" - done < <(base_kargs) - options="${options} rootflags=subvol=root,${BTRFS_OPTS}" - options="${options} ${ostree_arg}" - - # fdtdir (not a single devicetree): armada-bootimg-update reads this to find - # the DTBs it appends to /KERNEL, so the ABL model picker can pick among them. - bootdir=$(dirname "$linux") - cat > "$entry" </dev/null - tmp=$(mktemp -d -t armada-root.XXXXXX) - mount "$ROOT_PART" "$tmp" - btrfs subvolume create "$tmp/root" >/dev/null - btrfs subvolume create "$tmp/var" >/dev/null - btrfs subvolume create "$tmp/home" >/dev/null - umount "$tmp" - rmdir "$tmp" -} - -mount_root() { - mount -o "${BTRFS_OPTS},subvol=root" "$ROOT_PART" "$TARGET" - mkdir -p "$TARGET/var" - mount -o "${BTRFS_OPTS},subvol=var" "$ROOT_PART" "$TARGET/var" - mkdir -p "$TARGET/var/home" - mount -o "${BTRFS_OPTS},subvol=home" "$ROOT_PART" "$TARGET/var/home" -} - -deploy_to_internal() { - local commit - - for part in "$ESP_PART" "$BOOT_PART" "$ROOT_PART"; do - if findmnt -n "$part" >/dev/null 2>&1; then - umount "$part" - fi - done - - format_root - - TARGET=$(mktemp -d -t armada-install.XXXXXX) - - mount_root - ostree admin init-fs --modern "$TARGET" - - # ARMADA_ROOT is good; only now reformat the (re)bootable ESP + BOOT. Past this - # point a failure leaves no bootable boot.img; the trap surfaces the recovery. - destructive=1 - # The working SD ESP (BIB-made) is FAT16, and the ABL reads FAT16, not FAT32. - # -S 4096 = device 4 KiB sectors; -s 4 keeps the 512 MiB ESP in FAT16 cluster range. - mkfs.vfat -F 16 -S 4096 -s 4 -n "$ESP_PARTLABEL" "$ESP_PART" >/dev/null - mkfs.ext4 -F -L boot "$BOOT_PART" >/dev/null - ROOT_UUID=$(blkid -s UUID -o value "$ROOT_PART") - BOOT_UUID=$(blkid -s UUID -o value "$BOOT_PART") - ESP_UUID=$(blkid -s UUID -o value "$ESP_PART") - - mkdir -p "$TARGET/boot" - mount "$BOOT_PART" "$TARGET/boot" - mkdir -p "$TARGET/boot/efi" - mount "$ESP_PART" "$TARGET/boot/efi" - - ostree admin os-init --sysroot="$TARGET" default - commit=$(ostree admin status --json | jq -r '.deployments[] | select(.booted) | .checksum' | head -n1) - [[ -n $commit && $commit != null ]] || { echo "ERROR: could not determine booted ostree commit" >&2; exit 1; } - - copy_current_bootc_deployment - # --no-merge: a fresh install takes the image's clean /etc, not the booted - # system's /etc edits (the default upgrade-style merge would carry them over). - ostree admin deploy --no-merge --sysroot="$TARGET" --os=default "$commit" - - # Seed /var from the image commit (it carries armada-owned /var/home/armada); - # ostree admin deploy doesn't populate /var, so the home would land root-owned. - local varseed - varseed=$(mktemp -d -t armada-var.XXXXXX) - ostree checkout --repo="$TARGET/ostree/repo" --subpath=/var "$commit" "$varseed/v" - cp -a "$varseed/v/." "$TARGET/var/" - rm -rf "$varseed" - - write_fstab - set_origin - rewrite_bls - seed_kernel - sync -} - -cmd_detect() { - need_root - check_device - detect_mode - if [[ $mode == occupied ]]; then - find_userdata - collect_our_tail - local installed - if (( has_armada || has_armada_boot || has_armada_root )); then - installed=armada - elif (( has_rocknix || has_storage )); then - installed=rocknix - else - installed=unknown - fi - echo "mode=occupied" - echo "installed=${installed}" - echo "android_gib=${UD_ORIG_GIB}" - echo "linux_gib=$(( LINUX_BYTES / 1073741824 ))" - else - find_userdata - if compute_ud_bounds; then - echo "mode=fresh" - echo "android_min_gib=$((MIN_NEW_UD_MIB / 1024))" - echo "android_max_gib=$((MAX_NEW_UD_MIB / 1024))" - echo "android_current_gib=${UD_ORIG_GIB}" - else - echo "mode=toosmall" - echo "needed_gib=$((RESERVE_MIB / 1024))" - echo "android_current_gib=${UD_ORIG_GIB}" - fi - fi -} - -cmd_install() { - while [[ $# -gt 0 ]]; do - case "$1" in - -y|--assume-yes) ASSUME_YES=1 ;; - --userdata-gib) UD_GIB="${2:-}"; shift ;; - --userdata-gib=*) UD_GIB="${1#*=}" ;; - *) echo "ERROR: unknown argument: $1" >&2; exit 2 ;; - esac - shift - done - - need_root - need_cmds - check_device - refuse_self - trap cleanup EXIT - inhibit_sleep - - detect_mode - case "$mode" in - occupied) - # An existing ROCKNIX/Armada install: replace its Linux partitions in - # place, keeping Android. (Reclaiming the space for Android is `reset`.) - find_userdata - collect_our_tail - (( ${#OUR_NUMS[@]} >= 1 )) || { echo "ERROR: found no removable ROCKNIX/Armada partitions on $DEVICE" >&2; exit 1; } - if (( OUR_FOREIGN_AFTER )); then - echo "ERROR: an unrecognized partition lies after userdata on $DEVICE; refusing." >&2 - parted -s "$DEVICE" print >&2 - exit 1 - fi - install_replace - ;; - fresh) - find_userdata - require_userdata_last - cat <&2; exit 2 ;; - esac - shift - done - - OPERATION=reset - need_root - need_cmds - check_device - refuse_self - trap cleanup EXIT - inhibit_sleep - - detect_mode - [[ $mode == occupied ]] || { echo "Nothing to remove: no ROCKNIX or Armada install found on $DEVICE." >&2; exit 1; } - - find_userdata - collect_our_tail - (( ${#OUR_NUMS[@]} >= 1 )) || { echo "ERROR: found no removable ROCKNIX/Armada partitions on $DEVICE" >&2; exit 1; } - if (( OUR_FOREIGN_AFTER )); then - echo "ERROR: an unrecognized partition lies after userdata on $DEVICE; refusing to remove." >&2 - parted -s "$DEVICE" print >&2 - exit 1 - fi - - local new_ud_end_mib new_ud_gib installed n p - new_ud_end_mib=$(( OUR_MAX_END / 1048576 )) - new_ud_gib=$(( (new_ud_end_mib - UD_START_MIB) / 1024 )) - if (( has_armada || has_armada_boot || has_armada_root )); then installed="Armada"; else installed="ROCKNIX"; fi - - cat </dev/null 2>&1; then - umount "$p" || { echo "ERROR: $p is mounted and could not be unmounted; aborting before any change." >&2; exit 1; } - fi - done - if findmnt -n "$UD_PART" >/dev/null 2>&1; then - umount "$UD_PART" || { echo "ERROR: $UD_PART is mounted and could not be unmounted; aborting before any change." >&2; exit 1; } - fi - - # Past this point the layout is being torn down; a failure leaves internal - # storage half-modified, so arm the recovery message. - destructive=1 - # Highest number first: deleting a lower number would renumber the rest. - for n in $(printf '%s\n' "${OUR_NUMS[@]}" | sort -rn); do - parted -s "$DEVICE" rm "$n" - done - # resizepart preserves userdata's GPT type GUID + name (so Android still finds - # it); only the end LBA moves out to reclaim the freed window. - parted -a optimal -s "$DEVICE" resizepart "$UD_NUM" "${new_ud_end_mib}MiB" - - partprobe "$DEVICE" || true - udevadm settle - [[ -b $UD_PART ]] || { echo "ERROR: $UD_PART missing after resize" >&2; exit 1; } - dd if=/dev/zero of="$UD_PART" bs=1M count=8 status=none - sync - - cat </dev/null 2>&1 - exit 1 -} - -# Heartbeat drives the dialog (the install's output is too sparse to); wait gives the true code. -gui_run() { - local text="$1" pid; shift - sudo "$SELF" "$@" >"$GUI_LOG" 2>&1 & - pid=$! - ( while kill -0 "$pid" 2>/dev/null; do printf '\n'; sleep 1; done ) \ - | zenity --progress --pulsate --auto-close --no-cancel \ - --title="$GUI_TITLE" --width=480 --text="$text" >/dev/null 2>&1 - wait "$pid" -} - -gui_offer_poweroff() { - zenity --question --title="$GUI_TITLE" --icon="$GUI_ICON" --width=460 --no-wrap \ - --ok-label="Power off" --cancel-label="Close" --text="$1" \ - && sudo systemctl poweroff || true -} - -gui_install_flow() { - local info="$1" amin amax acur default_android ud - amin=$(sed -n 's/^android_min_gib=//p' <<<"$info") - amax=$(sed -n 's/^android_max_gib=//p' <<<"$info") - acur=$(sed -n 's/^android_current_gib=//p' <<<"$info") - - zenity --question --title="$GUI_TITLE" --icon="$GUI_ICON" --width=480 --no-wrap \ - --ok-label="Continue" --cancel-label="Cancel" \ - --text="Install Armada alongside Android?\n\nThis factory-resets Android: you lose installed Android apps and data\n(the Android system itself is kept). Your SD card is not touched." \ - || exit 0 - - # Default Android to a usable size when there's room, else the floor - # (Armada-first). - default_android=$amin - (( amax >= 32 )) && default_android=32 - ud=$(zenity --scale --title="$GUI_TITLE" --icon="$GUI_ICON" \ - --text="Choose Android's size\n\nThe slider sets Android's storage in GB.\nArmada gets the rest.\n\nCurrent Android: ${acur} GB." \ - --min-value="$amin" --max-value="$amax" --value="$default_android" --step=4) \ - || exit 0 - - zenity --question --title="$GUI_TITLE" --icon="$GUI_ICON" --width=480 --no-wrap \ - --ok-label="Install" --cancel-label="Cancel" \ - --text="Ready to install\n\nAndroid: ${ud} GB\nArmada: $((acur - ud)) GB\n\nResizing Android factory-resets it: you lose installed apps and data (the Android system is kept)." \ - || exit 0 - - gui_run "Installing Armada, do not power off…" install --assume-yes --userdata-gib "$ud" \ - || gui_die "Install failed (details in ${GUI_LOG}).\n\nIf internal storage was modified, select UNINSTALL CFW in ABL to abandon the installation." - gui_offer_poweroff "Install complete.\n\nPower off, remove the SD card, then power on." -} - -gui_manage_flow() { - local info="$1" installed android linux name primary remove out rc - installed=$(sed -n 's/^installed=//p' <<<"$info") - android=$(sed -n 's/^android_gib=//p' <<<"$info") - linux=$(sed -n 's/^linux_gib=//p' <<<"$info") - case "$installed" in - armada) name="Armada"; primary="Reinstall Armada" ;; - rocknix) name="ROCKNIX"; primary="Switch to Armada" ;; - *) gui_die "Internal storage has an unrecognized Linux layout.\n\nThis tool only manages installs it created. To remove it, select UNINSTALL CFW in ABL." ;; - esac - remove="Remove & Restore Android" - local name_e remove_e primary_e - name_e=$(esc "$name"); remove_e=$(esc "$remove"); primary_e=$(esc "$primary") - - # Three choices: primary (keep Android) = OK; remove (wipe Android) = extra - # button (echoed on stdout, exit 1); Cancel/close = exit 1, no stdout. - out=$(zenity --question --title="$GUI_TITLE" --icon="$GUI_ICON" --width=540 --no-wrap \ - --ok-label="$primary" --extra-button="$remove" --cancel-label="Cancel" \ - --text="${name_e} is installed on internal storage.\n\nAndroid: ${android} GB\n${name_e}: ${linux} GB\n\n${remove_e} erases everything and gives the disk back to Android.\n${primary_e} keeps your Android.") && rc=0 || rc=$? - - if (( rc == 0 )); then - gui_run "Installing Armada, do not power off…" install --assume-yes \ - || gui_die "Install failed (details in ${GUI_LOG}).\n\nIf internal storage was modified, select UNINSTALL CFW in ABL to abandon the installation." - gui_offer_poweroff "Armada installed. Your Android is unchanged.\n\nPower off, remove the SD card, then power on." - elif [[ "$out" == "$remove" ]]; then - zenity --question --title="$GUI_TITLE" --icon="$GUI_ICON" --width=500 --no-wrap \ - --ok-label="Remove" --cancel-label="Cancel" \ - --text="Remove ${name_e} and give all storage back to Android?\n\nThis ERASES ${name_e} and factory-resets Android. It can't be undone." \ - || exit 0 - gui_run "Removing ${name}, do not power off…" reset --assume-yes \ - || gui_die "Remove failed (details in ${GUI_LOG}).\n\nTo finish removing ${name_e}, select UNINSTALL CFW in ABL." - gui_offer_poweroff "${name_e} removed. Android has the full internal disk again.\n\nPower off and remove the SD card to boot Android, or relaunch to install Armada." - fi -} - -cmd_gui() { - GUI_TITLE="Armada Installer" - GUI_ICON="drive-harddisk" - GUI_LOG=/tmp/armada-installer.log - command -v zenity >/dev/null 2>&1 || { echo "zenity not installed" >&2; exit 1; } - - local info gmode - info=$(sudo "$SELF" detect 2>/dev/null) || gui_die "Couldn't inspect internal storage." - gmode=$(sed -n 's/^mode=//p' <<<"$info") - case "$gmode" in - fresh) gui_install_flow "$info" ;; - occupied) gui_manage_flow "$info" ;; - toosmall) - local need - need=$(sed -n 's/^needed_gib=//p' <<<"$info") - gui_die "Internal storage is too small to install Armada.\n\nArmada needs about ${need} GB free on internal storage." ;; - *) gui_die "Unexpected internal-storage state: ${gmode:-unknown}." ;; - esac -} - -usage() { - cat >&2 < - - gui desktop (zenity) front-end to install or manage the install - detect read-only probe: print mode + sizes (k=v) - install [opts] fresh install of the running image to internal storage - -y, --assume-yes skip prompts - --userdata-gib N new Android userdata size - reset [opts] remove ROCKNIX/Armada and grow Android back to full disk - -y, --assume-yes skip prompts -EOF - exit 2 -} - -cmd="${1:-}" -[[ $# -gt 0 ]] && shift -case "$cmd" in - gui) cmd_gui "$@" ;; - detect) cmd_detect "$@" ;; - install) cmd_install "$@" ;; - reset) cmd_reset "$@" ;; - -h|--help|help|"") usage ;; - *) echo "ERROR: unknown command: $cmd" >&2; usage ;; -esac + if args.expect_table is not None and args.expect_table != table_fingerprint(table): + raise Error("The target device or partition table changed after confirmation; start the installer again") + require_commands() + refuse_boot_disk(device) + with open("/run/armada-installer.lock", "w") as lock: + try: + fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB) + except BlockingIOError as error: + raise Error("Another installation is already running") from error + size = getattr(args, "userdata_gib", None) + if args.command == "install" and table.info()["mode"] == "fresh" and size is None: + if args.assume_yes: + raise Error("Specify --userdata-gib for an unattended fresh install") + info = table.info() + try: + size = int(input(f"New Android size in GiB ({info['android_min_gib']}..{info['android_max_gib']}): ")) + except ValueError as error: + raise Error("Android size must be an integer") from error + plan = Plan.make(table, size) + print(plan.describe(), flush=True) + if not args.assume_yes and input("Proceed? [y/N]: ").strip().lower() not in ("y", "yes"): + raise Cancelled() + require_idle(plan) + with inhibit_sleep(): + kargs = base_kargs() + with locked_source() as source: + with operation(plan) as job: + job.partition() + job.deploy(source, kargs) + os.sync() + print("Install complete. Power off, remove the SD card, then power on.", flush=True) + + + +def choose_android_size(minimum, maximum, total): + import gi + gi.require_version("Gtk", "4.0") + gi.require_version("Adw", "1") + from gi.repository import Adw, Gio, Gtk + + selected = [] + app = Adw.Application(application_id="org.armada.Installer.Size", flags=Gio.ApplicationFlags.NON_UNIQUE) + + def activate(application): + window = Adw.MessageDialog(application=application, title="Armada Installer", heading="Armada Installer") + window.set_default_size(480, -1) + box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12) + box.append(Gtk.Label(label="Choose how to split internal storage", wrap=True)) + sizes = Gtk.Label() + box.append(sizes) + row = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=12) + minus, plus = Gtk.Button(), Gtk.Button() + slider = Gtk.Scale.new_with_range(Gtk.Orientation.HORIZONTAL, minimum, max(maximum, minimum+1), 1) + slider.set_draw_value(False) + slider.set_digits(0) + slider.set_round_digits(0) + slider.set_hexpand(True) + slider.set_value(min(maximum, 32)) + slider.set_sensitive(maximum > minimum) + for button, icon, tooltip in ((minus, "list-remove-symbolic", "Decrease Android storage by 1 GiB"), + (plus, "list-add-symbolic", "Increase Android storage by 1 GiB")): + button.set_child(Gtk.Image(icon_name=icon, pixel_size=16)) + button.set_size_request(56, 56) + button.set_tooltip_text(tooltip) + button.update_property([Gtk.AccessibleProperty.LABEL], [tooltip]) + for widget in (minus, slider, plus): + row.append(widget) + box.append(row) + + def changed(*_): + value = max(minimum, min(maximum, round(slider.get_value()))) + sizes.set_text(f"Android: {value} GiB Armada: {total-value} GiB") + minus.set_sensitive(value > minimum) + plus.set_sensitive(value < maximum) + + slider.connect("value-changed", changed) + minus.connect("clicked", lambda _: slider.set_value(max(minimum, round(slider.get_value())-1))) + plus.connect("clicked", lambda _: slider.set_value(min(maximum, round(slider.get_value())+1))) + changed() + window.set_extra_child(box) + window.add_response("cancel", "Cancel") + window.add_response("continue", "Continue") + window.set_default_response("continue") + window.set_close_response("cancel") + + def respond(dialog, response): + if response == "continue": + selected.append(max(minimum, min(maximum, round(slider.get_value())))) + dialog.destroy() + + window.connect("response", respond) + window.present() + + app.connect("activate", activate) + app.run([]) + if not selected: + raise Cancelled() + return selected[0] + + +class Gui: + def __init__(self, device): + self.command = ["sudo", SELF, *(["--device", device] if device else [])] + + def dialog(self, kind, text, *options): + return run("zenity", "--" + kind, "--title=Armada Installer", "--width=480", "--text=" + html.escape(text), + *options, capture=True, check=False) + + def confirm(self, text, label): + if self.dialog("question", text, "--ok-label=" + label, "--cancel-label=Cancel").returncode: + raise Cancelled() + + def progress(self, command): + fd, name = tempfile.mkstemp(prefix="armada-installer.", suffix=".log", + dir="/run" if os.geteuid() == 0 else f"/run/user/{os.getuid()}") + with os.fdopen(fd, "w") as stream: + progress = subprocess.Popen(["zenity", "--progress", "--pulsate", "--auto-close", "--no-cancel", + "--title=Armada Installer", "--text=Working, do not power off…"], stdin=subprocess.PIPE, text=True) + try: + progress.stdin.write("0\n") + progress.stdin.flush() + result = run(*self.command, *command, "--assume-yes", stdout=stream, stderr=subprocess.STDOUT, check=False) + finally: + try: + progress.stdin.close() + except BrokenPipeError: + pass + progress.wait() + if result.returncode: + with open(name, "rb") as log: + log.seek(max(0, os.fstat(log.fileno()).st_size - 4096)) + recent = "\n".join(log.read().decode(errors="replace").splitlines()[-12:]) + raise Error(f"Operation failed.\n\n{recent}\n\nFull log (available until reboot): {name}\n\n" + "If internal storage was modified: " + RECOVERY) + + def start(self): + info = json.loads(output(*self.command, "detect", "--json")) + self.command = ["sudo", SELF, "--device", info["device"]] + mode = info["mode"] + if mode == "toosmall": + raise Error(f"Internal storage is too small. Armada needs about {info['needed_gib']} GiB alongside Android.") + if mode == "fresh": + self.confirm("Install Armada alongside Android?\n\nInstalling Armada will factory-reset Android and erase all Android user data.", "Continue") + minimum, maximum = info["android_min_gib"], info["android_max_gib"] + gib = choose_android_size(minimum, maximum, info["android_current_gib"]) + self.confirm(f"Resize Android to {gib} GiB and install Armada? All Android user data will be erased.", "Install") + command = ["install", "--userdata-gib", str(gib)] + elif mode == "occupied": + self.confirm("Replace the existing installation?\n\n" + "Internal storage already has space in use alongside Android. Installing Armada will replace everything in that space.\n\n" + "All data in that space will be erased. Android and its user data will be kept.\n\n" + f"Partitions to erase: {info['partition_names']}", + "Replace with Armada") + command = ["install"] + else: + raise Error("Unknown internal storage layout") + self.progress([*command, "--expect-table", info["table_fingerprint"]]) + if self.dialog("question", "Operation complete. Power off and remove the SD card before booting internal storage.", + "--ok-label=Power off", "--cancel-label=Close").returncode == 0: + run("sudo", "systemctl", "poweroff") + + +def main(argv=None): + parser = argparse.ArgumentParser(description=__doc__, epilog="To uninstall, select UNINSTALL CFW in ABL.") + parser.add_argument("--device", default=os.environ.get("ARMADA_INTERNAL_DEVICE")) + commands = parser.add_subparsers(dest="command", required=True) + commands.add_parser("gui", help="desktop installer") + commands.add_parser("detect", help="inspect internal storage without changing it").add_argument("--json", action="store_true") + commands.add_parser("preflight", help="validate the running source without touching internal storage") + install = commands.add_parser("install", help="install the running image") + install.add_argument("--userdata-gib", type=int) + install.add_argument("--expect-table", help="require the target fingerprint returned by detect") + install.add_argument("-y", "--assume-yes", action="store_true") + args = parser.parse_args(argv) + + def interrupt(signum, _frame): + raise Interrupted(signum) + + for signum in (signal.SIGHUP, signal.SIGINT, signal.SIGTERM): + signal.signal(signum, interrupt) + try: + if args.command == "gui": + Gui(args.device).start() + else: + execute(args) + return 0 + except Cancelled: + print("Aborted.") + return 0 + except Exception as error: + print(f"ERROR: {error}", file=sys.stderr) + if args.command == "gui": + Gui(args.device).dialog("error", str(error)) + return 128 + error.signum if isinstance(error, Interrupted) else 1 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/system_files/usr/libexec/armada/controller-type b/system_files/usr/libexec/armada/controller-type index ab5bd4dc..07f7dc5c 100755 --- a/system_files/usr/libexec/armada/controller-type +++ b/system_files/usr/libexec/armada/controller-type @@ -1,5 +1,6 @@ #!/usr/bin/env python3 import re +import shlex import subprocess import sys import time @@ -8,35 +9,55 @@ from pathlib import Path CONFIG = Path("/etc/armada/controller.conf") SERVICE = "org.shadowblip.InputPlumber" IFACE = "org.shadowblip.Input.CompositeDevice" -DEFAULT_TYPE = "deck-uhid" +DEVICE_ENV = "/usr/libexec/armada/device-env" CONTROLLER_TYPES = { "deck-uhid": "Steam Deck", + "xbox-series": "Xbox Series", "xb360": "Xbox 360", "ds5": "DualSense", } -ARMADA_PROFILE_NAMES = { - "AYANEO Japanese Layout", - "AYANEO Layout", - "AYANEO Standard Layout", - "AYN Layout", - "AYN Thor Layout", - "KONKR Pocket FIT Elite", - "Retroid Layout", -} -def load_type(): +def available_types(): + try: + result = subprocess.run( + [DEVICE_ENV], + check=True, + capture_output=True, + text=True, + timeout=5, + ) + except (OSError, subprocess.SubprocessError): + return list(CONTROLLER_TYPES) + raw = "" + for line in result.stdout.splitlines(): + key, sep, value = line.partition("=") + if sep and key.strip() == "ARMADA_IP_TARGETS": + try: + raw = shlex.split(value)[0] if value.strip() else "" + except ValueError: + raw = value.strip() + break + types = [] + for item in raw.split(","): + item = item.strip() + if item in CONTROLLER_TYPES and item not in types: + types.append(item) + return types or list(CONTROLLER_TYPES) + + +def load_type(types): try: lines = CONFIG.read_text(encoding="utf-8", errors="replace").splitlines() except OSError: - return DEFAULT_TYPE + return types[0] value = "" for line in lines: key, sep, raw = line.partition("=") if sep and key.strip() == "controller_type": value = raw.strip() break - return value if value in CONTROLLER_TYPES else DEFAULT_TYPE + return value if value in types else types[0] def save_type(value): @@ -83,17 +104,39 @@ def composite_name(path): return parts[1] if len(parts) >= 2 else "" +def current_target_paths(path): + try: + result = subprocess.run( + ["busctl", "--system", "get-property", SERVICE, path, IFACE, "TargetDevices"], + check=True, + capture_output=True, + text=True, + timeout=2, + ) + except (OSError, subprocess.SubprocessError): + return [] + return re.findall(r'"([^"]*)"', result.stdout) + + +def extra_targets(path): + extras = [] + for target_path in current_target_paths(path): + segment = target_path.rsplit("/", 1)[-1].rstrip("0123456789") + if segment in ("keyboard", "mouse") and segment not in extras: + extras.append(segment) + return extras + + def apply_type(value): paths = composite_paths() if not paths: return False ok = False for path in paths: - if composite_name(path) not in ARMADA_PROFILE_NAMES: - continue + targets = [value] + extra_targets(path) try: subprocess.run( - ["busctl", "--system", "call", SERVICE, path, IFACE, "SetTargetDevices", "as", "2", value, "keyboard"], + ["busctl", "--system", "call", SERVICE, path, IFACE, "SetTargetDevices", "as", str(len(targets)), *targets], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, @@ -116,13 +159,14 @@ def apply_with_retry(value): def main(argv): command = argv[1] if len(argv) > 1 else "get" if command == "get": - print(load_type()) + print(load_type(available_types())) return 0 if command == "set": + types = available_types() if len(argv) != 3: - print("usage: controller-type set ", file=sys.stderr) + print(f"usage: controller-type set <{'|'.join(types)}>", file=sys.stderr) return 2 - if argv[2] not in CONTROLLER_TYPES: + if argv[2] not in types: print(f"invalid controller type: {argv[2]}", file=sys.stderr) return 2 if not apply_with_retry(argv[2]): @@ -130,7 +174,7 @@ def main(argv): save_type(argv[2]) return 0 if command == "apply": - return 0 if apply_with_retry(load_type()) else 1 + return 0 if apply_with_retry(load_type(available_types())) else 1 print("usage: controller-type get|set|apply", file=sys.stderr) return 2 diff --git a/system_files/usr/libexec/armada/device-env b/system_files/usr/libexec/armada/device-env index 3f8609d9..f2f6a809 100755 --- a/system_files/usr/libexec/armada/device-env +++ b/system_files/usr/libexec/armada/device-env @@ -15,9 +15,11 @@ case "$model" in "AYN Odin 2 Mini") profile=ayn-odin-2-mini ;; "AYN Odin 2 Portal") profile=ayn-odin-2-portal ;; "AYN Thor") profile=ayn-thor ;; + "AYN Thor Lite") profile=ayn-thor-lite ;; "AYANEO Pocket ACE") profile=ayaneo-pocket-ace ;; "AYANEO Pocket DMG") profile=ayaneo-pocket-dmg ;; "AYANEO Pocket DS") profile=ayaneo-pocket-ds ;; + "AYANEO Pocket S 1K") profile=ayaneo-pocket-s1k ;; "AYANEO Pocket S 2K") profile=ayaneo-pocket-s2k ;; "AYANEO Pocket S2") profile=ayaneo-pocket-s2 ;; "KONKR Pocket FIT") profile=konkr-pocket-fit ;; @@ -25,7 +27,9 @@ case "$model" in "AYN Odin 3") profile=ayn-odin-3 ;; "Xiaomi Pad 6S Pro"*) profile=sm8550-xiaomi-sheng ;; "Retroid Pocket 5") profile=retroid-pocket-5 ;; + "Retroid Pocket 5 Visionox") profile=retroid-pocket-5 ;; "Retroid Pocket Flip2") profile=retroid-pocket-flip2 ;; + "Retroid Pocket Flip2 Visionox") profile=retroid-pocket-flip2 ;; "Retroid Pocket Mini") profile=retroid-pocket-mini ;; "Retroid Pocket Mini V2") profile=retroid-pocket-mini-v2 ;; "Retroid Pocket 6") profile=retroid-pocket-6 ;; @@ -117,9 +121,7 @@ vars=( ARMADA_PANEL_ORIENTATION ARMADA_HDR_NITS ARMADA_GAMEPAD_QUIRK - ARMADA_RGB_BACKEND - ARMADA_RGB_TARGETS - ARMADA_RGB_CORRECTION + ARMADA_IP_TARGETS ARMADA_LITTLE_CORES ARMADA_BIG_CORES ARMADA_PRIME_CORES diff --git a/system_files/usr/libexec/armada/device-quirks b/system_files/usr/libexec/armada/device-quirks index 3b8f8750..9b8d0b6a 100755 --- a/system_files/usr/libexec/armada/device-quirks +++ b/system_files/usr/libexec/armada/device-quirks @@ -27,10 +27,30 @@ ayaneo_xbox_mode() { echo "device-quirks: AYANEO MCU switched to Xbox 360 mode" } +ayaneo_default_mode() { + local serial_device=/dev/ttyHS0 + + if [[ ! -e "$serial_device" ]]; then + echo "device-quirks: $serial_device not present, skipping AYANEO default mode" + return 0 + fi + + stty -F "$serial_device" 115200 -clocal -opost -isig -icanon -echo + printf '\xe7\x55\x05\x00\x00\x00\x00\x00\x00\x5a\xed' >"$serial_device" + sleep 0.1 + printf '\x35\x35\x30\x35\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30' >"$serial_device" + sleep 0.1 + + echo "device-quirks: AYANEO MCU switched back to default mode" +} + case "${ARMADA_GAMEPAD_QUIRK:-none}" in ayaneo-xbox) ayaneo_xbox_mode ;; + ayaneo-default) + ayaneo_default_mode + ;; none) ;; esac diff --git a/system_files/usr/libexec/armada/session-control b/system_files/usr/libexec/armada/session-control index acedfef4..e6392dbf 100755 --- a/system_files/usr/libexec/armada/session-control +++ b/system_files/usr/libexec/armada/session-control @@ -123,7 +123,13 @@ case "${1:-}" in ;; switch-gamemode) session=gamescope-session-steam.desktop ;; default-gamemode) session=gamescope-session-steam.desktop; default_only=1 ;; - *) echo "usage: $0 {switch-desktop|switch-gamemode|default-gamemode}" >&2; exit 1 ;; + default-desktop) + initialize_plasma_configs + activate_plasma_config "${desktop_mode}" + session=$desktop_session + default_only=1 + ;; + *) echo "usage: $0 {switch-desktop|switch-gamemode|default-gamemode|default-desktop}" >&2; exit 1 ;; esac printf '[Autologin]\nSession=%s\n' "${session}" > /etc/sddm.conf.d/zz-steamos-autologin.conf diff --git a/system_files/usr/share/alsa/ucm2/AYN/Odin3/HiFi.conf b/system_files/usr/share/alsa/ucm2/AYN/Odin3/HiFi.conf index b863976c..f3c86f5d 100644 --- a/system_files/usr/share/alsa/ucm2/AYN/Odin3/HiFi.conf +++ b/system_files/usr/share/alsa/ucm2/AYN/Odin3/HiFi.conf @@ -6,6 +6,14 @@ SectionVerb { cset "name='SECONDARY_MI2S_RX Audio Mixer MultiMedia1' 1" cset "name='RX_CODEC_DMA_RX_0 Audio Mixer MultiMedia2' 1" cset "name='MultiMedia3 Mixer TX_CODEC_DMA_TX_3' 1" + cset "name='DISPLAY_PORT_RX_0 Audio Mixer MultiMedia4' 1" + ] + + DisableSequence [ + cset "name='SECONDARY_MI2S_RX Audio Mixer MultiMedia1' 0" + cset "name='RX_CODEC_DMA_RX_0 Audio Mixer MultiMedia2' 0" + cset "name='MultiMedia3 Mixer TX_CODEC_DMA_TX_3' 0" + cset "name='DISPLAY_PORT_RX_0 Audio Mixer MultiMedia4' 0" ] Include.wcde.File "/codecs/wcd939x/DefaultEnableSeq.conf" @@ -20,7 +28,7 @@ SectionDevice."Speaker" { Value { PlaybackChannels 2 - PlaybackPriority 100 + PlaybackPriority 150 PlaybackPCM "hw:${CardId},0" PlaybackMixer "default:${CardId}" } @@ -59,3 +67,17 @@ SectionDevice."Headphones" { JackHWMute "Speaker" } } + +# A dedicated PCM keeps DisplayPort in the same card profile as the local outputs. +SectionDevice."HDMI" { + Comment "HDMI / DisplayPort playback" + + Value { + PlaybackChannels 2 + PlaybackPriority 100 + PlaybackPCM "hw:${CardId},3" + PlaybackMixer "default:${CardId}" + JackControl "DP0 Jack" + JackHWMute "Speaker" + } +} diff --git a/system_files/usr/share/alsa/ucm2/KONKR/PocketFitElite/HiFi.conf b/system_files/usr/share/alsa/ucm2/KONKR/PocketFitElite/HiFi.conf index 3b7a0cc7..0454412f 100644 --- a/system_files/usr/share/alsa/ucm2/KONKR/PocketFitElite/HiFi.conf +++ b/system_files/usr/share/alsa/ucm2/KONKR/PocketFitElite/HiFi.conf @@ -24,6 +24,14 @@ SectionVerb { cset "name='SECONDARY_MI2S_RX Audio Mixer MultiMedia1' 1" cset "name='RX_CODEC_DMA_RX_0 Audio Mixer MultiMedia2' 1" cset "name='MultiMedia3 Mixer TX_CODEC_DMA_TX_3' 1" + cset "name='DISPLAY_PORT_RX_0 Audio Mixer MultiMedia4' 1" + ] + + DisableSequence [ + cset "name='SECONDARY_MI2S_RX Audio Mixer MultiMedia1' 0" + cset "name='RX_CODEC_DMA_RX_0 Audio Mixer MultiMedia2' 0" + cset "name='MultiMedia3 Mixer TX_CODEC_DMA_TX_3' 0" + cset "name='DISPLAY_PORT_RX_0 Audio Mixer MultiMedia4' 0" ] Include.wcde.File "/codecs/wcd939x/DefaultEnableSeq.conf" @@ -38,7 +46,7 @@ SectionDevice."Speaker" { Value { PlaybackChannels 2 - PlaybackPriority 100 + PlaybackPriority 150 PlaybackPCM "hw:${CardId},0" PlaybackMixer "default:${CardId}" } @@ -76,3 +84,17 @@ SectionDevice."Headphones" { JackHWMute "Speaker" } } + +# A dedicated PCM keeps DisplayPort in the same card profile as the local outputs. +SectionDevice."HDMI" { + Comment "HDMI / DisplayPort playback" + + Value { + PlaybackChannels 2 + PlaybackPriority 100 + PlaybackPCM "hw:${CardId},3" + PlaybackMixer "default:${CardId}" + JackControl "DP0 Jack" + JackHWMute "Speaker" + } +} diff --git a/system_files/usr/share/alsa/ucm2/Qualcomm/sm8250/AYN-Thor-Lite-HiFi.conf b/system_files/usr/share/alsa/ucm2/Qualcomm/sm8250/AYN-Thor-Lite-HiFi.conf new file mode 100644 index 00000000..4f2e9571 --- /dev/null +++ b/system_files/usr/share/alsa/ucm2/Qualcomm/sm8250/AYN-Thor-Lite-HiFi.conf @@ -0,0 +1,122 @@ +# Use case configuration for AYN Thor Lite (SM8250) +# +# Hardware layout (matches sm8250-ayn-thorlite.dts): +# +# Speakers: MultiMedia2 -> q6afe TERTIARY_MI2S_RX -> AW88166 (i2c9 @0x34/@0x35) +# Headphones: MultiMedia1 -> q6afe RX_CODEC_DMA_RX_0 -> rx-macro -> wcd9385 +# Headset Mic: MultiMedia3 <- q6afe TX_CODEC_DMA_TX_3 <- tx-macro <- wcd9385 ADC2 (AMIC2) +# +# PCM device numbers come from the order of mmN-dai-link in the DTS: +# hw:${CardId},0 = MultiMedia1 (headphones) +# hw:${CardId},1 = MultiMedia2 (speakers) +# hw:${CardId},2 = MultiMedia3 (mic capture) +# +# Modeled on the working AYN Odin2 HiFi.conf. +# +# qdsp6 passthrough constraint: +# The ADM COPP is opened with NULL_COPP_TOPOLOGY -- a bit-exact +# passthrough that does no format / rate / channel conversion. The +# backends are hard-fixed to S16_LE / 48000 / 2ch by the kernel's +# sm8250_be_hw_params_fixup(), so every MultiMedia frontend below +# pins Playback/CaptureRate 48000 and 2 channels. UCM has no key for +# the sample format; S16LE is forced by a WirePlumber drop-in +# (51-ayn-thor-lite.conf) instead. + +SectionVerb { + EnableSequence [ + # Connect the FE PCMs to their backend DAIs. These + # " Audio Mixer MultiMediaN" / "MultiMediaN Mixer + # " controls are created by q6routing for every + # valid FE/BE combination; we enable just the ones we use. + # NOTE: the MI2S backend control name uses TERT_MI2S_RX, not + # TERTIARY_MI2S_RX -- q6afe abbreviates MI2S backends. + cset "name='RX_CODEC_DMA_RX_0 Audio Mixer MultiMedia1' 1" + cset "name='TERT_MI2S_RX Audio Mixer MultiMedia2' 1" + cset "name='MultiMedia3 Mixer TX_CODEC_DMA_TX_3' 1" + ] + + DisableSequence [ + cset "name='RX_CODEC_DMA_RX_0 Audio Mixer MultiMedia1' 0" + cset "name='TERT_MI2S_RX Audio Mixer MultiMedia2' 0" + cset "name='MultiMedia3 Mixer TX_CODEC_DMA_TX_3' 0" + ] + + Value { + TQ "HiFi" + } +} + +SectionDevice."Speaker" { + Comment "Internal stereo speakers (AW88166 over MI2S)" + + ConflictingDevice [ + "Headphones" + ] + + EnableSequence [ + # AW88166 powers from DAPM when MultiMedia2 starts streaming. + # Set a default volume on both amps; the per-channel volumes + # are exposed via the codec's sound-name-prefix. + # + # 'PCM Playback Volume' range is 0..1023 (AW88166_MUTE_VOL), + # where 0 is loudest and 1023 is fully muted. 50 is a mild + # attenuation -- move it toward 0 for more output. + cset "name='SpkrLeft PCM Playback Volume' 50" + cset "name='SpkrRight PCM Playback Volume' 50" + ] + + Value { + PlaybackPriority 100 + PlaybackPCM "hw:${CardId},1" + PlaybackChannels 2 + PlaybackRate 48000 + } +} + +SectionDevice."Headphones" { + Comment "3.5 mm headphone jack (WCD9385 HPHL/HPHR)" + + ConflictingDevice [ + "Speaker" + ] + + # Bring up the WCD938x headphone path and the rx-macro that feeds + # it. These four snippets ship with alsa-ucm-conf and are exactly + # the same ones the AYN Odin2 (sm8550) UCM uses with success. + Include.wcdhpe.File "/codecs/wcd938x/HeadphoneEnableSeq.conf" + Include.wcdhpd.File "/codecs/wcd938x/HeadphoneDisableSeq.conf" + Include.rxmhpe.File "/codecs/qcom-lpass/rx-macro/HeadphoneEnableSeq.conf" + Include.rxmhpd.File "/codecs/qcom-lpass/rx-macro/HeadphoneDisableSeq.conf" + + Value { + PlaybackPriority 200 + PlaybackPCM "hw:${CardId},0" + PlaybackChannels 2 + PlaybackRate 48000 + PlaybackMixer "default:${CardId}" + PlaybackMixerElem "HP" + JackControl "Headphone Jack" + JackHWMute "Speaker" + } +} + +SectionDevice."Mic" { + Comment "Headset / built-in microphone (WCD9385 AMIC2)" + + Include.wcdmice.File "/codecs/wcd938x/HeadphoneMicEnableSeq.conf" + Include.wcdmicd.File "/codecs/wcd938x/HeadphoneMicDisableSeq.conf" + Include.txmhpe.File "/codecs/qcom-lpass/tx-macro/HeadphoneMicEnableSeq.conf" + Include.txmhpd.File "/codecs/qcom-lpass/tx-macro/HeadphoneMicDisableSeq.conf" + + # CaptureChannels is 2, not 1: sm8250_be_hw_params_fixup() forces + # the capture backend to 2ch and the qdsp6 COPP does no channel + # conversion, so the frontend must be opened 2ch as well. The mono + # AMIC2 simply lands on the channels of a stereo capture stream. + Value { + CapturePriority 100 + CapturePCM "hw:${CardId},2" + CaptureChannels 2 + CaptureRate 48000 + JackControl "Mic Jack" + } +} diff --git a/system_files/usr/share/alsa/ucm2/Qualcomm/sm8250/AYN-Thor-Lite.conf b/system_files/usr/share/alsa/ucm2/Qualcomm/sm8250/AYN-Thor-Lite.conf new file mode 100644 index 00000000..2dfe4c19 --- /dev/null +++ b/system_files/usr/share/alsa/ucm2/Qualcomm/sm8250/AYN-Thor-Lite.conf @@ -0,0 +1,36 @@ +Syntax 4 + +# Use case configuration for AYN Thor Lite (SM8250) +# +# The card driver is "sm8250" so the UCM lookup falls through +# Qualcomm/sm8250/. The card name comes from the `model` property +# in the device tree ("AYN Thor Lite"); a matching symlink in +# conf.d/sm8250/ points back here. +# +# Modeled on the working AYN Odin2 (sm8550) UCM config, which is +# from the same vendor, uses the same wcd938x codec, and is known +# to work. Differences from Odin2: speaker path uses TERTIARY MI2S +# (vs Primary MI2S on Odin2), and PCM device order matches the DTS +# mm1/mm2/mm3 dai-link order. + +Comment "AYN Thor Lite" + +SectionUseCase."HiFi" { + File "/Qualcomm/sm8250/AYN-Thor-Lite-HiFi.conf" + Comment "Speakers, headphones and headset mic" +} + +# Set sane initial volumes. Without these, the wcd938x boots with +# the HPH analog volume near minimum and the rx-macro digital +# volumes also low, producing very quiet, intermittent-sounding +# audio on the headphone path. Values copied from AYN Odin2. +BootSequence [ + cset "name='HPHL Volume' 20" + cset "name='HPHR Volume' 20" + cset "name='ADC2 Volume' 10" +] + +Include.card-init.File "/lib/card-init.conf" +Include.ctl-remap.File "/lib/ctl-remap.conf" +Include.wcd-init.File "/codecs/wcd938x/init.conf" +Include.rxm-init.File "/codecs/qcom-lpass/rx-macro/init.conf" diff --git a/system_files/usr/share/alsa/ucm2/conf.d/sm8250/AYN Thor Lite.conf b/system_files/usr/share/alsa/ucm2/conf.d/sm8250/AYN Thor Lite.conf new file mode 120000 index 00000000..948cc996 --- /dev/null +++ b/system_files/usr/share/alsa/ucm2/conf.d/sm8250/AYN Thor Lite.conf @@ -0,0 +1 @@ +../../Qualcomm/sm8250/AYN-Thor-Lite.conf \ No newline at end of file diff --git a/system_files/usr/share/alsa/ucm2/conf.d/sm8250/ayn-ATNThorLite-.conf b/system_files/usr/share/alsa/ucm2/conf.d/sm8250/ayn-ATNThorLite-.conf new file mode 120000 index 00000000..948cc996 --- /dev/null +++ b/system_files/usr/share/alsa/ucm2/conf.d/sm8250/ayn-ATNThorLite-.conf @@ -0,0 +1 @@ +../../Qualcomm/sm8250/AYN-Thor-Lite.conf \ No newline at end of file diff --git a/system_files/usr/share/applications/armada-installer.desktop b/system_files/usr/share/applications/armada-installer.desktop index 97c1641a..883a59f3 100644 --- a/system_files/usr/share/applications/armada-installer.desktop +++ b/system_files/usr/share/applications/armada-installer.desktop @@ -1,7 +1,7 @@ [Desktop Entry] Type=Application Name=Armada Installer -Comment=Install Armada alongside Android on the device's internal storage, or remove an existing install +Comment=Install Armada alongside Android on the device's internal storage Exec=/usr/libexec/armada/armada-installer gui TryExec=/run/armada/installable Icon=drive-harddisk diff --git a/system_files/usr/share/inputplumber/capability_maps/ayaneo_mcu_xbox_standard.yaml b/system_files/usr/share/inputplumber/capability_maps/ayaneo_mcu_xbox_standard.yaml deleted file mode 100644 index 60c3f51c..00000000 --- a/system_files/usr/share/inputplumber/capability_maps/ayaneo_mcu_xbox_standard.yaml +++ /dev/null @@ -1,252 +0,0 @@ -# yaml-language-server: $schema=https://raw.githubusercontent.com/ShadowBlip/InputPlumber/main/rootfs/usr/share/inputplumber/schema/capability_map_v2.json -# Schema version number -version: 2 - -# The type of configuration schema -kind: CapabilityMap - -# Name for the device event map -name: AYANEO MCU Standard Mapping (Xbox mode) - -# Unique identifier of the capability mapping -id: ayaneo_mcu_xbox_standard - -# List of mapped events -mapping: - - name: Guide Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_MODE - value_type: button - target_event: - gamepad: - button: Guide - - - name: South Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_SOUTH - value_type: button - target_event: - gamepad: - button: South - - - name: West Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_WEST - value_type: button - target_event: - gamepad: - button: West - - - name: North Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_NORTH - value_type: button - target_event: - gamepad: - button: North - - - name: East Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_EAST - value_type: button - target_event: - gamepad: - button: East - - - name: Start Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_START - value_type: button - target_event: - gamepad: - button: Start - - - name: Select Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_SELECT - value_type: button - target_event: - gamepad: - button: Select - - - name: F1 Key - source_events: - - evdev: - event_type: KEY - event_code: BTN5 - value_type: button - target_event: - keyboard: KeyF1 - - - name: Right Trigger - source_events: - - evdev: - event_type: ABS - event_code: ABS_GAS - value_type: trigger - target_event: - gamepad: - trigger: - name: RightTrigger - - - name: Left Trigger - source_events: - - evdev: - event_type: ABS - event_code: ABS_BRAKE - value_type: trigger - target_event: - gamepad: - trigger: - name: LeftTrigger - - - name: Right Bumper - source_events: - - evdev: - event_type: KEY - event_code: BTN_TR - value_type: button - target_event: - gamepad: - button: RightBumper - - - name: Left Bumper - source_events: - - evdev: - event_type: KEY - event_code: BTN_TL - value_type: button - target_event: - gamepad: - button: LeftBumper - - - name: Right Paddle - source_events: - - evdev: - event_type: KEY - event_code: BTN_C - value_type: button - target_event: - gamepad: - button: RightPaddle1 - - - name: Left Paddle - source_events: - - evdev: - event_type: KEY - event_code: BTN_Z - value_type: button - target_event: - gamepad: - button: LeftPaddle1 - - - name: Right Stick - source_events: - - evdev: - event_type: ABS - event_code: ABS_RX - value_type: joystick_x - - evdev: - event_type: ABS - event_code: ABS_RY - value_type: joystick_y - target_event: - gamepad: - axis: - name: RightStick - - - name: Left Stick - source_events: - - evdev: - event_type: ABS - event_code: ABS_X - value_type: joystick_x - - evdev: - event_type: ABS - event_code: ABS_Y - value_type: joystick_y - target_event: - gamepad: - axis: - name: LeftStick - - - name: Right Stick Click - source_events: - - evdev: - event_type: KEY - event_code: BTN_THUMBR - value_type: button - target_event: - gamepad: - button: RightStick - - - name: Left Stick Click - source_events: - - evdev: - event_type: KEY - event_code: BTN_THUMBL - value_type: button - target_event: - gamepad: - button: LeftStick - - - name: Dpad Left - source_events: - - evdev: - event_type: ABS - event_code: ABS_HAT0X - value_type: button - axis_direction: negative - target_event: - gamepad: - button: DPadLeft - - - name: Dpad Right - source_events: - - evdev: - event_type: ABS - event_code: ABS_HAT0X - value_type: button - axis_direction: positive - target_event: - gamepad: - button: DPadRight - - - name: Dpad Down - source_events: - - evdev: - event_type: ABS - event_code: ABS_HAT0Y - value_type: button - axis_direction: positive - target_event: - gamepad: - button: DPadDown - - - name: Dpad Up - source_events: - - evdev: - event_type: ABS - event_code: ABS_HAT0Y - value_type: button - axis_direction: negative - target_event: - gamepad: - button: DPadUp - -# List of events to filter from the source devices -filtered_events: [] diff --git a/system_files/usr/share/inputplumber/capability_maps/ayn_mcu.yaml b/system_files/usr/share/inputplumber/capability_maps/ayn_mcu.yaml deleted file mode 100644 index fcdc8dd1..00000000 --- a/system_files/usr/share/inputplumber/capability_maps/ayn_mcu.yaml +++ /dev/null @@ -1,258 +0,0 @@ -# yaml-language-server: $schema=https://raw.githubusercontent.com/ShadowBlip/InputPlumber/main/rootfs/usr/share/inputplumber/schema/capability_map_v2.json -# Schema version number -version: 2 - -# The type of configuration schema -kind: CapabilityMap - -# Name for the device event map -name: AYN MCU Mapping - -# Unique identifier of the capability mapping -id: ayn_mcu - -# List of mapped events -mapping: - - name: Guide Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_MODE - value_type: button - target_event: - gamepad: - button: Guide - - - name: South Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_SOUTH - value_type: button - target_event: - gamepad: - button: South - - - name: West Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_NORTH - value_type: button - target_event: - gamepad: - button: West - - - name: North Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_WEST - value_type: button - target_event: - gamepad: - button: North - - - name: East Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_EAST - value_type: button - target_event: - gamepad: - button: East - - - name: Start Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_START - value_type: button - target_event: - gamepad: - button: Start - - - name: Select Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_SELECT - value_type: button - target_event: - gamepad: - button: Select - - - name: Quick Access Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_BACK - value_type: button - target_event: - gamepad: - button: QuickAccess - - - name: Home Key - source_events: - - evdev: - event_type: KEY - event_code: KEY_F24 - value_type: button - target_event: - keyboard: KeyHome - - - name: Right Trigger - source_events: - - evdev: - event_type: ABS - event_code: ABS_RZ - value_type: trigger - target_event: - gamepad: - trigger: - name: RightTrigger - - - name: Left Trigger - source_events: - - evdev: - event_type: ABS - event_code: ABS_Z - value_type: trigger - target_event: - gamepad: - trigger: - name: LeftTrigger - - - name: Right Bumper - source_events: - - evdev: - event_type: KEY - event_code: BTN_TR - value_type: button - target_event: - gamepad: - button: RightBumper - - - name: Left Bumper - source_events: - - evdev: - event_type: KEY - event_code: BTN_TL - value_type: button - target_event: - gamepad: - button: LeftBumper - - - name: Right Paddle - source_events: - - evdev: - event_type: KEY - event_code: BTN_C - value_type: button - target_event: - gamepad: - button: RightPaddle1 - - - name: Left Paddle - source_events: - - evdev: - event_type: KEY - event_code: BTN_Z - value_type: button - target_event: - gamepad: - button: LeftPaddle1 - - - name: Right Stick - source_events: - - evdev: - event_type: ABS - event_code: ABS_RX - value_type: joystick_x - - evdev: - event_type: ABS - event_code: ABS_RY - value_type: joystick_y - target_event: - gamepad: - axis: - name: RightStick - - - name: Left Stick - source_events: - - evdev: - event_type: ABS - event_code: ABS_X - value_type: joystick_x - - evdev: - event_type: ABS - event_code: ABS_Y - value_type: joystick_y - target_event: - gamepad: - axis: - name: LeftStick - - - name: Right Stick Click - source_events: - - evdev: - event_type: KEY - event_code: BTN_THUMBR - value_type: button - target_event: - gamepad: - button: RightStick - - - name: Left Stick Click - source_events: - - evdev: - event_type: KEY - event_code: BTN_THUMBL - value_type: button - target_event: - gamepad: - button: LeftStick - - - name: Dpad Left - source_events: - - evdev: - event_type: KEY - event_code: BTN_DPAD_LEFT - value_type: button - target_event: - gamepad: - button: DPadLeft - - - name: Dpad Right - source_events: - - evdev: - event_type: KEY - event_code: BTN_DPAD_RIGHT - value_type: button - target_event: - gamepad: - button: DPadRight - - - name: Dpad Down - source_events: - - evdev: - event_type: KEY - event_code: BTN_DPAD_DOWN - value_type: button - target_event: - gamepad: - button: DPadDown - - - name: Dpad Up - source_events: - - evdev: - event_type: KEY - event_code: BTN_DPAD_UP - value_type: button - target_event: - gamepad: - button: DPadUp - -# List of events to filter from the source devices -filtered_events: [] diff --git a/system_files/usr/share/inputplumber/capability_maps/konkr_gamepad.yaml b/system_files/usr/share/inputplumber/capability_maps/konkr_gamepad.yaml deleted file mode 100644 index 31a64852..00000000 --- a/system_files/usr/share/inputplumber/capability_maps/konkr_gamepad.yaml +++ /dev/null @@ -1,18 +0,0 @@ -# yaml-language-server: $schema=https://raw.githubusercontent.com/ShadowBlip/InputPlumber/main/rootfs/usr/share/inputplumber/schema/capability_map_v2.json -version: 2 -kind: CapabilityMap -name: KONKR Gamepad Mapping -id: konkr_gamepad - -# The SPI gamepad's front-top-left button is BTN_MODE in hardware; the KONKR -# UART button is the device's Guide instead (konkr_sysbtn.yaml), so route -# this one to a bindable hotkey. Everything else passes through untouched. -mapping: - - name: Front-top-left (KeyF3) - source_events: - - evdev: - event_type: KEY - event_code: BTN_MODE - value_type: button - target_event: - keyboard: KeyF3 diff --git a/system_files/usr/share/inputplumber/capability_maps/konkr_sysbtn.yaml b/system_files/usr/share/inputplumber/capability_maps/konkr_sysbtn.yaml deleted file mode 100644 index cfaed66c..00000000 --- a/system_files/usr/share/inputplumber/capability_maps/konkr_sysbtn.yaml +++ /dev/null @@ -1,64 +0,0 @@ -# yaml-language-server: $schema=https://raw.githubusercontent.com/ShadowBlip/InputPlumber/main/rootfs/usr/share/inputplumber/schema/capability_map_v2.json -version: 2 -kind: CapabilityMap -name: KONKR System Buttons Mapping -id: konkr_sysbtn - -# The konkr_sysbtn kernel serdev driver reads the AYANEO MCU UART and emits the -# device's "system" buttons as BTN_TRIGGER_HAPPY1..5. -# -# KONKR -> Guide. The two extra shoulder buttons become the DualSense Edge's -# back-lever buttons, which is the only pair of spare gamepad-class buttons the -# ds5-edge target offers. The remaining two front buttons have no gamepad -# equivalent, so they go to keyboard F-keys and are bindable as hotkeys. -# -# The device also has two physical back buttons, but the MCU emits nothing for -# them (see the key_lc_back/key_rc_back sysfs attributes on the serdev device). -mapping: - - name: Front-bottom-right (KeyF1) - source_events: - - evdev: - event_type: KEY - event_code: BTN_TRIGGER_HAPPY1 - value_type: button - target_event: - keyboard: KeyF1 - - - name: KONKR (Guide) - source_events: - - evdev: - event_type: KEY - event_code: BTN_TRIGGER_HAPPY2 - value_type: button - target_event: - gamepad: - button: Guide - - - name: Left extra shoulder (LeftPaddle2) - source_events: - - evdev: - event_type: KEY - event_code: BTN_TRIGGER_HAPPY3 - value_type: button - target_event: - gamepad: - button: LeftPaddle2 - - - name: Right extra shoulder (RightPaddle2) - source_events: - - evdev: - event_type: KEY - event_code: BTN_TRIGGER_HAPPY4 - value_type: button - target_event: - gamepad: - button: RightPaddle2 - - - name: Front-top-right (KeyF2) - source_events: - - evdev: - event_type: KEY - event_code: BTN_TRIGGER_HAPPY5 - value_type: button - target_event: - keyboard: KeyF2 diff --git a/system_files/usr/share/inputplumber/capability_maps/retroid_flip2.yaml b/system_files/usr/share/inputplumber/capability_maps/retroid_flip2.yaml deleted file mode 100644 index e662c09d..00000000 --- a/system_files/usr/share/inputplumber/capability_maps/retroid_flip2.yaml +++ /dev/null @@ -1,271 +0,0 @@ -# yaml-language-server: $schema=https://raw.githubusercontent.com/ShadowBlip/InputPlumber/main/rootfs/usr/share/inputplumber/schema/capability_map_v2.json -# Schema version number -version: 2 - -# The type of configuration schema -kind: CapabilityMap - -# Name for the device event map -name: Retroid MCU Mapping (Flip2) - -# Unique identifier of the capability mapping -id: retroid_flip2 - -# List of mapped events -# Keep shared controls aligned with retroid_mcu; only Home/QAM differs. -mapping: - - name: Guide Button - mapping_type: - evdev: delayed_chord - source_events: - - evdev: - event_type: KEY - event_code: BTN_MODE - value_type: button - target_event: - gamepad: - button: Guide - - # Chords are first-match; keep this before the single-source South mapping. - - name: Quick Access Chord - mapping_type: - evdev: chord - source_events: - - evdev: - event_type: KEY - event_code: BTN_MODE - value_type: button - - evdev: - event_type: KEY - event_code: BTN_SOUTH - value_type: button - target_event: - gamepad: - button: QuickAccess - - - name: South Button - mapping_type: - evdev: chord - source_events: - - evdev: - event_type: KEY - event_code: BTN_SOUTH - value_type: button - target_event: - gamepad: - button: South - - - name: West Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_NORTH - value_type: button - target_event: - gamepad: - button: West - - - name: North Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_WEST - value_type: button - target_event: - gamepad: - button: North - - - name: East Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_EAST - value_type: button - target_event: - gamepad: - button: East - - - name: Start Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_START - value_type: button - target_event: - gamepad: - button: Start - - - name: Select Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_SELECT - value_type: button - target_event: - gamepad: - button: Select - - - name: Quick Access Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_BACK - value_type: button - target_event: - gamepad: - button: QuickAccess - - - name: Right Trigger - source_events: - - evdev: - event_type: ABS - event_code: ABS_HAT2Y - value_type: trigger - target_event: - gamepad: - trigger: - name: RightTrigger - - - name: Left Trigger - source_events: - - evdev: - event_type: ABS - event_code: ABS_HAT2X - value_type: trigger - target_event: - gamepad: - trigger: - name: LeftTrigger - - - name: Right Bumper - source_events: - - evdev: - event_type: KEY - event_code: BTN_TR - value_type: button - target_event: - gamepad: - button: RightBumper - - - name: Left Bumper - source_events: - - evdev: - event_type: KEY - event_code: BTN_TL - value_type: button - target_event: - gamepad: - button: LeftBumper - - - name: Right Paddle - source_events: - - evdev: - event_type: KEY - event_code: BTN_C - value_type: button - target_event: - gamepad: - button: RightPaddle1 - - - name: Left Paddle - source_events: - - evdev: - event_type: KEY - event_code: BTN_Z - value_type: button - target_event: - gamepad: - button: LeftPaddle1 - - - name: Right Stick - source_events: - - evdev: - event_type: ABS - event_code: ABS_RX - value_type: joystick_x - - evdev: - event_type: ABS - event_code: ABS_RY - value_type: joystick_y - target_event: - gamepad: - axis: - name: RightStick - - - name: Left Stick - source_events: - - evdev: - event_type: ABS - event_code: ABS_X - value_type: joystick_x - - evdev: - event_type: ABS - event_code: ABS_Y - value_type: joystick_y - target_event: - gamepad: - axis: - name: LeftStick - - - name: Right Stick Click - source_events: - - evdev: - event_type: KEY - event_code: BTN_THUMBR - value_type: button - target_event: - gamepad: - button: RightStick - - - name: Left Stick Click - source_events: - - evdev: - event_type: KEY - event_code: BTN_THUMBL - value_type: button - target_event: - gamepad: - button: LeftStick - - - name: Dpad Left - source_events: - - evdev: - event_type: KEY - event_code: BTN_DPAD_LEFT - value_type: button - target_event: - gamepad: - button: DPadLeft - - - name: Dpad Right - source_events: - - evdev: - event_type: KEY - event_code: BTN_DPAD_RIGHT - value_type: button - target_event: - gamepad: - button: DPadRight - - - name: Dpad Down - source_events: - - evdev: - event_type: KEY - event_code: BTN_DPAD_DOWN - value_type: button - target_event: - gamepad: - button: DPadDown - - - name: Dpad Up - source_events: - - evdev: - event_type: KEY - event_code: BTN_DPAD_UP - value_type: button - target_event: - gamepad: - button: DPadUp - -# List of events to filter from the source devices -filtered_events: [] diff --git a/system_files/usr/share/inputplumber/capability_maps/retroid_mcu.yaml b/system_files/usr/share/inputplumber/capability_maps/retroid_mcu.yaml deleted file mode 100644 index 61a78a08..00000000 --- a/system_files/usr/share/inputplumber/capability_maps/retroid_mcu.yaml +++ /dev/null @@ -1,269 +0,0 @@ -# yaml-language-server: $schema=https://raw.githubusercontent.com/ShadowBlip/InputPlumber/main/rootfs/usr/share/inputplumber/schema/capability_map_v2.json -# Schema version number -version: 2 - -# The type of configuration schema -kind: CapabilityMap - -# Name for the device event map -name: Retroid MCU Mapping - -# Unique identifier of the capability mapping -id: retroid_mcu - -# List of mapped events -mapping: - - name: Guide Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_MODE - value_type: button - target_event: - gamepad: - button: Guide - - - name: South Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_SOUTH - value_type: button - target_event: - gamepad: - button: South - - - name: West Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_NORTH - value_type: button - target_event: - gamepad: - button: West - - - name: North Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_WEST - value_type: button - target_event: - gamepad: - button: North - - - name: East Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_EAST - value_type: button - target_event: - gamepad: - button: East - - - name: Start Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_START - value_type: button - target_event: - gamepad: - button: Start - - - name: Select Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_SELECT - value_type: button - target_event: - gamepad: - button: Select - - - name: Quick Access Button - source_events: - - evdev: - event_type: KEY - event_code: BTN_BACK - value_type: button - target_event: - gamepad: - button: QuickAccess - - - name: Right Trigger - source_events: - - evdev: - event_type: ABS - event_code: ABS_HAT2Y - value_type: trigger - target_event: - gamepad: - trigger: - name: RightTrigger - - - name: Left Trigger - source_events: - - evdev: - event_type: ABS - event_code: ABS_HAT2X - value_type: trigger - target_event: - gamepad: - trigger: - name: LeftTrigger - - - name: Right Bumper - source_events: - - evdev: - event_type: KEY - event_code: BTN_TR - value_type: button - target_event: - gamepad: - button: RightBumper - - - name: Left Bumper - source_events: - - evdev: - event_type: KEY - event_code: BTN_TL - value_type: button - target_event: - gamepad: - button: LeftBumper - - - name: Right Paddle - source_events: - - evdev: - event_type: KEY - event_code: BTN_C - value_type: button - target_event: - gamepad: - button: RightPaddle1 - - - name: Left Paddle - source_events: - - evdev: - event_type: KEY - event_code: BTN_Z - value_type: button - target_event: - gamepad: - button: LeftPaddle1 - - - name: Right Stick - source_events: - - evdev: - event_type: ABS - event_code: ABS_RX - value_type: joystick_x - - evdev: - event_type: ABS - event_code: ABS_RY - value_type: joystick_y - target_event: - gamepad: - axis: - name: RightStick - - - name: Left Stick - source_events: - - evdev: - event_type: ABS - event_code: ABS_X - value_type: joystick_x - - evdev: - event_type: ABS - event_code: ABS_Y - value_type: joystick_y - target_event: - gamepad: - axis: - name: LeftStick - - - name: Right Stick Click - source_events: - - evdev: - event_type: KEY - event_code: BTN_THUMBR - value_type: button - target_event: - gamepad: - button: RightStick - - - name: Left Stick Click - source_events: - - evdev: - event_type: KEY - event_code: BTN_THUMBL - value_type: button - target_event: - gamepad: - button: LeftStick - - - name: Dpad Left - source_events: - - evdev: - event_type: KEY - event_code: BTN_DPAD_LEFT - value_type: button - target_event: - gamepad: - button: DPadLeft - - - name: Dpad Right - source_events: - - evdev: - event_type: KEY - event_code: BTN_DPAD_RIGHT - value_type: button - target_event: - gamepad: - button: DPadRight - - - name: Dpad Down - source_events: - - evdev: - event_type: KEY - event_code: BTN_DPAD_DOWN - value_type: button - target_event: - gamepad: - button: DPadDown - - - name: Dpad Up - source_events: - - evdev: - event_type: KEY - event_code: BTN_DPAD_UP - value_type: button - target_event: - gamepad: - button: DPadUp - - - name: Left Paddle - source_events: - - evdev: - event_type: KEY - event_code: BTN_C - value_type: button - target_event: - gamepad: - button: LeftPaddle1 - - - name: Right Paddle - source_events: - - evdev: - event_type: KEY - event_code: BTN_Z - value_type: button - target_event: - gamepad: - button: RightPaddle1 - -# List of events to filter from the source devices -filtered_events: [] diff --git a/system_files/usr/share/inputplumber/devices/01-ayaneo-controller.yaml b/system_files/usr/share/inputplumber/devices/01-ayaneo-controller.yaml index db4ae9fa..32f5d166 100644 --- a/system_files/usr/share/inputplumber/devices/01-ayaneo-controller.yaml +++ b/system_files/usr/share/inputplumber/devices/01-ayaneo-controller.yaml @@ -17,11 +17,6 @@ matches: attributes: - name: model value: AYANEO Pocket EVO - - udev: - sys_path: /sys/firmware/devicetree/base - attributes: - - name: model - value: AYANEO Pocket DS - udev: sys_path: /sys/firmware/devicetree/base attributes: diff --git a/system_files/usr/share/inputplumber/devices/01-ayn-controller.yaml b/system_files/usr/share/inputplumber/devices/01-ayn-controller.yaml deleted file mode 100644 index a54c3251..00000000 --- a/system_files/usr/share/inputplumber/devices/01-ayn-controller.yaml +++ /dev/null @@ -1,50 +0,0 @@ -# yaml-language-server: $schema=https://raw.githubusercontent.com/ShadowBlip/InputPlumber/main/rootfs/usr/share/inputplumber/schema/composite_device_v1.json -# Schema version number -version: 1 - -# The type of configuration schema -kind: CompositeDevice - -# Name of the composite device mapping -name: AYN Layout - -# Only use this profile if *any* of the given matches matches. If this list is -# empty, then the source devices will *always* be checked. -# /sys/class/dmi/id/product_name -matches: - - udev: - sys_path: /sys/firmware/devicetree/base - attributes: - - name: model - value: AYN Odin 3 - -# Only allow a single source device per composite device of this type. -single_source: false - -# One or more source devices to combine into a single virtual device. The events -# from these devices will be watched and translated according to the key map. -source_devices: - - group: gamepad - evdev: - phys_path: rsinput-gamepad/input0 - handler: event* - capability_map_id: ayn_mcu - passthrough: true - - - group: gamepad - evdev: - name: gpio-keys-paddles - handler: event* - capability_map_id: ayn_mcu - -# Optional configuration for the composite device -options: - # If true, InputPlumber will automatically try to manage the input device. If - # this is false, InputPlumber will not try to manage the device unless an - # external service enables management of the device. Defaults to 'false' - auto_manage: true - -# The target input device(s) to emulate by default -target_devices: - - deck-uhid - - keyboard diff --git a/system_files/usr/share/inputplumber/devices/02-ayn-controller.yaml b/system_files/usr/share/inputplumber/devices/02-ayn-controller.yaml deleted file mode 100644 index ce65b922..00000000 --- a/system_files/usr/share/inputplumber/devices/02-ayn-controller.yaml +++ /dev/null @@ -1,82 +0,0 @@ -# yaml-language-server: $schema=https://raw.githubusercontent.com/ShadowBlip/InputPlumber/main/rootfs/usr/share/inputplumber/schema/composite_device_v1.json -# Schema version number -version: 1 - -# The type of configuration schema -kind: CompositeDevice - -# Name of the composite device mapping -name: AYN Layout - -# Only use this profile if *any* of the given matches matches. If this list is -# empty, then the source devices will *always* be checked. -# /sys/class/dmi/id/product_name -matches: - - udev: - sys_path: /sys/firmware/devicetree/base - attributes: - - name: model - value: AYN Odin 2 - - udev: - sys_path: /sys/firmware/devicetree/base - attributes: - - name: model - value: AYN Odin 2 Mini - - udev: - sys_path: /sys/firmware/devicetree/base - attributes: - - name: model - value: AYN Odin 2 Portal - - udev: - sys_path: /sys/firmware/devicetree/base - attributes: - - name: model - value: Retroid Pocket 6 - - udev: - sys_path: /sys/firmware/devicetree/base - attributes: - - name: model - value: Retroid Pocket 6 TOP-DPAD - - udev: - sys_path: /sys/firmware/devicetree/base - attributes: - - name: model - value: Retroid Pocket Nova - -# Only allow a single source device per composite device of this type. -single_source: false - -# One or more source devices to combine into a single virtual device. The events -# from these devices will be watched and translated according to the key map. -source_devices: - - group: gamepad - evdev: - phys_path: rsinput-gamepad/input0 - handler: event* - capability_map_id: ayn_mcu - passthrough: true - - - group: gamepad - evdev: - name: gpio-keys - phys_path: gpio-keys/input0 - handler: event* - capability_map_id: ayn_mcu - - - group: gamepad - evdev: - name: gpio-keys-paddles - handler: event* - capability_map_id: ayn_mcu - -# Optional configuration for the composite device -options: - # If true, InputPlumber will automatically try to manage the input device. If - # this is false, InputPlumber will not try to manage the device unless an - # external service enables management of the device. Defaults to 'false' - auto_manage: true - -# The target input device(s) to emulate by default -target_devices: - - deck-uhid - - keyboard diff --git a/system_files/usr/share/inputplumber/devices/02-ayn-thor-controller.yaml b/system_files/usr/share/inputplumber/devices/02-ayn-thor-controller.yaml deleted file mode 100644 index b20e079b..00000000 --- a/system_files/usr/share/inputplumber/devices/02-ayn-thor-controller.yaml +++ /dev/null @@ -1,51 +0,0 @@ -# yaml-language-server: $schema=https://raw.githubusercontent.com/ShadowBlip/InputPlumber/main/rootfs/usr/share/inputplumber/schema/composite_device_v1.json -# Schema version number -version: 1 - -# The type of configuration schema -kind: CompositeDevice - -# Name of the composite device mapping -name: AYN Thor Layout - -# Only use this profile if *any* of the given matches matches. If this list is -# empty, then the source devices will *always* be checked. -# /sys/class/dmi/id/product_name -matches: - - udev: - sys_path: /sys/firmware/devicetree/base - attributes: - - name: model - value: AYN Thor - -# Only allow a single source device per composite device of this type. -single_source: false - -# One or more source devices to combine into a single virtual device. The events -# from these devices will be watched and translated according to the key map. -source_devices: - - group: gamepad - evdev: - phys_path: rsinput-gamepad/input0 - handler: event* - capability_map_id: ayn_mcu - passthrough: true - - - group: gamepad - evdev: - name: gpio-keys-ayn - phys_path: gpio-keys-ayn/input0 - handler: event* - capability_map_id: ayn_mcu - -# Optional configuration for the composite device -options: - # If true, InputPlumber will automatically try to manage the input device. If - # this is false, InputPlumber will not try to manage the device unless an - # external service enables management of the device. Defaults to 'false' - auto_manage: true - -# The target input device(s) to emulate by default -target_devices: - - deck-uhid - - keyboard diff --git a/system_files/usr/share/inputplumber/devices/03-ayaneo-standard-controller.yaml b/system_files/usr/share/inputplumber/devices/03-ayaneo-standard-controller.yaml deleted file mode 100644 index d4b3c8a3..00000000 --- a/system_files/usr/share/inputplumber/devices/03-ayaneo-standard-controller.yaml +++ /dev/null @@ -1,55 +0,0 @@ -# yaml-language-server: $schema=https://raw.githubusercontent.com/ShadowBlip/InputPlumber/main/rootfs/usr/share/inputplumber/schema/composite_device_v1.json -# Schema version number -version: 1 - -# The type of configuration schema -kind: CompositeDevice - -# Name of the composite device mapping -name: AYANEO Standard Layout - -# Only use this profile if *any* of the given matches matches. If this list is -# empty, then the source devices will *always* be checked. -# /sys/class/dmi/id/product_name -matches: - - udev: - sys_path: /sys/firmware/devicetree/base - attributes: - - name: model - value: KONKR Pocket FIT - - udev: - sys_path: /sys/firmware/devicetree/base - attributes: - - name: model - value: AYANEO Pocket S2 - -# Only allow a single source device per composite device of this type. -single_source: false - -# One or more source devices to combine into a single virtual device. The events -# from these devices will be watched and translated according to the key map. -source_devices: - - group: gamepad - evdev: - vendor_id: "1c4f" - product_id: "0002" - handler: event* - capability_map_id: ayaneo_mcu_xbox_standard - - group: gamepad - evdev: - vendor_id: "045e" - product_id: "028e" - handler: event* - capability_map_id: ayaneo_mcu_xbox_standard - -# Optional configuration for the composite device -options: - # If true, InputPlumber will automatically try to manage the input device. If - # this is false, InputPlumber will not try to manage the device unless an - # external service enables management of the device. Defaults to 'false' - auto_manage: true - -# The target input device(s) to emulate by default -target_devices: - - xb360 - - keyboard diff --git a/system_files/usr/share/inputplumber/devices/03-retroid-controller.yaml b/system_files/usr/share/inputplumber/devices/03-retroid-controller.yaml deleted file mode 100644 index 8295a693..00000000 --- a/system_files/usr/share/inputplumber/devices/03-retroid-controller.yaml +++ /dev/null @@ -1,38 +0,0 @@ -# yaml-language-server: $schema=https://raw.githubusercontent.com/ShadowBlip/InputPlumber/main/rootfs/usr/share/inputplumber/schema/composite_device_v1.json -version: 1 -kind: CompositeDevice -name: Retroid Layout - -matches: - - udev: - sys_path: /sys/firmware/devicetree/base - attributes: - - name: model - value: Retroid Pocket 5 - - udev: - sys_path: /sys/firmware/devicetree/base - attributes: - - name: model - value: Retroid Pocket Mini - - udev: - sys_path: /sys/firmware/devicetree/base - attributes: - - name: model - value: Retroid Pocket Mini V2 - -single_source: false - -source_devices: - - group: gamepad - evdev: - phys_path: retroid-pocket-gamepad/input0 - handler: event* - capability_map_id: retroid_mcu - passthrough: true - -options: - auto_manage: true - -target_devices: - - deck-uhid - - keyboard diff --git a/system_files/usr/share/inputplumber/devices/04-retroid-flip2-controller.yaml b/system_files/usr/share/inputplumber/devices/04-retroid-flip2-controller.yaml deleted file mode 100644 index 3fe1a6f0..00000000 --- a/system_files/usr/share/inputplumber/devices/04-retroid-flip2-controller.yaml +++ /dev/null @@ -1,28 +0,0 @@ -# yaml-language-server: $schema=https://raw.githubusercontent.com/ShadowBlip/InputPlumber/main/rootfs/usr/share/inputplumber/schema/composite_device_v1.json -version: 1 -kind: CompositeDevice -name: Retroid Layout - -matches: - - udev: - sys_path: /sys/firmware/devicetree/base - attributes: - - name: model - value: Retroid Pocket Flip2 - -single_source: false - -source_devices: - - group: gamepad - evdev: - phys_path: retroid-pocket-gamepad/input0 - handler: event* - capability_map_id: retroid_flip2 - passthrough: true - -options: - auto_manage: true - -target_devices: - - deck-uhid - - keyboard diff --git a/system_files/usr/share/inputplumber/devices/50-konkr_pf_elite.yaml b/system_files/usr/share/inputplumber/devices/50-konkr_pf_elite.yaml deleted file mode 100644 index e56f4ab8..00000000 --- a/system_files/usr/share/inputplumber/devices/50-konkr_pf_elite.yaml +++ /dev/null @@ -1,47 +0,0 @@ -# yaml-language-server: $schema=https://raw.githubusercontent.com/ShadowBlip/InputPlumber/main/rootfs/usr/share/inputplumber/schema/composite_device_v1.json -version: 1 -kind: CompositeDevice -name: KONKR Pocket FIT Elite - -# Compose this device's two input sources into one virtual controller: -# - the AYANEO MCU SPI gamepad (kernel mcu_joystick driver, patch 0058) -# - the 5 "system" buttons (KONKR/Home/menu/grips) from the konkr_sysbtn -# kernel serdev driver, which reads them off the MCU UART (patch 0069) -# so applications see a single standard pad instead of two devices. -matches: - - udev: - sys_path: /sys/firmware/devicetree/base - attributes: - - name: model - value: KONKR Pocket FIT Elite - -single_source: false - -source_devices: - # Main gamepad: standard evdev layout (BTN_SOUTH.. + ABS sticks/triggers/hat), - # so InputPlumber's built-in evdev translation handles it (no capability map). - - group: gamepad - evdev: - name: AYANEO MCU Gamepad - handler: event* - capability_map_id: konkr_gamepad - # System buttons: non-standard, remapped via the capability map below. - - group: gamepad - evdev: - name: KONKR System Buttons - handler: event* - capability_map_id: konkr_sysbtn - -options: - auto_manage: true - -# ds5-edge (DualSense Edge) rather than plain ds5, matching the AYN Odin 3 on -# this same platform: the Edge is the DualSense variant with back paddles, so -# this device's grip buttons can be emitted as real gamepad buttons instead of -# keyboard keys. NOT deck-uhid (hidraw-only: ES/SDL only enumerate evdev pads). -# The keyboard target stays for the remaining auxiliary buttons, which have no -# gamepad equivalent and are useful as bindable hotkeys (see the capability -# maps). -target_devices: - - ds5 - - keyboard diff --git a/system_files/usr/share/wireplumber/wireplumber.conf.d/51-ayn-thor-lite.conf b/system_files/usr/share/wireplumber/wireplumber.conf.d/51-ayn-thor-lite.conf new file mode 100644 index 00000000..78e9ebc7 --- /dev/null +++ b/system_files/usr/share/wireplumber/wireplumber.conf.d/51-ayn-thor-lite.conf @@ -0,0 +1,37 @@ +# WirePlumber drop-in for the AYN Thor Lite (SM8250). +# +# Install to: /etc/wireplumber/wireplumber.conf.d/51-ayn-thor-lite.conf +# (WirePlumber 0.5+; this is SPA-JSON syntax.) +# +# Why this exists: +# The Qualcomm qdsp6 routing path opens its ADM "COPP" with +# NULL_COPP_TOPOLOGY -- a bit-exact passthrough that performs no +# sample-format conversion. The MI2S / CODEC_DMA backends are +# hard-fixed to S16_LE by the kernel's sm8250_be_hw_params_fixup(), +# so the MultiMedia frontend PCMs must also be opened S16LE or the +# speaker / headphone output is noise. +# +# Rate (48000) and channel count (2) are already pinned by the ALSA +# UCM config (Playback/CaptureRate, Playback/CaptureChannels); UCM +# has no equivalent key for the sample format, so it is forced here. +# +# This is scoped to the Thor Lite card only (via alsa.card_name), so +# it replaces any global "force S16LE" override you may have set. +# Confirm the card name matches with: +# pw-dump | grep -i card_name +# If it differs, adjust the alsa.card_name value below. + +monitor.alsa.rules = [ + { + matches = [ + { + alsa.card_name = "AYN Thor Lite" + } + ] + actions = { + update-props = { + audio.format = "S16LE" + } + } + } +] diff --git a/tests/armada-control-rgb-test.sh b/tests/armada-control-rgb-test.sh index 33cf289c..5cf4197d 100755 --- a/tests/armada-control-rgb-test.sh +++ b/tests/armada-control-rgb-test.sh @@ -20,6 +20,7 @@ control = importlib.util.module_from_spec(spec) loader.exec_module(control) commands = [] +supported = False def check_output(command, **kwargs): @@ -29,12 +30,17 @@ def check_output(command, **kwargs): return '{"version":1,"enabled":true,"brightness":40,"color":"A1B2C3"}' +def run(command, **kwargs): + assert command == [control.RGB_TOOL, "supported"] + return control.subprocess.CompletedProcess(command, 0 if supported else 1) + + control.subprocess.check_output = check_output -control.device_env = lambda: {} +control.subprocess.run = run assert control.action_get_rgb({}) is None assert commands == [] -control.device_env = lambda: {"ARMADA_RGB_BACKEND": "multicolor"} +supported = True state = control.action_get_rgb({}) assert state["color"] == "FFFFFF" assert commands.pop() == [control.RGB_TOOL, "get"] @@ -67,8 +73,13 @@ for request in ( sys.path.insert(0, str(root / "decky/armada-control/py_modules")) from armada_control import rgb +rgb.call = lambda action, **payload: None +assert not rgb.rgb_supported() + calls = [] rgb.call = lambda action, **payload: calls.append((action, payload)) or {} +assert rgb.rgb_supported() +assert calls.pop() == ("get_rgb", {}) assert rgb.get_rgb() == {} assert calls.pop() == ("get_rgb", {}) rgb.set_rgb(True, "112233", 50) @@ -78,6 +89,8 @@ assert calls.pop() == ( ) PYEOF +! rg -q 'ARMADA_RGB_' "$ROOT/system_files/usr/lib/armada/devices" +! rg -q 'ARMADA_RGB_' "$ROOT/system_files/usr/libexec/armada/device-env" grep -Fq 'ConditionPathExists=/etc/armada/rgb.json' "$ROOT/system_files/usr/lib/systemd/system/armada-rgb.service" grep -Fq 'ExecStart=/usr/bin/armada-rgb apply' "$ROOT/system_files/usr/lib/systemd/system/armada-rgb.service" grep -Fq 'systemctl enable armada-rgb.service' "$ROOT/build_files/40-vendor-system-files.sh" diff --git a/tests/boot-hotkeys-test.sh b/tests/boot-hotkeys-test.sh new file mode 100755 index 00000000..893962d9 --- /dev/null +++ b/tests/boot-hotkeys-test.sh @@ -0,0 +1,161 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)" +HOTKEYS="$ROOT/system_files/usr/libexec/armada/armada-boot-hotkeys" +UNIT="$ROOT/system_files/usr/lib/systemd/system/armada-boot-hotkeys.service" +INPUT_LIB="$ROOT/system_files/usr/lib/armada/input-lib" +WORK="$(mktemp -d)" +trap 'rm -rf "$WORK"' EXIT + +fail() { printf 'FAIL: %s\n' "$*" >&2; exit 1; } +assert_file() { [[ -e "$1" ]] || fail "$2: expected $1 to exist"; } +assert_grep() { grep -qF -- "$2" "$1" || fail "$3: expected ${2@Q} in $1"; } +assert_no_grep() { [[ -e "$1" ]] && grep -qF -- "$2" "$1" && fail "$3: unexpected ${2@Q} in $1"; return 0; } + +BIN="$WORK/bin"; DEV="$WORK/dev"; SYS="$WORK/sys" +mkdir -p "$BIN" "$DEV" "$SYS" +export WORK + +# event0 has no EV_KEY bitmap at all, event1 carries BTN_SELECT (314), and +# event2 carries the neighbouring BTN_START (315): only event1 may be polled. +for n in 0 1 2; do : > "$DEV/event$n"; mkdir -p "$SYS/event$n/device/capabilities"; done +printf '0\n' > "$SYS/event0/device/capabilities/key" +printf '400000000000000 0 0 0 0\n' > "$SYS/event1/device/capabilities/key" +printf '800000000000000 0 0 0 0\n' > "$SYS/event2/device/capabilities/key" + +cat > "$BIN/evtest" <<'STUB' +#!/usr/bin/env bash +dev="${@: -3:1}" +printf '%s\n' "$dev" >> "$WORK/queried" +[[ -e "$WORK/pressed" ]] || exit 0 +[[ -r "$WORK/pressed-dev" ]] || exit 10 +[[ "$dev" == "$(cat "$WORK/pressed-dev")" ]] && exit 10 +exit 0 +STUB +cat > "$BIN/systemctl" <<'STUB' +#!/usr/bin/env bash +printf '%s\n' "$*" >> "$WORK/systemctl.log" +[[ "$1" == start ]] && exit 0 +[[ "$1" == is-failed ]] && { [[ -e "$WORK/dm-failed" ]] && exit 0; exit 1; } +[[ " $* " == *" display-manager.service "* && -e "$WORK/dm-active" ]] && exit 0 +exit 3 +STUB +cat > "$BIN/logger" <<'STUB' +#!/usr/bin/env bash +printf '%s\n' "${@: -1}" >> "$WORK/log" +STUB +cat > "$WORK/progress" <<'STUB' +#!/usr/bin/env bash +printf '%s\n' "$*" >> "$WORK/status.log" +STUB +cat > "$WORK/session-control" <<'STUB' +#!/usr/bin/env bash +printf '%s\n' "$*" >> "$WORK/session.log" +STUB +chmod 0755 "$BIN"/* "$WORK/session-control" "$WORK/progress" + +run_hotkeys() { + rm -f "$WORK/queried" "$WORK/log" "$WORK/session.log" "$WORK/systemctl.log" "$WORK/recovery-mode" "$WORK/status.log" + PATH="$BIN:$PATH" \ + ARMADA_INPUT_LIB="$INPUT_LIB" \ + ARMADA_INPUT_CLASS="$SYS" \ + ARMADA_INPUT_DEV_DIR="$DEV" \ + ARMADA_SESSION_CONTROL="$WORK/session-control" \ + ARMADA_SPLASH_PROGRESS="$WORK/progress" \ + ARMADA_RECOVERY_MARKER="$WORK/recovery-mode" \ + ARMADA_BOOT_HOTKEY_POLL_MS=10 \ + ARMADA_BOOT_HOTKEY_HOLD_MS=30 \ + ARMADA_BOOT_HOTKEY_MAX=1 \ + ARMADA_SPLASH_CEF_PORT="${CEF_PORT:-1}" \ + bash "$HOTKEYS" > "$WORK/out.log" 2>&1 +} + +# Only the device that reports the key code is polled. +rm -f "$WORK/pressed" "$WORK/dm-active" +run_hotkeys +[[ -e "$WORK/session.log" ]] && fail "no hold: switched sessions anyway" +[[ -e "$WORK/recovery-mode" ]] && fail "no hold: marked recovery mode anyway" +sort -u "$WORK/queried" > "$WORK/queried.uniq" +[[ "$(cat "$WORK/queried.uniq")" == "$DEV/event1" ]] \ + || fail "device selection: polled $(tr '\n' ' ' < "$WORK/queried.uniq")" + +# Held before the display manager is up: write the autologin drop-in only. +: > "$WORK/pressed" +run_hotkeys +assert_grep "$WORK/session.log" "default-desktop" "pre-sddm hold" +assert_grep "$WORK/systemctl.log" "start armada-session-default.service" "waits for the autologin reset" +# The marker is what a desktop recovery tool would key off. +assert_file "$WORK/recovery-mode" "recovery marker written" +assert_grep "$WORK/status.log" "Starting Desktop" "splash announce" +assert_grep "$WORK/log" "holding Desktop Mode" "journal notes the hold" +assert_grep "$WORK/log" "triggering Desktop Mode" "journal notes the trigger" + +# Held once the session is running: restart it the way Steam's own switch does. +: > "$WORK/dm-active" +run_hotkeys +assert_grep "$WORK/session.log" "switch-desktop" "post-sddm hold" + +# Steam's UI ends the watch, so the button goes back to being Steam's. +python3 -c 'import socket,sys,time +s=socket.socket(); s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) +s.bind(("127.0.0.1",0)); s.listen() +print(s.getsockname()[1], flush=True) +time.sleep(20)' > "$WORK/port" & +port_pid=$! +for _ in {1..100}; do [[ -s "$WORK/port" ]] && break; sleep 0.05; done +CEF_PORT="$(cat "$WORK/port")" run_hotkeys +kill "$port_pid" 2>/dev/null || true +[[ -e "$WORK/session.log" ]] && fail "steam up: switched sessions anyway" +[[ -e "$WORK/queried" ]] && fail "steam up: kept polling the volume key" + +# Device replacement: the key moves to another node after a successful scan. +# Fails without the periodic rescan, which is the point of the case. +rm -f "$WORK/dm-active" "$WORK/dm-failed" "$WORK/session.log" +printf '%s\n' "$DEV/event2" > "$WORK/pressed-dev" +printf '400000000000000 0 0 0 0\n' > "$SYS/event1/device/capabilities/key" +printf '0\n' > "$SYS/event2/device/capabilities/key" +( sleep 0.3 + printf '0\n' > "$SYS/event1/device/capabilities/key" + printf '400000000000000 0 0 0 0\n' > "$SYS/event2/device/capabilities/key" ) & +appear_pid=$! +PATH="$BIN:$PATH" \ +ARMADA_INPUT_LIB="$INPUT_LIB" ARMADA_INPUT_CLASS="$SYS" ARMADA_INPUT_DEV_DIR="$DEV" \ +ARMADA_RECOVERY_MARKER="$WORK/recovery-mode" \ +ARMADA_SESSION_CONTROL="$WORK/session-control" \ +ARMADA_BOOT_HOTKEY_POLL_MS=10 ARMADA_BOOT_HOTKEY_HOLD_MS=30 \ +ARMADA_BOOT_HOTKEY_RESCAN_MS=20 ARMADA_BOOT_HOTKEY_MAX=3 \ +ARMADA_SPLASH_CEF_PORT=1 \ + bash "$HOTKEYS" > "$WORK/out.log" 2>&1 +wait "$appear_pid" 2>/dev/null || true +assert_grep "$WORK/session.log" "default-desktop" "key moving to another node is rescanned" +rm -f "$WORK/pressed-dev" +printf '400000000000000 0 0 0 0\n' > "$SYS/event1/device/capabilities/key" +printf '800000000000000 0 0 0 0\n' > "$SYS/event2/device/capabilities/key" + +# Nothing else retries a failed sddm: session-control resets the failure state +# without starting it. +rm -f "$WORK/dm-active" +: > "$WORK/dm-failed" +run_hotkeys +assert_grep "$WORK/session.log" "default-desktop" "failed sddm still sets autologin" +assert_grep "$WORK/systemctl.log" "start display-manager.service" "failed sddm is started" +rm -f "$WORK/dm-failed" + +# Not started yet is the normal case: systemd starts it next, so do not race it. +run_hotkeys +assert_no_grep "$WORK/systemctl.log" "start display-manager.service" "pre-sddm must not start it" + +grep -qE '^ *"314:BTN_SELECT:Desktop Mode:action_desktop"' "$HOTKEYS" \ + || fail "the hotkey table entry changed shape" +grep -q 'Before=display-manager.service' "$UNIT" || fail "unit must start before sddm" +grep -q 'ConditionPathExists=!/etc/armada/boot-hotkeys-disabled' "$UNIT" \ + || fail "unit needs an escape hatch" +grep -q 'WantedBy=sysinit.target' "$UNIT" \ + || fail "unit must start with the splash, not at basic.target" +grep -q 'After=.*armada-session-default' "$UNIT" \ + && fail "static ordering after armada-session-default pins the hold onto sddm's start" +grep -q 'systemctl enable armada-boot-hotkeys.service' "$ROOT/build_files/40-vendor-system-files.sh" \ + || fail "armada-boot-hotkeys.service is not enabled in the image" + +echo "PASS: boot-hotkeys" diff --git a/tests/disk-image-digest-test.sh b/tests/disk-image-digest-test.sh new file mode 100644 index 00000000..eca7ae83 --- /dev/null +++ b/tests/disk-image-digest-test.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)" +WORK=$(mktemp -d) +trap 'rm -rf "$WORK"' EXIT +mkdir "$WORK/bin" + +python3 - "$ROOT/Justfile" "$WORK/load-image" <<'PY' +from pathlib import Path +import sys +# Extraction depends on these recipe names and their order. +recipe = Path(sys.argv[1]).read_text().split('_rootful_load_image $', 1)[1] +recipe = recipe.split('\n', 1)[1].split('\n_build-bib ', 1)[0] +Path(sys.argv[2]).write_text('\n'.join(line[4:] for line in recipe.splitlines())) +PY + +cat > "$WORK/bin/just" <<'SH' +#!/usr/bin/env bash +set -euo pipefail +printf '%s\n' "$*" >> "$TEST_LOG" +[[ "${FAIL_PULL:-}" != 1 || "$3" != pull ]] +SH +cat > "$WORK/bin/sudo" <<'SH' +#!/usr/bin/env bash +set -euo pipefail +printf '%s\n' "$*" >> "$TEST_LOG" +SH +chmod +x "$WORK/bin/just" "$WORK/bin/sudo" +export PATH="$WORK/bin:$PATH" TEST_LOG="$WORK/log" +export target_image=ghcr.io/armada-os/armada tag=testing +export ARMADA_IMAGE_DIGEST="sha256:$(printf 'a%.0s' {1..64})" + +bash "$WORK/load-image" 2>/dev/null +printf 'sudoif podman pull %s@%s\nsudoif podman tag %s@%s %s:testing\n' \ + "$target_image" "$ARMADA_IMAGE_DIGEST" "$target_image" "$ARMADA_IMAGE_DIGEST" \ + "$target_image" > "$WORK/expected" +cmp "$WORK/expected" "$TEST_LOG" + +: > "$TEST_LOG" +if ARMADA_IMAGE_DIGEST=invalid bash "$WORK/load-image" 2>"$WORK/error"; then + echo 'Invalid image digest accepted' >&2 + exit 1 +fi +[[ ! -s "$TEST_LOG" ]] +grep -q 'Invalid ARMADA_IMAGE_DIGEST' "$WORK/error" + +if FAIL_PULL=1 bash "$WORK/load-image" 2>/dev/null; then + echo 'Failed digest pull accepted' >&2 + exit 1 +fi +[[ "$(wc -l < "$TEST_LOG")" == 1 ]] + +: > "$TEST_LOG" +ARMADA_IMAGE_DIGEST='' SUDO_USER=fixture bash "$WORK/load-image" 2>/dev/null +[[ "$(cat "$TEST_LOG")" == "podman pull ${target_image}:testing" ]] + +python3 - "$ROOT" "$WORK" <<'PY' +import json +import os +from pathlib import Path +import subprocess +import sys +import textwrap + +workflow = (Path(sys.argv[1]) / '.github/workflows/build-disk.yml').read_text() +# Extraction depends on the step name and the following step boundary. +step = workflow.split(' - name: Inspect disk source image\n', 1)[1] +script = textwrap.dedent(step.split(' run: |\n', 1)[1].split('\n - name:', 1)[0]) +root = Path(sys.argv[2]) +(root/'bin/sudo').write_text('#!/usr/bin/env bash\nprintf "%s\\n" "$INSPECTION"\n') +digest = 'sha256:' + 'a'*64 +revision = 'b'*40 +for case in ['pinned', 'mismatch', 'manual', 'missing-revision', 'artifact']: + labels = {} if case in ('missing-revision', 'artifact') else {'org.opencontainers.image.revision': revision} + output = root / ('inspect-' + case) + env = dict(os.environ, IMAGE_REGISTRY='ghcr.io/armada-os', IMAGE_NAME='armada', + CONTAINER_TAG='testing', EXPECTED_DIGEST='sha256:'+'c'*64 if case == 'mismatch' else digest, + PUBLISH_R2='false' if case == 'artifact' else 'true', GITHUB_OUTPUT=str(output), + INSPECTION=json.dumps([{'Digest': digest, 'Config': {'Labels': labels}}])) + if case in ('manual', 'artifact'): + env['EXPECTED_DIGEST'] = '' + result = subprocess.run(['bash', '-c', script], env=env, capture_output=True, text=True) + if case in ('mismatch', 'missing-revision'): + assert result.returncode != 0 and not output.exists(), case + else: + assert result.returncode == 0, result.stderr + assert f'digest={digest}\n' in output.read_text() + assert f'revision={revision if labels else ""}\n' in output.read_text() + print(f'PASS: Disk source inspection {case}') +PY + +echo 'Disk image digest tests passed' diff --git a/tests/esp-rename-test.sh b/tests/esp-rename-test.sh index 4bba8dbb..877e1589 100755 --- a/tests/esp-rename-test.sh +++ b/tests/esp-rename-test.sh @@ -5,7 +5,6 @@ ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)" RENAME="$ROOT/system_files/usr/libexec/armada/armada-esp-rename" UNIT="$ROOT/system_files/usr/lib/systemd/system/armada-esp-rename.service" FSCK_DROPIN="$ROOT/system_files/usr/lib/systemd/system/systemd-fsck@.service.d/10-armada-esp-rename.conf" -INSTALLER="$ROOT/system_files/usr/libexec/armada/armada-installer" VENDOR_BUILD="$ROOT/build_files/40-vendor-system-files.sh" WORK="$(mktemp -d)" trap 'rm -rf "$WORK"' EXIT @@ -151,17 +150,4 @@ grep -q '^After=armada-esp-rename.service$' "$FSCK_DROPIN" || fail "fsck can rac grep -q '^systemctl enable armada-esp-rename.service$' "$VENDOR_BUILD" || fail "unit is not enabled" [[ -x "$RENAME" ]] || fail "rename helper is not executable" -grep -q 'ESP_PARTLABEL="ARMADA"' "$INSTALLER" || fail "new ESP label is not ARMADA" -grep -q 'ROCKNIX|ARMADA|ARMADA_BOOT|ARMADA_ROOT' "$INSTALLER" || fail "legacy ESP is not removable" -eval "$(sed -n '/^detect_mode()/,/^}/p' "$INSTALLER")" -eval "$(sed -n '/^cmd_detect()/,/^}/p' "$INSTALLER")" -partition_names() { echo ARMADA; } -need_root() { :; } -check_device() { :; } -find_userdata() { UD_ORIG_GIB=8; } -collect_our_tail() { LINUX_BYTES=536870912; } -detected=$(cmd_detect) -assert_eq "new ESP mode" "$(sed -n 's/^mode=//p' <<<"$detected")" occupied -assert_eq "new ESP owner" "$(sed -n 's/^installed=//p' <<<"$detected")" armada - echo "ESP rename tests passed" diff --git a/tests/installer-bootc-refs-test.sh b/tests/installer-bootc-refs-test.sh deleted file mode 100644 index 9cfbae9a..00000000 --- a/tests/installer-bootc-refs-test.sh +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)" -INSTALLER="$ROOT/system_files/usr/libexec/armada/armada-installer" -WORK=$(mktemp -d) -trap 'rm -rf "$WORK"' EXIT - -fail() { printf 'FAIL: %s\n' "$*" >&2; exit 1; } -assert_logged() { - grep -Fxq "$1" "$WORK/log" || fail "missing operation: $1" -} -assert_not_logged() { - grep -Fxq "$1" "$WORK/log" && fail "unexpected operation: $1" - return 0 -} -pulled_marker() { - printf '%s/pulled-%s' "$WORK" "${1//\//_}" -} - -commit=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -layer_one=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb -layer_two=cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc -unrelated=dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd -blob_one="ostree/container/blob/sha256_3A_${layer_one}" -blob_two="ostree/container/blob/sha256_3A_${layer_two}" -image_ref=ostree/container/image/docker_3A__2F__2F_ghcr_2E_io/armada-os/armada_3A_testing -other_image=ostree/container/image/docker_3A__2F__2F_example_2E_invalid/os_3A_latest -TARGET="$WORK/target" -mkdir -p "$TARGET/ostree/repo" -: > "$WORK/log" - -ostree() { - local command="$1" ref - shift - case "$command" in - pull-local) - ref="${*: -1}" - printf 'pull %s\n' "$ref" >> "$WORK/log" - [[ $ref != "$blob_two" || ! -e $WORK/fail-layer-two ]] || return 1 - [[ $ref != "$blob_two" || ! -e $WORK/drop-layer-two ]] || return 0 - touch "$(pulled_marker "$ref")" - ;; - show) - if [[ " $* " == *" --print-metadata-key=ostree.manifest "* ]]; then - printf "'{\"schemaVersion\":2,\"layers\":[{\"digest\":\"sha256:%s\"},{\"digest\":\"sha256:%s\"}]}'\n" \ - "$layer_one" "$layer_two" - else - printf 'commit %s\n' "$commit" - fi - ;; - refs) - [[ ! -e $WORK/no-image-ref ]] || return 0 - printf '%s\n' "$blob_one" "$blob_two" "$image_ref" "$other_image" - ;; - rev-parse) - ref="${*: -1}" - if [[ " $* " == *" --repo=$TARGET/ostree/repo "* ]]; then - [[ -e $(pulled_marker "$ref") ]] || return 1 - printf '%s\n' "$ref" - return 0 - fi - case "$ref" in - "$image_ref") printf '%s\n' "$commit" ;; - "$other_image") printf '%s\n' "$unrelated" ;; - *) return 1 ;; - esac - ;; - *) fail "unexpected ostree command: $command $*" ;; - esac -} - -# Exercise the shipped functions without running the installer's command dispatch. -eval "$(sed -n '/^copy_bootc_ref()/,/^seed_kernel()/p' "$INSTALLER" | sed '$d')" - -copy_current_bootc_deployment -assert_logged "pull $commit" -assert_logged "pull $blob_one" -assert_logged "pull $blob_two" -assert_logged "pull $image_ref" -assert_not_logged "pull $other_image" - -# A missing layer commit must abort rather than leave a bootc deployment that boots -# but cannot compute status or upgrade. -rm -f "$WORK"/pulled-* -: > "$WORK/log" -touch "$WORK/fail-layer-two" -if copy_current_bootc_deployment >/dev/null 2>&1; then - fail "missing manifest layer unexpectedly succeeded" -fi -assert_not_logged "pull $image_ref" -rm -f "$WORK/fail-layer-two" - -# Successful pull output is not enough: verify that every expected ref actually -# resolves in the destination before allowing the install to continue. -rm -f "$WORK"/pulled-* -: > "$WORK/log" -touch "$WORK/drop-layer-two" -if copy_current_bootc_deployment >/dev/null 2>&1; then - fail "missing target layer ref unexpectedly succeeded validation" -fi -rm -f "$WORK/drop-layer-two" - -# Without the image ref, the copied commit is not a complete bootc deployment. -rm -f "$WORK"/pulled-* -: > "$WORK/log" -touch "$WORK/no-image-ref" -if copy_current_bootc_deployment >/dev/null 2>&1; then - fail "deployment without a matching image ref unexpectedly succeeded" -fi -rm -f "$WORK/no-image-ref" - -printf 'installer bootc ref tests passed\n' diff --git a/tests/installer-disk-test.py b/tests/installer-disk-test.py new file mode 100644 index 00000000..ee2bc388 --- /dev/null +++ b/tests/installer-disk-test.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +"""Exercise real GPT edits on sparse regular files, never on block devices.""" +from dataclasses import replace +from pathlib import Path +import runpy +import tempfile +import unittest + +ROOT = Path(__file__).resolve().parents[1] +i = runpy.run_path(str(ROOT / "system_files/usr/libexec/armada/armada-installer")) +run, output = i["run"], i["output"] + + +class DiskTests(unittest.TestCase): + def test_fresh_and_position_based_replacement(self): + for names in (None, ("OTHER_BOOT", "OTHER_ROOT"), ("vendor", "metadata"), ("", "")): + existing = names is not None + with self.subTest(names=names), tempfile.TemporaryDirectory() as work: + disk = Path(work) / "disk.img" + with disk.open("wb") as stream: + stream.truncate(128 * i["GIB"]) + self.assertTrue(disk.is_file()) + self.assertFalse(disk.is_block_device()) + sector = 512 + end = 128 * i["GIB"] // sector - 2048 + userdata_end = 32 * i["GIB"] // sector if existing else end + run("sgdisk", "--clear", "--new=30:2048:32767", '--change-name=30:vendor "A"\\backup α\n', "--typecode=30:8300", + f"--new=17:{i['GIB']//sector}:{userdata_end-1}", "--change-name=17:userdata", "--typecode=17:8300", "--attributes=17:set:0", "--attributes=17:set:63", disk) + if existing: + boot_end = userdata_end + 512 * i["MIB"] // sector + run("sgdisk", f"--new=1:{userdata_end}:{boot_end-1}", f"--change-name=1:{names[0]}", "--typecode=1:0700", + f"--new=2:{boot_end}:{end-1}", f"--change-name=2:{names[1]}", "--typecode=2:0700", disk) + original = i["read_table"](str(disk)) + plan = i["Plan"].make(original, None if existing else 16) + plan.write() + after = i["read_table"](str(disk)) + plan.verify(after) + self.assertIn("No problems found", output("sgdisk", "--verify", disk)) + ud = next(p for p in after.parts if p.name == "userdata") + self.assertEqual(replace(ud, end=plan.userdata.end), plan.userdata) + self.assertIn(next(p for p in original.parts if p.number == 30), after.parts) + if existing: + self.assertEqual(ud, plan.userdata) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/installer-gui-test.py b/tests/installer-gui-test.py new file mode 100644 index 00000000..ebc1912f --- /dev/null +++ b/tests/installer-gui-test.py @@ -0,0 +1,133 @@ +#!/usr/bin/python3 +"""Exercise the touch size picker with GTK under a disposable X server.""" +import os +from pathlib import Path +import runpy +import select +import shutil +import tempfile +import subprocess +import sys +import time +import unittest + +ROOT = Path(__file__).resolve().parents[1] +i = runpy.run_path(str(ROOT / "system_files/usr/libexec/armada/armada-installer")) + + +class PickerTests(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.framebuffer = tempfile.TemporaryDirectory() + cls.display = subprocess.Popen(["Xvfb", ":99", "-screen", "0", "800x600x24", "-nolisten", "tcp", "-fbdir", cls.framebuffer.name]) + deadline = time.monotonic() + 5 + while not Path("/tmp/.X11-unix/X99").exists() and time.monotonic() < deadline: + time.sleep(0.01) + os.environ["DISPLAY"] = ":99" + os.environ["GSK_RENDERER"] = "cairo" + import gi + gi.require_version("Gtk", "4.0") + gi.require_version("Adw", "1") + from gi.repository import Adw, Gio, GLib, Gtk + cls.Adw = Adw + cls.Gio, cls.GLib, cls.Gtk = Gio, GLib, Gtk + + @classmethod + def tearDownClass(cls): + cls.display.terminate() + cls.display.wait() + cls.framebuffer.cleanup() + + def widgets(self, root): + yield root + child = root.get_first_child() + while child is not None: + yield from self.widgets(child) + child = child.get_next_sibling() + + def drive(self, action): + app = self.Gio.Application.get_default() + window = app.get_active_window() + widgets = list(self.widgets(window)) + slider = next(w for w in widgets if isinstance(w, self.Gtk.Scale)) + buttons = {(w.get_child().get_icon_name() if isinstance(w.get_child(), self.Gtk.Image) else w.get_label()): w + for w in widgets if isinstance(w, self.Gtk.Button)} + try: + self.assertIsInstance(window, self.Adw.MessageDialog) + action(window, slider, buttons, widgets) + except BaseException as error: + self.failure = error + window.close() + return False + + def test_drag_and_fine_adjustments(self): + self.failure = None + def action(window, slider, buttons, widgets): + slider.set_value(48) + buttons["list-add-symbolic"].emit("clicked") + self.assertEqual(slider.get_value(), 49) + buttons["list-remove-symbolic"].emit("clicked") + self.assertEqual(slider.get_value(), 48) + slider.set_value(8) + self.assertFalse(buttons["list-remove-symbolic"].get_sensitive()) + slider.set_value(92) + self.assertFalse(buttons["list-add-symbolic"].get_sensitive()) + slider.set_value(32) + labels = [w.get_text() for w in widgets if isinstance(w, self.Gtk.Label)] + self.assertIn("Android: 32 GiB Armada: 95 GiB", labels) + if os.environ.get("ARMADA_TEST_SCREENSHOT"): + shutil.copyfile(Path(self.framebuffer.name) / "Xvfb_screen0", os.environ["ARMADA_TEST_SCREENSHOT"]) + buttons["list-add-symbolic"].emit("clicked") + buttons["Continue"].emit("clicked") + self.GLib.timeout_add(400, self.drive, action) + self.assertEqual(i["choose_android_size"](8, 92, 127), 33) + if self.failure: + raise self.failure + + def test_cancel_with_only_one_size(self): + self.failure = None + def action(window, slider, buttons, widgets): + self.assertFalse(slider.get_sensitive()) + self.assertFalse(buttons["list-remove-symbolic"].get_sensitive()) + self.assertFalse(buttons["list-add-symbolic"].get_sensitive()) + buttons["Cancel"].emit("clicked") + self.GLib.timeout_add(400, self.drive, action) + with self.assertRaises(i["Cancelled"]): + i["choose_android_size"](8, 8, 43) + if self.failure: + raise self.failure + + + @unittest.skipUnless(os.environ.get("DBUS_SESSION_BUS_ADDRESS"), "requires dbus-run-session") + def test_picker_opens_while_another_instance_owns_the_application_id(self): + peer = subprocess.Popen([sys.executable, "-c", """ +from gi.repository import Gio, GLib +app = Gio.Application(application_id="org.armada.Installer.Size") +app.register(None) +assert not app.get_is_remote() +print("ready", flush=True) +GLib.MainLoop().run() +"""], stdout=subprocess.PIPE) + self.failure = None + timer = None + def action(window, slider, buttons, widgets): + nonlocal timer + timer = None + buttons["Continue"].emit("clicked") + try: + self.assertTrue(select.select([peer.stdout], [], [], 5)[0]) + self.assertEqual(peer.stdout.readline(), b"ready\n") + timer = self.GLib.timeout_add(400, self.drive, action) + self.assertEqual(i["choose_android_size"](8, 8, 43), 8) + if self.failure: + raise self.failure + finally: + if timer is not None: + self.GLib.source_remove(timer) + peer.terminate() + peer.wait(timeout=5) + peer.stdout.close() + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/installer-source-test.py b/tests/installer-source-test.py new file mode 100644 index 00000000..30ed4ae7 --- /dev/null +++ b/tests/installer-source-test.py @@ -0,0 +1,340 @@ +#!/usr/bin/python3 +"""Run with root and bootc/OSTree/PyGObject in a disposable Armada container.""" +import hashlib +import io +import json +import os +from pathlib import Path +import runpy +import subprocess +import sys +import tarfile +import tempfile +import unittest +from unittest.mock import Mock + +import gi +gi.require_version("OSTree", "1.0") +from gi.repository import Gio, GLib, OSTree + +ROOT = Path(__file__).resolve().parents[1] +INSTALLER = ROOT / "system_files/usr/libexec/armada/armada-installer" +module = runpy.run_path(str(INSTALLER)) +SourceImage = module["SourceImage"] +Error = module["Error"] +EXT = ["bootc", "internals", "ostree-ext", "container", "image"] +ORIGIN = "ostree-image-signed:docker://ghcr.io/armada-os/armada:beta" + + +def run(*args): + return subprocess.check_output([str(arg) for arg in args], text=True, stderr=subprocess.STDOUT).strip() + + +def oci(dest, marker): + (dest / 'blobs/sha256').mkdir(parents=True) + + def blob(data, media): + h = hashlib.sha256(data).hexdigest() + (dest / 'blobs/sha256' / h).write_bytes(data) + return {'mediaType': media, 'digest': 'sha256:' + h, 'size': len(data)} + + layers = [] + for files in [ + {'usr/lib/os-release': b'ID=armada-audit\nVERSION_ID=1\n', + 'usr/share/audit/base': b'base layer\n', + 'usr/lib/modules/6.1.0/vmlinuz': b'FAKE KERNEL FOR METADATA TEST ONLY\n', + 'usr/lib/modules/6.1.0/initramfs.img': b'FAKE INITRAMFS\n'}, + {'usr/share/audit/content': marker.encode(), + 'usr/etc/audit.conf': b'factory=true\n'}, + ]: + stream = io.BytesIO() + with tarfile.open(fileobj=stream, mode='w') as tar: + dirs = sorted({str(parent) for f in files for parent in Path(f).parents + if str(parent) != '.'}) + for d in dirs: + info = tarfile.TarInfo(d) + info.type = tarfile.DIRTYPE + info.mode = 0o755 + tar.addfile(info) + for f, data in files.items(): + info = tarfile.TarInfo(f) + info.mode = 0o644 + info.size = len(data) + tar.addfile(info, io.BytesIO(data)) + layers.append(blob(stream.getvalue(), 'application/vnd.oci.image.layer.v1.tar')) + config = {'architecture': 'arm64', 'os': 'linux', 'config': { + 'Labels': {'containers.bootc': '1', 'ostree.bootable': 'true'}}, + 'rootfs': {'type': 'layers', 'diff_ids': [x['digest'] for x in layers]}} + config_desc = blob(json.dumps(config).encode(), 'application/vnd.oci.image.config.v1+json') + manifest = {'schemaVersion': 2, 'mediaType': 'application/vnd.oci.image.manifest.v1+json', + 'config': config_desc, 'layers': layers} + desc = blob(json.dumps(manifest).encode(), manifest['mediaType']) + desc['annotations'] = {'org.opencontainers.image.ref.name': 'latest'} + (dest / 'index.json').write_text(json.dumps({'schemaVersion': 2, 'manifests': [desc]})) + (dest / 'oci-layout').write_text('{"imageLayoutVersion":"1.0.0"}') + return f'ostree-unverified-image:oci:{dest}:latest' + + +class SourceTests(unittest.TestCase): + def setUp(self): + self.temp = tempfile.TemporaryDirectory(prefix="installer-source-test.") + self.addCleanup(self.temp.cleanup) + self.work = Path(self.temp.name) + self.path = self.work / "repo" + run("ostree", "init", f"--repo={self.path}", "--mode=bare") + run(*EXT, "pull", self.path, oci(self.work / "v1", "running image")) + self.repo = OSTree.Repo.new(Gio.File.new_for_path(str(self.path))) + self.repo.open(None) + self.image_ref = next(r for r in self.refs() if r.startswith("ostree/container/image/")) + self.commit = run("ostree", "rev-parse", f"--repo={self.path}", self.image_ref) + self.origin = GLib.KeyFile.new() + self.origin.set_string("origin", "container-image-reference", ORIGIN) + self.deployment = OSTree.Deployment.new(0, "default", self.commit, 7, None, 0) + self.deployment.set_origin(self.origin) + self.prepared = self.work / "prepared" + self.prepared.mkdir() + + def refs(self): + return run("ostree", "refs", f"--repo={self.path}").splitlines() + + def prepare(self): + self.source = SourceImage.read(self.repo, self.deployment) + + def target(self): + target = self.work / "target" + target.mkdir() + run("ostree", "admin", "init-fs", "--modern", target) + repo = target / "ostree/repo" + run("ostree", "config", f"--repo={repo}", "set", "sysroot.bootloader", "none") + run("ostree", "config", f"--repo={repo}", "set", "sysroot.bootprefix", "true") + run("ostree", "config", f"--repo={repo}", "set", "sysroot.readonly", "true") + run("ostree", "admin", "os-init", f"--sysroot={target}", "default") + self.source.copy(target) + (self.prepared / "origin").write_text(self.source.origin.to_data()[0]) + run("ostree", "admin", "deploy", "--no-merge", f"--sysroot={target}", + "--os=default", f"--origin-file={self.prepared / 'origin'}", self.commit) + run(*EXT, "prune-layers", "--repo", repo) + run("ostree", "prune", "--refs-only", "--depth=0", f"--repo={repo}") + run("ostree", "fsck", f"--repo={repo}") + for ref, expected in self.source.refs.items(): + self.assertEqual(run("ostree", "rev-parse", f"--repo={repo}", ref), expected) + self.assertFalse(any(r.startswith("ostree/container/image/") for r in + run("ostree", "refs", f"--repo={repo}").splitlines())) + origins = list((target / "ostree/deploy/default/deploy").glob("*.origin")) + self.assertEqual(len(origins), 1) + self.assertIn(ORIGIN, origins[0].read_text()) + self.assertEqual((origins[0].with_suffix("") / "etc/audit.conf").read_text(), "factory=true\n") + module["configure_deployment"](target, self.source, dict(root="root-uuid", boot="boot-uuid", esp="esp-uuid"), ["quiet"]) + entry = next((target / "boot/loader/entries").glob("*.conf")).read_text() + self.assertIn("root=UUID=root-uuid", entry) + self.assertIn("rootflags=subvol=root,", entry) + self.assertIn("fdtdir /boot/", entry) + self.assertIn("UUID=root-uuid /var/home", (origins[0].with_suffix("") / "etc/fstab").read_text()) + return repo + + def check_deployment_history(self, selected_index): + sd = self.work / "sd" + sd.mkdir() + run("ostree", "admin", "init-fs", "--modern", sd) + self.path = sd / "ostree/repo" + run("ostree", "config", f"--repo={self.path}", "set", "sysroot.bootloader", "none") + run("ostree", "admin", "os-init", f"--sysroot={sd}", "default") + origin_file = self.work / "history.origin" + origin_file.write_text(self.origin.to_data()[0]) + images = {} + for version in range(5): + ref = oci(self.work / f"history-{version}", f"image {version}") + run(*EXT, "pull", self.path, ref) + image_ref = next(r for r in self.refs() if r.startswith("ostree/container/image/")) + checksum = run("ostree", "rev-parse", f"--repo={self.path}", image_ref) + images[checksum] = ref + run("ostree", "admin", "deploy", "--no-merge", "--retain", f"--sysroot={sd}", + "--os=default", f"--origin-file={origin_file}", checksum) + history = OSTree.Sysroot.new(Gio.File.new_for_path(str(sd))) + history.load(None) + if len(history.get_deployments()) > 2: + run("ostree", "admin", "undeploy", f"--sysroot={sd}", "2") + run("ostree", "refs", f"--repo={self.path}", "--delete", image_ref) + run(*EXT, "prune-layers", "--repo", self.path) + run("ostree", "prune", "--refs-only", "--depth=0", f"--repo={self.path}") + sysroot = OSTree.Sysroot.new(Gio.File.new_for_path(str(sd))) + sysroot.load(None) + deployments = sysroot.get_deployments() + self.assertEqual(len(deployments), 2) + self.deployment = deployments[selected_index] + self.commit = self.deployment.get_csum() + self.repo = OSTree.Repo.new(Gio.File.new_for_path(str(self.path))) + self.repo.open(None) + with self.assertRaises(GLib.Error): + self.repo.load_commit(next(iter(images))) + for deployment in deployments: + root = sd / "ostree/deploy/default/deploy" / f"{deployment.get_csum()}.{deployment.get_deployserial()}" + (root / "etc/audit.conf").write_text("local-user-change=true\n") + (sd / "ostree/deploy/default/var/local-user-data").write_text("do not copy") + self.assertFalse(any(r.startswith("ostree/container/image/") for r in self.refs())) + fresh = self.work / "fresh-repo" + run("ostree", "init", f"--repo={fresh}", "--mode=bare") + run(*EXT, "pull", fresh, images[self.commit]) + fresh_ref = next(r for r in run("ostree", "refs", f"--repo={fresh}").splitlines() + if r.startswith("ostree/container/image/")) + fresh_commit = run("ostree", "rev-parse", f"--repo={fresh}", fresh_ref) + fresh_repo = OSTree.Repo.new(Gio.File.new_for_path(str(fresh))) + fresh_repo.open(None) + selected = self.repo.load_commit(self.commit)[1].unpack() + imported = fresh_repo.load_commit(fresh_commit)[1].unpack() + # Import timestamps can differ; tree checksums identify filesystem content. + self.assertEqual(selected[6:], imported[6:]) + self.prepare() + target = self.target() + self.assertFalse((target.parents[1] / "ostree/deploy/default/var/local-user-data").exists()) + for key in ("ostree.manifest", "ostree.manifest-digest", "ostree.container.image-config"): + self.assertEqual(selected[0][key], imported[0][key]) + for ref, checksum in self.source.refs.items(): + fresh_checksum = fresh_commit if ref == self.commit else run("ostree", "rev-parse", f"--repo={fresh}", ref) + self.assertEqual(self.repo.load_commit(checksum)[1].unpack()[6:], + fresh_repo.load_commit(fresh_checksum)[1].unpack()[6:]) + self.assertEqual(run("ostree", "cat", f"--repo={target}", self.commit, "/usr/share/audit/content"), + f"image {4-selected_index}") + + def test_repeated_deployments_and_pruning_match_fresh_import(self): + self.check_deployment_history(0) + + def test_older_selected_deployment_survives_newer_image_and_pruning(self): + self.check_deployment_history(1) + + def test_pending_image_does_not_change_selected_commit(self): + run(*EXT, "pull", self.path, oci(self.work / "v2", "pending image")) + pending_ref = next(r for r in self.refs() if "/v2_3A_latest" in r) + pending = run("ostree", "rev-parse", f"--repo={self.path}", pending_ref) + run("ostree", "refs", f"--repo={self.path}", "--force", f"--create={self.image_ref}", pending) + before = {ref: run("ostree", "rev-parse", f"--repo={self.path}", ref) for ref in self.refs()} + self.prepare() + self.assertEqual(self.source.checksum, self.commit) + target = self.target() + self.assertEqual(run("ostree", "cat", f"--repo={target}", self.commit, "/usr/share/audit/content"), "running image") + self.assertEqual(before, {ref: run("ostree", "rev-parse", f"--repo={self.path}", ref) for ref in self.refs()}) + + @unittest.skipUnless(os.environ.get("ARMADA_TEST_MOUNTS") == "1", "requires a disposable container with CAP_SYS_ADMIN") + def test_readonly_source_copies_and_corruption_does_not_write_markers(self): + for damaged in (False, True): + if damaged: + content = next(p for p in (self.path / "objects").glob("*/*.file") + if p.is_file() and p.read_bytes() == b"running image") + content.unlink() + before = {str(p.relative_to(self.path)): (p.lstat().st_size, p.lstat().st_mtime_ns) + for p in self.path.rglob("*")} + run("mount", "--bind", self.path, self.path) + try: + run("mount", "-o", "remount,bind,ro", self.path) + with self.assertRaises(OSError) as error: + (self.path / "write-probe").write_text("must fail") + self.assertEqual(error.exception.errno, 30) + if damaged: + self.prepare() + target = self.work / "damaged-target" + target.mkdir() + run("ostree", "admin", "init-fs", "--modern", target) + with self.assertRaises(Error): + self.source.copy(target) + with self.assertRaises(Error): + module["run"]("ostree", "fsck", f"--repo={self.path}") + else: + self.prepare() + self.target() + after = {str(p.relative_to(self.path)): (p.lstat().st_size, p.lstat().st_mtime_ns) + for p in self.path.rglob("*")} + self.assertEqual(before, after) + finally: + run("umount", self.path) + + def test_missing_image_name_is_supported(self): + run("ostree", "refs", f"--repo={self.path}", "--delete", self.image_ref) + self.prepare() + self.target() + + def test_fd_backed_repository_path_is_resolved_for_children(self): + fd = os.open(self.path, os.O_RDONLY | os.O_DIRECTORY) + try: + repo = Mock(wraps=self.repo) + repo.get_path.return_value = Gio.File.new_for_path(f"/proc/self/fd/{fd}") + self.source = SourceImage.read(repo, self.deployment) + self.target() + finally: + os.close(fd) + + def test_missing_layer_fails_before_prepared_source_exists(self): + layer = next(r for r in self.refs() if r.startswith("ostree/container/blob/")) + run("ostree", "refs", f"--repo={self.path}", "--delete", layer) + with self.assertRaisesRegex(Error, "no supported complete container image"): + self.prepare() + self.assertEqual(list(self.prepared.iterdir()), []) + + def test_corrupt_object_fails_during_verified_copy(self): + content = next(p for p in (self.path / "objects").glob("*/*.file") + if p.is_file() and p.read_bytes() == b"running image") + content.chmod(0o644) + content.write_bytes(b"damaged image") + self.prepare() + with self.assertRaises(Error): + self.target() + self.assertEqual(list(self.prepared.iterdir()), []) + + def test_origin_is_exact_selected_deployment(self): + other = OSTree.Deployment.new(1, "default", self.commit, 8, None, 0) + other_origin = GLib.KeyFile.new() + other_origin.set_string("origin", "container-image-reference", ORIGIN.replace(":beta", ":testing")) + other.set_origin(other_origin) + self.prepare() + self.assertEqual(self.source.origin.get_string("origin", "container-image-reference"), ORIGIN) + self.assertNotIn(":testing", self.source.origin.to_data()[0]) + + def test_missing_or_modified_origin_is_rejected(self): + self.deployment.set_origin(None) + with self.assertRaisesRegex(Error, "Missing update origin"): + self.prepare() + self.origin.set_string("packages", "requested", "example") + self.deployment.set_origin(self.origin) + with self.assertRaisesRegex(Error, "local package modifications"): + self.prepare() + self.assertEqual(list(self.prepared.iterdir()), []) + + def test_derived_commit_does_not_fall_back_to_parent(self): + derived = run("ostree", "commit", f"--repo={self.path}", "--branch=derived", + f"--parent={self.commit}", f"--tree=ref={self.commit}") + self.deployment = OSTree.Deployment.new(0, "default", derived, 0, None, 0) + self.deployment.set_origin(self.origin) + with self.assertRaises(Error): + self.prepare() + self.assertEqual(list(self.prepared.iterdir()), []) + + def test_native_image_bindings(self): + native = run("ostree", "commit", f"--repo={self.path}", "--branch=native", + "--parent=none", f"--tree=ref={self.commit}") + image = f"oci:{self.work}/native:latest" + run("bootc", "internals", "ostree-ext", "container", "encapsulate", "--repo", self.path, native, image) + run(*EXT, "pull", self.path, "ostree-unverified-image:" + image) + image_ref = next(r for r in self.refs() if "/native_3A_latest" in r) + self.commit = run("ostree", "rev-parse", f"--repo={self.path}", image_ref) + self.deployment = OSTree.Deployment.new(0, "default", self.commit, 2, None, 0) + self.deployment.set_origin(self.origin) + self.prepare() + self.target() + + def test_non_booted_system_is_rejected(self): + with self.assertRaisesRegex(Error, "booted OSTree system"): + with module["locked_source"](): + self.fail("accepted a non-booted container") + + def test_normalizing_origin_does_not_modify_source_origin(self): + unsigned = ORIGIN.replace("ostree-image-signed:docker://", "ostree-unverified-registry:") + self.origin.set_string("origin", "container-image-reference", unsigned) + self.deployment.set_origin(self.origin) + self.prepare() + self.assertEqual(self.source.origin.get_string("origin", "container-image-reference"), ORIGIN) + self.assertEqual(self.deployment.get_origin().get_string("origin", "container-image-reference"), unsigned) + + +if __name__ == "__main__": + if Path("/run/ostree-booted").exists(): + sys.exit("Run these tests inside a disposable container, not a booted OSTree host") + unittest.main() diff --git a/tests/installer-test.py b/tests/installer-test.py new file mode 100644 index 00000000..a7c544a7 --- /dev/null +++ b/tests/installer-test.py @@ -0,0 +1,526 @@ +#!/usr/bin/env python3 +import argparse +from contextlib import contextmanager, nullcontext +from dataclasses import replace +import importlib.machinery +import importlib.util +import io +import json +import os +from pathlib import Path +import signal +import subprocess +import sys +import tempfile +import time +import unittest +from unittest.mock import Mock, patch +import uuid + +ROOT = Path(__file__).resolve().parents[1] +SCRIPT = ROOT / "system_files/usr/libexec/armada/armada-installer" +loader = importlib.machinery.SourceFileLoader("installer", str(SCRIPT)) +spec = importlib.util.spec_from_loader(loader.name, loader) +i = importlib.util.module_from_spec(spec) +sys.modules[spec.name] = i +loader.exec_module(i) + + +def table(names=(), device="/dev/sda", sector=4096): + def part(number, start_mib, end_mib, name, kind=i.LINUX_TYPE): + return i.Partition(number, start_mib * i.MIB // sector, end_mib * i.MIB // sector, + name, kind, str(uuid.UUID(int=number))) + parts = [part(30, 1, 16, "vendor_a", "01234567-1234-1234-1234-123456789abc"), + part(17, 1024, 32 * 1024 if names else 128 * 1024, "userdata")] + bounds = [32 * 1024, 32 * 1024 + 512, 34 * 1024, 128 * 1024] + for index, name in enumerate(names): + end = bounds[index + 1] if index < len(names) - 1 else 128 * 1024 + parts.append(part(index + 1, bounds[index], end, name, i.ESP_TYPE if index == 0 else i.LINUX_TYPE)) + return i.Table(device, sector, 34, 256 * i.GIB // sector - 34, str(uuid.UUID(int=100)), tuple(sorted(parts, key=lambda p: p.number))) + + +def applied(plan): + parts = [replace(p, end=plan.userdata_end) if p == plan.userdata else p + for p in plan.table.parts if p not in plan.remove] + parts += [replace(p, uuid=str(uuid.UUID(int=1000 + p.number))) for p in plan.create] + return replace(plan.table, parts=tuple(sorted(parts, key=lambda p: p.number)), unused=()) + + +def table_json(t): + return dict(partitiontable=dict(device=t.device, label="gpt", unit="sectors", sectorsize=t.sector_size, + firstlba=t.first, lastlba=t.last, id=t.disk_id, **{"table-length": str(t.entry_count)}, + partitions=[dict(node=i.part_node(t.device, p.number), start=p.start, size=p.end-p.start, + name=p.name, type=p.type, uuid=p.uuid, attrs=p.attrs) for p in t.parts])) + + +class PlanningTests(unittest.TestCase): + def test_unused_gpt_slots_ignore_stale_overlapping_geometry(self): + t = replace(table(), entry_count=32) + data = table_json(t) + data["partitiontable"]["partitions"].append(dict(node="/dev/sda18", start=1000, size=999999999, + type="00000000-0000-0000-0000-000000000000")) + t = replace(t, unused=(18,)) + self.assertEqual(i.Table.parse(t.device, data), t) + plan = i.Plan.make(t, 32) + self.assertNotIn("999999999", plan.script()) + plan.verify(applied(plan)) + with self.assertRaises(i.Error): + plan.verify(replace(applied(plan), entry_count=128)) + + def test_planner_does_not_allocate_beyond_gpt_capacity(self): + t = table() + t = replace(t, entry_count=3, parts=tuple(replace(p, number=n) for n, p in enumerate(t.parts, 1))) + with self.assertRaisesRegex(i.Error, "Not enough free GPT partition slots"): + i.Plan.make(t, 32) + + def test_parse_roundtrip_devices_and_sector_sizes(self): + for device in ("/dev/sda", "/dev/mmcblk0", "/dev/nvme0n1"): + for sector in (512, 4096): + t = table(device=device, sector=sector) + self.assertEqual(i.Table.parse(device, table_json(t)), t) + plan = i.Plan.make(t, 16) + plan.verify(applied(plan)) + self.assertEqual(plan.create[0].start, plan.userdata_end) + self.assertEqual((plan.create[0].end-plan.create[0].start)*sector, i.ESP_SIZE) + self.assertGreaterEqual((plan.create[-1].end-plan.create[-1].start)*sector, i.ROOT_MIN) + + def test_bad_partition_output_is_rejected(self): + t = table() + for change in ( + lambda d: d.update(label="dos"), + lambda d: d.pop("sectorsize"), + lambda d: d.update(sectorsize=True), + lambda d: d["partitions"][0].update(node="/dev/sdb1"), + lambda d: d["partitions"][0].update(size=-1), + lambda d: d["partitions"][0].update(start=True), + lambda d: d["partitions"][0].update(start=d["lastlba"]), + lambda d: d["partitions"][1].update(start=d["partitions"][0]["start"]), + ): + data = table_json(t) + change(data["partitiontable"]) + with self.assertRaises(i.Error): + i.Table.parse(t.device, data) + + def test_fresh_preserves_android_start_type_uuid_and_high_numbered_vendor(self): + plan = i.Plan.make(table(), 16) + actual = applied(plan) + plan.verify(actual) + android = next(p for p in actual.parts if p.name == "userdata") + self.assertEqual(replace(android, end=plan.userdata.end), plan.userdata) + self.assertEqual([p.number for p in plan.create], [18, 19, 20]) + self.assertIn(next(p for p in plan.table.parts if p.name == "vendor_a"), actual.parts) + self.assertIn(f"uuid={plan.userdata.uuid}", plan.script()) + self.assertIn(f"/dev/sda17: start={plan.userdata.start}, size={plan.userdata_end-plan.userdata.start}", plan.script()) + + def test_replacement_reuses_slots_immediately_after_userdata(self): + t = table(["ARMADA", "ARMADA_BOOT", "ARMADA_ROOT"]) + t = replace(t, parts=tuple(replace(p, number=p.number+17) if p.number < 4 else p for p in t.parts)) + plan = i.Plan.make(t) + self.assertEqual([p.number for p in plan.create], [18, 19, 20]) + plan.verify(applied(plan)) + + def test_occupied_preferred_slot_falls_back_without_moving_vendor(self): + for names in ((), ("OTHER_BOOT", "OTHER_ROOT")): + for occupied in (18, 19, 20): + with self.subTest(names=names, occupied=occupied): + t = table(names) + t = replace(t, parts=tuple(replace(p, number=occupied) if p.number == 30 else p for p in t.parts)) + plan = i.Plan.make(t, None if names else 16) + self.assertEqual([p.number for p in plan.create], [1, 2, 3]) + self.assertIn(next(p for p in t.parts if p.number == occupied), applied(plan).parts) + plan.verify(applied(plan)) + + def test_preferred_slots_beyond_capacity_fall_back(self): + t = table() + t = replace(t, entry_count=32, parts=tuple(replace(p, number=31) if p.name == "userdata" else p for p in t.parts)) + plan = i.Plan.make(t, 16) + self.assertEqual([p.number for p in plan.create], [1, 2, 3]) + plan.verify(applied(plan)) + + def test_userdata_attributes_are_preserved(self): + attrs = "RequiredPartition LegacyBIOSBootable GUID:48,60,63" + t = table() + t = replace(t, parts=tuple(replace(p, attrs=attrs) if p.name == "userdata" else p for p in t.parts)) + self.assertIn('attrs="' + attrs + '"', i.Plan.make(t, 16).script()) + + def test_replacement_uses_position_regardless_of_names_or_types(self): + for names in (["ARMADA", "ARMADA_BOOT", "ARMADA_ROOT"], ["OTHER_BOOT", "OTHER_ROOT"], + ["ROCKNIX", "STORAGE"], ["vendor", "metadata"], ["root", "root"], ["", ""]): + with self.subTest(names=names): + t = table(names) + t = replace(t, parts=tuple(replace(p, type="01234567-1234-1234-1234-123456789abc") + if p.name in names else p for p in t.parts)) + plan = i.Plan.make(t) + self.assertEqual(t.info()["mode"], "occupied") + self.assertEqual(plan.operation, "replace") + self.assertEqual(plan.userdata_end, plan.userdata.end) + self.assertEqual(plan.remove, tuple(sorted((p for p in t.parts if p.start >= plan.userdata.end), key=lambda p: p.start))) + self.assertNotIn(plan.userdata, plan.remove) + self.assertIn("Erase ALL partitions after Android userdata", plan.describe()) + for p in plan.remove: + self.assertIn(i.part_node(t.device, p.number), plan.describe()) + self.assertIn(i.part_node(t.device, p.number), t.info()["partition_names"]) + plan.verify(applied(plan)) + + def test_single_unknown_tail_partition_can_be_replaced(self): + plan = i.Plan.make(table(["custom-storage"])) + self.assertEqual(len(plan.remove), 1) + self.assertEqual(len(plan.create), 3) + + def test_earlier_partitions_are_preserved_regardless_of_label_or_number(self): + for name in ("ARMADA", "vendor_a", ""): + t = table(["custom-storage"]) + t = replace(t, parts=tuple(replace(p, name=name) if p.number == 30 else p for p in t.parts)) + plan = i.Plan.make(t) + before = next(p for p in t.parts if p.number == 30) + self.assertNotIn(before, plan.remove) + self.assertIn(before, applied(plan).parts) + plan.verify(applied(plan)) + + def test_missing_or_duplicate_userdata_is_rejected(self): + for old, new in (("vendor_a", "userdata"), ("userdata", "data")): + t = table() + parts = tuple(replace(p, name=new) if p.name == old else p for p in t.parts) + with self.assertRaises(i.Error): + i.Plan.make(replace(t, parts=parts), 16) + + def test_too_small_and_invalid_sizes_are_rejected(self): + t = table() + for size in (None, True, 0, 7, 1000): + with self.assertRaises(i.Error): + i.Plan.make(t, size) + short = replace(t, parts=tuple(replace(p, end=p.start+16*i.GIB//t.sector_size) if p.name == "userdata" else p for p in t.parts)) + self.assertEqual(short.info()["mode"], "toosmall") + with self.assertRaises(i.Error): + i.Plan.make(short, 8) + with self.assertRaises(i.Error): + i.Plan.make(table(["OTHER_BOOT", "OTHER_ROOT"]), 16) + + def test_verification_rejects_changed_android_and_extra_partitions(self): + plan = i.Plan.make(table(["OTHER_BOOT", "OTHER_ROOT"])) + good = applied(plan) + for t in (replace(good, disk_id=str(uuid.uuid4())), + replace(good, parts=tuple(replace(p, end=p.end-1) if p.name == "userdata" else p for p in good.parts)), + replace(good, parts=tuple(replace(p, uuid=str(uuid.uuid4())) if p.name == "vendor_a" else p for p in good.parts)), + replace(good, parts=good.parts[:-1])): + with self.assertRaises(i.Error): + plan.verify(t) + + +class ExecutionTests(unittest.TestCase): + def test_fingerprint_binds_table_and_kernel_device_identity(self): + t = table() + with patch.object(i.os, "stat", return_value=argparse.Namespace(st_rdev=os.makedev(8, 0))), patch.object(Path, "read_text", return_value="10\n"): + expected = i.table_fingerprint(t) + self.assertEqual(expected, i.table_fingerprint(t)) + for changed in (replace(t, device="/dev/sdb"), replace(t, disk_id="changed"), + replace(t, parts=tuple(replace(p, end=p.end-1) if p.name == "userdata" else p for p in t.parts))): + self.assertNotEqual(expected, i.table_fingerprint(changed)) + with patch.object(Path, "read_text", return_value="11\n"): + self.assertNotEqual(expected, i.table_fingerprint(t)) + with patch.object(i.os, "stat", return_value=argparse.Namespace(st_rdev=os.makedev(8, 16))): + self.assertNotEqual(expected, i.table_fingerprint(t)) + + def test_changed_confirmation_aborts_before_planning(self): + args = argparse.Namespace(command="install", device="/dev/sda", expect_table="confirmed") + with patch.object(i.os, "geteuid", return_value=0), patch.object(i, "discover_device", return_value="/dev/sda"), patch.object(i, "read_table", return_value=table()), patch.object(i, "table_fingerprint", return_value="changed"), patch.object(i.Plan, "make") as make, patch.object(i, "run") as run: + with self.assertRaisesRegex(i.Error, "changed after confirmation"): + i.execute(args) + make.assert_not_called() + run.assert_not_called() + + def test_kernel_geometry_in_512_byte_sectors_and_device_nodes(self): + for sector in (512, 4096): + for names, size in (((), 16), (("OTHER_BOOT", "OTHER_ROOT"), None)): + plan = i.Plan.make(table(names, sector=sector), size) + parts = {i.part_node(plan.table.device, p.number): p for p in applied(plan).parts} + def read(path): + p = parts["/dev/" + path.parent.name] + return dict(start=str(p.start * sector // 512), size=str((p.end-p.start) * sector // 512), dev=f"8:{p.number}")[path.name] + def stat(node): + return argparse.Namespace(st_rdev=os.makedev(8, parts[node].number)) + with patch.object(Path, "read_text", read), patch.object(i.os, "stat", side_effect=stat): + plan.verify_kernel() + for attribute in ("start", "size", "dev"): + def bad_read(path): + return ("8:99" if attribute == "dev" else "1") if path.name == attribute else read(path) + with patch.object(Path, "read_text", bad_read), self.assertRaisesRegex(i.Error, "does not match"): + plan.verify_kernel() + with patch.object(Path, "read_text", side_effect=FileNotFoundError("missing partition")), self.assertRaisesRegex(i.Error, "Could not verify"): + plan.verify_kernel() + + def test_kernel_mismatch_stops_before_userdata_wipe(self): + plan = i.Plan.make(table(), 16) + job = i.Installation(plan) + with patch.object(i, "refuse_boot_disk"), patch.object(i, "require_idle"), patch.object(i, "read_table", side_effect=[plan.table, applied(plan)]), patch.object(i.Plan, "verify_kernel", side_effect=i.Error("stale kernel geometry")), patch.object(i, "run") as run: + with self.assertRaisesRegex(i.Error, "stale kernel geometry"): + job.partition() + self.assertFalse(any(call.args[0] == "dd" for call in run.call_args_list)) + self.assertTrue(job.changed) + + def test_preflight_uses_source_context_without_target_discovery(self): + for failed in (False, True): + events = [] + @contextmanager + def source(): + events.append("locked") + try: + if failed: + raise i.Error("corrupt source") + yield Mock(checksum="selected") + finally: + events.append("released") + with patch.object(i.os, "geteuid", return_value=0), patch.object(i, "locked_source", source), patch.object(i, "inhibit_sleep", return_value=nullcontext()), patch.object(i, "repo_path", return_value="/source/repo"), patch.object(i, "run") as run, patch.object(i, "discover_device") as discover, patch.object(i.Installation, "partition") as partition, patch("sys.stdout", new_callable=io.StringIO) as out: + if failed: + with self.assertRaisesRegex(i.Error, "corrupt source"): + i.execute(argparse.Namespace(command="preflight")) + else: + i.execute(argparse.Namespace(command="preflight")) + self.assertIn("Validated source commit: selected", out.getvalue()) + self.assertIn("seconds; internal storage was not touched", out.getvalue()) + run.assert_called_once_with("ostree", "fsck", "--repo=/source/repo") + self.assertEqual(events, ["locked", "released"]) + discover.assert_not_called() + partition.assert_not_called() + + def test_changed_table_aborts_without_writing(self): + plan = i.Plan.make(table(), 16) + job = i.Installation(plan) + with patch.object(i, "refuse_boot_disk"), patch.object(i, "read_table", return_value=replace(plan.table, disk_id="changed")), patch.object(i, "run") as run: + with self.assertRaisesRegex(i.Error, "changed after inspection"): + job.partition() + run.assert_not_called() + self.assertFalse(job.changed) + + def test_in_use_target_aborts_without_writing(self): + plan = i.Plan.make(table(), 16) + job = i.Installation(plan) + with patch.object(i, "refuse_boot_disk"), patch.object(i, "read_table", return_value=plan.table), patch.object(i, "require_idle", side_effect=i.Error("in use")), patch.object(i, "run") as run: + with self.assertRaisesRegex(i.Error, "in use"): + job.partition() + run.assert_not_called() + self.assertFalse(job.changed) + + def test_partition_operations_wipe_android_only_on_fresh_install(self): + for t, size in ((table(), 16), (table(["OTHER_BOOT", "OTHER_ROOT"]), None)): + plan = i.Plan.make(t, size) + job = i.Installation(plan) + with patch.object(i, "refuse_boot_disk"), patch.object(i, "require_idle"), patch.object(i, "read_table", side_effect=[t, applied(plan)]), patch.object(i.Plan, "verify_kernel"), patch.object(i, "run") as run: + job.partition() + commands = [call.args for call in run.call_args_list] + self.assertEqual(sum(c[0] == "dd" for c in commands), int(plan.operation == "fresh")) + self.assertTrue(job.changed) + + def test_partition_failure_arms_recovery_and_stops_commands(self): + plan = i.Plan.make(table(), 16) + with patch.object(i, "refuse_boot_disk"), patch.object(i, "require_idle"), patch.object(i, "read_table", return_value=plan.table), patch.object(i, "run", side_effect=i.Error("write failed")) as run, patch("sys.stderr", new_callable=io.StringIO) as err: + with self.assertRaisesRegex(i.Error, "write failed"): + with i.operation(plan) as job: + job.partition() + self.assertEqual(run.call_count, 1) + self.assertIn("Internal storage was modified", err.getvalue()) + + def test_source_repository_is_readonly_before_validation(self): + for remount_fails in (False, True): + api = Mock() + sysroot = api.Sysroot.new_default.return_value + repo = Mock() + repo.get_path.return_value.get_path.return_value = "/sysroot/ostree/repo" + sysroot.get_repo.return_value = (True, repo) + events = [] + def command(*args): + events.append(args) + if remount_fails and "remount,bind,ro" in args: + raise i.Error("read-only mount failed") + def validate(*args): + self.assertIn(("mount", "-o", "remount,bind,ro", "/sysroot/ostree/repo"), events) + return "validated" + with patch.object(i, "ostree_api", return_value=(Mock(), api)), patch.object(i, "repo_path", return_value="/sysroot/ostree/repo"), patch.object(i, "run", side_effect=command), patch.object(i.SourceImage, "read", side_effect=validate) as read: + if remount_fails: + with self.assertRaisesRegex(i.Error, "read-only mount failed"): + with i.locked_source(): + self.fail("unprotected source was accepted") + read.assert_not_called() + else: + with i.locked_source() as source: + self.assertEqual(source, "validated") + sysroot.unlock.assert_not_called() + self.assertEqual(events[-1], ("umount", "/sysroot/ostree/repo")) + sysroot.unlock.assert_called_once() + + def test_source_failure_never_reaches_partitioning(self): + args = argparse.Namespace(command="install", device=None, userdata_gib=16, assume_yes=True, expect_table=None) + @contextmanager + def bad_source(): + raise i.Error("missing source layer") + yield + with tempfile.TemporaryFile() as lock, patch.object(i.os, "geteuid", return_value=0), patch.object(i, "discover_device", return_value="/dev/sda"), patch.object(i, "read_table", return_value=table()), patch.object(i, "require_commands"), patch.object(i, "refuse_boot_disk"), patch.object(i, "require_idle"), patch.object(i, "open", return_value=lock, create=True), patch.object(i, "inhibit_sleep", return_value=nullcontext()), patch.object(i, "base_kargs", return_value=[]), patch.object(i, "locked_source", bad_source), patch.object(i.Installation, "partition") as partition: + with self.assertRaisesRegex(i.Error, "missing source layer"): + i.execute(args) + partition.assert_not_called() + + def test_boot_image_scratch_ignores_sd_tmpdir(self): + job = i.Installation(i.Plan.make(table(), 16)) + source = Mock(checksum="selected") + source.origin.to_data.return_value = ("origin", 6) + mkdtemp = tempfile.mkdtemp + with tempfile.TemporaryDirectory() as work: + def temporary(*args, **kwargs): + if kwargs.get("dir") == "/run": + kwargs["dir"] = work + return mkdtemp(*args, **kwargs) + def command(*args, **kwargs): + if args[:2] == ("ostree", "checkout"): + args[-1].mkdir() + elif args[0] == i.BOOTIMG: + env = kwargs["env"] + scratch = Path(env["TMPDIR"]) + self.assertEqual(scratch.parent, job.work / "target") + self.assertTrue(scratch.is_dir()) + (Path(env["ESP"]) / "KERNEL").write_bytes(b"boot image") + with patch.dict(i.os.environ, TMPDIR="/sd/slow"), patch.object(i.tempfile, "mkdtemp", side_effect=temporary), patch.object(i, "output", return_value="valid-uuid"), patch.object(i, "run", side_effect=command) as run, patch.object(i, "configure_deployment"): + job.deploy(source, []) + self.assertTrue(any(call.args[0] == i.BOOTIMG for call in run.call_args_list)) + self.assertTrue(any(call.args[-2:] == ("sysroot.readonly", "true") for call in run.call_args_list)) + self.assertEqual(list((job.work / "target").glob(".armada-bootimg.*")), []) + job.close() + + def test_interrupted_mount_is_still_cleaned_up(self): + for mounted in (True, False): + job = i.Installation(i.Plan.make(table(), 16)) + with tempfile.TemporaryDirectory() as work: + target = Path(work) / "target" + with patch.object(i, "run", side_effect=i.Interrupted(signal.SIGTERM)), patch.object(Path, "is_mount", return_value=mounted): + with self.assertRaises(i.Interrupted): + job.mount("/dev/fake", target) + self.assertEqual(job.mounts, [target] if mounted else []) + + def test_copy_failure_prevents_deployment_and_boot_image(self): + job = i.Installation(i.Plan.make(table(), 16)) + source = Mock() + source.copy.side_effect = i.Error("corrupt destination") + with tempfile.TemporaryDirectory() as work: + with patch.object(i.tempfile, "mkdtemp", return_value=work), patch.object(i, "output", return_value="a-valid-uuid"), patch.object(i, "run") as run: + with self.assertRaisesRegex(i.Error, "corrupt destination"): + job.deploy(source, []) + commands = [call.args for call in run.call_args_list] + self.assertFalse(any(c[:3] == ("ostree", "admin", "deploy") or c[0] == i.BOOTIMG for c in commands)) + source.copy.assert_called_once_with(Path(work) / "target") + mounts = list(job.mounts) + job.close() + self.assertEqual([call.args[1] for call in run.call_args_list if call.args[0] == "umount"][1:], list(reversed(mounts))) + + def test_cleanup_is_reverse_order_and_preserves_failed_mount(self): + job = i.Installation(i.Plan.make(table(), 16)) + with tempfile.TemporaryDirectory() as work: + job.work = Path(work) / "keep" + job.work.mkdir() + job.mounts = [job.work / "root", job.work / "root/boot", job.work / "root/boot/efi"] + def unmount(*args): + if args[1] == job.mounts[-1]: + raise i.Error("busy") + with patch.object(i, "run", side_effect=unmount) as run, patch("sys.stderr", new_callable=io.StringIO): + with self.assertRaises(i.Error): + job.close() + self.assertEqual([call.args[1] for call in run.call_args_list], list(reversed(job.mounts))) + self.assertTrue(job.work.exists()) + + def test_cleanup_failure_does_not_hide_original_failure(self): + with patch.object(i.Installation, "close", side_effect=i.Error("cleanup failed")): + with self.assertRaisesRegex(i.Error, "original"): + with i.operation(i.Plan.make(table(), 16)): + raise i.Error("original") + + def test_boot_disk_alias_is_rejected(self): + with patch.object(Path, "is_mount", return_value=True), patch.object(Path, "is_block_device", return_value=True), patch.object(i, "output", side_effect=["/dev/dm-0[/root]", "253:0\n8:2\n8:0"]), patch.object(i.os, "stat", return_value=argparse.Namespace(st_rdev=os.makedev(8, 0))): + with self.assertRaisesRegex(i.Error, "booted from"): + i.refuse_boot_disk("/dev/disk/by-id/internal") + + def test_mount_in_pid1_namespace_blocks_install(self): + plan = i.Plan.make(table(), 16) + def read(path, *args, **kwargs): + return "1 0 8:17 / /android rw - ext4 /dev/sda17 rw\n" if str(path) == "/proc/1/mountinfo" else "Filename Type Size Used Priority\n" if str(path) == "/proc/swaps" else "" + with patch.object(Path, "read_text", read), patch.object(Path, "iterdir", return_value=iter(())), patch.object(i.os, "stat", return_value=argparse.Namespace(st_rdev=os.makedev(8, 17))): + with self.assertRaisesRegex(i.Error, "in use"): + i.require_idle(plan) + + def test_gui_confirms_all_tail_partitions_without_distro_detection(self): + info = table(["vendor", "metadata"]).info() + info.update(device="/dev/sda", table_fingerprint="confirmed") + gui = i.Gui(None) + with patch.object(i, "output", return_value=json.dumps(info)), patch.object(gui, "confirm") as confirm, patch.object(gui, "progress") as progress, patch.object(gui, "dialog", return_value=Mock(returncode=1)): + gui.start() + self.assertIn("All data in that space will be erased", confirm.call_args.args[0]) + self.assertIn(info["partition_names"], confirm.call_args.args[0]) + progress.assert_called_once_with(["install", "--expect-table", "confirmed"]) + self.assertEqual(gui.command, ["sudo", i.SELF, "--device", "/dev/sda"]) + + def test_gui_failure_shows_bounded_log_and_recovery(self): + gui = i.Gui(None) + with tempfile.TemporaryDirectory() as work: + log = Path(work) / "install.log" + fd = os.open(log, os.O_CREAT | os.O_WRONLY, 0o600) + def command(*args, **kwargs): + kwargs["stdout"].write("old output\n" * 1000 + "ERROR: missing source layer\n") + return Mock(returncode=1) + with patch.object(i.tempfile, "mkstemp", return_value=(fd, str(log))), patch.object(i.subprocess, "Popen"), patch.object(i, "run", side_effect=command): + with self.assertRaises(i.Error) as error: + gui.progress(["install"]) + message = str(error.exception) + self.assertIn("ERROR: missing source layer", message) + self.assertIn("select SD as the boot source in ABL", message) + self.assertIn("available until reboot", message) + self.assertLess(len(message), 5000) + + def test_reset_is_not_a_command(self): + result = subprocess.run([sys.executable, str(SCRIPT), "reset", "-y"], capture_output=True, text=True) + self.assertEqual(result.returncode, 2) + result = subprocess.run([sys.executable, str(SCRIPT), "--help"], capture_output=True, text=True) + self.assertEqual(result.returncode, 0) + self.assertIn("UNINSTALL CFW", result.stdout) + self.assertNotIn("reset", result.stdout) + + def test_toml_kargs_are_parsed_and_filtered(self): + with tempfile.TemporaryDirectory() as work: + root = Path(work) + (root/"a.toml").write_text('kargs = ["quiet", "root=old", "rootflags=old", "ostree=old"]\n') + (root/"b.toml").write_text('match-architectures = ["other"]\nkargs = ["bad"]\n') + self.assertEqual(i.base_kargs(root), ["quiet"]) + + def test_subprocess_cancellation_waits_for_cleanup(self): + with tempfile.TemporaryDirectory() as work: + ready, cleaned = Path(work)/"ready", Path(work)/"cleaned" + child_code = f""" +import signal,sys,time +from pathlib import Path +def stop(signum, frame): + time.sleep(0.1) + Path({str(cleaned)!r}).touch() + sys.exit(0) +signal.signal(signal.SIGTERM, stop) +Path({str(ready)!r}).touch() +time.sleep(10) +""" + parent_code = f""" +import runpy,sys +m=runpy.run_path({str(SCRIPT)!r}) +try: m['run'](sys.executable, '-c', {child_code!r}) +except m['Interrupted']: sys.exit(143) +""" + parent = subprocess.Popen([sys.executable, "-c", parent_code]) + try: + deadline = time.monotonic()+5 + while not ready.exists() and time.monotonic()=22.0.0" + } + }, + "node_modules/@cloudflare/unenv-preset": { + "version": "2.16.1", + "resolved": "https://registry.npmjs.org/@cloudflare/unenv-preset/-/unenv-preset-2.16.1.tgz", + "integrity": "sha512-ECxObrMfyTl5bhQf/lZCXwo5G6xX9IAUo+nDMKK4SZ8m4Jvvxp52vilxyySSWh2YTZz8+HQ07qGH/2rEom1vDw==", + "dev": true, + "license": "MIT OR Apache-2.0", + "peerDependencies": { + "unenv": "2.0.0-rc.24", + "workerd": ">1.20260305.0 <2.0.0-0" + }, + "peerDependenciesMeta": { + "workerd": { + "optional": true + } + } + }, + "node_modules/@cloudflare/workerd-darwin-64": { + "version": "1.20260908.1", + "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-64/-/workerd-darwin-64-1.20260908.1.tgz", + "integrity": "sha512-t3juyCXFn12OklBL0S7UC98py3nLEmuioBOUOazeyeVsLUu8fv+pfJrR+XzwSH2Uh6rCXZNogRh+LtV0YpzMcQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=16" + } + }, + "node_modules/@cloudflare/workerd-darwin-arm64": { + "version": "1.20260908.1", + "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-arm64/-/workerd-darwin-arm64-1.20260908.1.tgz", + "integrity": "sha512-I1nwA4qm/fUNSKhPSO76YA6JAhcA0KU63yFcYHN6AiDowGbDyfjDPH9KCVopT5rI1LY4GfbdAi5b9gODqZsAkQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=16" + } + }, + "node_modules/@cloudflare/workerd-linux-64": { + "version": "1.20260908.1", + "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-64/-/workerd-linux-64-1.20260908.1.tgz", + "integrity": "sha512-s/h5uSW1UC6dGeVKSqrPLpTu+vo0fKJZCNEokW1Ol1qcCB2oN6WCRHhoyzo4Y69oONAXRgLfLBYaHWe7z51Vnw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16" + } + }, + "node_modules/@cloudflare/workerd-linux-arm64": { + "version": "1.20260908.1", + "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-arm64/-/workerd-linux-arm64-1.20260908.1.tgz", + "integrity": "sha512-PP/nUKl0R6colwfocggL8dctO/dFMqMft12unzFUkoAJr0aXQeT+ia0JuNmOUWXe6EfvyCSmAbijEsTKQ5t/ew==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16" + } + }, + "node_modules/@cloudflare/workerd-windows-64": { + "version": "1.20260908.1", + "resolved": "https://registry.npmjs.org/@cloudflare/workerd-windows-64/-/workerd-windows-64-1.20260908.1.tgz", + "integrity": "sha512-jkaS5EKKTvzAdIlbMfOYrHoTucWVRwYBwIig+xRsjXQv5BXTLA2Llg+iM8djlKtk0CjkztZhXmuxuqoqWKZmFw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=16" + } + }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@emnapi/runtime": { + "version": "1.11.3", + "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.11.3.tgz", + "integrity": "sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.1.tgz", + "integrity": "sha512-Svl7tq8k/08+p6CXPpRjQ1fKX+1odH/BQbb48fV6fj3CWHhsoIOoY87w1oHXm0qEpkIK3ZfVgp0hed3XBXzXMQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.28.1.tgz", + "integrity": "sha512-0k2F129Xdio1TdJfzJ8sy1Q47vUD2NnwdhiAf7drUN1EBTfPf4hsFCtmMgu/6m8JSzsBrlmVjudMBQqOfG8usQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.28.1.tgz", + "integrity": "sha512-34EGEbCIAgosYz6goLcopX6Mo7NyGv9tfwEM2/7Ce2VcVRk568iSvniGWcUXIy7wEDR1wzolcxcriFVrWYcwBg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.28.1.tgz", + "integrity": "sha512-dbwY7ltSMDWsRatcRpCnES4F+im88OCUgGZjy52shC7GqHRE/cYlxNbB4Z4UpJswpcc4Qxd2oE/ufM0p61IKng==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.28.1.tgz", + "integrity": "sha512-TZbWkQY7kvTAXbXUT7uVACR5cMHsDiSz9z7ZKAX/RTq/WJEk3QyRr0wZpNhBDX+/0CtdqUIJlOiodQcta6tY3Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.28.1.tgz", + "integrity": "sha512-zfdzgK9ACBNZLI/CyHTOx81SyNbM6YXn7rxSgX97VjyiPl9W1i4Ka4fgKECEoFCKGpvBj5qArWIGgQjOwkgskQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.28.1.tgz", + "integrity": "sha512-wG2EA8ENdEI0qhkSZMjfqrdY+ziCYCPMmtZjjIwOmXFjmyzEHn+UUxk5of+SYsjtfs3VpnlC7QLzSI5hY/rOAw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.28.1.tgz", + "integrity": "sha512-i7dZ9vQgnvSCzi/rYCXNgtF/U+eKZNJBzu3eTQbRgHnM7tNSizLOkRFAl3qzVc/Op/u5YkHHa4pf/3DOYHthLQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.28.1.tgz", + "integrity": "sha512-qVXBOHQS+d5Y722GwJzJUtOLlX7km3CraOaGormF1pDtPd2C/l1SHRPgjLunLGe51Sh5YYWKMFDyV4SxgMQYTQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.28.1.tgz", + "integrity": "sha512-yHs+0uc8+nvEAfAfxrWQKK5peSNzBc4PegcMO0EJ2hT71uA7vB8Ihg2e77R2P7SG5uYjPbHlLLmve4LLLRCf0g==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.28.1.tgz", + "integrity": "sha512-d1z4ZuP0ajrfz/FhGT4vv278rX8KnPPJx8i5+AtK7TYbx9Le9F1hyzurZpkEyjkGa9dUGhQow4C1NmeGvqxN2w==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.28.1.tgz", + "integrity": "sha512-M5sRjUVZrkm1OAPR3dlOYzNmN+loZKGVi1VUQGrwuqLcbR6qeAz+famMhjASeH3YVKvZz+zT1jlh/keC3Rj/lg==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.28.1.tgz", + "integrity": "sha512-mRObBZeHh2OxcBFPWE/FjylkRgZdYuiTR3vaTozquCGOH14iP9oN4x4Ge81CoIDYQrXmIxpFumJBu5MtZpnQJQ==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.28.1.tgz", + "integrity": "sha512-slScBsMAb3GFDcdrCgLwZtPYRoH2H/youv10QiZyRjmsP48fznoveWytSgCI/R0ZcUgpc0ZhIUEx6LHts8yrfQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.28.1.tgz", + "integrity": "sha512-kw0owk1o0GFETUJyW0jc0G4Yzs0BHZn0JDZ8JRT088vjJYX777BAs1fDGxAC+q831qOs2DTC96mNsG2opdfyyQ==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.28.1.tgz", + "integrity": "sha512-/lAIjX8aYFRByhh6L5rYtPEDRqa9de/4V/juOXcta5frjvzXO4/sqEtyytse0g3zZFuWu5cDN0MkLz2qRDD2Ag==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.28.1.tgz", + "integrity": "sha512-u/anNYF2mmVOEDwLtnQ1wOr3EZ9sTNGLWrsYGYwHWzGA3Si84IOkHXlbWTD1NB+9/1lcnweYKO54uhxZydNzfA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.28.1.tgz", + "integrity": "sha512-oks0DYbLwWMmaakTsCb+zL4E+aHRVLom9IJZOAthMQEPiQmydXHkziYEsGYRx0uNV/IjEKGAV941JzH02pflqw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.28.1.tgz", + "integrity": "sha512-aeL6lAnN89Hz43Mlh1G8ARasbuoYvSITDEx0tHh5b7jJnHcssqgjy9Yx430GDpmCa6OyrKoS0aNRjKundRizGg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.28.1.tgz", + "integrity": "sha512-MEFJe5C3R8pwXdZ5Y21oo6m7ePiS0d9pWucn99O/wvyJZChoIQKrQDxKrGeW8F5+T0okTHesAmDeiHDTIq0V/Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.28.1.tgz", + "integrity": "sha512-i/ZLIOafE0Z8cI/XANJAixoJL/uRAoS2xOA3rb0xN+KK0K177cMAsQYkzHtBrtMXAKuAc7HGgcWiZ/sRC1Nxgw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.28.1.tgz", + "integrity": "sha512-ge+Z7EXFNt2BO1oAMsVpiQ8EwndV9i1xXerAeTIK7AtPs3bKFXQM7nlRxDSIUIMeueR1CNXxqztLzdNeReKBJg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.28.1.tgz", + "integrity": "sha512-BEjgtECkL3vY+SaSQ6nzVfiALUeFxpawyp8Jmf5PtYhf1Ug40N1h/hxlhts+f1FvSvarEigdxS3BlSMI2PJLcQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.28.1.tgz", + "integrity": "sha512-lCv9eK/H6ZJWbE7bh2nw54CZ9M2nupBxJcTsdk/QQnWkdSjKGuxmmH8/GWrlT1eMmZfn4dGcCjRte397WqfQXA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.28.1.tgz", + "integrity": "sha512-zvb/mB2bSCoJOpoCBgYKKpX6YM6mJBlBUVUtVj41DlZJVEB6/0CKlRYxP5wWl1C1ILiCoAU5wZZ4q1P3qeS6Eg==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.28.1.tgz", + "integrity": "sha512-bm4Mowrv+GXMlpWX++EcXw/iLyd1o3+bJkC2DkWXYVvgZCqD/bSj9ctZeAMC3cIxgjRVR2Dufaiu4YPxr5gW1A==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@img/colour": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@img/colour/-/colour-1.1.0.tgz", + "integrity": "sha512-Td76q7j57o/tLVdgS746cYARfSyxk8iEfRxewL9h4OMzYhbW4TAcppl0mT4eyqXddh6L/jwoM75mo7ixa/pCeQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/@img/sharp-darwin-arm64": { + "version": "0.35.2", + "resolved": "https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.35.2.tgz", + "integrity": "sha512-eEieHsMksAW4IiO5NzauESRl2D2qz3J/kwUxUrSfV06A93eEaRfMpHXyUb1mAqrR7i8U9A0GRqE9pjn6u1Jjpg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-darwin-arm64": "1.3.1" + } + }, + "node_modules/@img/sharp-darwin-x64": { + "version": "0.35.2", + "resolved": "https://registry.npmjs.org/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.35.2.tgz", + "integrity": "sha512-BaktuGPCeHJMARpodR8jK4uKiZrPAy9WrfQW0sdI37clracq8Bp01AYS3SZgi5FS/y5twa9t4+LIuuxQjqRrWw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-darwin-x64": "1.3.1" + } + }, + "node_modules/@img/sharp-freebsd-wasm32": { + "version": "0.35.2", + "resolved": "https://registry.npmjs.org/@img/sharp-freebsd-wasm32/-/sharp-freebsd-wasm32-0.35.2.tgz", + "integrity": "sha512-YoAxdnd8hPUkvLHd3bWY+YA8nw3xM/RyRopYucNsWHVSan8NLVM3X2volsfoRDcXdUJPg6tXahSd7HXPK7lRnw==", + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "dependencies": { + "@img/sharp-wasm32": "0.35.2" + }, + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-darwin-arm64": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-arm64/-/sharp-libvips-darwin-arm64-1.3.1.tgz", + "integrity": "sha512-4V/M3roRMTYjiwZY9IOVQOE8OyeCxFAkYmyZDrZl51uOKjibm3oeEJ4WAmLxutAfzFbC9jqUiPs2gbnGflH+7g==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "darwin" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-darwin-x64": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-x64/-/sharp-libvips-darwin-x64-1.3.1.tgz", + "integrity": "sha512-c0/DxItpJv2+dGhgycJBBgotdqruGYDvA79drdh0MD1dFpy7JzJ/PlXwi1H4rFf0eTy8tgbI91aHDnZIceY3jQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "darwin" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-arm": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm/-/sharp-libvips-linux-arm-1.3.1.tgz", + "integrity": "sha512-aGGy9aWzXgHBG7HNyQPWorZthlp7+x6fDRoPAQbGO3ThcttuTyKIx3NuSHb6zb4gBNq6/yNn9f1cy9nFKS/Vmg==", + "cpu": [ + "arm" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-arm64": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm64/-/sharp-libvips-linux-arm64-1.3.1.tgz", + "integrity": "sha512-JznefmcK9j1JKPz8AkQDh89kjojubyfOasWBPKfzMIhPwsgDy9evpE/naJTXXXmghS1iFwR8u/kTwh/I2/+GCw==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-ppc64": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-ppc64/-/sharp-libvips-linux-ppc64-1.3.1.tgz", + "integrity": "sha512-1EkwGNCZk6iWNCMWqrvdJ+r1j0PT1zIz60CNPhYnJlK/zyeWqlsPZIe+ocBVqPF8k/Ssee/NCk+tE9Ryrko6ng==", + "cpu": [ + "ppc64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-riscv64": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-riscv64/-/sharp-libvips-linux-riscv64-1.3.1.tgz", + "integrity": "sha512-Ilays+w2bXdnxzxtQdmXR62u8o8GYa3eL4+Gr+1KiE4xperMZUslRaVPJwwPkzlHEjGfXAfRVAa/7CYCtSqsBw==", + "cpu": [ + "riscv64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-s390x": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-s390x/-/sharp-libvips-linux-s390x-1.3.1.tgz", + "integrity": "sha512-VfBwVHQTbRoj4XlpA/KLZ7ltgMpz+4WSejFzQ+GnoImjo1PtEJ59QB2qR1xQEeRPYIkNrPIm2L4cICMvz4C2ew==", + "cpu": [ + "s390x" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-x64": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-x64/-/sharp-libvips-linux-x64-1.3.1.tgz", + "integrity": "sha512-+c8ukgwU62DS54nCAjw7keOfHUkmr0B5QHEdcOqRnodF/MNXJbVI8Eopoj4B/0H8Asr65I+A4Amrn7a85/md6A==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linuxmusl-arm64": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-arm64/-/sharp-libvips-linuxmusl-arm64-1.3.1.tgz", + "integrity": "sha512-qlKb/pwbkAi1WMsJrYHk7CuDrd12s27U2QnRhFYUoJNrRCmkosMTttuRFat/DDB3IlDm5qE1TJgZ4JDnHX8Ldw==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linuxmusl-x64": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.3.1.tgz", + "integrity": "sha512-yO21HwoUVLN8Qa+/SBjQLMYwBWAVJjeGPNe+hc0OUeMeifEtJqu5a1c4HayE1nNpDih9y3/KkoltfkDodmKAlg==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-linux-arm": { + "version": "0.35.2", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm/-/sharp-linux-arm-0.35.2.tgz", + "integrity": "sha512-SE4kzF2mepn6z+6E7L6lsV8FzuLL6IPQdyX8ZiwROAG/G8td+hP/m7FsFPwidtrF19gvajuC9l6TxAVcsA4S7A==", + "cpu": [ + "arm" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-arm": "1.3.1" + } + }, + "node_modules/@img/sharp-linux-arm64": { + "version": "0.35.2", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm64/-/sharp-linux-arm64-0.35.2.tgz", + "integrity": "sha512-af12Pnd0ZGu2HfP8NayB0kk6eC/lrfbQE6HlR4jD+34wdJ1Vw9TF6TMn6ZvffT+WgqVsl0hRbmNvz2u/23VmwA==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-arm64": "1.3.1" + } + }, + "node_modules/@img/sharp-linux-ppc64": { + "version": "0.35.2", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-ppc64/-/sharp-linux-ppc64-0.35.2.tgz", + "integrity": "sha512-hYSBm7zcNtDCozCxQHYZJiu63b/bXsgRZuOxCIBZsStMM9Vap47iFHdbX4kCvQsblPB/k+clhELpdQJHQLSHvg==", + "cpu": [ + "ppc64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-ppc64": "1.3.1" + } + }, + "node_modules/@img/sharp-linux-riscv64": { + "version": "0.35.2", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-riscv64/-/sharp-linux-riscv64-0.35.2.tgz", + "integrity": "sha512-qQt0Kc13+Hoan/Awq/qMSQw3L+RI1NCRPgD5cUJ/1WSSmIoysLOc72jlRM3E0OHN9Yr313jgeQ2T+zW+F03QFA==", + "cpu": [ + "riscv64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-riscv64": "1.3.1" + } + }, + "node_modules/@img/sharp-linux-s390x": { + "version": "0.35.2", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-s390x/-/sharp-linux-s390x-0.35.2.tgz", + "integrity": "sha512-E4fLLfRPzDLlEeDaTzI98OFLcv++WL5ChLLMwPoVd0CIoZQqupBSNbOisPL5am9XsbQ9T84+iiMpUvbFtkunbA==", + "cpu": [ + "s390x" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-s390x": "1.3.1" + } + }, + "node_modules/@img/sharp-linux-x64": { + "version": "0.35.2", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.35.2.tgz", + "integrity": "sha512-gi0zFJJRLswfCZmHtJdikXPOc5u7qamSOS3NHedLqLd4W8Q0NqjdBr6TTRIgsfFjqfTsHFgdfvJ9LwqSgcHiAA==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-x64": "1.3.1" + } + }, + "node_modules/@img/sharp-linuxmusl-arm64": { + "version": "0.35.2", + "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-arm64/-/sharp-linuxmusl-arm64-0.35.2.tgz", + "integrity": "sha512-siWbOW1u6HFnFLrp0waKyW7VEf7jYvcDWdrXEFa8AkdAQgEvuu5Fz8/Y70w9EeqAdwDtfU012BhEHHaDqvQNzg==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linuxmusl-arm64": "1.3.1" + } + }, + "node_modules/@img/sharp-linuxmusl-x64": { + "version": "0.35.2", + "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.35.2.tgz", + "integrity": "sha512-YBqMMcjDi4QGYiSn4vNOYBhmlC4z5AXqkOUUqI2e0AFA4urNv4ESgOgwNl3K+4etQhha0twXlzeF20bbULm9Yg==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linuxmusl-x64": "1.3.1" + } + }, + "node_modules/@img/sharp-wasm32": { + "version": "0.35.2", + "resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.35.2.tgz", + "integrity": "sha512-Mrv4JQNYVQ94xH+jzZ9r+gowleN8mv2FTgKT+PI6bx5C0G8TdNYndu161pg2i7uoBwxy2ImPMHrJOM2LZef7Bw==", + "dev": true, + "license": "Apache-2.0 AND LGPL-3.0-or-later AND MIT", + "optional": true, + "dependencies": { + "@emnapi/runtime": "^1.11.1" + }, + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-webcontainers-wasm32": { + "version": "0.35.2", + "resolved": "https://registry.npmjs.org/@img/sharp-webcontainers-wasm32/-/sharp-webcontainers-wasm32-0.35.2.tgz", + "integrity": "sha512-QNV27pxs9wpApEiCfvHM1RDoP1w1+2KrUWWDPEhEwg+latvOrfuhWrHWZKwdSFwU6jh3myjw/yOCRsUIuOft3g==", + "cpu": [ + "wasm32" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "dependencies": { + "@img/sharp-wasm32": "0.35.2" + }, + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-win32-arm64": { + "version": "0.35.2", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-arm64/-/sharp-win32-arm64-0.35.2.tgz", + "integrity": "sha512-BiVRYc/t6/Vl3e1hBx0hugG4oN9Pydf4fgMSpxTQJmwGUg/YoXTWHiFeRymHfCZzifxu4F4rpk/I67D0LQ20wQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0 AND LGPL-3.0-or-later", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-win32-ia32": { + "version": "0.35.2", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-ia32/-/sharp-win32-ia32-0.35.2.tgz", + "integrity": "sha512-YYEhx9PImCC7T0tI8JDMi4DB9LwLCXCU5OWNYEXAxh5Q1ShKkyC6byxzoBJ3gEFDnH2lQckWuDe70G7mB2XJog==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "Apache-2.0 AND LGPL-3.0-or-later", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-win32-x64": { + "version": "0.35.2", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-x64/-/sharp-win32-x64-0.35.2.tgz", + "integrity": "sha512-imoOyBcoM/iiUr4J6VPpCNjPnjvP/Gks95898yB8YqoGGYmHYbOyCuNv9FMhFgtaiHFGbHW8bxKqRV6VjtXThQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0 AND LGPL-3.0-or-later", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", + "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz", + "integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, + "node_modules/@poppinss/colors": { + "version": "4.1.6", + "resolved": "https://registry.npmjs.org/@poppinss/colors/-/colors-4.1.6.tgz", + "integrity": "sha512-H9xkIdFswbS8n1d6vmRd8+c10t2Qe+rZITbbDHHkQixH5+2x1FDGmi/0K+WgWiqQFKPSlIYB7jlH6Kpfn6Fleg==", + "dev": true, + "license": "MIT", + "dependencies": { + "kleur": "^4.1.5" + } + }, + "node_modules/@poppinss/dumper": { + "version": "0.6.5", + "resolved": "https://registry.npmjs.org/@poppinss/dumper/-/dumper-0.6.5.tgz", + "integrity": "sha512-NBdYIb90J7LfOI32dOewKI1r7wnkiH6m920puQ3qHUeZkxNkQiFnXVWoE6YtFSv6QOiPPf7ys6i+HWWecDz7sw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@poppinss/colors": "^4.1.5", + "@sindresorhus/is": "^7.0.2", + "supports-color": "^10.0.0" + } + }, + "node_modules/@poppinss/exception": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/@poppinss/exception/-/exception-1.2.3.tgz", + "integrity": "sha512-dCED+QRChTVatE9ibtoaxc+WkdzOSjYTKi/+uacHWIsfodVfpsueo3+DKpgU5Px8qXjgmXkSvhXvSCz3fnP9lw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@sindresorhus/is": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-7.2.0.tgz", + "integrity": "sha512-P1Cz1dWaFfR4IR+U13mqqiGsLFf1KbayybWwdd2vfctdV6hDpUkgCY0nKOLLTMSoRd/jJNjtbqzf13K8DCCXQw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sindresorhus/is?sponsor=1" + } + }, + "node_modules/@speed-highlight/core": { + "version": "1.2.24", + "resolved": "https://registry.npmjs.org/@speed-highlight/core/-/core-1.2.24.tgz", + "integrity": "sha512-qeW2e1l78afw8VhRPfPQ1Gjj+KU5XFQ/OFV5ti6eTa9bruO7mJyZtA4vw0ofqmA3tKCkROE9xLk3VZoeRc98nw==", + "dev": true, + "license": "CC0-1.0" + }, + "node_modules/blake3-wasm": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/blake3-wasm/-/blake3-wasm-2.1.5.tgz", + "integrity": "sha512-F1+K8EbfOZE49dtoPtmxUQrpXaBIl3ICvasLh+nJta0xkz+9kF/7uet9fLnwKqhDrmj6g+6K3Tw9yQPUg2ka5g==", + "dev": true, + "license": "MIT" + }, + "node_modules/cookie": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-1.1.1.tgz", + "integrity": "sha512-ei8Aos7ja0weRpFzJnEA9UHJ/7XQmqglbRwnf2ATjcB9Wq874VKH9kfjjirM6UhU2/E5fFYadylyhFldcqSidQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/detect-libc": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", + "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=8" + } + }, + "node_modules/error-stack-parser-es": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/error-stack-parser-es/-/error-stack-parser-es-1.0.5.tgz", + "integrity": "sha512-5qucVt2XcuGMcEGgWI7i+yZpmpByQ8J1lHhcL7PwqCwu9FPP3VUXzT4ltHe5i2z9dePwEHcDVOAfSnHsOlCXRA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/antfu" + } + }, + "node_modules/esbuild": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.1.tgz", + "integrity": "sha512-HrJrvZv5ayxBzPfwphOoNzkzOIIlifzk0KJrGK2c8R4+LKpMtpYLQeUdjnwjWv/LZlkH2laZk+4w78pi99D4Vw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.28.1", + "@esbuild/android-arm": "0.28.1", + "@esbuild/android-arm64": "0.28.1", + "@esbuild/android-x64": "0.28.1", + "@esbuild/darwin-arm64": "0.28.1", + "@esbuild/darwin-x64": "0.28.1", + "@esbuild/freebsd-arm64": "0.28.1", + "@esbuild/freebsd-x64": "0.28.1", + "@esbuild/linux-arm": "0.28.1", + "@esbuild/linux-arm64": "0.28.1", + "@esbuild/linux-ia32": "0.28.1", + "@esbuild/linux-loong64": "0.28.1", + "@esbuild/linux-mips64el": "0.28.1", + "@esbuild/linux-ppc64": "0.28.1", + "@esbuild/linux-riscv64": "0.28.1", + "@esbuild/linux-s390x": "0.28.1", + "@esbuild/linux-x64": "0.28.1", + "@esbuild/netbsd-arm64": "0.28.1", + "@esbuild/netbsd-x64": "0.28.1", + "@esbuild/openbsd-arm64": "0.28.1", + "@esbuild/openbsd-x64": "0.28.1", + "@esbuild/openharmony-arm64": "0.28.1", + "@esbuild/sunos-x64": "0.28.1", + "@esbuild/win32-arm64": "0.28.1", + "@esbuild/win32-ia32": "0.28.1", + "@esbuild/win32-x64": "0.28.1" + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/kleur": { + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/kleur/-/kleur-4.1.5.tgz", + "integrity": "sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/miniflare": { + "version": "5.20260908.0-alpha", + "resolved": "https://registry.npmjs.org/miniflare/-/miniflare-5.20260908.0-alpha.tgz", + "integrity": "sha512-BHIknb0u6vLIvb+R8PsUAzgoWWk3OlW85DrV2SG0EydfSpIba28YT0rH6xZThjnSwDxzNuW3FDRNSWvbiI/DVw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@cspotcode/source-map-support": "0.8.1", + "sharp": "0.35.2", + "undici": "7.29.0", + "workerd": "1.20260908.1", + "ws": "8.21.0", + "youch": "4.1.0-beta.10" + }, + "engines": { + "node": ">=22.0.0" + } + }, + "node_modules/path-to-regexp": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.3.0.tgz", + "integrity": "sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/pathe": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz", + "integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==", + "dev": true, + "license": "MIT" + }, + "node_modules/semver": { + "version": "7.8.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz", + "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/sharp": { + "version": "0.35.2", + "resolved": "https://registry.npmjs.org/sharp/-/sharp-0.35.2.tgz", + "integrity": "sha512-FVtFjtBCMiJS6yb5CX7Sop45WFMpeGw6oRKuJnXYgf/f1ms/D7LE/ZUSNxnW7rZ/dbslQWYkoqFHGPaDBtaK4w==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@img/colour": "^1.1.0", + "detect-libc": "^2.1.2", + "semver": "^7.8.4" + }, + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-darwin-arm64": "0.35.2", + "@img/sharp-darwin-x64": "0.35.2", + "@img/sharp-freebsd-wasm32": "0.35.2", + "@img/sharp-libvips-darwin-arm64": "1.3.1", + "@img/sharp-libvips-darwin-x64": "1.3.1", + "@img/sharp-libvips-linux-arm": "1.3.1", + "@img/sharp-libvips-linux-arm64": "1.3.1", + "@img/sharp-libvips-linux-ppc64": "1.3.1", + "@img/sharp-libvips-linux-riscv64": "1.3.1", + "@img/sharp-libvips-linux-s390x": "1.3.1", + "@img/sharp-libvips-linux-x64": "1.3.1", + "@img/sharp-libvips-linuxmusl-arm64": "1.3.1", + "@img/sharp-libvips-linuxmusl-x64": "1.3.1", + "@img/sharp-linux-arm": "0.35.2", + "@img/sharp-linux-arm64": "0.35.2", + "@img/sharp-linux-ppc64": "0.35.2", + "@img/sharp-linux-riscv64": "0.35.2", + "@img/sharp-linux-s390x": "0.35.2", + "@img/sharp-linux-x64": "0.35.2", + "@img/sharp-linuxmusl-arm64": "0.35.2", + "@img/sharp-linuxmusl-x64": "0.35.2", + "@img/sharp-webcontainers-wasm32": "0.35.2", + "@img/sharp-win32-arm64": "0.35.2", + "@img/sharp-win32-ia32": "0.35.2", + "@img/sharp-win32-x64": "0.35.2" + } + }, + "node_modules/supports-color": { + "version": "10.2.2", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-10.2.2.tgz", + "integrity": "sha512-SS+jx45GF1QjgEXQx4NJZV9ImqmO2NPz5FNsIHrsDjh2YsHnawpan7SNQ1o8NuhrbHZy9AZhIoCUiCeaW/C80g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/chalk/supports-color?sponsor=1" + } + }, + "node_modules/tslib": { + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", + "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", + "dev": true, + "license": "0BSD", + "optional": true + }, + "node_modules/undici": { + "version": "7.29.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-7.29.0.tgz", + "integrity": "sha512-IDxfleLmmbSskfWSUATiN1nfn2rDuvnMOqb5CWR92iIfojA0Ud+ulOAAEQ57LPr9rWmsreUyf5lwyao+7GNNVw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=20.18.1" + } + }, + "node_modules/unenv": { + "version": "2.0.0-rc.24", + "resolved": "https://registry.npmjs.org/unenv/-/unenv-2.0.0-rc.24.tgz", + "integrity": "sha512-i7qRCmY42zmCwnYlh9H2SvLEypEFGye5iRmEMKjcGi7zk9UquigRjFtTLz0TYqr0ZGLZhaMHl/foy1bZR+Cwlw==", + "dev": true, + "license": "MIT", + "dependencies": { + "pathe": "^2.0.3" + } + }, + "node_modules/workerd": { + "version": "1.20260908.1", + "resolved": "https://registry.npmjs.org/workerd/-/workerd-1.20260908.1.tgz", + "integrity": "sha512-rYhpW6NWHD++p34ej+VXWzi5Pdnmd7ncdbB/ux4s+i3mf7IeOpW3O4roqClQ+Z8ernvyMCknBLCb76z1rA+a7Q==", + "dev": true, + "hasInstallScript": true, + "license": "Apache-2.0", + "bin": { + "workerd": "bin/workerd" + }, + "engines": { + "node": ">=16" + }, + "optionalDependencies": { + "@cloudflare/workerd-darwin-64": "1.20260908.1", + "@cloudflare/workerd-darwin-arm64": "1.20260908.1", + "@cloudflare/workerd-linux-64": "1.20260908.1", + "@cloudflare/workerd-linux-arm64": "1.20260908.1", + "@cloudflare/workerd-windows-64": "1.20260908.1" + } + }, + "node_modules/wrangler": { + "version": "4.130.0", + "resolved": "https://registry.npmjs.org/wrangler/-/wrangler-4.130.0.tgz", + "integrity": "sha512-fzNjnTzyZl31PGJOFXbiLeZqEIToQ9KOzkkvGdQz4wlB+BoHnl3BRwCR5xg8AqYyzVunvvMHlMzvlbThQ7rrAA==", + "dev": true, + "license": "MIT OR Apache-2.0", + "dependencies": { + "@cloudflare/kv-asset-handler": "0.5.0", + "@cloudflare/unenv-preset": "2.16.1", + "blake3-wasm": "2.1.5", + "esbuild": "0.28.1", + "miniflare": "5.20260908.0-alpha", + "path-to-regexp": "6.3.0", + "unenv": "2.0.0-rc.24", + "workerd": "1.20260908.1" + }, + "bin": { + "cf-wrangler": "bin/cf-wrangler.js", + "wrangler": "bin/wrangler.js", + "wrangler2": "bin/wrangler.js" + }, + "engines": { + "node": ">=22.0.0" + }, + "optionalDependencies": { + "fsevents": "2.3.3" + }, + "peerDependencies": { + "@cloudflare/workers-types": "^5.20260908.1" + }, + "peerDependenciesMeta": { + "@cloudflare/workers-types": { + "optional": true + } + } + }, + "node_modules/ws": { + "version": "8.21.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.21.0.tgz", + "integrity": "sha512-Vsp28b7DRcimFQvrqu2Wek3z1iYxDCWqHYB8Qsnk/S4RfaCQzPGPyBNuVjJV3cd6UiKtUtp6sNM77gWvzcCH+g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, + "node_modules/youch": { + "version": "4.1.0-beta.10", + "resolved": "https://registry.npmjs.org/youch/-/youch-4.1.0-beta.10.tgz", + "integrity": "sha512-rLfVLB4FgQneDr0dv1oddCVZmKjcJ6yX6mS4pU82Mq/Dt9a3cLZQ62pDBL4AUO+uVrCvtWz3ZFUL2HFAFJ/BXQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@poppinss/colors": "^4.1.5", + "@poppinss/dumper": "^0.6.4", + "@speed-highlight/core": "^1.2.7", + "cookie": "^1.0.2", + "youch-core": "^0.3.3" + } + }, + "node_modules/youch-core": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/youch-core/-/youch-core-0.3.3.tgz", + "integrity": "sha512-ho7XuGjLaJ2hWHoK8yFnsUGy2Y5uDpqSTq1FkHLK4/oqKtyUU1AFbOOxY4IpC9f0fTLjwYbslUz0Po5BpD1wrA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@poppinss/exception": "^1.2.2", + "error-stack-parser-es": "^1.0.5" + } + } + } +} diff --git a/workers/downloads/package.json b/workers/downloads/package.json new file mode 100644 index 00000000..9eb27eef --- /dev/null +++ b/workers/downloads/package.json @@ -0,0 +1,13 @@ +{ + "name": "armada-downloads", + "private": true, + "type": "module", + "scripts": { + "dev": "wrangler dev", + "test": "node --test", + "deploy": "wrangler deploy" + }, + "devDependencies": { + "wrangler": "4.130.0" + } +} diff --git a/workers/downloads/worker.mjs b/workers/downloads/worker.mjs new file mode 100644 index 00000000..2e6c55af --- /dev/null +++ b/workers/downloads/worker.mjs @@ -0,0 +1,141 @@ +const DOWNLOAD_ORIGIN = "https://downloads.armadaos.dev"; +const MANIFEST_KEY = "preview/builds.json"; +const INDEX_PATHS = new Set(["/", "/preview", "/preview/"]); +const IMAGE_ALIAS = "/preview/latest"; +const IMAGE_KEY = /^preview\/armada-\d{8}(?:\.[a-f0-9]{7,40})?\.img\.gz$/; + +export default { + async fetch(request, env) { + const url = new URL(request.url); + const index = INDEX_PATHS.has(url.pathname); + const alias = url.pathname === IMAGE_ALIAS; + if (!index && !alias) { + // A Worker route forwards these requests to the existing R2 custom domain. + return fetch(new Request(new URL(url.pathname + url.search, DOWNLOAD_ORIGIN), request)); + } + if (request.method !== "GET" && request.method !== "HEAD") { + return new Response("Method not allowed", { + status: 405, + headers: { Allow: "GET, HEAD", "Cache-Control": "no-store" }, + }); + } + + try { + const object = await env.DOWNLOADS.get(MANIFEST_KEY); + if (!object) throw new Error("Preview manifest is missing"); + const manifest = await object.json(); + if (manifest.channel !== "preview" || + !Array.isArray(manifest.builds) || !manifest.builds.length || + !manifest.builds.every(build => + /^[a-f0-9]{40}$/.test(build.build_commit) && + typeof build.build_commit_title === "string" && + IMAGE_KEY.test(build.image?.key) && + build.image.filename === build.image.key.slice("preview/".length) && + build.checksum?.key === `${build.image.key}.sha256` && + /^[a-f0-9]{64}$/.test(build.image.sha256) && + Number.isSafeInteger(build.image.size) && build.image.size > 0)) { + throw new Error("Invalid Preview manifest"); + } + const latest = manifest.builds.find(build => build.version === manifest.latest); + if (!latest) throw new Error("Latest Preview build is missing from manifest"); + if (alias) { + return new Response(null, { + status: 302, + headers: { + Location: `${DOWNLOAD_ORIGIN}/${latest.image.key}`, + "Cache-Control": "no-store", + }, + }); + } + const previous = manifest.builds.filter(build => build !== latest); + return new Response(request.method === "HEAD" ? null : renderPage(latest, previous), { + headers: { + "Content-Type": "text/html; charset=utf-8", + "Cache-Control": "no-store", + "X-Content-Type-Options": "nosniff", + "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'", + }, + }); + } catch (error) { + console.error("Cannot read Preview download metadata", error); + return new Response(request.method === "HEAD" ? null : "Preview downloads are temporarily unavailable. Please try again shortly.", { + status: 503, + headers: { "Content-Type": "text/plain; charset=utf-8", "Cache-Control": "no-store" }, + }); + } + }, +}; + +function escapeHtml(value) { + return String(value).replace(/[&<>"']/g, character => ({ + "&": "&", "<": "<", ">": ">", '"': """, "'": "'", + })[character]); +} + +function formatDate(value) { + const date = new Date(value); + return Number.isNaN(date.getTime()) ? "Date unavailable" : + new Intl.DateTimeFormat("en", { dateStyle: "long", timeStyle: "short", timeZone: "UTC" }).format(date) + " UTC"; +} + +function commitLink(commit, title) { + return `${escapeHtml(title)} · ${commit.slice(0, 7)} ↗`; +} + +function renderPage(latest, previous) { + const rows = [latest, ...previous].map(build => { + const current = build === latest; + return ` + ${escapeHtml(build.version)}${current ? ' Latest' : ""} +
${commitLink(build.build_commit, build.build_commit_title)}
+ ${escapeHtml(formatDate(build.published_at))} + ${(build.image.size / 1e9).toFixed(2)} GB + Image (.img.gz)
SHA-256 checksum + `; + }).join("\n"); + return ` + + + + + + Preview downloads · Armada + + + + +
+

Preview disk images

+

Download latest image · Supported devices · Installation guide

+
+ + + ${rows} +
Build / commitPublishedSizeFiles
+
+ ${previous.length ? "" : '

No previous Preview builds are available yet.

'} +
+ +`; +} diff --git a/workers/downloads/worker.test.mjs b/workers/downloads/worker.test.mjs new file mode 100644 index 00000000..d63cd946 --- /dev/null +++ b/workers/downloads/worker.test.mjs @@ -0,0 +1,152 @@ +import assert from "node:assert/strict"; +import { test } from "node:test"; +import worker from "./worker.mjs"; + +function build(version = "20260909.249e21d") { + const filename = `armada-${version}.img.gz`; + const key = `preview/${filename}`; + return { + version, + published_at: "2026-09-09T14:17:22Z", + build_commit: "249e21d2eb8be0241d73513fc8b97ec89a756eda", + build_commit_title: "fix(ci): publish Preview images", + image: { filename, key, size: 6267990432, sha256: "a".repeat(64) }, + checksum: { key: `${key}.sha256` }, + }; +} + +function manifest(version = "20260909.249e21d") { + return { channel: "preview", latest: version, builds: [build(version)] }; +} + +function bucket(index = manifest()) { + return { DOWNLOADS: { async get(key) { + assert.equal(key, "preview/builds.json"); + return index === null ? null : { json: async () => index }; + }, list() { throw new Error("The page must only read builds.json"); } } }; +} + +function request(path, method = "GET") { + return new Request(`https://downloads.armadaos.dev${path}`, { method }); +} + +test("stable image link redirects to the current dated file", async () => { + for (const path of ["/preview/latest", "/preview/latest?download=1"]) { + const response = await worker.fetch(request(path), bucket()); + assert.equal(response.status, 302); + assert.equal(response.headers.get("Location"), + "https://downloads.armadaos.dev/preview/armada-20260909.249e21d.img.gz"); + assert.equal(response.headers.get("Cache-Control"), "no-store"); + } +}); + +test("the next request sees an updated manifest", async () => { + let latest = manifest(); + const env = { DOWNLOADS: { get: async () => ({ json: async () => latest }) } }; + const first = await worker.fetch(request("/preview/latest"), env); + latest = manifest("20260910.abcdef0"); + const second = await worker.fetch(request("/preview/latest"), env); + assert.notEqual(first.headers.get("Location"), second.headers.get("Location")); + assert.ok(second.headers.get("Location").endsWith("armada-20260910.abcdef0.img.gz")); +}); + +test("index renders the published image, checksum, date, and size without client scripts", async () => { + for (const path of ["/", "/preview", "/preview/"]) { + const response = await worker.fetch(request(path), bucket()); + assert.equal(response.status, 200); + assert.equal(response.headers.get("Cache-Control"), "no-store"); + assert.equal(response.headers.get("Content-Security-Policy"), "default-src 'none'; style-src 'unsafe-inline'"); + const html = await response.text(); + assert.match(html, /20260909\.249e21d/); + assert.match(html, /6\.27 GB/); + assert.match(html, /September 9, 2026/); + assert.ok(html.includes(build().image.key)); + assert.ok(html.includes(build().checksum.key)); + assert.ok(!html.includes(" { + const latest = manifest(); + latest.builds[0].version = ''; + latest.latest = latest.builds[0].version; + latest.builds[0].build_commit_title = 'fix: & "quotes" — café 🚀'; + const response = await worker.fetch(request("/"), bucket(latest)); + const html = await response.text(); + assert.ok(!html.includes(latest.builds[0].version)); + assert.ok(html.includes("<img")); + assert.ok(html.includes('fix: <markup> & "quotes" — café 🚀')); + assert.ok(html.includes(`href="https://github.com/armada-os/armada/commit/${latest.builds[0].build_commit}"`)); +}); + +test("the page reads latest and history entirely from builds.json", async () => { + const index = manifest(); + const older = build("20260907.abcdef0"); + const newer = build("20260908.abcdef1"); + newer.build_commit = "abcdef1" + "b".repeat(33); + newer.build_commit_title = 'fix: & brightness — café 🚀'; + index.builds = [newer, index.builds[0], older]; + const response = await worker.fetch(request("/"), bucket(index)); + const html = await response.text(); + assert.equal(response.status, 200); + assert.match(html, /class="label">Latest(.*?)<\/span>/g)].map(match => match[1]), + [index.latest, newer.version, older.version]); + assert.ok(html.includes(`https://github.com/armada-os/armada/commit/${newer.build_commit}`)); + assert.ok(html.includes('fix: <screen> & brightness — café 🚀')); + for (const item of [older, newer]) { + assert.ok(html.includes(`href="https://downloads.armadaos.dev/${item.image.key}"`)); + assert.ok(html.includes(`href="https://downloads.armadaos.dev/${item.checksum.key}"`)); + } +}); + +test("an empty history is explained, and redirects never need a bucket listing", async () => { + const env = bucket(); + assert.match(await (await worker.fetch(request("/"), env)).text(), /No previous Preview builds/); + env.DOWNLOADS.list = () => { throw new Error("Listing should not be called"); }; + assert.equal((await worker.fetch(request("/preview/latest"), env)).status, 302); +}); + +test("HEAD has no response body; writes to managed paths are rejected", async () => { + for (const path of ["/", "/preview/latest"]) { + const head = await worker.fetch(request(path, "HEAD"), bucket()); + assert.equal(await head.text(), ""); + const post = await worker.fetch(request(path, "POST"), {}); + assert.equal(post.status, 405); + assert.equal(post.headers.get("Allow"), "GET, HEAD"); + } +}); + +test("missing, unreadable, or invalid manifests do not advertise a download", async t => { + t.mock.method(console, "error", () => {}); + const invalid = manifest(); + invalid.builds[0].image.key = "//external.example/file.img.gz"; + const missingLatest = manifest(); + missingLatest.latest = "not-present"; + for (const env of [bucket(null), bucket(invalid), bucket(missingLatest), + { DOWNLOADS: { get: async () => { throw new Error("R2 unavailable"); } } }]) { + const response = await worker.fetch(request("/preview/latest"), env); + assert.equal(response.status, 503); + assert.equal(response.headers.get("Location"), null); + assert.equal(response.headers.get("Cache-Control"), "no-store"); + } +}); + +test("existing R2 paths preserve range requests and origin responses", async t => { + for (const path of ["/release/armada.img.gz", "/testing/other.zip", "/preview/builds.json", + "/preview/armada-20260909.249e21d.img.gz", "/armada-preview.img.gz", + "/armada-preview.img.gz.sha256", "/preview/latest.sha256"]) { + const origin = new Response("partial", { status: 206, headers: { "Content-Range": "bytes 0-6/100" } }); + const fetchMock = t.mock.method(globalThis, "fetch", async req => { + assert.equal(req.url, `https://downloads.armadaos.dev${path}`); + assert.equal(req.headers.get("Range"), "bytes=0-6"); + return origin; + }); + const response = await worker.fetch(new Request(`https://downloads.armadaos.dev${path}`, { + headers: { Range: "bytes=0-6" }, + }), {}); + assert.equal(response, origin); + fetchMock.mock.restore(); + } +}); diff --git a/workers/downloads/wrangler.jsonc b/workers/downloads/wrangler.jsonc new file mode 100644 index 00000000..aa1b4eaa --- /dev/null +++ b/workers/downloads/wrangler.jsonc @@ -0,0 +1,17 @@ +{ + "$schema": "node_modules/wrangler/config-schema.json", + "name": "armada-downloads", + "main": "worker.mjs", + "compatibility_date": "2026-09-09", + "workers_dev": false, + "preview_urls": false, + "routes": [ + { "pattern": "downloads.armadaos.dev/", "zone_name": "armadaos.dev" }, + { "pattern": "downloads.armadaos.dev/preview", "zone_name": "armadaos.dev" }, + { "pattern": "downloads.armadaos.dev/preview/", "zone_name": "armadaos.dev" }, + { "pattern": "downloads.armadaos.dev/preview/latest*", "zone_name": "armadaos.dev" } + ], + "r2_buckets": [ + { "binding": "DOWNLOADS", "bucket_name": "armada" } + ] +}