News:

Welcome to the Retrode Community Forums

Main Menu

Raspberry Pi Retrode Bash Script

Started by korori, 03/May/2013 03:46:12 AM

Previous topic - Next topic

korori

Hey everyone. Below is a script I put together to automatically launch the correct emulator based on the rom extension.  If I made any mistakes or add to post the changes in your post. I'm kinda new at creating bash scripts.

I do not have it setup when it boots. If you wish to do so you need to setup auto login and put the script launch the script in the .profile.

You will need to follow these instructions before using this.
http://supernintendopi.wordpress.com/


Basically this will mount the retrode.
Then checks which Type of game you have.
It then copies the game to the rom folder for the emulator. Also makes it faster to load next time.
It also copies the save if it does not exist.
Then it runs the Emulator for that Rom.


#!/bin/bash

#Check and Make Temporary Directory for Retrode Roms/Save Files
DIR="/home/pi/retrode"

if [ -d "$DIR" ]; then
echo "$DIR directory  exists!"
else
mkdir $DIR
fi

#Mount Retrode to Folder
if [ $(mount | grep -c /home/pi/retrode) != 1 ]; then
    mount /dev/sda /home/pi/retrode || exit 1
else
    echo "Retrode is Already Mounted"
fi


#Super Nintendo/Super Famicom
sfcfind=(`find /home/pi/retrode -maxdepth 1 -name "*.sfc"`)

#Mega Drive/Sega Genesis
binfind=(`find /home/pi/retrode -maxdepth 1 -name "*.bin"`)

#Gameboy/Gameboy Colour
gbfind=(`find /home/pi/retrode -maxdepth 1 -name "*.gb"`)

#Gameboy Advance
gbafind=(`find /home/pi/retrode -maxdepth 1 -name "*.gba"`)

#Sega Master System
smsfind=(`find /home/pi/retrode -maxdepth 1 -name "*.sms"`)

