Initial commit

This commit is contained in:
Wyrrrd
2021-06-13 15:40:19 +02:00
parent 9ae7817a81
commit df2393db1b
4 changed files with 162 additions and 1 deletions

View File

@@ -1,2 +1,76 @@
# RetroPie-sync
Sync ROMs from network directory.
## Description
Syncs your ROMs and metadata from a network (or any other) directory.
Be careful with this quick hacky script, it might stir up or delete your ROMs, gamelists and boxarts if you are not careful. Always backup and test. Use read-only where possible. Read "[Known Issues](#known-issues)" below.
## Setup
### Configuration Options
Configurations are made in the file `retropie_sync.conf`. The following options have to be set for the script to work.
| Parameter | Usage | Default |
| --- | --- | --- |
| sourcepath | path your data will be synced from (should be read-only) | - |
| romspath | path your ROMs will be synced to, empty disables this | romspath="/home/pi/RetroPie/roms" |
| metapath | path your EmulationStation metadata will be synced to, empty disables this | metapath="/home/pi/.emulationstation" |
| systems | list of systems to sync data for | systems=("gb" "gbc" "gba" "nes" "snes") |
| restart | if EmulationStation should be restarted on changes (hacky, read "[Known Issues](#known-issues)" below) | restart=false |
| retries | number of retries until script stops for good, set to 0 if using local sync | retries=10 |
| retryinterval | number of seconds between retries | retryinterval=10 |
### Intended Setup
I wrote this script for a [PiBoy DMG](https://www.experimentalpi.com/PiBoy-DMG--Full-Kit_p_18.html), but keep my master ROMs directory on a CIFS network share in my home network. The following steps are needed to replicate my setup, which I tested, works for me :)
#### Network directory setup
If ROM sync is enabled, this script expects your ROMs to be sorted on your network share as they would be in RetroPie (separated by subfolders named after their respective systems). More nested folders inside of those (e.g. "Romhacks", "Pokemon" etc.) are okay.
Additionally, if metadata sync is enabled, the script expects a directory `.emulationstation` in the network share root, that contains subfolders for gamelists and downloaded images. You can copy them from your RetroPie under `/home/pi/.emulationstation/gamelists` and `/home/pi/.emulationstation/downloaded_images`.
#### Move Savestates and Savegames
Savestates and savegames are normally stored in `/home/pi/RetroPie/roms`. Since we want to sync ROMs to that directory, we need to move them.
Connect to your RetroPie via SSH.
```
mkdir /home/pi/RetroPie/saves
find $directory -type f -name "*.srm" -or -name "*.sav" -or -name "*.state*" -exec mv {} /home/pi/RetroPie/saves/ \;
```
Then, in EmulationStation, open Retroarch Settings, go to "Settings" #8594; "Directories" and set both "Savegames" and "Savestates" to `/home/pi/RetroPie/saves`.
Go to "Settings" #8594; "Configuration", check "Save configuration on exit", then exit.
#### Install autofs
```
sudo apt-get install autofs
```
#### Configure autofs
Add the following line to `/etc/auto.master`:
```
/media/cifs /etc/auto.cifs-shares --timeout=60 --ghost
```
Add the file `/etc/auto.cifs-shares` with the following contents:
```
roms -fstype=cifs,uid=1000,credentials=/home/pi/.smbcredentials,ro ://path.to/network/share
```
Add the file `/home/pi/.smbcredentials` with your read-only network share credentials:
```
username=changeme
password=changeme
```
#### Make RetroPie-sync autostart
Add the following line to `/opt/retropie/configs/all/autostart.sh`, as first line before everything else:
```
/home/pi/RetroPie-sync/retropie_sync.sh &
```
### Known Issues
- [ ] Gamelists are not being merged. If EmulationStation updates local gamelist, older but more up to date remote gamelist might not be synced.
- [ ] Even if gamelists are synced, "LastPlayed" info is lost.
- [ ] Only sound to signal changes to the user is not sufficient, adding a visual notification would be better.
- [ ] EmulationStation restart is hacky. If a game is started, and quit after EmulationStation restart, Retropie doesn't find it's way back to EmulationStation.
## Credits
The sound `done.wav` is "[Laser Cannon](https://soundbible.com/1771-Laser-Cannon.html)" by Mike Koenig, which is licensed under [Attribution 3.0](https://creativecommons.org/licenses/by/3.0/). Though the file was renamed, the sound within was not modified.

BIN
done.wav Normal file

Binary file not shown.

7
retropie_sync.conf Normal file
View File

@@ -0,0 +1,7 @@
sourcepath="/media/cifs/roms" #changeme
romspath="/home/pi/RetroPie/roms"
metapath="/home/pi/.emulationstation"
systems=("gb" "gbc" "gba" "nes" "snes")
restart=false
retries=10
retryinterval=10

80
retropie_sync.sh Normal file
View File

@@ -0,0 +1,80 @@
#!/bin/bash
# Sync ROMs from network directory.
# Version 1.0.0, c/o Wyrrrd
# 09.06.2021
echo "# retropie_sync"
echo "# Sync ROMs from other directory."
echo "# Version 1.0.0, c/o Wyrrrd"
echo "# 09.06.2021"
romspath="/home/pi/RetroPie/roms"
metapath="/home/pi/.emulationstation"
systems=("gb" "gbc" "gba" "nes" "snes")
restart=false
retries=10
retryinterval=10
. $(dirname $0)/retropie_sync.conf
if [[ -z $sourcepath ]]
then
for (( i=0; $i<=$retries; i++ ))
do
if [[ -z $sourcepath && "$(ls -A $sourcepath)" ]]
then
echo "Source path is not empty. Starting sync."
len=${#systems[@]}
for (( j=0; $j<$len; j++ ))
do
system=${systems[j]}
if [[ "$ls -A $sourcepath/$system)" ]]
then
echo "Syncing system $system ($((j+1))/$len)"
if [[ -z $romspath ]]
then
echo " - Syncing ROMs"
mkdir -p $romspath/$system
[[ $(rsync -aiz --delete $sourcepath/$system/* $romspath/$system) ]] && changes=true
fi
if [[ -z $metapath ]]
then
echo " - Syncing gamelist"
mkdir -p $metapath/gamelists/$system
[[ $(rsync -aiz --delete $sourcepath/.emulationstation/gamelists/$system/* $metapath/gamelists/$system) ]] && changes=true
echo " - Syncing boxarts"
mkdir -p $metapath/downloaded_images/$system
[[ $(rsync -aiz --delete $sourcepath/.emulationstation/downloaded_images/$system/* $metapath/downloaded_images/$system) ]] && changes=true
fi
fi
done
echo "Sync completed."
if [[ $changes ]]
then
echo "There are changes. Playing change laser."
aplay $(dirname $0)/done.wav > /dev/null
fi
if [[ $retries -gt 0 ]]
then
echo "$i of $retries retries needed."
fi
break
else
echo "Source path is empty. Not syncing to avoid data loss."
if [[ $retries -gt 0 ]]
then
echo " - Retrying in $retryinterval seconds."
sleep 10
else
break
fi
fi
done
else
echo "Source path not set, aborting."
fi