-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpi4_pushroms.sh
executable file
·290 lines (270 loc) · 7.66 KB
/
pi4_pushroms.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#!/bin/bash
. ./settings
# a few things to set beforehand
SCRIPTPATH=$(pwd)
# the extension of the roms
EXT='zip'
# the location of the MAME (current) fullset
MAMEROMDIR=$GAMESDIR/mame/
# the location of the MAME 2003 fullset on the local host
MAME2k3ROMDIR=$GAMESDIR/mame2003/
# the location of the Final Burn Neo fullset on the local host
FBNEOROMDIR=$GAMESDIR/fbneo/
# the complete list of games
$MAMEBIN -listfull | sort | uniq > ${SCRIPTPATH}/LISTFULL
# the complete list of clones only
$MAMEBIN -listclones | awk '{print $1}' | sort | uniq > ${SCRIPTPATH}/LISTCLONES
# the complete list of drivers
$MAMEBIN -listsource | sort | uniq > ${SCRIPTPATH}/LISTSOURCE
# Print things in beautiful colors
# This is the generic formatting function
# Colors are defined in specific functions below
print_color() {
printf "%-10.9s%-10.9s\e[1;${4}m%-60s\e[0m\n" "$1" "$2" "$3"
}
print_red() {
print_color "$1" "$2" "$3" "31"
}
print_green() {
print_color "$1" "$2" "$3" "32"
}
print_yellow() {
print_color "$1" "$2" "$3" "33"
}
print_blue() {
print_color "$1" "$2" "$3" "34"
}
# The standard usage message when no argument is given
usage() {
printf "Usage: $0 <MAME gamename>"
exit 1
}
# Print out an error message when an error is encountered
die() {
printf "ERROR: $1"
exit 1
}
# Test if a game is present in the clone list
is_clone() {
return $(grep -q -w -e "^${1}" ${SCRIPTPATH}/LISTCLONES)
}
# Test if a game is already present on the remote Pi
is_present() {
return $(ssh ${PI4_USER}@${PI4_IP} "test -f ${PI4_ROMPATH}/*/${1}.${EXT}")
}
# Upload a game to the remote host
push_game() {
if is_present ${2}; then
# If the game is already on the remote host we just skip it
print_yellow "dup" "$2" "${FULLNAME}"
else
# Otherwise we upload it to the appropriate folder
if [ -f ${2}.${EXT} ]; then
# Unless STAGING=1 is set at runtime, then we're only doing a dry run
if [ -n "${STAGING+1}" ]; then
print_yellow "staging" "$2" "not pushing"
else
print_green "$1" "$2" "$FULLNAME"
# Push the rom through an SSH tunnel
rsync -aq --update -e ssh ${2}.${EXT} ${PI4_USER}@${PI4_IP}:${PI4_ROMPATH}/${1}/${2}.${EXT}
fi
else
# If the rom is not found, display a message but continue
print_red "critical" "$2" "not found"
fi
fi
}
# merge parent game $1 with correct version $2
# maybe this could replace the cps3 function in the future
merge_parent_game() {
if is_present ${2}; then
# If the game is already on the remote host we just skip it
print_yellow "dup" "$2" "${FULLNAME}"
else
# not necessary for now since all games are FBNeo, but present in case
if [ -f ${FBNEOROMDIR}/${1}.${EXT} ]; then
EMUROMDIR="fbneo"
elif [ -f ${MAME2k3ROMDIR}/${1}.${EXT} ]; then
EMUROMDIR="mame2003"
else
die "rom files for $1 not found"
fi
# create a temp folder
mkdir -p /tmp/${2}
cd /tmp/${2}
# merge the parent rom with the child rom
echo "Merging $2 into $1"
if [ ${EXT} == 'zip' ]; then
unzip -qo ${GAMESDIR}/${EMUROMDIR}/${1}.${EXT}
unzip -qo ${GAMESDIR}/${EMUROMDIR}/${2}.${EXT}
zip -qo -9 ${1}.${EXT} *
elif [ ${EXT} == '7z' ]; then
7z x -y ${GAMESDIR}/${EMUROMDIR}/${1}.${EXT} > /dev/null
7z x -y ${GAMESDIR}/${EMUROMDIR}/${2}.${EXT} > /dev/null
7z a -y ${1}.${EXT} * > /dev/null
else
die "unknown extension"
fi
# upload the resulting game
# not using push_game as the alternative name might not be in MAME anymore
print_green "$EMUROMDIR" "$2" "$FULLNAME"
rsync -aq --update -e ssh /tmp/${2}/${1}.${EXT} ${PI4_USER}@${PI4_IP}:${PI4_ROMPATH}/${EMUROMDIR}/${1}.${EXT}
cd /tmp
# remove the temp folder
[[ -d /tmp/${2} ]] && rm -rf /tmp/${2}
fi
}
# find if we need to push an alternate game
push_alt_game() {
case "$2" in
simpsons)
ALTROM="simpsons2p"
merge_parent_game ${2} ${ALTROM}
;;
ssriders)
ALTROM="ssridersubc"
merge_parent_game ${2} ${ALTROM}
;;
tmnt)
ALTROM="tmht2p"
merge_parent_game ${2} ${ALTROM}
;;
tmnt2)
ALTROM="tmnt22pu"
merge_parent_game ${2} ${ALTROM}
;;
xmen)
ALTROM="xmen2pu"
merge_parent_game ${2} ${ALTROM}
;;
esac
# with Konami games we need to merge
# this might not be necessary with future cases
}
# handle specific cases
push_emu() {
case "$2" in
${KONAMI})
push_alt_game "$1" "$2"
;;
${BOOTLEG})
print_yellow "bootleg" "$2" "${FULLNAME}"
;;
${CONVERSION})
print_yellow "convert" "$2" "${FULLNAME}"
;;
${FISHING})
print_yellow "fishing" "$2" "${FULLNAME}"
;;
${GUN})
print_yellow "lightgun" "$2" "${FULLNAME}"
;;
${KOREA})
print_yellow "korea" "$2" "${FULLNAME}"
;;
${MAHJONG})
print_yellow "mahjong" "$2" "${FULLNAME}"
;;
${MATURE})
print_yellow "mature" "$2" "${FULLNAME}"
;;
${PURIKURA})
print_yellow "purikura" "$2" "${FULLNAME}"
;;
${PROTOTYPE})
print_yellow "prototype" "$2" "${FULLNAME}"
;;
${QUIZZES})
print_yellow "quiz" "$2" "${FULLNAME}"
;;
${RACING})
print_yellow "racing" "$2" "${FULLNAME}"
;;
${REJECTS})
print_yellow "blacklist" "$2" "${FULLNAME}"
;;
*)
push_game "$1" "$2"
;;
esac
}
# find out if game will run with MAME 2003 or Final Burn Neo
select_emu() {
# default emulator is FBNeo
if [ -f ${FBNEOROMDIR}/"$1".${EXT} ]
then
cd ${FBNEOROMDIR}
push_emu fbneo "$1"
elif [ -f $MAME2k3ROMDIR/"$1".${EXT} ]
then
cd ${MAME2k3ROMDIR}/
push_emu mame2003 "$1"
else print_red "notfound" "$1" "skipping..."
fi
}
# handle driver-specific cases
select_driver() {
case "$2" in
model1|model2|stv|segabill)
cd ${MAMEROMDIR}
push_emu mame "$1"
;;
cps[23]|neogeo|raiden2|segaxbd|segas16a|segas16b|toaplan2)
# FBNeo mandatory with Pi 4 but better perfs with less overheating
cd ${FBNEOROMDIR}
push_emu fbneo "$1"
;;
# cps3)
# # CPS3 games must be handled separately to deal with NoCD roms
# push_cps3_game "$1"
# ;;
dec0)
# issues with Final Burn, forcing MAME here
cd ${MAME2k3ROMDIR}
push_emu mame2003 "$1"
;;
# blacklisted drivers
# some could be whitelisted for Pi4
namcos11|jalmah|mahjong|royalmah)
print_red "denied" "$1" "driver not allowed"
;;
*)
select_emu "$1"
;;
esac
}
# test argument presence
if [ $# -lt 1 ]
then
usage
fi
# main loop
while [ $# -ne 0 ]
do
if is_present "$1"; then
# not pushing again a game already present
# TODO: make sure this is not redundant with code above
print_yellow "dup" "$1" "game already present, skipping driver"
else
# find which driver this is, using current version of MAME
# we *really* don't want to parse XML files
# this should be replaced by a flat file though
DRIVER=$(grep -w -e "^${1}" ${SCRIPTPATH}/LISTSOURCE | awk '{print $2}' | cut -d '.' -f 1)
print_blue "Emulator" "Rom" "Driver: ${DRIVER}"
# push games running on the same driver
# this helps discovering lesser-known games that are probably of interest
for GAME in $(grep -w "${DRIVER}.cpp" ${SCRIPTPATH}/LISTSOURCE | awk '{print $1}')
do
# avoid clones, we only want originals
if ! is_clone ${GAME}
then
# get the game's fullname from MAME
FULLNAME=$(grep -w -e "^${GAME}" ${SCRIPTPATH}/LISTFULL | cut -d '"' -f 2 | tr '/' '_' | sed 's/\ \~\ /\)\(/')
select_driver ${GAME} ${DRIVER}
fi
done
fi
shift
done
rm -f ${SCRIPTPATH}/LISTFULL ${SCRIPTPATH}/LISTSOURCE ${SCRIPTPATH}/LISTCLONES
exit 0