Skip to content

Commit

Permalink
chore(deck): Import files and changes from Bazzite
Browse files Browse the repository at this point in the history
  • Loading branch information
zelikos committed Dec 22, 2024
1 parent 7a86bc3 commit bcca353
Show file tree
Hide file tree
Showing 20 changed files with 173 additions and 21 deletions.
3 changes: 3 additions & 0 deletions files/system_files/deck/etc/systemd/logind.conf.d/deck.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Login]
HandlePowerKey=suspend
KillUserProcesses=true
9 changes: 9 additions & 0 deletions files/system_files/deck/usr/bin/gnome-session-oneshot
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#!/usr/bin/bash

set -e

die() { echo >&2 "!! $*"; exit 1; }

SENTINEL_FILE="steamos-session-select"

# If we proceed, execute this
CHAINED_SESSION="/usr/bin/gnome-session"
# If we decide the sentinel is consumed, execute this command instead and fail
RESTORE_SESSION=(/usr/bin/steamos-session-select) # No arguments restores the session

# Find or check config sentinel
function check_sentinel()
{
Expand All @@ -14,6 +19,7 @@ function check_sentinel()
# Rather than break we'll just launch plasma and hope for the best?
return 0
fi

local config_dir="${XDG_CONF_DIR:-"$HOME/.config"}"
(
cd "$HOME"
Expand All @@ -25,10 +31,13 @@ function check_sentinel()
return 1
fi
rm "$SENTINEL_FILE"

) || return 1 # If we couldn't read the value or it wasn't what we wanted

# Found value and removed it, we're good to continue
return 0
}

if CONFIGURED_CHAINED_SESSION=$(check_sentinel); then
# We found and consumed the oneshot sentinel, proceed to launch plasma
echo >&2 "$0: Found and removed sentinel file for one-shot desktop, proceeding to launch"
Expand Down
4 changes: 4 additions & 0 deletions files/system_files/deck/usr/bin/return-to-gamemode
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/usr/bin/env bash

USER=$(id -nu 1000)
HOME=$(getent passwd $USER | cut -d: -f6)

# SteamOS autologin SDDM config
AUTOLOGIN_CONF='/etc/sddm.conf.d/zz-steamos-autologin.conf'

