Skip to content

Commit

Permalink
jovian-support-scripts: Init with format scripts
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
samueldr committed Oct 6, 2024
1 parent 751641e commit 19494f5
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 0 deletions.
1 change: 1 addition & 0 deletions overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 { };
Expand Down
49 changes: 49 additions & 0 deletions pkgs/jovian-support-scripts/default.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
89 changes: 89 additions & 0 deletions pkgs/jovian-support-scripts/steamos-format-device
Original file line number Diff line number Diff line change
@@ -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"
10 changes: 10 additions & 0 deletions pkgs/jovian-support-scripts/steamos-format-sdcard
Original file line number Diff line number Diff line change
@@ -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 "$@"

0 comments on commit 19494f5

Please sign in to comment.