fix: never leave Steam a file it would reinstall itself over

The patch that keeps the script's length was the good path and appending was
the fallback, with -noverifyfiles on everything that starts Steam to cover for
it. That cover does not exist.

Steam checks its files at the shutdown it runs itself, not only at a start
somebody handed arguments to, and that run carries no -noverifyfiles whatever
the session was started with. One wrong length there costs the whole client
package downloaded, extracted and installed again - and the client quits at the
end of it instead of coming up, which is the "Steam just closed itself" that
this was seen as:

    BVerifyInstalledFiles: steamwebhelper.sh is 130 bytes, expected 84
    Update wird heruntergeladen ... Paket wird extrahiert ...
    Aktualisierung abgeschlossen, Steam wird geladen ... Shutdown

So the flag now either fits in the space the comments give back or it is not
written at all, and the status screen says Steam is not patched. No autoscroll
in the interface is a far smaller thing than a client that reinstalls itself.

With no growing patch left to prop up, -noverifyfiles has nothing to do and is
gone with everything that carried it: Steam's launcher entry, its autostart
entry, the shortcuts on the desktop and the ones it writes for single games.
Steam repairs its own installation again. An installation from an older version
is taken back once through the flag scheme, and a patch that version appended
is rebuilt to fit at the next apply - or taken back, if the comments cannot pay
for it.
This commit is contained in:
Felitendo committed 2026-09-05 01:07:15 +02:00
1 parent c1841ec169
commit dcdf2c1df3
11 files changed
+135 -260

No files matched your search

