Last active
May 30, 2024 03:34
-
-
Save major-gnuisance/4fad491e37c5ac7efa72f9473d4e95bd to your computer and use it in GitHub Desktop.
Installer for a workaround Steam shim.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # exit on error or unset variables | |
| set -ue | |
| # configurable paths and filenames | |
| readonly shim_name=steam-shim | |
| readonly desktop_filename=steam.desktop | |
| readonly applications_dir=/usr/share/applications | |
| # array to store uninstallation commands | |
| declare -a uninstall_commands | |
| if [ "$UID" == 0 ]; then | |
| # when running as root | |
| readonly shim_install_dir=/usr/local/bin | |
| else | |
| # when running as user | |
| readonly shim_install_dir="$HOME/.local/bin" | |
| fi | |
| # create work directory | |
| tempdir="$(mktemp -d)" | |
| readonly tempdir | |
| # cleanup | |
| function cleanup() { | |
| cd | |
| rm -r "$tempdir" | |
| } | |
| trap cleanup EXIT | |
| # create shim script | |
| cat >"$shim_name" <<-"EOF" | |
| #!/bin/bash | |
| # Shim to work around issues with Steam | |
| declare -a steam_options | |
| # Disable GPU acceleration in Steam's embedded browser when using | |
| # non-default GPU, to avoid crashes. | |
| # See: https://github.com/ValveSoftware/steam-for-linux/issues/9383 | |
| if [ -n "$DRI_PRIME" ] ; then | |
| steam_options+=(-cef-disable-gpu) | |
| fi | |
| exec steam "${steam_options[@]}" "$@" | |
| EOF | |
| readonly shim_full_path="$shim_install_dir/$shim_name" | |
| # install shim script | |
| install -D --mode=755 --target-directory="$shim_install_dir" "$shim_name" | |
| uninstall_commands+=("rm ${shim_full_path@Q}") | |
| readonly shim_full_path_escaped="${shim_full_path//\//\\/}" | |
| readonly desktop_file_source="$applications_dir/$desktop_filename" | |
| # create altered version of desktop file | |
| sed "s/^Exec=[^ ]*/Exec=$shim_full_path_escaped/" "$desktop_file_source" >"$desktop_filename" | |
| # install altered version of desktop file | |
| if [ "$UID" == 0 ]; then | |
| install -D --mode=755 --target-directory="/usr/local/share/applications" "$desktop_filename" | |
| uninstall_commands+=("rm /usr/local/share/applications/${desktop_filename@Q}" | |
| "xdg-desktop-menu forceupdate") | |
| else | |
| xdg-desktop-menu install --novendor "$desktop_filename" | |
| uninstall_commands+=("xdg-desktop-menu uninstall ${desktop_filename@Q}") | |
| fi | |
| # Print uninstallation instructions | |
| echo "Installation successful." | |
| function print_uninstallation_commands() { | |
| echo "To uninstall, run the following commands:" | |
| if [ "$UID" == 0 ]; then | |
| printf "sudo %s\n" "${uninstall_commands[@]}" | |
| else | |
| printf "%s\n" "${uninstall_commands[@]}" | |
| fi | |
| } | |
| print_uninstallation_commands | |
| print_uninstallation_commands | sed 's/^/# /' >> "$shim_full_path" | |
| echo "You may also find these instructions at the end of the shim script, found here:" | |
| echo "${shim_full_path@Q}" |
Updated to support systems with proprietary Nvidia drivers. Hopefully. Waiting for reports that it works.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script installs a fix for this issue: ValveSoftware/steam-for-linux#9383
Tested on Fedora 40 Workstation with Gnome 3 and with Steam installed using the system's package manager, not Flatpak.
How to use, for the careless
Copy and paste this line into a terminal and press enter:
(Protip: triple clicking on text selects whole lines at once. Middle click pastes your most recent text selection.)
Disclaimer: you shouldn't really execute scripts straight off the web like this if you care about security. See the next section for a more cautious approach.
How to use, for the cautious
Notes
Your desktop environment might not reflect the change immediately.
If it doesn't seem to work, try logging out and back in.
The script does two main things:
If the script is run as a regular user, it will install just for that user.
If it's run as root, it will install for all users.
The effective locations for the files it installs are as follows.
When run as root:
/usr/local/bin/steam-shim
/usr/local/share/applications/steam.desktop
When run as a regular user:
~/.local/bin/steam-shim
~/.local/share/applications/steam.desktop
Critical assumptions: