From 19494f5bed5d6d71373ae15b60a3b8a86a42e3cf Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Mon, 30 Sep 2024 02:10:05 -0400 Subject: [PATCH] jovian-support-scripts: Init with format scripts The support scripts are intended to replace vendor scripts for the little details we can't do the same way. We're adding the pair of scripts required to format external devices. Note that the scripts end-up relying on the steamos-manager service, which in turn already knows how to launch the hw-support scripts. How convenient. --- overlay.nix | 1 + pkgs/jovian-support-scripts/default.nix | 49 ++++++++++ .../steamos-format-device | 89 +++++++++++++++++++ .../steamos-format-sdcard | 10 +++ 4 files changed, 149 insertions(+) create mode 100644 pkgs/jovian-support-scripts/default.nix create mode 100755 pkgs/jovian-support-scripts/steamos-format-device create mode 100755 pkgs/jovian-support-scripts/steamos-format-sdcard diff --git a/overlay.nix b/overlay.nix index 42764be8..abaaa2f5 100644 --- a/overlay.nix +++ b/overlay.nix @@ -53,6 +53,7 @@ rec { jovian-stubs = final.callPackage ./pkgs/jovian-stubs { }; jovian-greeter = final.callPackage ./pkgs/jovian-greeter { }; jovian-steam-protocol-handler = final.callPackage ./pkgs/jovian-steam-protocol-handler { }; + jovian-support-scripts = final.callPackage ./pkgs/jovian-support-scripts { }; jovian-documentation = final.callPackage ./support/docs { pagefind = final.callPackage ./pkgs/pagefind { }; diff --git a/pkgs/jovian-support-scripts/default.nix b/pkgs/jovian-support-scripts/default.nix new file mode 100644 index 00000000..ba602429 --- /dev/null +++ b/pkgs/jovian-support-scripts/default.nix @@ -0,0 +1,49 @@ +{ stdenv +, resholve + +, bash +, jq +, systemd +, util-linux +}: + +let + solution = { + scripts = [ "bin/steamos-polkit-helpers/*" ]; + interpreter = "${bash}/bin/bash"; + inputs = [ + jq + systemd + util-linux + ]; + keep = { + "${placeholder "out"}/bin/steamos-polkit-helpers/steamos-format-device" = true; + }; + }; +in +stdenv.mkDerivation { + name = "jovian-support-scripts"; + + buildCommand = '' + install -D -m 755 ${./steamos-format-sdcard} $out/bin/steamos-format-sdcard + install -D -m 755 ${./steamos-format-device} $out/bin/steamos-format-device + + substituteInPlace $out/bin/steamos-format-sdcard \ + --replace-fail "/usr/bin/steamos-polkit-helpers/steamos-format-device" "$out/bin/steamos-polkit-helpers/steamos-format-device" + ( + cd $out/bin + + mkdir -v steamos-polkit-helpers + cd steamos-polkit-helpers + ln -v -t . ../steamos-format-* + ) + + ${resholve.phraseSolution "steamos-format-sdcard" solution} + ${resholve.phraseSolution "steamos-format-device" solution} + ''; + + meta = { + # Any script defined here should be prioritized over Steam's own. + priority = -10; + }; +} diff --git a/pkgs/jovian-support-scripts/steamos-format-device b/pkgs/jovian-support-scripts/steamos-format-device new file mode 100755 index 00000000..2a146a0c --- /dev/null +++ b/pkgs/jovian-support-scripts/steamos-format-device @@ -0,0 +1,89 @@ +#!/usr/bin/env bash + +set -eu + +# [Jovian] +# +# Not a polkit helper anymore, this calls the steamos-manager system service +# to poke through the fhsenv used here. +# +# Note that this is uh... quite a hack, but uh... works? +# +# The TLDR is: +# +# - We poke the steamos-manager to run the dbus endpoint for formatting +# - We `tail` the journal for the output from the script +# +# And uh, this fulfills the requirements for Steam (stage=... flags). +# + +cleanup() { + >/dev/null 2>&1 \ + kill -9 % || : +} + +trap cleanup EXIT SIGINT SIGTERM + +_call() { + object="$1"; shift + interface="$1"; shift + busctl --timeout=99y --expect-reply=yes -j \ + call \ + com.steampowered.SteamOSManager1 \ + "$object" \ + com.steampowered.SteamOSManager1."${interface}" \ + "$@" \ + | jq -r .data[0] +} + +# Only supported flags, from the DBUS interface shape (ssb) +# • --skip-validation|--force) +# • --device) +# • --label) + +DEVICE="" +LABEL="STEAM-$RANDOM" +VALIDATE="true" + +OPTS=$(getopt -l force,skip-validation,device:,label: -n steamos-format-device -- "" "$@") + +eval set -- "$OPTS" + +while true; do + case "$1" in + --force) + # yes, this is just like --skip-validate in the vendor script + VALIDATE="false" + shift + ;; + --skip-validation) + # yes, this is just like --force in the vendor script + VALIDATE="false" + shift + ;; + --label) + LABEL="$2"; + shift 2 + ;; + --device) + DEVICE="$2" + shift 2 + ;; + --) shift; break ;; + esac +done + +if [[ "$DEVICE" == "" ]]; then + >&2 printf "Error: --device flag mandatory\n" + exit 1 +fi + +journalctl --lines=0 --follow \ + --output cat \ + --unit steamos-manager.service \ + SYSLOG_IDENTIFIER=steamos-format-device & + +process=$(_call "/com/steampowered/SteamOSManager1" Manager FormatDevice ssb "$DEVICE" "$LABEL" "$VALIDATE") +res="$(_call "${process}" "SubProcess" Wait)" + +exit "$res" diff --git a/pkgs/jovian-support-scripts/steamos-format-sdcard b/pkgs/jovian-support-scripts/steamos-format-sdcard new file mode 100755 index 00000000..15d095d2 --- /dev/null +++ b/pkgs/jovian-support-scripts/steamos-format-sdcard @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -eu + +# [Jovian] +# Not a polkit helper anymore, this calls the `format-device` helper following +# the same semantics as `usr/lib/hwsupport/format-sdcard.sh`. + +exec /usr/bin/steamos-polkit-helpers/steamos-format-device \ + --device /dev/mmcblk0 "$@"