+10 -22
View File
@@ -103,7 +103,9 @@ mca_apply() {
mca_desktop_apply "$id" "$file" "$(mca_flags "$kind")"
;;
steam)
mca_steam_desktop_apply "$id" "$file" "$packaging"
# Nothing is done to the entry itself: what Steam needs is
# in its own installation, and the same patch serves every
# way of starting the client.
if (( ! steam_done )); then
mca_steam_apply
steam_done=1
@@ -118,30 +120,16 @@ mca_apply() {
mca_steam_apply
fi
# The shortcuts Steam writes for single games. They are not applications
# and are not offered as ones, but starting a game with Steam closed is a
# Steam start like any other: without the switch the client finds the
# patched helper script, puts its own back, and the interface loses
# autoscroll for the rest of the session.
if [[ $CFG_STEAM == yes ]]; then
for i in "${!MCA_STEAM_LINKS[@]}"; do
mca_steam_desktop_apply "${MCA_STEAM_LINKS[i]}" \
"${MCA_STEAM_LINK_FILES[i]}" "${MCA_STEAM_LINK_PACK[i]}"
done
fi
# Steam's autostart entry carries Steam's own switch and follows the Steam
# setting, not this one - leaving it out while Steam is patched is what puts
# the client in an update loop - so both are checked inside.
if [[ $CFG_AUTOSTART == yes || $CFG_STEAM == yes ]]; then
# Autostart entries. A Chromium application that starts itself at login
# points straight at its binary and never reads the entry in the menu, so
# Discord at login used to behave differently from Discord from the menu.
if [[ $CFG_AUTOSTART == yes ]]; then
mca_autostart_apply
fi
# Shortcuts on the desktop itself. Nothing above has seen them - the XDG
# search path does not go there - and a game started from one starts Steam
# without its switch, which is the difference between autoscroll working
# and autoscroll working most of the time. Each entry is gated on its own,
# so there is nothing to check out here.
# Shortcuts on the desktop itself, which nothing above has seen: the XDG
# search path does not go there. Each entry is gated on its own, so there is
# nothing to check out here.
mca_shortcuts_apply
[[ $CFG_SPOTIFY == yes ]] && mca_spotify_apply
+8 -4
View File
@@ -45,10 +45,14 @@ MCA_BROWSER_FLAG="--enable-features=MiddleClickAutoscroll,HeliumMiddleClickAutos
MCA_FEATURE="MiddleClickAutoscroll"
MCA_BROWSER_FEATURES="MiddleClickAutoscroll,HeliumMiddleClickAutoscroll"
# Bumped when the flags above change. An installation that was set up by a
# version with a different answer is taken back and done again once, because a
# file that is already patched is otherwise left alone. See mca_apply.
MCA_FLAG_SCHEME=2
# Bumped when the flags above change, and when what gets written where does.
# An installation that was set up by a version with a different answer is taken
# back and done again once, because a file that is already patched is otherwise
# left alone. See mca_apply.
#
# 3 is what takes -noverifyfiles back out of the Steam entries an older version
# put it in.
MCA_FLAG_SCHEME=3
MCA_LIBDIR="${MCA_LIBDIR:-@LIBDIR@}"
MCA_LOCALEDIR="${MCA_LOCALEDIR:-@LOCALEDIR@}"
+6 -23
View File
@@ -615,16 +615,6 @@ MCA_PROGS=() # resolved program, or a Flatpak app id or a snap name
MCA_KINDS=() # app | browser | steam | unknown | no
MCA_PACKAGING=() # native | flatpak | snap
# The shortcuts Steam writes for single games. Not applications of their own - a
# game is whatever engine it was built with, and none of those reads a Chromium
# argument - so they are kept apart from the list rather than listed as
# something that got switched on. They do start Steam, which is why they are
# kept at all: the Steam module gives them Steam's own switch.
MCA_STEAM_LINKS=() # desktop file id
MCA_STEAM_LINK_FILES=() # the entry that is in effect for it
MCA_STEAM_LINK_PACK=() # native | flatpak | snap, which decides where the
# switch goes on the command line
# A scan reads every desktop entry on the system, so the menu does it once and
# then redraws from what it found. Applying rescans on its own, so nothing else
# has to remember to invalidate this.
@@ -642,7 +632,6 @@ mca_scan() {
MCA_IDS=(); MCA_FILES=(); MCA_NAMES=(); MCA_PROGS=(); MCA_KINDS=()
MCA_PACKAGING=()
MCA_STEAM_LINKS=(); MCA_STEAM_LINK_FILES=(); MCA_STEAM_LINK_PACK=()
# Pass one: read the entries and work out what each of them starts. No
# detection yet - that needs a stat per program, and those are collected so
@@ -682,18 +671,12 @@ mca_scan() {
prog="snap:$MCA_PROG"
fi
if mca_exec_is_steam_link "$exec_line" "$prog"; then
MCA_STEAM_LINKS+=("$id")
MCA_STEAM_LINK_FILES+=("$file")
if [[ $prog == flatpak:* ]]; then
MCA_STEAM_LINK_PACK+=(flatpak)
elif [[ $prog == snap:* ]]; then
MCA_STEAM_LINK_PACK+=(snap)
else
MCA_STEAM_LINK_PACK+=(native)
fi
continue
fi
# The shortcuts Steam writes for single games are not
# applications of their own - a game is whatever engine it was
# built with, and none of those reads a Chromium argument - and
# starting the client through one needs nothing on its command
# line either.
mca_exec_is_steam_link "$exec_line" "$prog" && continue
c_ids+=("$id"); c_files+=("$file"); c_names+=("$name")
c_progs+=("$prog")
-3
View File
@@ -178,9 +178,6 @@ mca_ui_status() {
if mca_steam_installed; then
if mca_steam_patched; then
_mca_row "$(mca_msg "Steam")" "$(_mca_onoff yes)"
elif [[ $CFG_STEAM == yes && $CFG_ENABLED == yes ]] && mca_steam_waiting; then
_mca_row "$(mca_msg "Steam")" \
"${MCA_C_DIM}$(mca_msg "waiting until Steam is closed")${MCA_C_RESET}"
elif [[ $CFG_STEAM == yes && $CFG_ENABLED == yes ]]; then
_mca_row "$(mca_msg "Steam")" \
"${MCA_C_YELLOW}$(mca_msg "not patched yet")${MCA_C_RESET}"
+24 -35
View File
@@ -410,15 +410,6 @@ mca_desktop_apply() {
# The desktop folder, where a shortcut somebody dragged out of the menu -
# or asked Steam for - lives and nowhere else.
#
# Steam is in both, even though it is not a Chromium process itself: its
# entries need -noverifyfiles exactly like the menu one. The autostart entry is
# the one most likely to exist, because Steam writes it as soon as "run at
# startup" is ticked; without it a Steam started at login restores the patched
# web helper script and the watcher patches it back, over and over. The desktop
# ones are the gap behind "autoscroll works, except sometimes": starting a game
# from the desktop is a Steam start like any other, and a Steam start without
# the switch costs the interface its autoscroll for the rest of the session.
#
# Neither can be shadowed from anywhere, so both are edited where they stand,
# with the original kept.
@@ -426,11 +417,10 @@ mca_desktop_apply() {
# One desktop entry that lives outside the XDG search path, edited where it is
# because there is nowhere to shadow it from.
#
# Anything that starts Steam gets Steam's own switch; a Chromium application
# gets the flag. What decides whether a Chromium application here is in scope
# differs by where the entry came from, which is what the gate says: an
# autostart entry follows the autostart setting, a shortcut follows the same
# rules as the application it is a shortcut to.
# What decides whether an application here is in scope differs by where the
# entry came from, which is what the gate says: an autostart entry follows the
# autostart setting, a shortcut follows the same rules as the application it is
# a shortcut to.
_mca_entry_patch_inplace() {
local file="$1" gate="$2"
local id prog packaging=native content backup kind
@@ -456,30 +446,29 @@ _mca_entry_patch_inplace() {
packaging=snap
fi
if mca_prog_is_steam "$prog"; then
[[ $CFG_STEAM == yes ]] || return 0
content="$(_mca_desktop_transform "$file" "$MCA_MARK_INPLACE" \
"$MCA_STEAM_LAUNCH_FLAG" "$(mca_steam_flag_position "$packaging")")"
# An entry that starts Steam is left where it is. Steam takes nothing
# from a command line that would help, and what it does take belongs to
# the web helper script in its own installation.
mca_prog_is_steam "$prog" && return 0
case "$packaging" in
flatpak) mca_flatpak_is_chromium "${prog#flatpak:}" || return 0 ;;
snap) mca_snap_is_chromium "${prog#snap:}" || return 0 ;;
*) mca_is_chromium "$prog" || return 0 ;;
esac
mca_desktop_is_browser && kind=browser || kind=app
if [[ $gate == autostart ]]; then
[[ $CFG_AUTOSTART == yes ]] || return 0
else
case "$packaging" in
flatpak) mca_flatpak_is_chromium "${prog#flatpak:}" || return 0 ;;
snap) mca_snap_is_chromium "${prog#snap:}" || return 0 ;;
*) mca_is_chromium "$prog" || return 0 ;;
esac
mca_desktop_is_browser && kind=browser || kind=app
if [[ $gate == autostart ]]; then
[[ $CFG_AUTOSTART == yes ]] || return 0
else
id="${file##*/}"; id="${id%.desktop}"
mca_kind_wanted "$kind" "$id" "$packaging" || return 0
fi
content="$(_mca_desktop_transform "$file" "$MCA_MARK_INPLACE" \
"$(mca_flags "$kind")")"
id="${file##*/}"; id="${id%.desktop}"
mca_kind_wanted "$kind" "$id" "$packaging" || return 0
fi
content="$(_mca_desktop_transform "$file" "$MCA_MARK_INPLACE" \
"$(mca_flags "$kind")")"
[[ -n $content ]] || return 0
[[ "$content" == "$(< "$file")" ]] && return 0
+55 -129
View File
@@ -18,25 +18,19 @@
# and the flag survives however Steam was started - from the menu, from a game
# shortcut, from a launcher like Heroic, from a terminal.
#
# That is the part that has to work, because there is no way to make every
# possible way of starting Steam carry an argument. -noverifyfiles on the
# launcher entries is the second line rather than the first: it covers the case
# where the script has no comments left to pay for the flag and the patch has
# to grow the file. The trade-off is real and belongs to the user, so it is a
# switch of its own rather than part of the general application handling: with
# verification off, Steam no longer repairs a damaged installation by itself.
#
# A patch that does change the size still has to stay out of the way of a
# client that is already running, or the two programs spend the session undoing
# each other: Steam restores the script, the watcher patches it again, Steam
# restores it again, and the client never gets past its update dialog. A patch
# that keeps the size is invisible to that check and goes in either way.
# A patch that changes the length is not an option, and no switch covers for
# one. Steam checks its files at a start it was given arguments for, but also
# at the shutdown it runs itself - and that one has no -noverifyfiles on its
# command line, whatever the session was started with. What a single wrong
# length costs is the whole client package downloaded, extracted and installed
# again, and a client that quits at the end of it instead of coming up. So the
# flag either fits in the space the comments give back, or it is not written at
# all: no autoscroll in the interface is a smaller thing than a client that
# reinstalls itself.
#
# The file comes back on every client update, and the watcher re-applies the
# patch when that happens.
MCA_STEAM_LAUNCH_FLAG='-noverifyfiles'
# Every place a Steam installation is known to live, resolved and de-duplicated
# because ~/.steam/steam is normally a symlink into ~/.local/share.
#
@@ -88,24 +82,6 @@ mca_steam_installed() {
return 1
}
# mca_steam_running
# Steam records its own process id beside its installation while it runs. The
# file outlives a crash, so the id is checked rather than believed.
mca_steam_running() {
local f pid
for f in \
"$HOME/.steam/steam.pid" \
"$HOME/.var/app/com.valvesoftware.Steam/.steam/steam.pid" \
"$HOME/snap/steam/common/.steam/steam.pid"
do
[[ -r $f ]] || continue
pid="$(< "$f")"
[[ $pid =~ ^[0-9]+$ ]] || continue
kill -0 "$pid" 2>/dev/null && return 0
done
return 1
}
# mca_steam_script_patched <script>
mca_steam_script_patched() {
grep -q -- "$MCA_FEATURE" "$1" 2>/dev/null
@@ -120,26 +96,6 @@ mca_steam_patched() {
return 1
}
# mca_steam_deferred <script>
# Whether the patch is being held back rather than simply missing: the script
# was patched before, its own copy is back, and Steam is still running. See
# mca_steam_apply for why that is left alone.
mca_steam_deferred() {
[[ -e "$MCA_BACKUPDIR/$(mca_backup_name "$1")" ]] && mca_steam_running
}
# mca_steam_waiting
# The same question for the status screen, which has no script in hand.
mca_steam_waiting() {
local root script
while IFS= read -r root; do
script="$(mca_steam_script "$root")" || continue
mca_steam_script_patched "$script" && continue
mca_steam_deferred "$script" && return 0
done < <(mca_steam_roots)
return 1
}
# _mca_steam_exec_line <script>
# The line number of the command that starts the web helper: the last
# uncommented line that both names steamwebhelper and forwards "$@". Both the
@@ -154,27 +110,25 @@ _mca_steam_exec_line() {
' "$1" 2>/dev/null
}
# _mca_steam_build <script> <flags> <reclaim: 0|1>
# _mca_steam_build <script> <flags>
# The patched script on stdout: the flags appended to the line that starts the
# web helper, and - when asked for - the same number of bytes taken back out of
# the script's comments, so that the file Steam finds is the length Steam wrote
# down. Everything else - setting up the container runtime, deciding whether
# the sandbox can be used - is left alone.
# web helper, and the same number of bytes taken back out of the script's
# comments, so that the file Steam finds is the length Steam wrote down.
# Everything else - setting up the container runtime, deciding whether the
# sandbox can be used - is left alone.
#
# Comments are eaten from the bottom up, so the header that says what the
# script is for is the last thing to lose anything, and the '#' itself always
# stays: a line that loses it stops being a comment and starts being a command.
# Fails when the comments are too short to pay for the flags.
_mca_steam_build() {
local script="$1" flags="$2" reclaim="$3" lineno need=0
local script="$1" flags="$2" lineno need
lineno="$(_mca_steam_exec_line "$script")"
[[ -n $lineno ]] || return 1
if (( reclaim )); then
need="$(printf '%s' " $flags" | wc -c)"
need="${need//[^0-9]/}"
fi
need="$(printf '%s' " $flags" | wc -c)"
need="${need//[^0-9]/}"
# LC_ALL=C so awk counts bytes: a comment with an accent in it is shorter
# in characters than it is on disk, and it is the disk that Steam measures.
@@ -222,44 +176,50 @@ _mca_steam_refresh_backup() {
cp -p -- "$script" "$MCA_BACKUPDIR/$name" 2>/dev/null || true
}
# _mca_steam_reneutralise <script> <flags>
# An earlier version of this program patched by appending and left the script
# longer than Steam expects, which is a patch that only survives because
# -noverifyfiles is there to stop Steam looking. If the same flags can be made
# to fit, they are: the file goes back to the length and the timestamp Steam
# wrote down and stops depending on that switch.
# _mca_steam_settle <script> <flags>
# The script is already patched. Whether that is a patch Steam can live with is
# a question of length: an earlier version of this program appended the flag
# where the comments could not pay for it, which leaves the script longer than
# the file Steam wrote down - and a client that checks its files reinstalls
# itself over that, then quits instead of starting.
#
# The new copy is built from the untouched original that was kept when the
# script was first patched, never from the patched file - patching a patched
# file is how a flag ends up in there twice.
_mca_steam_reneutralise() {
# Rebuilt from the untouched original kept when the script was first patched,
# never from the patched file, the flag either fits this time or the original
# goes back and Steam is left with a client it recognises.
_mca_steam_settle() {
local script="$1" flags="$2" name copy out
name="$(mca_backup_name "$script")"
copy="$MCA_BACKUPDIR/$name"
[[ -f $copy ]] || return 1
# Already the length Steam expects: there is nothing to gain.
(( $(wc -c < "$script") == $(wc -c < "$copy") )) && return 1
# Nothing to compare against, so nothing can be said about the length.
[[ -f $copy ]] || return 0
out="$(_mca_steam_build "$copy" "$flags" 1)" || return 1
_mca_steam_same_size "$copy" "$out" || return 1
# Already the length Steam expects: the patch is a good one.
(( $(wc -c < "$script") == $(wc -c < "$copy") )) && return 0
if mca_write_if_changed "$script" "$out"$'\n'; then
MCA_CHANGES=$(( MCA_CHANGES + 1 ))
if out="$(_mca_steam_build "$copy" "$flags")" && _mca_steam_same_size "$copy" "$out"; then
if mca_write_if_changed "$script" "$out"$'\n'; then
MCA_CHANGES=$(( MCA_CHANGES + 1 ))
fi
chmod +x -- "$script" 2>/dev/null || true
touch -r "$copy" -- "$script" 2>/dev/null || true
mca_ledger_add steam "$script" "$name"
return 0
fi
chmod +x -- "$script" 2>/dev/null || true
touch -r "$copy" -- "$script" 2>/dev/null || true
mca_ledger_add steam "$script" "$name"
mca_steam_revert "$script" "$name"
mca_ledger_forget "$script"
mca_note "$(mca_msg "Steam's interface cannot be given the flag without leaving a file Steam would reinstall; the change has been taken back.")"
return 0
}
# mca_steam_apply
# Puts the flags into every Steam installation that has the script, preferring
# the patch that keeps the file's size and falling back to the one that does
# not. Returns 1 when there is no Steam to patch at all.
# Puts the flags into every Steam installation that has the script, and only
# where that can be done without changing how long the file is. Returns 1 when
# there is no Steam to patch at all.
mca_steam_apply() {
local root script backup flags found=0 out neutral
local root script backup flags found=0 out
flags="$(mca_flags)"
@@ -268,35 +228,21 @@ mca_steam_apply() {
found=1
if mca_steam_script_patched "$script"; then
_mca_steam_reneutralise "$script" "$flags" || true
_mca_steam_settle "$script" "$flags"
continue
fi
_mca_steam_refresh_backup "$script"
neutral=1
if ! { out="$(_mca_steam_build "$script" "$flags" 1)" \
# Either the comments can pay for the flag or nothing is written.
# A longer file is one Steam reinstalls itself over; a client update
# that changed how the helper is started leaves no line to patch at
# all. Both end here, and this script is what starts Steam's entire
# interface, so leaving it alone is the only safe answer to either.
if ! { out="$(_mca_steam_build "$script" "$flags")" \
&& _mca_steam_same_size "$script" "$out"; }
then
neutral=0
out="$(_mca_steam_build "$script" "$flags" 0)" || {
# A client update changed how the helper is started. Leaving
# the file alone is the only safe answer: this script is what
# starts Steam's entire interface.
mca_note "$(mca_msg "Steam starts its interface in a way this version does not recognise; leaving it alone.")"
continue
}
fi
# The patch has to grow the file, and it is not patched now but was
# before: Steam has just put its own copy back. Patching it again
# while the client watches is what turns one size mismatch into an
# endless update dialog, and it would not help this session anyway -
# the helper is started once, at the start. The patch waits for the
# next apply with Steam closed. A patch that keeps the size has
# nothing to wait for.
if (( ! neutral )) && mca_steam_deferred "$script"; then
mca_note "$(mca_msg "Steam is running and has put its own file back; the change waits until Steam is closed.")"
mca_note "$(mca_msg "Steam starts its interface in a way this version cannot change without Steam noticing; leaving it alone.")"
continue
fi
@@ -339,23 +285,3 @@ mca_steam_revert() {
chmod +x -- "$script" 2>/dev/null || true
return 0
}
# mca_steam_flag_position <packaging>
# Where Steam's own switch goes on a command line. Straight after the program
# for a native or snap entry, because Steam reads its options before the
# steam:// argument that the right-click actions pass. For a Flatpak the first
# token is flatpak itself, which would take the switch for one of its own and
# refuse to start, so there it goes at the end of the arguments - after the
# application id, where flatpak hands everything on to Steam.
mca_steam_flag_position() {
[[ ${1:-native} == flatpak ]] && { printf 'before-fields\n'; return; }
printf 'after-program\n'
}
# mca_steam_desktop_apply <id> <source entry> [packaging]
# Steam restores its own files at every start unless it is told not to verify
# them, so the launcher entry carries that switch.
mca_steam_desktop_apply() {
mca_desktop_apply "$1" "$2" "$MCA_STEAM_LAUNCH_FLAG" \
"$(mca_steam_flag_position "${3:-native}")"
}