Simple Bash Script Needs a Little Love

I want to make the following bash script a bit more user friendly so that when ever a retroarch supported rom is selected the appropriate retroarch core will run the game.

Consider the following (incomplete, but) working code:

#!/bin/bash

config="$HOME/.config/retroarch/retroarch.cfg"

core_nes="$HOME/.config/retroarch/cores/mesen_libretro.so"

FILE=zenity --file-selection --filename="$HOME/.config/retroarch/roms/" --file-filter=" "*"" --title="Select a Game"

retroarch -L “$core_nes” “$FILE” --fullscreen --config="$config"`

Now that code works for just nes roms but I want to add a bit of code that after the user has selected a rom (zenity part - a file explorer window will open to a path called roms, within that folder will be rom directories - Ex: Nintendo/nes/snes/gb etc…), the correct retroarch core will load and run the game.

It currently works for nes roms only, so I believe I will need a case statement to store the retroarch cores and then an if statement that basically goes like:

Psuedo code:

If $FILE variable (in the zenity part of the ) has a .nes extension then the retroarch launch codte will launch the nes core, if the $FILE variable has a .snes extension, then the retroarch launch code will launch the snes core etc…

Can some brilliant individual please help me accomplish this, or something along those lines so it will be a possible to run any retroarch core and rom from a bash script, and not have to open several different windows (prevent a crash) to launch a core when the correct file is loaded?

I don’t se an elegant way to do this but you can add something like this after defining FILE:

[ ${FILE##*.} = "nes" ] && CORE=$core_nes
[ ${FILE##*.} = "sfc" ] && CORE=$core_snes
# and so on...

[ -z "$CORE" ] && exit # if string is empty then no core is set for the extension, so exit

retroarch -L "$CORE" "$FILE" --fullscreen --config="$config"

Thank you metchebe! That works great!

Can I go a bit further and ask a couple of more questions?

  1. how can the following part of your code:

[ ${FILE##*.} = “nes” ] && CORE=$core_nes

be made to also use a folder? Reason for this change is that I want to try it for a certain core that requires the path (NOT THE FILE extension) to be specified on the command line vs the $FILE, perhaps $FOLDER?

The second question relates to the possibility of having cores that use the same extension (perhaps zip being the culprit?) I am not sure if that will be an issue or not, but is there some way to prevent that from becoming an issue?

Regards, Brian

@average-gamer Glad it works.

For the folder load question, could you give me an example of the command line that you need? What core is it?

For the zip question I think you would need to set a fixed core, or choose it after choosing the file, or somehow deduce it from the path (e.g. the folder the zip is in). Again, an example would be useful.

H metchebe,

I have made some progress (from not over thinking, a bad habit of mine)…I simply used:

FOLDER=zenity --file-selection --directory --title="Choose Game Directory"

and specifying the $FOLDER variable on the retroarch launch line, (replacing $FILE) but it appears that something in this line is giving me a problem:

[ ${FOLDER##*.} = “” ] && CORE=$core_scummvm

Error is: line 25: [: =: unary operator expected

Line 25: [ ${FOLDER##*.} = “” ] && CORE=$core_scummvm

Could you help resolve?

Edit: Could it be done without creating both a file & folder variable? I am going to try to create a variable to the game directory and see if that will run. I will post back with that result.

Edit 2: I’ve added:

FOLDER=zenity --file-selection --directory --title="Choose Game Directory"

and my retroarch launch line looks like:

retroarch -L “$CORE” “$FOLDER” --fullscreen --config="$config"

Result: [: =: unary operator expected

on all the lines like:

[ ${FILE##*.} = “nes” ] && CORE=$core_nes etc…

Regards, Brian

Here is my whole code:

#!/bin/bash

config="$HOME/.config/retroarch/retroarch.cfg"

core_nes="$HOME/.config/retroarch/cores/mesen_libretro.so" core_snes="$HOME/.config/retroarch/cores/snes9x_libretro.so" core_dos="$HOME/.config/retroarch/cores/dosbox_pure_libretro.so" core_arcade="$HOME/.config/retroarch/cores/fbneo_libretro.so" core_scummvm="$HOME/.config/retroarch/cores/scummvm_libretro.so"

FILE=zenity --file-selection --filename="$HOME/Desktop/" --file-filter=" "*"" --title="Select a Game"

FOLDER=zenity --file-selection --directory --title="Choose Game Directory"

[ ${FILE##.} = “nes” ] && CORE=$core_nes [ ${FILE##.} = “smc” ] && CORE=$core_snes [ ${FILE##.} = “zip” ] && CORE=$core_dos [ ${FILE##.} = “zip” ] && CORE=$core_arcade [ ${FILE##.} = “zip” ] && CORE=$core_atari_2600 [ ${FILE##.} = “zip” ] && CORE=$core_atari_5200 [ ${FILE##.} = “zip” ] && CORE=$core_atari_7800 [ ${FILE##.} = “zip” ] && CORE=$core_atari_jaguar [ ${FILE##.} = “zip” ] && CORE=$core_atari_lynx [ ${FILE##.} = “zip” ] && CORE=$core_atari_st

and so on…

[ -z “$CORE” ] && exit # if string is empty then no core is set for the extension, so exit

retroarch -L “$CORE” “$FOLDER” --fullscreen --config="$config"

Edit: I have uncommented the FILE=zenity line while testing, but I uncommented both FILE and FOLDER lines since this editor treats hash tag with large fonts.

I am not familiar with scummvm. Is there a file in the folder that you could choose with a particular extension? If not you could:

  1. Create dummy file to load somegame.scummvm in the folder.
  2. Load that file and by extension select the appropriate core.
  3. Redefine FILE to just the path.

Code would be like:

[ ${FILE##*.} = "scummvm" ] && CORE=$core_scummvm && FILE=${FILE%/*}

Here are some tips for string manipulation that are used:

https://tldp.org/LDP/LG/issue18/bash.html

@average-gamer Unfortunately your code for zip files won’t work, see my second post.

You know something, come to think of if, scummvm has another way to load…The way I seen it, was like: gamename.scummvm and inside that file, it was like a windows batch file to run the exe file

gamename.exe

I think there is supposed to be another line, but that’s mainly it, I will have a go at that option, and if that works, it will keep your original code on track, without having to change anything. Hope it works.

Edit: I tried creating the .scummvm file and putting the name of the executable file in the file but it still didn’t work, the closest I came was scummvm core did launch but not the game. The only way that I know of to get the scummvm games to work (from the terminal) is to launch retroarch from the terminal and use the folder path on the retroarch command line.

Regards, Brian

Actually,

I made a small typo, the only way I can get scummvm games to work is to launch retroarch, then load content. I am using the same files for the bash script as I am with retroarch gui.

You also need a properly configured scummvm.ini. I can post an example when I get to my computer.

Duimon,

I am running linux I am not sure if the ini is specific to windows or not.

Regards, Brian

1 Like

the scummvm core is a lot like the MAME core. (Barely a core, more of a wrapper.)

The internal scummvm needs the same info as the standalone version.

Load the core and run it.

Add your games in the interface.

When you add a game it will update your scummvm.ini in the RA system folder.

Here is a snippet.

[scummvm]
lastselectedgame=baseball
gui_browser_show_hidden=false
browser_lastpath=E:\Emulation\ScummVM\Backyard Baseball\
mute=false
versioninfo=2.1.1

[baseball]
gameid=baseball
description=Backyard Baseball (English)
language=en
path=E:\Emulation\ScummVM\Backyard Baseball\
guioptions=sndNoMIDI launchNoLoad noAspect lang_English

Then you need to create the *.scummvm shortcuts in your roms folder.

The games should all be in folders using the “long name” of the game. The shortcut can be named the same. i.e %long name%.scummvm.

The shortcut contents needs the path (I think they can be relative but I use absolute paths.) and the short name of the game, plus a couple of switches.

For the above snippet example:

The long name (folder name and shortcut filename.) is…

Backyard Baseball

the “Backyard Baseball.scummvm” shortcut contains.

-f -p "E:\Emulation\ScummVM\Backyard Baseball" baseball

“baseball” is the short name of the game. You can get a list of short names from the scummvm site.

It is a bit of work but only needs to be done once. If you scour the interwebs you may find a working setup you can use as a reference.


Backyard Baseball running on the Mega Bezel.

Duimon,

When you say I need to create the .scummvm shortcuts in my roms folder, is that folder referring to the actual game folder or could it be like such:

My rom folder structure:

roms/scummvm/game_folder/

does the .scummvm file need to be in the game_folder (shown above) or could it be in the scummvm folder (also shown above) ? Another words, should the .scummvm file reside with the game files or does it not have to be with them?

Duimon,

I have followed the page: https://docs.libretro.com/library/scummvm/#google_vignette

Running a Game

I got the game running from the .scummvm file, but I loaded from the retroarch load content, but when I tried to run the game using a bash script, and pointing to that same .scummvm file, it just returns to the terminal (Linux - Ubuntu 18.04)

Edit: I GOT IT! Thank you Duimon & metchebe! You guys are awesome! I appreciate both of your help on this.

1 Like

Quick question:

Could it be possible to add multiple extensions for a core?

Example like the following: I added exe com bat as the extensions (would that work) [ ${FILE##*.} = “exe com bat” ] && CORE=$core_dos

FWIIW, use the same expression found within the core info file, i.e.,

grep supported_extensions /retroarch/cores/*.info | more

… and you can reference that to this bash example:

CORE=
FILE="/retroarch/roms/Nintendo Entertainment System/Moon Crystal (Japan).nes"
TITLE=`basename "${FILE%.*}"`
EXT="${FILE##*.}"
[[ "$EXT" =~ nes|fds|unf|unif ]] && CORE=nestopia
[[ "$EXT" =~ d64|d71|d80|d81|d82|g64|g41|x64|t64|tap|prg|p00|crt|bin|zip|gz|d6z|d7z|d8z|g6z|g4z|x6z|cmd|m3u|vfl|vsf|nib|nbz|d2m|d4m ]] && CORE=vice_x64sc
echo "Play $TITLE using $CORE"

I didn’t think of looking into the /retroarch/cores/*.info files. I will do that tomorrow morning.

Thanks for the info, theflyingape!