HGL
like-gold

[Solved] Running a shell script before launching a game and after exiting that game

I thought it will be easy to do that as there's already options for both (launch & exit). But I cant get it to work. I wanna use ludusavi which was installed using flatpak. Ludusavi already had a guide for heroic but I cant get it to work so I was thinking about creating my own script. Heroic is installed as native package. Distro: Fedora 42 KDE
35 Replies
like-gold
like-goldOP2mo ago
#!/usr/bin/env bash

# Ludusavi Manager Script
# Usage: ./script.sh [backup|restore] [game-name]

run_ludusavi="flatpak run com.github.mtkennerly.ludusavi"
config_dir="$HOME/.var/app/com.github.mtkennerly.ludusavi/config/ludusavi"

# Validate arguments
if [ $# -ne 2 ]; then
echo "Error: Invalid number of arguments"
echo "Usage: $0 backup|restore game-name"
exit 1
fi

operation=$1
game_name=$2

# Determine operation
case "$operation" in
backup) option="--backup" ;;
restore) option="--restore" ;;
*)
echo "Error: Invalid operation '$operation'. Must be 'backup' or 'restore'"
exit 1
;;
esac

# Execute command
$run_ludusavi --config "$config_dir" $option --force "$game_name"
#!/usr/bin/env bash

# Ludusavi Manager Script
# Usage: ./script.sh [backup|restore] [game-name]

run_ludusavi="flatpak run com.github.mtkennerly.ludusavi"
config_dir="$HOME/.var/app/com.github.mtkennerly.ludusavi/config/ludusavi"

# Validate arguments
if [ $# -ne 2 ]; then
echo "Error: Invalid number of arguments"
echo "Usage: $0 backup|restore game-name"
exit 1
fi

operation=$1
game_name=$2

# Determine operation
case "$operation" in
backup) option="--backup" ;;
restore) option="--restore" ;;
*)
echo "Error: Invalid operation '$operation'. Must be 'backup' or 'restore'"
exit 1
;;
esac

