[SOLVED] Variables with runcommand-onstart.sh
-
@obsidianspider cool, thanks! Best of luck
-
Woo hoo! It's working!
# /opt/retropie/configs/all/runcommand-onstart.sh # get the full path filename of the ROM rom=$3 # rom_bn receives $rom excluding everything from the first char to the last slash '/' rom_bn="${rom##*/}" # rom_bn receives $rom_bn excluding everything from the last char to the first dot '.' rom_bn="${rom_bn%.*}" # get the system name system=$1 # set the image file to the first result matching the ROM name - accounts for various possible file extensions img="$(find "/opt/retropie/configs/all/emulationstation/downloaded_images/${system}" -type f -name "${rom_bn}-image.*" | head -1)" # check to see if there was a file found (length of the file name not zero), if not, use an image based on system if [[ -z "${img}" ]]; then img="/home/pi/Adafruit_Python_ILI9341/examples/$system.jpg" fi # run the python script to display the image sudo python ~/Adafruit_Python_ILI9341/examples/imageparam.py "$img"
[Edit] Updated script to use @meleu 's line for looking for any file regardless of extension, used a different method to see if the file exists
[Edit 2] Updated syntax for checking for zero length strings and an updated findNow back to getting the darn screen to turn on consistently…
-
@obsidianspider great, dude!
just a touch: there's no need for that else (img=$img
) ;-) -
@meleu Thanks for the tip on the
else
. I updated the script above.Looks like I need to do a bit more tweaking with my "is there an image to display" part of the script.
I have some games with a .png extension for the image and instead of saying the file isn't found, it displays a blank screen instead of the default image and a few other games where there's a different image name than the ROM name (due to me tweaking after scraping) and things are hanging instead of displaying the default.
-
@obsidianspider maybe this line can give you what you need:
img=$(ls -1 "/opt/retropie/configs/all/emulationstation/downloaded_images/${system}/${rom_bn}-image".* | head -1)
[EDIT: the command is "ls dash one", not "ls dash el". ;-)]
[EDIT2: use double quotes to avoid problems with roms with spaces in file name.] -
@meleu That helped a lot. Things are working now. I've updated the script above.
Here's a short video of it working with a game that has art, a game with no art, and another game with art, always reverting back to the RetroPie image when on EmulationStation. I don't know if there's a way to detect what system is up on EmulationStation as you're browsing, but maybe I can look into that in the future.
-
@obsidianspider really cool man! I remember of somebody asking for this kind of trick here in the forum. And I think he would like to see it, but I can't remember his name...
-
@meleu said in Variables with runcommand-onstart.sh:
@obsidianspider maybe this line can give you what you need:
img=$(ls -1 "/opt/retropie/configs/all/emulationstation/downloaded_images/${system}/${rom_bn}-image".* | head -1)
[EDIT: the command is "ls dash one", not "ls dash el". ;-)]
[EDIT2: use double quotes to avoid problems with roms with spaces in file name.]ls will throw an error if there is no matching filename - you can redirect stderr or alternatively use find
img="$(find "/opt/retropie/configs/all/emulationstation/downloaded_images/${system}" -type f -name "${rom_bn}-image.*" | head -1)"
-
@BuZz Thanks! I updated the script to use
find
-
@obsidianspider Your updated script with comments is really cool to share with others the bash tricks.
I only would like to share two tips with you:
- The use of
[[ ... ]]
is preferred over[ ... ]
ortest ...
; it reduces errors as no pathname expansion or word splitting takes place between[[
and]]
(I learned it in RetroPie Shell Style Guide) - The common practice to check if a string is empty is to use
[[ -z "$string" ]]
.
- The use of
-
@obsidianspider
Oh! I look more carefully: This line is wrong:img=$(find "/opt/retropie/configs/all/emulationstation/downloaded_images/${system}/${rom_bn}-image".* | head -1)
What BuZz suggested is:
img="$(find "/opt/retropie/configs/all/emulationstation/downloaded_images/${system}" -type f -name "${rom_bn}-image.*" | head -1)"
-
Thanks for all the help, I've updated the script with the suggestions you gave.
I'm learning a LOT from this community and I want to share what I've learned so someone else can make something even better with their own project. The comments help because a lot of the examples you see online don't explain what a particular thing is doing, they just say "do this" but not why you should do that.
Now that I've got the screen working and finding images properly the next step is a pushbutton to control a script that toggles the backlight…
-
Looks interesting! We've had a Pi in a Gameboy, now we need someone to create their own DS-like console with the artwork displayed on the second screen (!)
-
Hey guys! Just sharing a
find
trick I've learned today...Using this:
find /directory -type f -name "filename.*" -print -quit
Is better than use this:
find /directory -type f -name "filename.*" | head -1
Benefit: the
-quit
makesfind
exit immediately after the first match. Well, if we want the first match only, there's no need to let thefind
keep looking for files after the first match.
OBS.: when using-quit
you have to use-print
, otherwise thefind
won't print the file name. -
Here is a proof:
$ time find /usr -type f -print -quit /usr/i686-w64-mingw32/bin/ar.exe real 0m0.266s user 0m0.000s sys 0m0.140s $ time find /usr -type f | head -1 /usr/i686-w64-mingw32/bin/ar.exe real 0m2.093s user 0m0.140s sys 0m0.403s
(Yeah, I'm not using an actual Linux system. It's Cygwin running on Windows. But the test is valid anyway.)
-
Nice find! I'm away on a business trip for the next two weeks and had to leave my Pi at home so I am hoping to find a way to mess with some scripts while it's inaccessible.
I have Googled emulating a Pi in a VM but it doesn't seem like anyone's done that, just approximated things with installing Debian.
-
@obsidianspider
This is right up my ally. I actually want to do something similar to this, but with something like a 20x2 LCD to just display the system and game title.
However, I might want to get an OLED screen for displaying the information.
I might ask you for some help setting up my own script..
My only thing is that I will then need to make a custom case to hold the Pi, as well as the screen and keep it all clean. -
@Nathan1031982 The script he posted above gives a good direction to your script.
The runcommand wiki can give some inspiration too: https://github.com/retropie/retropie-setup/wiki/runcommand#runcommand-onstart-and-runcommand-onend-scripts -
This is a very old topic, but I wanted to throw my script in so you can edit it to your liking. I don't have an Adafruit display, so I had to do some tinkering but you've all done the heavy lifting. Here are the minor edits for using a 3.5" display with fbi. Make sure you have the system.jpg images in the correct system rom folders.:
# /opt/retropie/configs/all/runcommand-onstart.sh # get the full path filename of the ROM rom=$3 # rom_bn receives $rom excluding everything from the first char to the last slash '/' rom_bn="${rom##*/}" # rom_bn receives $rom_bn excluding everything from the last char to the first dot '.' rom_bn="${rom_bn%.*}" # get the system name system=$1 # set the image file to the first result matching the ROM name - accounts for various possible file extensions img="$(find "/opt/retropie/configs/all/emulationstation/downloaded_images/${system}" -type f -name "${rom_bn}-image.*" | head -1)" # check to see if there was a file found (length of the file name not zero), if not, use an image based on system if [[ -z "${img}" ]]; then img="/opt/retropie/configs/all/emulationstation/downloaded_images/$system/$system.jpg" fi # run the python script to display the image sudo fbi -T 2 -d /dev/fb1 -noverbose -a "$img"
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.