#Check if Retrode Game is Super Nintendo/Super Famicom
if [ ${#sfcfind[@]} -gt 0 ]; then

#Check if Save File is on Retrode
savefile=`basename /home/pi/retrode/*.srm`
if [ -f $savefile ]; then

#Check if File Exist in Rom Directory
if [ -f /home/pi/RetroPie/roms/snes/$savefile ]; then
printf "Save Data for this Game Exist"
else
cp -R /home/pi/retrode/*.srm /home/pi/RetroPie/roms/snes
fi
fi

#Check if File on the SNES Roms Folder
file=`basename /home/pi/retrode/*.sfc`

if [ -f /home/pi/RetroPie/roms/snes/$file ]; then
printf "Super Nintendo game Already Exist"
else
cp -R /home/pi/retrode/*.sfc /home/pi/RetroPie/roms/snes
fi

#Run SNES Emulator
/home/pi/RetroPie/supplementary/runcommand/runcommand.sh 1 "retroarch -L /home/pi/RetroPie/emulatorcores/pocketsnes-libretro/libretro.so --config /home/pi/RetroPie/configs/all/retroarch.cfg --appendconfig /home/pi/RetroPie/configs/snes/retroarch.cfg /home/pi/RetroPie/roms/snes/"$file

#Check if Retrode Game is Mega Drive/Sega Genesis
elif [ ${#binfind[@]} -gt 0 ]; then

#Check if Save File is on Retrode
savefile=`basename /home/pi/retrode/*.srm`
if [ -f $savefile ]; then

#Check if File Exist in Rom Directory
if [ -f /home/pi/RetroPie/roms/megadrive/$savefile ]; then
printf "Save Data for this Game Exist"
else
cp -R /home/pi/retrode/*.srm /home/pi/RetroPie/roms/megadrive
fi
fi

#Check if File on the SNES Roms Folder
file=`basename /home/pi/retrode/*.bin`

if [ -f /home/pi/RetroPie/roms/megadrive/$file ]; then
printf "Mega Drive game Already Exist"
else
cp -R /home/pi/retrode/*.bin /home/pi/RetroPie/roms/megadrive
fi

#Run Mega Drive/Sega Genesis Emulator
/home/pi/RetroPie/supplementary/runcommand/runcommand.sh 1 "/home/pi/RetroPie/emulators/dgen-sdl/dgen -f -r /home/pi/RetroPie/configs/all/dgenrc /home/pi/RetroPie/roms/megadrive/"$file

#Check if Retrode Game is Sega Master System
elif [ ${#smsfind[@]} -gt 0 ]; then

#Check if File on the SNES Roms Folder
file=`basename /home/pi/retrode/*.sms`

if [ -f /home/pi/RetroPie/roms/mastersystem/$file ]; then
printf "Sega Master System game Already Exist"
else
cp -R /home/pi/retrode/*.sms /home/pi/RetroPie/roms/mastersystem
fi

#Run Sega Master System Emulator
/home/pi/RetroPie/emulators/osmose-0.8.1+rpi20121122/osmose "/home/pi/RetroPie/roms/mastersystem/"$file -joy -tv -fs


#Check if Retrode Game is Gameboy/Gameboy Colour
elif [ ${#gbfind[@]} -gt 0 ]; then

#Check if Save File is on Retrode
savefile=`basename /home/pi/retrode/*.srm`
if [ -f $savefile ]; then

#Check if File Exist in Rom Directory
if [ -f /home/pi/RetroPie/roms/gb/$savefile ]; then
printf "Save Data for this Game Exist"
else
cp -R /home/pi/retrode/*.srm /home/pi/RetroPie/roms/gb
fi
fi

#Check if File on the SNES Roms Folder
file=`basename /home/pi/retrode/*.gb`

if [ -f /home/pi/RetroPie/roms/gb/$file ]; then
printf "Mega Drive game Already Exist"
else
cp -R /home/pi/retrode/*.gb /home/pi/RetroPie/roms/gb
fi

#Run Gameboy/Gameboy Colour Emulator
/home/pi/RetroPie/supplementary/runcommand/runcommand.sh 1 "retroarch -L /home/pi/RetroPie/emulatorcores/gambatte-libretro/libgambatte/gambatte_libretro.so --config /home/pi/RetroPie/configs/all/retroarch.cfg --appendconfig /home/pi/RetroPie/configs/gb/retroarch.cfg /home/pi/RetroPie/roms/gb/"$file

#Check if Retrode Game is Gameboy Advance
elif [ ${#gbafind[@]} -gt 0 ]; then

#Check if File on the SNES Roms Folder
file=`basename /home/pi/retrode/*.gba`

if [ -f /home/pi/RetroPie/roms/gba/$file ]; then
printf "Mega Drive game Already Exist"
else
cp -R /home/pi/retrode/*.gba /home/pi/RetroPie/roms/gba
fi

#Run Gameboy Advance Emulator
/home/pi/RetroPie/supplementary/runcommand/runcommand.sh 1 "/home/pi/RetroPie/emulators/gpsp/raspberrypi/gpsp  /home/pi/RetroPie/roms/gba/"$file


fi


Korori

blankspac3

#1
cron or init.d korori :P

ok found what i was looking for, so since matthias is going for like an all in one console, and now korori put the auto start together i was thinking ada fruit has a small 2.5" screen, so would it be possible to mount this on like the bottom of the plastic base, then basically flip the retrode on the side to use the cartridges as like a kickstand
heres a really really rough sketch

heres the screen http://www.adafruit.com/products/912

korori

There are two things I notice I screwed up with. I do not have a set where if it does not detect any of those types to echo out a message and my save check is kinda weird. But those who have experience please input your ideas.


Korori

Muzer

I'll take a look at this when I get a chance and post any improvements I can think of.

Incidentally, I might try writing something with a GUI.

korori

#4
Update


#!/bin/bash

#Check and Make Temporary Directory for Retrode Roms/Save Files
DIR="/home/pi/retrode"

if [ -d "$DIR" ]; then
echo "$DIR directory  exists!"
else
mkdir $DIR
fi

#Mount Retrode to Folder
if [ $(mount | grep -c /home/pi/retrode) != 1 ]; then
    mount /dev/sda /home/pi/retrode || exit 1
else
    echo "Retrode is Already Mounted"
fi

#Super Nintendo/Super Famicom
sfcfind=(`find /home/pi/retrode -maxdepth 1 -name "*.sfc"`)

#Save Data
srmfind=(`find /home/pi/retrode -maxdepth 1 -name "*.sfc"`)

#Mega Drive/Sega Genesis
binfind=(`find /home/pi/retrode -maxdepth 1 -name "*.bin"`)

#Gameboy/Gameboy Colour
gbfind=(`find /home/pi/retrode -maxdepth 1 -name "*.gb"`)

#Gameboy Advance
gbafind=(`find /home/pi/retrode -maxdepth 1 -name "*.gba"`)

#Sega Master System
smsfind=(`find /home/pi/retrode -maxdepth 1 -name "*.sms"`)

#Check if Retrode Game is Super Nintendo/Super Famicom
if [ ${#sfcfind[@]} -gt 0 ]; then

#Check if Save File is on Retrode
if [ ${#srmfind[@]} -gt 0 ]; then
savefile=`basename /home/pi/retrode/*.srm`
#Check if File Exist in Rom Directory
if [ -f /home/pi/RetroPie/roms/snes/$savefile ]; then
echo "Save Data for this Game Exist"
else
cp -R /home/pi/retrode/*.srm /home/pi/RetroPie/roms/snes
fi
fi

#Check if File on the SNES Roms Folder
file=`basename /home/pi/retrode/*.sfc`

if [ -f /home/pi/RetroPie/roms/snes/$file ]; then
echo "Super Nintendo game Already Exist"
else
cp -R /home/pi/retrode/*.sfc /home/pi/RetroPie/roms/snes
fi

#Run SNES Emulator
/home/pi/RetroPie/supplementary/runcommand/runcommand.sh 1 "retroarch -L /home/pi/RetroPie/emulatorcores/pocketsnes-libretro/libretro.so --config /home/pi/RetroPie/configs/all/retroarch.cfg --appendconfig /home/pi/RetroPie/configs/snes/retroarch.cfg /home/pi/RetroPie/roms/snes/"$file

#Check if Retrode Game is Mega Drive/Sega Genesis
elif [ ${#binfind[@]} -gt 0 ]; then

#Check if Save File is on Retrode
if [ ${#srmfind[@]} -gt 0 ]; then
savefile=`basename /home/pi/retrode/*.srm`
#Check if File Exist in Rom Directory
if [ -f /home/pi/RetroPie/roms/megadrive/$savefile ]; then
echo "Save Data for this Game Exist"
else
cp -R /home/pi/retrode/*.srm /home/pi/RetroPie/roms/megadrive
fi
fi

#Check if File on the SNES Roms Folder
file=`basename /home/pi/retrode/*.bin`

if [ -f /home/pi/RetroPie/roms/megadrive/$file ]; then
echo "Mega Drive game Already Exist"
else
cp -R /home/pi/retrode/*.bin /home/pi/RetroPie/roms/megadrive
fi

#Run Mega Drive/Sega Genesis Emulator
/home/pi/RetroPie/supplementary/runcommand/runcommand.sh 1 "/home/pi/RetroPie/emulators/dgen-sdl/dgen -f -r /home/pi/RetroPie/configs/all/dgenrc /home/pi/RetroPie/roms/megadrive/"$file

#Check if Retrode Game is Sega Master System
elif [ ${#smsfind[@]} -gt 0 ]; then

#Check if File on the SNES Roms Folder
file=`basename /home/pi/retrode/*.sms`

if [ -f /home/pi/RetroPie/roms/mastersystem/$file ]; then
echo "Sega Master System game Already Exist"
else
cp -R /home/pi/retrode/*.sms /home/pi/RetroPie/roms/mastersystem
fi

#Run Sega Master System Emulator
/home/pi/RetroPie/emulators/osmose-0.8.1+rpi20121122/osmose "/home/pi/RetroPie/roms/mastersystem/"$file -joy -tv -fs


#Check if Retrode Game is Gameboy/Gameboy Colour
elif [ ${#gbfind[@]} -gt 0 ]; then

#Check if Save File is on Retrode
if [ ${#srmfind[@]} -gt 0 ]; then
savefile=`basename /home/pi/retrode/*.srm`
#Check if File Exist in Rom Directory
if [ -f /home/pi/RetroPie/roms/gb/$savefile ]; then
echo "Save Data for this Game Exist"
else
cp -R /home/pi/retrode/*.srm /home/pi/RetroPie/roms/gb
fi
fi

#Check if File on the SNES Roms Folder
file=`basename /home/pi/retrode/*.gb`

if [ -f /home/pi/RetroPie/roms/gb/$file ]; then
echo "Mega Drive game Already Exist"
else
cp -R /home/pi/retrode/*.gb /home/pi/RetroPie/roms/gb
fi

#Run Gameboy/Gameboy Colour Emulator
/home/pi/RetroPie/supplementary/runcommand/runcommand.sh 1 "retroarch -L /home/pi/RetroPie/emulatorcores/gambatte-libretro/libgambatte/gambatte_libretro.so --config /home/pi/RetroPie/configs/all/retroarch.cfg --appendconfig /home/pi/RetroPie/configs/gb/retroarch.cfg /home/pi/RetroPie/roms/gb/"$file

#Check if Retrode Game is Gameboy Advance
elif [ ${#gbafind[@]} -gt 0 ]; then

#Check if File on the SNES Roms Folder
file=`basename /home/pi/retrode/*.gba`

if [ -f /home/pi/RetroPie/roms/gba/$file ]; then
echo "Mega Drive game Already Exist"
else
cp -R /home/pi/retrode/*.gba /home/pi/RetroPie/roms/gba
fi

#Run Gameboy Advance Emulator
/home/pi/RetroPie/supplementary/runcommand/runcommand.sh 1 "/home/pi/RetroPie/emulators/gpsp/raspberrypi/gpsp  /home/pi/RetroPie/roms/gba/"$file

#Unable to Load Game from Retrode
else
echo "Unable to Load Game from Retrode"
fi



Note we were talking about adding md5 check to make sure that it copied the file correctly. Also start removing un-needed linux objects.



Korori

abferm

I don't know how you would do this, but it should check to make sure you are not already running an emulator before launching one, and if it could automatically detect the retrode being plugged in that would be great(you could probably do this with a udev rule).

korori

This script is for when you boot making it more automated.

So basically right when you boot after the pi loads everything it then loads the script. I will make setup script to make this happen.

I am working on a newer version of the boot script as well. If anyone has bash knowledge be my guest and post what could be changed.

I am going back to using the emulationstation stuff to make it easier on blankspac and I.
--------------------------------------------------------------------------------------------
If you wish to auto login as user pi

1.) Edit /etc/inittab
2.) Comment this line
         1:2345:respawn:/sbin/getty --noclear 38400 tty1
3.) Type
        1:2345:respawn:/bin/login -f pi tty1</dev/tty1>/dev/tty1 2>&1
4.) This will autoboot as pi user
---------------------------------------------------------------------------------
To auto launch the boot script
1.) Edit /home/pi/.profile
2.) Depending on which script it will be either sudo or bash example:
     sudo bash retrode_boot.sh
--------------------------------------------------------------------
What I have done do far with the boot script. I am doing a completely redo the script. So the code below is still in testing that also goes with the code from previous post.


#!/bin/bash

#########################################################################################
#FILE EXTENSIONS#########################################################################
#########################################################################################

sfcExt="smc"
srmExt="srm"
mdExt="bin"

#########################################################################################
# LOCATION HANDLERS######################################################################
#########################################################################################

#Super Nintendo/Super Famicom
sfcfind=`find /home/pi/retrode/ -maxdepth 1 -name "\*.$sfcExt"`

#Save Data
srmfind=`find /home/pi/retrode/ -maxdepth 1 -name "\*.$srmExt"`

#Mega Drive/Sega Genesis
binfind=`find /home/pi/retrode/ -maxdepth 1 -name "\*.$mdExt"`

#Get Save File Name
savefile=`basename /home/pi/retrode/*.$srmExt`

#Save File Location Retrode
savelocretrode="/home/pi/retrode/*.$srmExt"

#Mount Directory of Retrode
mountdirectory="/home/pi/retrode"


#########################################################################################
# HELPER FUNCTIONS ######################################################################
#########################################################################################

function copySave()
{
if [[ $srmfind -gt 0 ]]; then
if [[ ! -f "$1/$savefile" ]]; then
cp -R "$savelocretrode $1"
fi
fi
}

function copyRom()
{
if [[ ! -f "$1/$2" ]]; then
cp -R "$mountdirectory/*.$3" "$1"
fi
}

function mountRetrode(){

sudo umount $1
sudo rm -rf $1
sudo mkdir -p $1
sudo mount -t vfat -o uid=pi,gid=pi /dev/sda $1
}


#########################################################################################
# PROGRAM STARTS#########################################################################
#########################################################################################

#Mount Retrode
mountRetrode "/home/pi/retrode"

#Check if Retrode Game is Super Nintendo/Super Famicom
if [[ $sfcfind -gt 0 ]]; then

#Check if Save File is on Retrode
copySave "/home/pi/RetroPie/roms/snes"

#Check if File on the SNES Roms Folder
file=`basename /home/pi/retrode/*.sfc`

copyRom "/home/pi/RetroPie/roms/snes" "$file" "$sfcExt"

#Run SNES Emulator
retroarch -L /home/pi/RetroPie/emulatorcores/pocketsnes-libretro/libretro.so --config /home/pi/RetroPie/configs/all/retroarch.cfg --appendconfig /home/pi/RetroPie/configs/snes/retroarch.cfg /home/pi/RetroPie/roms/snes/$file

#Check if Retrode Game is Mega Drive/Sega Genesis
elif [[ $binfind -gt 0 ]]; then


#Check if Save File is on Retrode
copySave "/home/pi/RetroPie/roms/megadrive"

#Check if File on the SNES Roms Folder
file=`basename /home/pi/retrode/*.bin`

copyRom "/home/pi/RetroPie/roms/megadrive" "$file" "$mdExt"

#Run Mega Drive/Sega Genesis Emulator
/home/pi/RetroPie/emulators/dgen-sdl/dgen -f -r /home/pi/RetroPie/configs/all/dgenrc /home/pi/RetroPie/roms/megadrive/$file

#Unable to Load Game from Retrode
else
echo "Unable to Load Game from Retrode"
fi



I hope this helps people out.


Korori

abferm

if you do it on boot, then you have to make sure you have the retrode plugged in at boot, and you can't unplug it and plug it back in with a different game without having to manually run the script.

korori

Sorry it took me a while. That is true you would have to completely reboot. I am still kinda new to bash scripting that is why blanc is helping me out. Not sure how I would fix that issue though since basically the script terminates after launching the emulator. If anyone has any idea on how to correct that issue it will be greatly appreciated. The only thing I could think of is scrapping the script or make a side program that launches and saves like an md5 of the rom in cache. Checks the retrode every 10 seconds or something while the emulator is running. But that is going beyond my knowledge at this time.

I have a Retrode Repo with anything/everything related to this project.

http://korori-gaming.com/repo/retrode/

Korori

emuDrache

The goal of database.trurip.org is to catalogue the software of as many classic systems as possible. database.trurip.org does not and will never host ISO or ROM downloads

abferm

I didn't think about crontab, that would be a good solution, but you would have to check running processes to see if there are already any emulators running. Also, I have a problem with you specifying sda as the device. If there is another storage device plugged into the pi it is hard to know which device will get assigned to sda.