forked from RetroPie/RetroPie-Setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathretropie_setup.sh
executable file
·2929 lines (2609 loc) · 114 KB
/
retropie_setup.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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# RetroPie-Setup - Shell script for initializing Raspberry Pi
# with RetroArch, various cores, and EmulationStation (a graphical
# front end).
#
# (c) Copyright 2012 Florian Müller ([email protected])
#
# RetroPie-Setup homepage: https://github.com/petrockblog/RetroPie-Setup
#
# Permission to use, copy, modify and distribute RetroPie-Setup in both binary and
# source form, for non-commercial purposes, is hereby granted without fee,
# providing that this license information and copyright notice appear with
# all copies and any derived work.
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event shall the authors be held liable for any damages
# arising from the use of this software.
#
# RetroPie-Setup is freeware for PERSONAL USE only. Commercial users should
# seek permission of the copyright holders first. Commercial use includes
# charging money for RetroPie-Setup or software derived from RetroPie-Setup.
#
# The copyright holders request that bug fixes and improvements to the code
# should be forwarded to them so everyone can benefit from the modifications
# in future versions.
#
# Many, many thanks go to all people that provide the individual packages!!!
#
# Raspberry Pi is a trademark of the Raspberry Pi Foundation.
#
__ERRMSGS=""
__INFMSGS=""
__doReboot=0
# HELPER FUNCTIONS ###
function ask()
{
echo -e -n "$@" '[y/n] ' ; read ans
case "$ans" in
y*|Y*) return 0 ;;
*) return 1 ;;
esac
}
function addLineToFile()
{
if [[ -f "$2" ]]; then
cp "$2" ./temp
sudo mv "$2" "$2.old"
fi
echo "$1" >> ./temp
sudo mv ./temp "$2"
echo "Added $1 to file $2"
}
# arg 1: key, arg 2: value, arg 3: file
# make sure that a key-value pair is set in file
# key = value
function ensureKeyValue()
{
if [[ -z $(egrep -i "#? *$1 = ""?[+|-]?[0-9]*[a-z]*"""? $3) ]]; then
# add key-value pair
echo "$1 = ""$2""" >> $3
else
# replace existing key-value pair
toreplace=`egrep -i "#? *$1 = ""?[+|-]?[0-9]*[a-z]*"""? $3`
sed $3 -i -e "s|$toreplace|$1 = ""$2""|g"
fi
}
# make sure that a key-value pair is NOT set in file
# # key = value
function disableKeyValue()
{
if [[ -z $(egrep -i "#? *$1 = ""?[+|-]?[0-9]*[a-z]*"""? $3) ]]; then
# add key-value pair
echo "# $1 = ""$2""" >> $3
else
# replace existing key-value pair
toreplace=`egrep -i "#? *$1 = ""?[+|-]?[0-9]*[a-z]*"""? $3`
sed $3 -i -e "s|$toreplace|# $1 = ""$2""|g"
fi
}
# arg 1: key, arg 2: value, arg 3: file
# make sure that a key-value pair is set in file
# key=value
function ensureKeyValueShort()
{
if [[ -z $(egrep -i "#? *$1\s?=\s?""?[+|-]?[0-9]*[a-z]*"""? $3) ]]; then
# add key-value pair
echo "$1=""$2""" >> $3
else
# replace existing key-value pair
toreplace=`egrep -i "#? *$1\s?=\s?""?[+|-]?[0-9]*[a-z]*"""? $3`
sed $3 -i -e "s|$toreplace|$1=""$2""|g"
fi
}
# make sure that a key-value pair is NOT set in file
# # key=value
function disableKeyValueShort()
{
if [[ -z $(egrep -i "#? *$1=""?[+|-]?[0-9]*[a-z]*"""? $3) ]]; then
# add key-value pair
echo "# $1=""$2""" >> $3
else
# replace existing key-value pair
toreplace=`egrep -i "#? *$1=""?[+|-]?[0-9]*[a-z]*"""? $3`
sed $3 -i -e "s|$toreplace|# $1=""$2""|g"
fi
}
# ensures pair of key ($1)-value ($2) in file $3
function ensureKeyValueBootconfig()
{
if [[ -z $(egrep -i "#? *$1=[+|-]?[0-9]*[a-z]*" $3) ]]; then
# add key-value pair
echo "$1=$2" >> $3
else
# replace existing key-value pair
toreplace=`egrep -i "#? *$1=[+|-]?[0-9]*[a-z]*" $3`
sed $3 -i -e "s|$toreplace|$1=$2|g"
fi
}
function printMsg()
{
echo -e "\n= = = = = = = = = = = = = = = = = = = = =\n$1\n= = = = = = = = = = = = = = = = = = = = =\n"
}
function rel2abs() {
cd "$(dirname $1)" && dir="$PWD"
file="$(basename $1)"
echo $dir/$file
}
function checkForInstalledAPTPackage()
{
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $1|grep "install ok installed")
echo Checking for somelib: $PKG_OK
if [ "" == "$PKG_OK" ]; then
echo "NOT INSTALLED: $1"
else
echo "installed: $1"
fi
}
function checkFileExistence()
{
if [[ -f "$1" ]]; then
ls -lh "$1" >> "$rootdir/debug.log"
else
echo "$1 does NOT exist." >> "$rootdir/debug.log"
fi
}
# clones or updates the sources of a repository $2 into the directory $1
function gitPullOrClone()
{
if [[ -d "$1/.git" ]]; then
pushd "$1"
git pull
else
rm -rf "$1" # makes sure that the directory IS empty
mkdir -p "$1"
git clone --depth=0 "$2" "$1"
pushd "$1"
fi
}
# END HELPER FUNCTIONS ###
function availFreeDiskSpace()
{
local __required=$1
local __avail=`df -P $rootdir | tail -n1 | awk '{print $4}'`
if [[ "$__required" -le "$__avail" ]] || ask "Minimum recommended disk space (500 MB) not available. Try 'sudo raspi-config' to resize partition to full size. Only $__avail available at $rootdir continue anyway?"; then
return 0;
else
exit 0;
fi
}
function install_rpiupdate()
{
# install latest rpi-update script (to enable firmware update)
printMsg "Installing latest rpi-update script"
# make sure that certificates are installed
apt-get install -y ca-certificates
wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update && chmod +x /usr/bin/rpi-update
}
function run_rpiupdate()
{
printMsg "Starting rpi-update script"
/usr/bin/rpi-update
__doReboot=1
chmod 777 /dev/fb0
ensureKeyValueShort "gpu_mem" "128" "/boot/config.txt"
}
# update APT repositories
function update_apt()
{
printMsg "Updating APT-GET database"
apt-get -y update
}
# upgrade APT packages
function upgrade_apt()
{
printMsg "Performing APT-GET upgrade"
apt-get -y upgrade
chmod 777 /dev/fb0
ensureKeyValueShort "gpu_mem" "128" "/boot/config.txt"
}
function configureBootConfig()
{
ensureKeyValueShort "gpu_mem" "128" "/boot/config.txt"
ensureKeyValueShort "overscan_scale" "1" "/boot/config.txt"
}
# add user $user to groups "video", "audio", and "input"
function add_to_groups()
{
printMsg "Adding user $user to groups video, audio, and input."
add_user_to_group $user video
add_user_to_group $user audio
add_user_to_group $user input
}
# add user $1 to group $2, create the group if it doesn't exist
function add_user_to_group()
{
if [ -z $(egrep -i "^$2" /etc/group) ]
then
sudo addgroup $2
fi
sudo adduser $1 $2
}
# make sure ALSA, uinput, and joydev modules are active
function ensure_modules()
{
printMsg "Enabling ALSA, uinput, and joydev modules permanently"
sudo modprobe snd_bcm2835
sudo modprobe uinput
sudo modprobe joydev
if ! grep -q "uinput" /etc/modules; then
addLineToFile "uinput" "/etc/modules"
else
echo -e "uinput module already contained in /etc/modules"
fi
if ! grep -q "joydev" /etc/modules; then
addLineToFile "joydev" "/etc/modules"
else
echo -e "joydev module already contained in /etc/modules"
fi
}
# needed by SDL for working joypads
function exportSDLNOMOUSE()
{
printMsg "Exporting SDL_NOMOUSE=1 permanently to $home/.bashrc"
export SDL_NOMOUSE=1
if ! grep -q "export SDL_NOMOUSE=1" $home/.bashrc; then
echo -e "\nexport SDL_NOMOUSE=1" >> $home/.bashrc
else
echo -e "SDL_NOMOUSE=1 already contained in $home/.bashrc"
fi
}
# make sure that all needed packages are installed
function installAPTPackages()
{
printMsg "Making sure that all needed packaged are installed"
apt-get install -y libsdl1.2-dev screen scons libasound2-dev pkg-config libgtk2.0-dev \
libboost-filesystem-dev libboost-system-dev zip python-imaging \
libfreeimage-dev libfreetype6-dev libxml2 libxml2-dev libbz2-dev \
libaudiofile-dev libsdl-sound1.2-dev libsdl-mixer1.2-dev \
joystick fbi gcc-4.7 automake1.4 libcurl4-openssl-dev libzip-dev \
build-essential nasm libgl1-mesa-dev libglu1-mesa-dev libsdl1.2-dev \
libvorbis-dev libpng12-dev libvpx-dev freepats subversion \
libboost-serialization-dev libboost-thread-dev libsdl-ttf2.0-dev \
cmake g++-4.7 unrar-free p7zip p7zip-full libeigen3-dev
# libgles2-mesa-dev
# remove PulseAudio since this is slowing down the whole system significantly
apt-get remove -y pulseaudio
apt-get -y autoremove
}
# remove all packages that are installed by the RetroPie Setup Script
function removeAPTPackages()
{
printMsg "Making sure that all packages that are installed by the script are removed."
apt-get remove -y libsdl1.2-dev screen scons libasound2-dev pkg-config libgtk2.0-dev \
libboost-filesystem-dev libboost-system-dev zip python-imaging \
libfreeimage-dev libfreetype6-dev libxml2 libxml2-dev libbz2-dev \
libaudiofile-dev libsdl-sound1.2-dev libsdl-mixer1.2-dev \
joystick fbi gcc-4.7 automake1.4 libcurl4-openssl-dev libzip-dev \
build-essential nasm libgl1-mesa-dev libglu1-mesa-dev libsdl1.2-dev \
libvorbis-dev libpng12-dev libvpx-dev freepats subversion \
libboost-serialization-dev libboost-thread-dev libsdl-ttf2.0-dev \
cmake g++-4.7 unrar-free p7zip p7zip-full libeigen3-dev
# libgles2-mesa-dev
apt-get -y autoremove
dialog --backtitle "PetRockBlock.com - RetroPie Setup. Installation folder: $rootdir for user $user" --msgbox "Successfully removed APT packages. For a complete uninstall you need to delete the 'RetroPie' folder on your own." 22 76
}
# start SNESDev on boot and configure RetroArch input settings
function enableSplashscreenAtStart()
{
clear
printMsg "Enabling custom splashscreen on boot."
chmod +x "$scriptdir/supplementary/asplashscreen/asplashscreen"
cp "$scriptdir/supplementary/asplashscreen/asplashscreen" /etc/init.d/
cp "$scriptdir/supplementary/asplashscreen/splashscreen.png" /etc/
# This command installs the init.d script so it automatically starts on boot
insserv /etc/init.d/asplashscreen
# not-so-elegant hack for later re-enabling the splashscreen
update-rc.d asplashscreen enable
}
# disable start SNESDev on boot and remove RetroArch input settings
function disableSplashscreenAtStart()
{
clear
printMsg "Disabling custom splashscreen on boot."
update-rc.d asplashscreen disable
}
# Show dialogue for enabling/disabling SNESDev on boot
function enableDisableSplashscreen()
{
cmd=(dialog --backtitle "PetRockBlock.com - RetroPie Setup. Installation folder: $rootdir for user $user" --menu "Choose the desired boot behaviour." 22 86 16)
options=(1 "Disable custom splashscreen on boot."
2 "Enable custom splashscreen on boot")
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
if [ "$choices" != "" ]; then
case $choices in
1) disableSplashscreenAtStart
dialog --backtitle "PetRockBlock.com - RetroPie Setup. Installation folder: $rootdir for user $user" --msgbox "Disabled custom splashscreen on boot." 22 76
;;
2) enableSplashscreenAtStart
dialog --backtitle "PetRockBlock.com - RetroPie Setup. Installation folder: $rootdir for user $user" --msgbox "Enabled custom splashscreen on boot." 22 76
;;
esac
else
break
fi
}
# prepare folder structure for emulator, cores, front end, and roms
function prepareFolders()
{
printMsg "Creating folder structure for emulator, front end, cores, and roms"
pathlist=()
pathlist+=("$rootdir/roms")
pathlist+=("$rootdir/roms/atari2600")
pathlist+=("$rootdir/roms/basiliskii")
pathlist+=("$rootdir/roms/c64")
pathlist+=("$rootdir/roms/cavestory")
pathlist+=("$rootdir/roms/doom")
pathlist+=("$rootdir/roms/duke3d/")
pathlist+=("$rootdir/roms/esconfig/")
pathlist+=("$rootdir/roms/gamegear")
pathlist+=("$rootdir/roms/gb")
pathlist+=("$rootdir/roms/gba")
pathlist+=("$rootdir/roms/gbc")
pathlist+=("$rootdir/roms/intellivision")
pathlist+=("$rootdir/roms/mame")
pathlist+=("$rootdir/roms/mastersystem")
pathlist+=("$rootdir/roms/megadrive")
pathlist+=("$rootdir/roms/nes")
pathlist+=("$rootdir/roms/pcengine")
pathlist+=("$rootdir/roms/psx")
pathlist+=("$rootdir/roms/psp")
pathlist+=("$rootdir/roms/snes")
pathlist+=("$rootdir/roms/zxspectrum")
pathlist+=("$rootdir/roms/fba")
pathlist+=("$rootdir/roms/amiga")
pathlist+=("$rootdir/roms/neogeo")
pathlist+=("$rootdir/roms/scummvm")
pathlist+=("$rootdir/roms/x86")
pathlist+=("$rootdir/roms/zmachine")
pathlist+=("$rootdir/emulatorcores")
pathlist+=("$rootdir/emulators")
pathlist+=("$rootdir/supplementary")
for elem in "${pathlist[@]}"
do
if [[ ! -d $elem ]]; then
mkdir -p $elem
chown $user $elem
chgrp $user $elem
fi
done
}
# settings for RetroArch
function configureRetroArch()
{
printMsg "Configuring RetroArch"
if [[ ! -f "$rootdir/configs/all/retroarch.cfg" ]]; then
mkdir -p "$rootdir/configs/all/"
mkdir -p "$rootdir/configs/atari2600/"
echo -e "# All settings made here will override the global settings for the current emulator core\n" >> $rootdir/configs/atari2600/retroarch.cfg
mkdir -p "$rootdir/configs/cavestory/"
echo -e "# All settings made here will override the global settings for the current emulator core\n" >> $rootdir/configs/cavestory/retroarch.cfg
mkdir -p "$rootdir/configs/doom/"
echo -e "# All settings made here will override the global settings for the current emulator core\n" >> $rootdir/configs/doom/retroarch.cfg
mkdir -p "$rootdir/configs/gb/"
echo -e "# All settings made here will override the global settings for the current emulator core\n" >> $rootdir/configs/gb/retroarch.cfg
mkdir -p "$rootdir/configs/gbc/"
echo -e "# All settings made here will override the global settings for the current emulator core\n" >> $rootdir/configs/gbc/retroarch.cfg
mkdir -p "$rootdir/configs/gamegear/"
echo -e "# All settings made here will override the global settings for the current emulator core\n" >> $rootdir/configs/gamegear/retroarch.cfg
mkdir -p "$rootdir/configs/mame/"
echo -e "# All settings made here will override the global settings for the current emulator core\n" >> $rootdir/configs/mame/retroarch.cfg
mkdir -p "$rootdir/configs/mastersystem/"
echo -e "# All settings made here will override the global settings for the current emulator core\n" >> $rootdir/configs/mastersystem/retroarch.cfg
mkdir -p "$rootdir/configs/nes/"
echo -e "# All settings made here will override the global settings for the current emulator core\n" >> $rootdir/configs/nes/retroarch.cfg
mkdir -p "$rootdir/configs/pcengine/"
echo -e "# All settings made here will override the global settings for the current emulator core\n" >> $rootdir/configs/pcengine/retroarch.cfg
mkdir -p "$rootdir/configs/psx/"
echo -e "# All settings made here will override the global settings for the current emulator core\n" >> $rootdir/configs/psx/retroarch.cfg
mkdir -p "$rootdir/configs/snes/"
echo -e "# All settings made here will override the global settings for the current emulator core\n" >> $rootdir/configs/snes/retroarch.cfg
mkdir -p "$rootdir/configs/fba/"
echo -e "# All settings made here will override the global settings for the current emulator core\n" >> $rootdir/configs/fba/retroarch.cfg
cp /etc/retroarch.cfg "$rootdir/configs/all/"
fi
ensureKeyValue "system_directory" "$rootdir/emulatorcores/" "$rootdir/configs/all/retroarch.cfg"
ensureKeyValue "video_aspect_ratio" "1.33" "$rootdir/configs/all/retroarch.cfg"
ensureKeyValue "video_smooth" "false" "$rootdir/configs/all/retroarch.cfg"
# enable hotkey ("select" button)
ensureKeyValue "input_exit_emulator" "escape" "$rootdir/configs/all/retroarch.cfg"
# enable and configure rewind feature
ensureKeyValue "rewind_enable" "true" "$rootdir/configs/all/retroarch.cfg"
ensureKeyValue "rewind_buffer_size" "10" "$rootdir/configs/all/retroarch.cfg"
ensureKeyValue "rewind_granularity" "2" "$rootdir/configs/all/retroarch.cfg"
ensureKeyValue "input_rewind" "r" "$rootdir/configs/all/retroarch.cfg"
# configure keyboard mappings
ensureKeyValue "input_player1_a" "x" "$rootdir/configs/all/retroarch.cfg"
ensureKeyValue "input_player1_b" "z" "$rootdir/configs/all/retroarch.cfg"
ensureKeyValue "input_player1_y" "a" "$rootdir/configs/all/retroarch.cfg"
ensureKeyValue "input_player1_x" "s" "$rootdir/configs/all/retroarch.cfg"
ensureKeyValue "input_player1_start" "enter" "$rootdir/configs/all/retroarch.cfg"
ensureKeyValue "input_player1_select" "rshift" "$rootdir/configs/all/retroarch.cfg"
ensureKeyValue "input_player1_l" "q" "$rootdir/configs/all/retroarch.cfg"
ensureKeyValue "input_player1_r" "w" "$rootdir/configs/all/retroarch.cfg"
ensureKeyValue "input_player1_left" "left" "$rootdir/configs/all/retroarch.cfg"
ensureKeyValue "input_player1_right" "right" "$rootdir/configs/all/retroarch.cfg"
ensureKeyValue "input_player1_up" "up" "$rootdir/configs/all/retroarch.cfg"
ensureKeyValue "input_player1_down" "down" "$rootdir/configs/all/retroarch.cfg"
}
# install RetroArch emulator
function install_retroarch()
{
printMsg "Installing RetroArch emulator"
gitPullOrClone "$rootdir/emulators/RetroArch" git://github.com/libretro/RetroArch.git
./configure
make
sudo make install
cp $scriptdir/supplementary/retroarch-zip "$rootdir/emulators/RetroArch/"
if [[ ! -f "/usr/local/bin/retroarch" ]]; then
__ERRMSGS="$__ERRMSGS Could not successfully compile and install RetroArch."
fi
popd
}
function configure_advmame()
{
$rootdir/emulators/advancemame-0.94.0/installdir/bin/advmame
mv /root/.advance/ /home/$user/
echo 'device_video_clock 5 - 50 / 15.62 / 50 ; 5 - 50 / 15.73 / 60' >> /home/$user/.advance/advmame.rc
chmod -R a+rwX /home/$user/.advance/
chown -R $user /home/$user/.advance/
}
# install AdvanceMAME emulator
install_advmame()
{
printMsg "Installing AdvMAME emulator"
wget -O advmame.tar.gz http://downloads.sourceforge.net/project/advancemame/advancemame/0.94.0/advancemame-0.94.0.tar.gz
apt-get -y install libsdl1.2-dev gcc-4.7
export CC=gcc-4.7
export GCC=g++-4.7
tar xzvf advmame.tar.gz -C "$rootdir/emulators/"
pushd "$rootdir/emulators/advancemame-0.94.0"
sed 's/MAP_SHARED | MAP_FIXED,/MAP_SHARED,/' <advance/linux/vfb.c >advance/linux/temp.c
mv advance/linux/temp.c advance/linux/vfb.c
sed 's/misc_quiet\", 0/misc_quiet\", 1/' <advance/osd/global.c >advance/osd/temp.c
mv advance/osd/temp.c advance/osd/global.c
sed '
/#include <string>/ i\
#include <stdlib.h>
' <advance/d2/d2.cc >advance/d2/temp.cc
mv advance/d2/temp.cc advance/d2/d2.cc
./configure --prefix="$rootdir/emulators/advancemame-0.94.0/installdir"
sed 's/LDFLAGS=-s/LDFLAGS=-s -lm -Wl,--no-as-needed/' <Makefile >Makefile.temp
mv Makefile.temp Makefile
make
make install
popd
configure_advmame
unset CC
unset GCC
}
function ensureEntryInSMBConf()
{
comp=`cat /etc/samba/smb.conf | grep "\[$1\]"`
if [ "$comp" == "[$1]" ]; then
echo "$1 already contained in /etc/samba/smb.conf."
else
chmod 666 /etc/samba/smb.conf
tee -a /etc/samba/smb.conf <<HDHD
[$1]
comment = $1
path = $rootdir/roms/$2
writeable = yes
guest ok = yes
create mask = 0777
directory mask = 0777
read only = no
browseable = yes
force user = $user
public = yes
HDHD
fi
chmod 644 /etc/samba/smb.conf
}
# install and configure SAMBA shares for each ROM directory of the emulators
configureSAMBA()
{
clear
printMsg "Installing and configuring SAMBA shares."
apt-get update
apt-get install -y samba samba-common-bin
ensureEntryInSMBConf "AMIGA" "amiga"
ensureEntryInSMBConf "APPLE2" "apple2"
ensureEntryInSMBConf "ATARI2600" "atari2600"
ensureEntryInSMBConf "BASILISKII" "basiliskii"
ensureEntryInSMBConf "C64" "c64"
ensureEntryInSMBConf "DOOM" "doom"
ensureEntryInSMBConf "DUKE3D" "duke3d"
ensureEntryInSMBConf "GAMEGEAR" "gamegear"
ensureEntryInSMBConf "FBA" "fba"
ensureEntryInSMBConf "GB" "gb"
ensureEntryInSMBConf "GBA" "gba"
ensureEntryInSMBConf "GBC" "gbc"
ensureEntryInSMBConf "INTELLIVISION" "intellivision"
ensureEntryInSMBConf "MAME" "mame"
ensureEntryInSMBConf "MASTERSYSTEM" "mastersystem"
ensureEntryInSMBConf "MEGADRIVE" "megadrive"
ensureEntryInSMBConf "NEOGEO" "neogeo"
ensureEntryInSMBConf "NES" "nes"
ensureEntryInSMBConf "X86" "x86"
ensureEntryInSMBConf "PCENGINE" "pcengine"
ensureEntryInSMBConf "PSX" "psx"
ensureEntryInSMBConf "PPSSPP" "psp"
ensureEntryInSMBConf "SNES" "snes"
ensureEntryInSMBConf "SCUMMVM" "scummvm"
ensureEntryInSMBConf "ZMACHINE" "zmachine"
ensureEntryInSMBConf "ZXSPECTRUM" "zxspectrum"
/etc/init.d/samba restart
dialog --backtitle "PetRockBlock.com - RetroPie Setup. Installation folder: $rootdir for user $user" --msgbox "The SAMBA shares can be accessed with a guest account" 22 76
}
# install Amiga emulator
install_amiga()
{
printMsg "Installing Amiga emulator"
if [[ -d "$rootdir/emulators/uae4all" ]]; then
rm -rf "$rootdir/emulators/uae4all"
fi
wget http://darcelf.free.fr/uae4all-src-rc3.chip.tar.bz2
tar -jxvf uae4all-src-rc3.chip.tar.bz2 -C "$rootdir/emulators/"
pushd "$rootdir/emulators/uae4all"
if [[ ! -f /opt/vc/include/interface/vmcs_host/vchost_config.h ]]; then
touch /opt/vc/include/interface/vmcs_host/vchost_config.h
fi
touch /opt/vc/include/interface/vmcs_host/vchost_config.h
make
chown -R $user "$rootdir/emulators/uae4all"
chgrp -R pi "$rootdir/emulators/uae4all"
if [[ ! -f "$rootdir/emulators/uae4all/uae4all" ]]; then
__ERRMSGS="$__ERRMSGS Could not successfully compile Amiga emulator."
fi
mkdir "roms"
popd
rm uae4all-src-rc3.chip.tar.bz2
__INFMSGS="$__INFMSGS The Amiga emulator can be started from command line with '$rootdir/emulators/uae4all/uae4all'. Note that you must manually copy a Kickstart rom with the name 'kick.rom' to the directory $rootdir/emulators/uae4all/."
}
# install Atari 800 emulator
function install_atari800()
{
printMsg "Installing Atari 800 emulator"
wget -O atari800-3.0.0.tar.gz http://sourceforge.net/projects/atari800/files/atari800/3.0.0/atari800-3.0.0.tar.gz/download
if [[ -d "$rootdir/emulators/atari800-3.0.0" ]]; then
rm -rf "$rootdir/emulators/atari800-3.0.0"
fi
tar xvfz atari800-3.0.0.tar.gz -C "$rootdir/emulators/"
pushd "$rootdir/emulators/atari800-3.0.0/src"
./configure --prefix="$rootdir/emulators/atari800-3.0.0/installdir"
make
if [[ ! -f "$rootdir/emulators/atari800-3.0.0/installdir/bin/atari800" ]]; then
__ERRMSGS="$__ERRMSGS Could not successfully compile Atari 800 emulator."
fi
popd
rm atari800-3.0.0.tar.gz
}
# install Atari 2600 core
function install_atari2600()
{
printMsg "Installing Atari 2600 RetroArch core"
gitPullOrClone "$rootdir/emulatorcores/stella-libretro" git://github.com/libretro/stella-libretro.git
# remove msse and msse2 flags from Makefile, just a hack here to make it compile on the Raspberry
sed 's|-msse2 ||g;s|-msse ||g' Makefile >> Makefile.rpi
make -f Makefile.rpi
if [[ -z `find $rootdir/emulatorcores/stella-libretro/ -name "*libretro*.so"` ]]; then
__ERRMSGS="$__ERRMSGS Could not successfully compile Atari 2600 core."
fi
popd
}
function install_stella()
{
printMsg "Installing Atari 2600 emulator Stella"
apt-get install -y stella
}
function install_basiliskII()
{
printMsg "Installing Basilisk II"
gitPullOrClone "$rootdir/emulators/basiliskii" git://github.com/cebix/macemu.git
cd BasiliskII/src/Unix
./autogen.sh
./configure --prefix="$rootdir/emulators/basiliskii/installdir" --enable-sdl-video --enable-sdl-audio --disable-vosf --disable-jit-compiler
make
make install
touch $rootdir/roms/basiliskii/Start.txt
if [[ -z "$rootdir/emulators/basiliskii/installdir/bin/BasiliskII" ]]; then
__ERRMSGS="$__ERRMSGS Could not successfully compile BasiliskII."
else
configure_cavestory
fi
popd
}
# install C64 ROMs
function install_c64roms()
{
printMsg "Retrieving Commodore 64 ROMs"
wget http://www.zimmers.net/anonftp/pub/cbm/crossplatform/emulators/VICE/old/vice-1.5-roms.tar.gz
tar -xvzf vice-1.5-roms.tar.gz
mkdir -p "$rootdir/emulators/vice-2.3.dfsg/installdir/lib/vice/"
cp -a vice-1.5-roms/data/* "$rootdir/emulators/vice-2.3.dfsg/installdir/lib/vice/"
rm -rf vice-1.5-roms
rm -rf vice-1.5-roms.tar.gz
}
# Install VICE C64 Emulator
function install_viceC64()
{
printMsg "Install VICE Commodore 64 core"
if [[ -d "$rootdir/emulators/vice-2.3.dsfg" ]]; then
rm -rf "$rootdir/emulators/vice-2.3.dsfg"
fi
if dpkg-query -Wf'${db:Status-abbrev}' vice 2>/dev/null | grep -q '^i'; then
printf 'Package vice is already installed - removing package\n' "${1}"
apt-get remove -y vice
fi
printMsg "Installing vice"
pushd "$rootdir/emulators"
echo 'deb-src http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi' >> /etc/apt/sources.list
apt-get update
apt-get build-dep -y vice
apt-get install -y libxaw7-dev automake checkinstall
apt-get source vice
cd vice-2.3.dfsg
./configure --prefix="$rootdir/emulators/vice-2.3.dfsg/installdir" --enable-sdlui --with-sdlsound
make
make install
popd
install_c64roms
}
# configure NXEngine / Cave Story core
function configure_cavestory()
{
if [[ ! -d $rootdir/roms/cavestory ]]; then
mkdir -p $rootdir/roms/cavestory
fi
touch $rootdir/roms/cavestory/Start.txt
}
# install NXEngine / Cave Story core
function install_cavestory()
{
printMsg "Installing NXEngine / Cave Story"
gitPullOrClone "$rootdir/emulatorcores/nxengine-libretro" git://github.com/libretro/nxengine-libretro.git
make
if [[ -z `find $rootdir/emulatorcores/nxengine-libretro/ -name "*libretro*.so"` ]]; then
__ERRMSGS="$__ERRMSGS Could not successfully compile NXEngine / Cave Story core."
else
configure_cavestory
fi
popd
}
# configure DGEN
function configureDGEN()
{
chmod 777 /dev/fb0
if [[ ! -f "$rootdir/configs/all/dgenrc" ]]; then
mkdir -p "$rootdir/configs/all/"
cp $rootdir/emulators/dgen-sdl/sample.dgenrc $rootdir/configs/all/dgenrc
fi
chown -R $user $rootdir/configs/all/
chgrp -R $user $rootdir/configs/all/
ensureKeyValue "joy_pad1_a" "joystick0-button0" $rootdir/configs/all/dgenrc
ensureKeyValue "joy_pad1_b" "joystick0-button1" $rootdir/configs/all/dgenrc
ensureKeyValue "joy_pad1_c" "joystick0-button2" $rootdir/configs/all/dgenrc
ensureKeyValue "joy_pad1_x" "joystick0-button3" $rootdir/configs/all/dgenrc
ensureKeyValue "joy_pad1_y" "joystick0-button4" $rootdir/configs/all/dgenrc
ensureKeyValue "joy_pad1_z" "joystick0-button5" $rootdir/configs/all/dgenrc
ensureKeyValue "joy_pad1_mode" "joystick0-button6" $rootdir/configs/all/dgenrc
ensureKeyValue "joy_pad1_start" "joystick0-button7" $rootdir/configs/all/dgenrc
ensureKeyValue "joy_pad2_a" "joystick1-button0" $rootdir/configs/all/dgenrc
ensureKeyValue "joy_pad2_b" "joystick1-button1" $rootdir/configs/all/dgenrc
ensureKeyValue "joy_pad2_c" "joystick1-button2" $rootdir/configs/all/dgenrc
ensureKeyValue "joy_pad2_x" "joystick1-button3" $rootdir/configs/all/dgenrc
ensureKeyValue "joy_pad2_y" "joystick1-button4" $rootdir/configs/all/dgenrc
ensureKeyValue "joy_pad2_z" "joystick1-button5" $rootdir/configs/all/dgenrc
ensureKeyValue "joy_pad2_mode" "joystick1-button6" $rootdir/configs/all/dgenrc
ensureKeyValue "joy_pad2_start" "joystick1-button7" $rootdir/configs/all/dgenrc
}
# install DGEN (Megadrive/Genesis emulator)
function install_dgen()
{
printMsg "Installing Megadrive/Genesis emulator"
if [[ -d "$rootdir/emulators/dgen" ]]; then
rm -rf "$rootdir/emulators/dgen"
fi
wget http://downloads.sourceforge.net/project/dgen/dgen/1.32/dgen-sdl-1.32.tar.gz
tar xvfz dgen-sdl-1.32.tar.gz -C "$rootdir/emulators/"
mv "$rootdir/emulators/dgen-sdl-1.32" "$rootdir/emulators/dgen-sdl"
pushd "$rootdir/emulators/dgen-sdl"
mkdir "installdir" # only used for creating the binaries archive
./configure --disable-opengl
make
make install DESTDIR=$rootdir/emulators/dgen-sdl/installdir
make install
if [[ ! -f "$rootdir/emulators/dgen-sdl/dgen" ]]; then
__ERRMSGS="$__ERRMSGS Could not successfully compile DGEN emulator."
fi
popd
rm dgen-sdl-1.32.tar.gz
}
function configure_doom()
{
mkdir -p $rootdir/roms/doom/
cp $rootdir/emulatorcores/libretro-prboom/prboom.wad $rootdir/roms/doom/
}
# install Doom WADs emulator core
function install_doom()
{
printMsg "Installing Doom core"
gitPullOrClone "$rootdir/emulatorcores/libretro-prboom" git://github.com/libretro/libretro-prboom.git
make
if [[ -z `find $rootdir/emulatorcores/libretro-prboom/ -name "*libretro*.so"` ]]; then
__ERRMSGS="$__ERRMSGS Could not successfully compile Doom core."
fi
popd
configure_doom
}
#install eDuke32
function install_eduke32()
{
printMsg "Installing eDuke32"
if [[ -d "$rootdir/emulators/eduke32" ]]; then
rm -rf "$rootdir/emulators/eduke32"
fi
mkdir -p $rootdir/emulators/eduke32
pushd "$rootdir/emulators/eduke32"
printMsg "Downloading eDuke core"
wget http://repo.berryboot.com/eduke32_2.0.0rpi+svn2789_armhf.deb
printMsg "Downloading eDuke32 Shareware files"
wget http://apt.duke4.net/pool/main/d/duke3d-shareware/duke3d-shareware_1.3d-23_all.deb
if [[ ! -f "$rootdir/emulators/eduke32/eduke32_2.0.0rpi+svn2789_armhf.deb" ]]; then
__ERRMSGS="$__ERRMSGS Could not successfully install eDuke32 core."
else
printMsg "Installing eDuke32"
sudo dpkg -i *duke*.deb
cp /usr/share/games/eduke32/DUKE.RTS $rootdir/roms/duke3d/
cp /usr/share/games/eduke32/duke3d.grp $rootdir/roms/duke3d/
fi
popd
rm -rf "$rootdir/emulators/eduke32"
}
# install Game Boy Advance emulator gpSP
function install_gba()
{
printMsg "Installing Game Boy Advance emulator gpSP"
gitPullOrClone "$rootdir/emulators/gpsp" git://github.com/DPRCZ/gpsp.git
cd raspberrypi
#if we are on the 256mb model, we will never have enough RAM to compile gpSP with compiler optimization
#if this is the case, use sed to remove the -O3 in the Makefile (line 20, "CFLAGS += -O3 -mfpu=vfp")
local RPiRev=`grep 'Revision' /proc/cpuinfo | cut -d " " -f 2`
if [ $RPiRev == "00d" ] || [ $RPiRev == "000e" ] || [ $RPiRev == "000f" ]; then
#RAM = 512mb, we're good
echo "512mb Pi, no de-optimization fix needed."
else
#RAM = 256mb, need to compile unoptimized
echo "Stripping -O[1..3] from gpSP Makefile to compile unoptimized on 256mb Pi..."
sed -i 's/-O[1..3]//g' Makefile
fi
#gpSP is missing an include in the Makefile
if [[ ! -z `grep '-I/opt/vc/include/interface/vmcs_host/linux' Makefile` ]]; then
echo "Skipping adding missing include to gpSP Makefile."
else
echo "Adding -I/opt/vc/include/interface/vmcs_host/linux to Makefile"
sed -i '23iCFLAGS += -I/opt/vc/include/interface/vmcs_host/linux' Makefile
fi
make
if [[ -z `find $rootdir/emulators/gpsp/ -name "gpsp"` ]]; then
__ERRMSGS="$__ERRMSGS Could not successfully compile Game Boy Advance emulator."
fi
popd
}
# install Game Boy Color emulator core
function install_gbc()
{
printMsg "Installing Game Boy Color core"
gitPullOrClone "$rootdir/emulatorcores/gambatte-libretro" git://github.com/libretro/gambatte-libretro.git
make -C libgambatte -f Makefile.libretro
if [[ -z `find $rootdir/emulatorcores/gambatte-libretro/libgambatte/ -name "*libretro*.so"` ]]; then
__ERRMSGS="$__ERRMSGS Could not successfully compile Game Boy Color core."
fi
popd
}
# install MAME emulator core
function install_mame()
{
printMsg "Installing MAME core"
gitPullOrClone "$rootdir/emulatorcores/imame4all-libretro" git://github.com/libretro/imame4all-libretro.git
make -f makefile.libretro ARM=1
if [[ -z `find $rootdir/emulatorcores/imame4all-libretro/ -name "*libretro*.so"` ]]; then
__ERRMSGS="$__ERRMSGS Could not successfully compile MAME core."
fi
popd
}
# install FBA emulator core
function install_fba()
{
printMsg "Installing FBA core"
gitPullOrClone "$rootdir/emulatorcores/fba-libretro" git://github.com/libretro/fba-libretro.git
apt-get install -y --force-yes cpp-4.5 gcc-4.5 g++-4.5
(
cd $rootdir/emulatorcores/fba-libretro/svn-current/trunk/
CC=gcc-4.5 CXX=g++-4.5 make -f makefile.libretro
)
mv svn-current/trunk/*libretro*.so $rootdir/emulatorcores/fba-libretro/
if [[ -z `find $rootdir/emulatorcores/fba-libretro/ -name "*libretro*.so"` ]]; then
__ERRMSGS="$__ERRMSGS Could not successfully compile FBA core."
fi
popd
}
# configure NeoGeo
function configureNeogeo()
{
mkdir /home/$user/.gngeo/
cp $rootdir/emulators/gngeo-0.7/sample_gngeorc /home/$user/.gngeo/gngeorc
chown -R $user /home/$user/.gngeo/
chgrp -R $user /home/$user/.gngeo/
sed -i -e "s/effect none/effect scale2x/g" /home/$user/.gngeo/gngeorc
sed -i -e "s/fullscreen false/fullscreen true/g" /home/$user/.gngeo/gngeorc
sed -i -e "s|rompath /usr/games/lib/xmame|rompath $rootdir/RetroPie/emulators/gngeo-0.7/installdir/share/gngeo/romrc.d|g" /home/$user/.gngeo/gngeorc
chmod 777 /dev/fb0
mkdir "$rootdir/emulators/gngeo-0.7/neogeo-bios"
__INFMSGS="$__INFMSGS You need to copy NeoGeo BIOS files to the folder '$rootdir/emulators/gngeo-0.7/neogeo-bios/'."
}
# configure AdvanceMenu
function configure_advancemenu()
{
printMsg "Configuring AdvanceMenu"
mkdir -p "/home/$user/.advance/"
cp "$scriptdir/supplementary/advmenu.rc" "/home/$user/.advance/"
cat >> "/home/$user/.advance/advmenu.rc" << _EOF_
emulator "Atari 2600" generic "/usr/local/bin/retroarch" "-L `find $rootdir/emulatorcores/stella-libretro/ -name "*libretro*.so"` --config $rootdir/configs/all/retroarch.cfg --appendconfig $rootdir/configs/atari2600/retroarch.cfg %p"
emulator_roms "Atari 2600" "$rootdir/roms/atari2600"
emulator "Doom" generic "/usr/local/bin/retroarch" "-L `find $rootdir/emulatorcores/libretro-prboom/ -name "*libretro*.so"` --config $rootdir/configs/all/retroarch.cfg --appendconfig $rootdir/configs/doom/retroarch.cfg %p"
emulator_roms "Doom" "$rootdir/roms/doom"
emulator "eDuke32" generic "/usr/local/bin/eduke32" "%p"
emulator "Gameboy Advance" generic "$rootdir/emulators/gpsp/gpsp" "%p"
emulator_roms "Gameboy Advance" "$rootdir/roms/gba"
emulator "Gameboy Color" generic "-L `find $rootdir/emulatorcores/gambatte-libretro/ -name "*libretro*.so"` --config $rootdir/configs/all/retroarch.cfg --appendconfig $rootdir/configs/gbc/retroarch.cfg %p"
emulator_roms "Gameboy Color" "$rootdir/roms/gbc"
emulator "Sega Game Gear" generic "$rootdir/emulators/osmose-0.8.1+rpi20121122/osmose" "%p -joy -tv -fs"
emulator_roms "Sega Game Gear" "$rootdir/roms/gamegear"
emulator "IntelliVision" generic "$rootdir/emulators/jzintv-1.0-beta4/bin/jzintv" "-z1 -f1 -q %p"
emulator_roms "IntelliVision" "$rootdir/roms/intellivision"
emulator "MAME" generic "/usr/local/bin/retroarch" "-L `find $rootdir/emulatorcores/imame4all-libretro/ -name "*libretro*.so"` --config $rootdir/configs/all/retroarch.cfg --appendconfig $rootdir/configs/mame/retroarch.cfg %p"
emulator_roms "MAME" "$rootdir/roms/mame"
emulator "ScummVM" generic "scummvm"
emulator_roms "ScummVM" "$rootdir/roms/scummvm"
emulator "Sega Master System" generic "$rootdir/emulators/osmose-0.8.1+rpi20121122/osmose" "%p -joy -tv -fs"
emulator_roms "Sega Master System" "$rootdir/roms/mastersystem"
emulator "Sega Mega Drive / Genesis" generic "$rootdir/emulators/dgen-sdl/dgen" "-f %p"
emulator_roms "Sega Mega Drive / Genesis" "$rootdir/roms/megadrive"
emulator "NeoGeo" generic "$rootdir/emulators/gngeo-0.7/src/gngeo" "-i $rootdir/roms/neogeo -B $rootdir/emulators/gngeo-0.7/neogeo-bios %p"
emulator_roms "NeoGeo" "$rootdir/roms/neogeo"
emulator "Nintendo Entertainment System" generic "/usr/local/bin/retroarch" "-L `find $rootdir/emulatorcores/fceu-next/ -name "*libretro*.so"` --config $rootdir/configs/all/retroarch.cfg --appendconfig $rootdir/configs/nes/retroarch.cfg %p"
emulator_roms "Nintendo Entertainment System" "$rootdir/roms/nes"
emulator "PC Engine/TurboGrafx 16" generic "/usr/local/bin/retroarch" "-L `find $rootdir/emulatorcores/mednafen-pce-libretro/ -name "*libretro*.so"` --config $rootdir/configs/all/retroarch.cfg --appendconfig $rootdir/configs/pcengine/retroarch.cfg %p"
emulator_roms "PC Engine/TurboGrafx 16" "$rootdir/roms/pcengine"
emulator "Sony Playstation 1" generic "/usr/local/bin/retroarch" "-L `find $rootdir/emulatorcores/pcsx_libretro/ -name "*libretro*.so"` --config $rootdir/configs/all/retroarch.cfg --appendconfig $rootdir/configs/psx/retroarch.cfg %p"
emulator_roms "Sony Playstation 1" "$rootdir/roms/psx"
emulator "Super Nintendo" generic "/usr/local/bin/retroarch" "-L `find $rootdir/emulatorcores/pocketsnes-libretro/ -name "*libretro*.so"` --config $rootdir/configs/all/retroarch.cfg --appendconfig $rootdir/configs/snes/retroarch.cfg %p"
emulator_roms "Super Nintendo" "$rootdir/roms/snes"
_EOF_