# Configure autologin if Steam has been updated
if [[ -f /var/home/$USER/.local/share/Steam/ubuntu12_32/steamui.so ]]; then
{
Expand Down
20 changes: 20 additions & 0 deletions files/system_files/deck/usr/bin/steamos-logger
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh
# -*- mode: sh; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# vim: et sts=4 sw=4

# SPDX-License-Identifier: LGPL-2.1+
#
# Copyright © 2020 Collabora Ltd.
Expand All @@ -12,21 +13,29 @@
# modify it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of the License,
# or (at your option) any later version.

set -e
set -u

usage() {
cat <<EOF
Usage: ${0##*/} [options] [<message>]
Echoes the message to standard output.
It displays the text message if splash screen is running.
The splash screen is cleared if message is empty.
Options:
-h, --help this help message
-l, --log-level LEVEL the level of logs
LEVELS
Valid levels: emergency alert critical error warning notice info debug.
EOF
}

declare -A LOG_LEVEL
LOG_LEVEL[emergency]="0"
LOG_LEVEL[fatal]="1"
Expand All @@ -36,6 +45,7 @@ LOG_LEVEL[warning]="4"
LOG_LEVEL[notice]="5"
LOG_LEVEL[info]="6"
LOG_LEVEL[debug]="7"

declare -A LOG_LEVEL_PREFIX
LOG_LEVEL_PREFIX[emergency]="<0>"
LOG_LEVEL_PREFIX[fatal]="<1>"
Expand All @@ -45,6 +55,7 @@ LOG_LEVEL_PREFIX[warning]="<4>"
LOG_LEVEL_PREFIX[notice]="<5>"
LOG_LEVEL_PREFIX[info]="<6>"
LOG_LEVEL_PREFIX[debug]="<7>"

declare -A PLYMOUTH_PREFIX
PLYMOUTH_PREFIX[emergency]="Emergency: "
PLYMOUTH_PREFIX[fatal]="Fatal: "
Expand All @@ -57,13 +68,15 @@ then
PLYMOUTH_PREFIX[info]="Info: "
PLYMOUTH_PREFIX[debug]="Debug: "
fi

if [[ "${0##*/}" != steamos-logger ]]
then
log_level="${0##*/}"
log_level="${log_level#steamos-}"
else
log_level="notice"
fi

while [[ "$#" -ne 0 ]]
do
if [[ "$1" =~ ^(-h|--help) ]]
Expand All @@ -73,6 +86,7 @@ do
elif [[ "$1" =~ ^(-l|--log-level) ]]
then
shift

if [[ "$#" -eq 0 ]] || [[ -z ${LOG_LEVEL_PREFIX[$1]:-} ]]
then
echo "${!LOG_LEVEL_PREFIX[@]}"
Expand All @@ -82,12 +96,14 @@ do
fi
exit 1
fi

log_level="$1"
else
break
fi
shift
done

if plymouth --ping &&
{ [[ ${STEAMOS_DEBUG:-} ]] ||
[[ "${LOG_LEVEL[$log_level]}" -lt "${LOG_LEVEL[info]}" ]]; }
Expand All @@ -98,15 +114,19 @@ then
text="$prefix"
fi
text+="${*:-}"

plymouth display-message --text="$text"
unset prefix text
fi

if [[ "$#" -eq 0 ]]
then
exit
fi

if ! [[ -t 1 ]]
then
prefix="${LOG_LEVEL_PREFIX[$log_level]:-}"
fi

exec printf "%s%s\n" "${prefix:-}" "${*:-}"
21 changes: 17 additions & 4 deletions files/system_files/deck/usr/bin/steamos-session-select
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
#!/bin/bash
#!/usr/bin/bash

set -e

die() { echo >&2 "!! $*"; exit 1; }

# File this script will modify, in addition to (potentially) the per-user sentinel file
CONF_FILE="/etc/sddm.conf.d/zz-steamos-autologin.conf"

SENTINEL_FILE="steamos-session-select"

# For sanity this shipped file must be present, to ensure we're still on a normal-looking steamos setup.
CHECK_FILE="/etc/sddm.conf.d/steamos.conf"

session="${1:-gamescope}"
session_type="wayland"

session_launcher=""
create_sentinel=""

if [[ "$2" == "--sentinel-created" ]]; then
SENTINEL_CREATED=1
session_type="wayland"
fi

# Update config sentinel
if [[ -z $SENTINEL_CREATED ]]; then
[[ $EUID == 0 ]] && die "Running $0 as root is not allowed"

[[ -n ${HOME+x} ]] || die "No \$HOME variable"
config_dir="${XDG_CONF_DIR:-"$HOME/.config"}"
session_type=$(
Expand All @@ -30,12 +40,11 @@ if [[ -z $SENTINEL_CREATED ]]; then
fi
cat "$SENTINEL_FILE"
)
# clear steam game desktop shortcut clutter
DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
grep --files-with-matches "Exec=steam steam://rungameid/" ${DATA_HOME}/applications/* | tr '\n' '\0' | xargs -0 -I {} rm {} || true

# If we were executed as a session user and then re-execute as root below, we don't want to set root's sentinel too
export SENTINEL_CREATED=1
fi

# We use "plasma" as "desktop" to hook up to SteamOS's scripts
case "$session" in
plasma-wayland-persistent)
Expand All @@ -57,16 +66,20 @@ case "$session" in
exit 1
;;
esac

echo "Updated user selected session to $session_launcher"

# Become root
if [[ $EUID != 0 ]]; then
exec pkexec "$(realpath $0)" "$session" --sentinel-created "$session_type"
exit 1
fi

{
echo "[Autologin]"
echo "Session=$session_launcher"
} > "$CONF_FILE"

echo "Updated system autologin session to $session_launcher"
systemctl reset-failed sddm
systemctl restart sddm
Expand Down
20 changes: 15 additions & 5 deletions files/system_files/deck/usr/bin/steamos-update
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/bin/bash
#!/usr/bin/bash

# The Steam client is known to call this script with the following parameter combinations:
# steamos-update --supports-duplicate-detection -- should do nothing
# steamos-update --enable-duplicate-detection check -- should check for update
# steamos-update check -- should check for update
# steamos-update --enable-duplicate-detection -- should perform an update
# steamos-update -- should perform an update


while [[ $# -gt 0 ]]; do
case $1 in
check)
Expand All @@ -20,6 +23,8 @@ while [[ $# -gt 0 ]]; do
;;
esac
done


if command -v ublue-update > /dev/null; then
if [ -n "${CHECK}" ]; then
if [ -f '/tmp/upgrade-installed' ]; then
Expand All @@ -46,7 +51,7 @@ if command -v ublue-update > /dev/null; then
fake_progress() {
local value=0
while [ ! -f '/tmp/upgrade-check' ]; do
sleep 10
sleep 12
if [ ${value} -lt '100' ]; then
echo ${value}'%'
value=$(( value + 1 ))
Expand All @@ -55,15 +60,20 @@ if command -v ublue-update > /dev/null; then
echo 100%
}
upgrade() {
# Log rotate the last session
if [ -f "${HOME}"/.steamos-update.log ]; then
cp "${HOME}"/.steamos-update.log "${HOME}"/.steamos-update.log.old
fi

# Pull exit code from ublue-update
systemctl start ublue-update-force > /dev/null 2>&1
systemctl start ublue-update-force > "${HOME}"/.steamos-update.log 2>&1
echo $? > /tmp/upgrade-check
}
upgrade | fake_progress
# Check if upgrade failed
UPGRADE_CHECK=/tmp/upgrade-check
UPGRADE_CHECK=$(cat /tmp/upgrade-check)
rm /tmp/upgrade-check
if [ ${UPGRADE_CHECK} -eq 0 ]; then
if [ "${UPGRADE_CHECK}" -eq 0 ]; then
touch /tmp/upgrade-installed
else
exit 0 # Upgrade failed
Expand Down
21 changes: 14 additions & 7 deletions files/system_files/deck/usr/bin/zelideck-steam
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#!/usr/bin/env bash
LAUNCH_OPTIONS=""
# If Steam has been launched before we can safely launch with -steamdeck
# to maintain the gamemode update branch
if [ -f $HOME/.local/share/Steam/ubuntu12_32/steamui.so ]; then
LAUNCH_OPTIONS="-steamos3 -gamepadui"
fi
/usr/bin/steam "$LAUNCH_OPTIONS" "$*"

SYS_ID="$(cat /sys/devices/virtual/dmi/id/product_name)"

if [ ! -d $HOME/.local/share/Steam ]; then
# Set up steam with the bootstrap before starting it, this allows steam to run for the first time even with no network access
if [[ -f "/usr/share/gamescope-session-plus/bootstrap_steam.tar.gz" ]]; then
mkdir -p ~/.local/share
tar xf /usr/share/gamescope-session-plus/bootstrap_steam.tar.gz -C ~/.local/share
fi
fi

# Required to maintain the Steam update branch between desktop & Steam Game Mode
DECK_OPTION="-steamdeck"

/usr/bin/steam "$DECK_OPTION" "$@"
4 changes: 4 additions & 0 deletions files/system_files/deck/usr/lib/systemd/system/ac.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Unit]
Description=On AC power
DefaultDependencies=no
StopWhenUnneeded=yes
4 changes: 4 additions & 0 deletions files/system_files/deck/usr/lib/systemd/system/battery.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Unit]
Description=On battery power
DefaultDependencies=no
StopWhenUnneeded=yes
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=Workaround pipewire needing to be written into by steamdeck-dsp
ConditionPathExists=/usr/share/pipewire
After=local-fs.target

[Service]
Type=oneshot
# Copy if it doesn't exist
ExecStartPre=/usr/bin/bash -c "[ -d /usr/local/share/.pipewire ] || /usr/bin/cp -r /usr/share/pipewire /usr/local/share/.pipewire"
ExecStart=/usr/bin/mount --bind /usr/local/share/.pipewire /usr/share/pipewire
# Clean-up after ourselves
ExecStop=/usr/bin/umount /usr/share/pipewire
ExecStop=/usr/bin/rm -r /usr/local/share/.pipewire
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
[Unit]
Description=Force Universal Blue Update Oneshot Service

[Service]
Type=oneshot
Environment="TOPGRADE_SKIP_BRKC_NOTIFY=true"
ExecStart=/usr/bin/ublue-update --force
RemainAfterExit=no
Nice=19
CPUSchedulingPolicy=batch
IOSchedulingClass=best-effort
IOSchedulingPriority=7
OOMScoreAdjust=1000
CPUWeight=30
CPUQuota=300%
IOWeight=30
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Service]
Environment="TOPGRADE_SKIP_BRKC_NOTIFY=true"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=Workaround wireplumber needing to be written into by steamdeck-dsp
ConditionPathExists=/usr/share/wireplumber
After=local-fs.target

[Service]
Type=oneshot
# Copy if it doesn't exist
ExecStartPre=/usr/bin/bash -c "[ -d /usr/local/share/.wireplumber ] || /usr/bin/cp -r /usr/share/wireplumber /usr/local/share/.wireplumber"
ExecStart=/usr/bin/mount --bind /usr/local/share/.wireplumber /usr/share/wireplumber
# Clean-up after ourselves
ExecStop=/usr/bin/umount /usr/share/wireplumber
ExecStop=/usr/bin/rm -r /usr/local/share/.wireplumber
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ Description=Enables ZeliDeck autologin
Before=display-manager.service
[Service]
Type=oneshot
ExecStart=/usr/bin/zelideck-autologin
ExecStart=/usr/libexec/zelideck-autologin
[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
z /sys/class/dmi/id/product_serial 440 root wheel - -
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C /usr/local/share/.wireplumber - - - - /usr/share/wireplumber
Loading

0 comments on commit bcca353

Please sign in to comment.