-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmove_gamelist.sh
executable file
·88 lines (80 loc) · 3.1 KB
/
move_gamelist.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
# use with bash /path/to/move_gamelist.sh on rpi
function sed_wrapper {
sed -i "s/$(echo $1 | sed -e 's/\([[\/.*]\|\]\)/\\&/g')/$(echo $2 | sed -e 's/[\/&]/\\&/g')/g" $3
}
function usage {
echo 'moves gamelist.xml and media from rpi .emulationstation to the roms folder, and put relative paths in gamelist.xml'
echo 'usage:' "$0" '<platform> <--media|--images to use .emulationstation/downloaded_media or .emulationstation/downloaded_images>'
}
if [ "$#" -ne 2 ]; then
usage "$0"
exit 1
fi
if [ "$2" = '--media' ]; then
if [ ! -d "/home/pi/.emulationstation/downloaded_media/$1" ]; then
echo '[w] warning!' "/home/pi/.emulationstation/downloaded_media/$1" 'do not exists!'
exit 1
fi
elif [ "$2" = '--images' ]; then
if [ ! -d "/home/pi/.emulationstation/downloaded_images/$1" ]; then
echo '[w] warning!' "/home/pi/.emulationstation/downloaded_media/$1" 'do not exists!'
exit 1
fi
else
usage "$0"
exit 1
fi
# move gamelist
if [ ! -d "/home/pi/.emulationstation/gamelists/$1" ]; then
echo '[w] warning!' "/home/pi/.emulationstation/gamelists/$1" 'do not exists!'
else
echo '. moving gamelist to' "/home/pi/RetroPie/roms/$1/gamelist.xml"
mv "/home/pi/.emulationstation/gamelists/$1"/* "/home/pi/RetroPie/roms/$1"
if [ "$?" -eq 0 ]; then
rm -rf "/home/pi/.emulationstation/gamelists/$1"
fi
fi
if [ "$2" = '--media' ]; then
echo '. moving media to' "/home/pi/RetroPie/roms/$1/media"
mkdir -p "/home/pi/RetroPie/roms/$1/media"
mv "/home/pi/.emulationstation/downloaded_media/$1"/* "/home/pi/RetroPie/roms/$1/media"
if [ "$?" -eq 0 ]; then
rm -rf "/home/pi/.emulationstation/downloaded_media/$1"
fi
else
echo '. moving images to' "/home/pi/RetroPie/roms/$1/media"
mkdir -p "/home/pi/RetroPie/roms/$1/media/snap"
mv "/home/pi/.emulationstation/downloaded_images/$1"/* "/home/pi/RetroPie/roms/$1/media/snap"
if [ "$?" -eq 0 ]; then
rm -rf "/home/pi/.emulationstation/downloaded_images/$1"
fi
fi
# replace
echo '. fixing paths in' "/home/pi/RetroPie/roms/$1/gamelist.xml"
if [ "$2" = '--media' ]; then
_old="/home/pi/RetroPie/roms/$1"
_new="."
sed_wrapper "$_old" "$_new" "/home/pi/RetroPie/roms/$1/gamelist.xml"
if [ "$?" -eq 0 ]; then
_old="/home/pi/.emulationstation/downloaded_media/$1"
_new="./media"
sed_wrapper "$_old" "$_new" "/home/pi/RetroPie/roms/$1/gamelist.xml"
_old="~/.emulationstation/downloaded_media/$1"
_new="./media"
sed_wrapper "$_old" "$_new" "/home/pi/RetroPie/roms/$1/gamelist.xml"
fi
else
_old="/home/pi/RetroPie/roms/$1"
_new="."
sed_wrapper "$_old" "$_new" "/home/pi/RetroPie/roms/$1/gamelist.xml"
if [ "$?" -eq 0 ]; then
_old="/home/pi/.emulationstation/downloaded_images/$1"
_new="./media/snap"
sed_wrapper "$_old" "$_new" "/home/pi/RetroPie/roms/$1/gamelist.xml"
_old="~/.emulationstation/downloaded_images/$1"
_new="./media/snap"
sed_wrapper "$_old" "$_new" "/home/pi/RetroPie/roms/$1/gamelist.xml"
fi
fi
echo '. done!'