# Execute command
$run_ludusavi --config "$config_dir" $option --force "$game_name"
I am trying to use this. right now running ludusavi-wrapper.sh backup "Assassins Creed IV Black Flag" in terminal works and the script exit with 0 but if I put this in "Select a script to run before the game is launched" then its stucked in launching state I would also like to get the game name from heroic if thats possible when I run heroic via cli i found this when launching the game Error occurred in handler for 'launch': spawn ~/games/.tools/ludusavi-wrapper.sh backup "Assassins Creed IV Black Flag" ENOENT I did added path and heroic should have access to this Error occurred in handler for 'launch': spawn flatpak run com.github.mtkennerly.ludusavi --config $HOME/.var/app/com.github.mtkennerly.ludusavi/config/ludusavi backup --force "Assassins Creed IV Black Flag" ENOENT if I just add the command
CommandMC
CommandMC2mo ago
You can't run a Flatpak from another Flatpak Add flatpak-spawn --host to the start of your command to execute the command on the host instead. Note that this requires the org.freedesktop.Flatpak talk and essentially disables the advantages of Flatpak To grant that talk permission, run
flatpak --user override --talk-name=org.freedesktop.Flatpak com.heroicgameslauncher.hgl
flatpak --user override --talk-name=org.freedesktop.Flatpak com.heroicgameslauncher.hgl
like-gold
like-goldOP2mo ago
Heroic isnt installed as flatpak
CommandMC
CommandMC2mo ago
Oh sorry, missed that note. I only read "I did added path and heroic should have access to this" and figured Flatpak I assume the script you created is executable?
like-gold
like-goldOP2mo ago
yep I tested manually before adding and looks like backup portion is working as I haven't tested restore yet
CommandMC
CommandMC2mo ago
Looking at the code, I don't think scripts can have parameters You should be able to do this though: https://github.com/mtkennerly/ludusavi/blob/master/docs/help/game-launch-wrapping.md#heroic (perhaps with slight changes since you're using the Flatpak Ludusavi)
like-gold
like-goldOP2mo ago
Sorry I am new to scripting dont know much as I said I was able to get it work when I ran it. I created another post too https://discord.com/channels/812703221789097985/1394735173282697236/1394735173282697236 this didnt explain much and idk how to add this wrapper. is it similar to adding script ?
CommandMC
CommandMC2mo ago
Create the file as instructed there, replacing ludusavi with flatpak run com.github.mtkennerly.ludusavi since you're on Flatpak Then add that script as a wrapper in Heroic ("Wrapper command" in the "Advanced" tab of the game settings)
like-gold
like-goldOP2mo ago
I assume
$!/bin/sh
ludusavi --config $HOME/.config/ludusavi wrap --gui --infer heroic -- "$@"
$!/bin/sh
ludusavi --config $HOME/.config/ludusavi wrap --gui --infer heroic -- "$@"
here ludusavi has to be changed to latpak run com.github.mtkennerly.ludusavi config dir to $HOME/.var/app/com.github.mtkennerly.ludusavi/config/ludusavi but I wasn't able to get it to work but let me try again
like-gold
like-goldOP2mo ago
does it look ok?
No description
CommandMC
CommandMC2mo ago
Just add the script as the wrapper, no arguments
like-gold
like-goldOP2mo ago
Error: spawn ~/.local/bin/test/ludusavi-wrapper.sh ENOENT
at Process.ChildProcess._handle.onexit (node:internal/child_process:285:19)
at onErrorNT (node:internal/child_process:483:16)
at processTicksAndRejections (node:internal/process/task_queues:90:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn ~/.local/bin/test/ludusavi-wrapper.sh',
path: '~/.local/bin/test/ludusavi-wrapper.sh',
Error: spawn ~/.local/bin/test/ludusavi-wrapper.sh ENOENT
at Process.ChildProcess._handle.onexit (node:internal/child_process:285:19)
at onErrorNT (node:internal/child_process:483:16)
at processTicksAndRejections (node:internal/process/task_queues:90:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn ~/.local/bin/test/ludusavi-wrapper.sh',
path: '~/.local/bin/test/ludusavi-wrapper.sh',
Did as you said
CommandMC
CommandMC2mo ago
Oh actually, I don't think you can use ~
like-gold
like-goldOP2mo ago
$HOME then ? lemme try
CommandMC
CommandMC2mo ago
Assuming ~/.local/bin/test/ is on your PATH, you should be able to just add ludusavi-wrapper.sh No, you'd have to write out the actual path
like-gold
like-goldOP2mo ago
from /home/*?
CommandMC
CommandMC2mo ago
/home/your_username/.local/bin/test/ludusavi-wrapper.sh, replacing your_username with your actual user's name
like-gold
like-goldOP2mo ago
yep tried now ludusavi can find the game
like-gold
like-goldOP2mo ago
No description
like-gold
like-goldOP2mo ago
No description
like-gold
like-goldOP2mo ago
if I say yes then I get crash notification BTW is it possible to get the game name from heroic ?
CommandMC
CommandMC2mo ago
Yeah figured, Ludusavi's Flatpak doesn't include Wine dependencies... The easiest way to resolve this would probably be to just use the native Ludusavi
like-gold
like-goldOP2mo ago
Alright . But I have never tried building from source https://github.com/mtkennerly/ludusavi/releases/download/v0.29.1/ludusavi-v0.29.1-linux.tar.gz idk how to use this, using llm i got to know that I can use it as any other script. this one is just compiled . does it mean if I put it in my script folder I can run normally ? sorry for the noob question This doesn't say if its rpm or deb build
CommandMC
CommandMC2mo ago
It isn't a package, it's simply an executable However depending on your distro, there might be a package for it in the official repos
like-gold
like-goldOP2mo ago
I tried looking for copr and rpmfusion and official there's none
CommandMC
CommandMC2mo ago
Also, please do not use LLMs to attempt to get help here. They will lie to you
like-gold
like-goldOP2mo ago
yes thats why I didn't try using that file I just use those to get direction then try to do my research Whats the difference then ? similar to running script or installing something ?
CommandMC
CommandMC2mo ago
Right, manual install it is then. Download the release (https://github.com/mtkennerly/ludusavi/releases/download/v0.29.1/ludusavi-v0.29.1-linux.tar.gz), then extract it and place the executable into ~/.local/bin/. Run a chmod +x ~/.local/bin/ludusavi to mark it as executable I assume ~/.local/bin is on your PATH. To check, open a terminal now and run which ludusavi. If that command finds it, you're good Open up your ludusavi-wrap.sh script and change it to match the contents of the guide again (replacing flatpak run ... with just ludusavi
like-gold
like-goldOP2mo ago
yep done that it looks like ludusavi still cant recognize the game. I did have this issue if name isn't same or what ludusavi expect when I was in windows. BTW is there a way to know what heroic launches ? in this way I can create an alias in ludusavi This time I was able to launch when I pressed yes
CommandMC
CommandMC2mo ago
it looks like ludusavi still cant recognize the game. I did have this issue if name isn't same or what ludusavi expect when I was in windows.
Could you send in a game log?
BTW is there a way to know what heroic launches ? in this way I can create an alias in ludusavi
I'm not sure what you're asking there. Heroic will launch the game with either Legendary (for Epic Games), GOGDL (for GOG) or Nile (Amazon)
like-gold
like-goldOP2mo ago
Sorry IDK where the log is
HeroicBot
HeroicBot2mo ago
To help you, we need a game log. Please see the following images on how to get it.
From An unknown user
From An unknown user
From An unknown user
From An unknown user
From An unknown user
From An unknown user
like-gold
like-goldOP2mo ago
Now it looks like with the wrapper script I cant launch the game anymore. BTW this is a non heroic game. I had it installed in my old windows partition and copied over https://0x0.st/8djt.log
CommandMC
CommandMC2mo ago
Sideloaded games probably won't work with Ludusavi. It doesn't have any metadata to find out the game you're playing
like-gold
like-goldOP2mo ago
Oh I see but dev suggested for emulators I can do it by adding custom games. BTW ig I should give it a try with my script earlier see if that works Thanks for your time But any idea why the script wont work that way ? The fix can be found here. https://discord.com/channels/812703221789097985/1395767977093238854

Did you find this page helpful?