Homepage › Forums › RetroPie Project › Everything else related to the RetroPie Project › Up for a challenge? I need a hand with a shell script
- This topic has 0 replies, 1 voice, and was last updated 8 years, 9 months ago by labelwhore.
-
AuthorPosts
-
02/10/2016 at 16:34 #116678labelwhoreParticipant
If anyone is good with shell scripting, I need some assistance.
First, let me explain what I’m trying to do. I want to be able to make mass edits to the emulator.cfg files. I want to copy what’s there and give 1 new launch option per emulator with some scripts inserted before and after the launch commands that are currently available.
Let’s start with a simple example, Descent. Here is /opt/retropie/configs/descent1/emulators.cfg before I run my script:
dxx-rebirth="/opt/retropie/ports/dxx-rebirth/d1x-rebirth -hogdir /home/pi/RetroPie/roms/ports/descent1" default="dxx-rebirth"
and after:
dxx-rebirth="/opt/retropie/ports/dxx-rebirth/d1x-rebirth -hogdir /home/pi/RetroPie/roms/ports/descent1" default="dxx-rebirth" dxx-rebirth-fade="bash /home/pi/.mpd/OtherScripts/stop_playback.sh && /opt/retropie/ports/dxx-rebirth/d1x-rebirth -hogdir /home/pi/RetroPie/roms/ports/descent1 && bash /home/pi/.mpd/OtherScripts/start_playback.sh"
If there is more than one emulator, then multiple new lines will be added.
Notice the new line with “-fade” added onto the emulator name, and the two new commands; “bash /home/pi/.mpd/OtherScripts/stop_playback.sh && “, and ” && bash /home/pi/.mpd/OtherScripts/start_playback.sh”, inserted before and after the original launch commands.
My current script, which I have attached, works fine but will be a pain in the ass to maintain. It’s all hardcoded.
What I need help with is this; What can I do to programmatically break apart the original launch commands to rebuild and add the new options? I want to keep the original lines intact, and add new options or every emulator via my script. Oh, and there is a caveat too. Some emulators need a second command to be issued right after the first script, so I need to way to run this on all emulators except for certain ones that I specify. And for those, I need to add an additional command after the first script is run, but before the game is launched.
So I’m thinking what I need is a way to grab the name of the emulator for the existing line, so everything before “=” on all lines except the “default=” line. I also need to capture everything after =” and before the last ” on each line ecept for the “default=” line. Then I need to rebuild each line and add them after the existing line like: oldname-fade=”newcommand && old command &&secondnewcommand”. Fot those “special” emulators I specifically call out, the new lines need to look like this: oldname-fade=”newcommand && bugfixcommand && old command &&secondnewcommand”.
I’m not asking anyone to do the work for me, what I probably need is help with a regular expression (which I know nothing about how to use properly) that can help me accomplish this.
Thanks in advance.
-
AuthorPosts
- The forum ‘Everything else related to the RetroPie Project’ is closed to new topics and replies.