-
Notifications
You must be signed in to change notification settings - Fork 161
/
retrogame.sh
executable file
·114 lines (102 loc) · 3.08 KB
/
retrogame.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
#!/bin/bash
if [ $(id -u) -ne 0 ]; then
echo "Installer must be run as root."
echo "Try 'sudo bash $0'"
exit 1
fi
# Given a list of strings representing options, display each option
# preceded by a number (1 to N), display a prompt, check input until
# a valid number within the selection range is entered.
selectN() {
for ((i=1; i<=$#; i++)); do
echo $i. ${!i}
done
echo
REPLY=""
while :
do
echo -n "SELECT 1-$#: "
read
if [[ $REPLY -ge 1 ]] && [[ $REPLY -le $# ]]; then
return $REPLY
fi
done
}
clear
echo "This script downloads and installs"
echo "retrogame, a GPIO-to-keypress utility"
echo "for adding buttons and joysticks, plus"
echo "one of several configuration files."
echo "Run time <1 minute. Reboot recommended."
echo
echo "Select configuration:"
selectN "PiGRRL 2 controls" \
"Pocket PiGRRL" \
"PiGRRL Zero" \
"Super Game Pi" \
"Two buttons + joystick" \
"Six buttons + joystick" \
"Adafruit Arcade Bonnet" \
"Cupcade (gen 1 & 2 only)" \
"Quit without installing"
RETROGAME_SELECT=$?
# These are the retrogame.cfg.* filenames on Github corresponding in
# order to each of the above selections (e.g. retrogame.cfg.pigrrl2):
CONFIGNAME=(pigrrl2 pocket zero super 2button 6button bonnet cupcade-orig)
if [ $RETROGAME_SELECT -lt 9 ]; then
if [ -e /boot/retrogame.cfg ]; then
echo "/boot/retrogame.cfg already exists."
echo "Continuing will overwrite file."
echo -n "CONTINUE? [y/N] "
read
if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
echo "Canceled."
exit 0
fi
fi
echo -n "Downloading, installing retrogame..."
# Download to tmpfile because might already be running
curl -f -s -o /tmp/retrogame https://raw.githubusercontent.com/adafruit/Adafruit-Retrogame/master/retrogame
if [ $? -eq 0 ]; then
mv /tmp/retrogame /usr/local/bin
chmod 755 /usr/local/bin/retrogame
echo "OK"
else
echo "ERROR"
fi
echo -n "Downloading, installing retrogame.cfg..."
curl -f -s -o /boot/retrogame.cfg https://raw.githubusercontent.com/adafruit/Adafruit-Retrogame/master/configs/retrogame.cfg.${CONFIGNAME[$RETROGAME_SELECT-1]}
if [ $? -eq 0 ]; then
echo "OK"
else
echo "ERROR"
fi
echo -n "Performing other system configuration..."
# Add udev rule (will overwrite if present)
echo "SUBSYSTEM==\"input\", ATTRS{name}==\"retrogame\", ENV{ID_INPUT_KEYBOARD}=\"1\"" > /etc/udev/rules.d/10-retrogame.rules
if [ $RETROGAME_SELECT -eq 7 ]; then
# If Bonnet, make sure I2C is enabled. Call the I2C
# setup function in raspi-config (noninteractive):
raspi-config nonint do_i2c 0
fi
# Start on boot
grep retrogame /etc/rc.local >/dev/null
if [ $? -eq 0 ]; then
# retrogame already in rc.local, but make sure correct:
sed -i "s/^.*retrogame.*$/\/usr\/local\/bin\/retrogame \&/g" /etc/rc.local >/dev/null
else
# Insert retrogame into rc.local before final 'exit 0'
sed -i "s/^exit 0/\/usr\/local\/bin\/retrogame \&\\nexit 0/g" /etc/rc.local >/dev/null
fi
echo "OK"
echo
echo -n "REBOOT NOW? [y/N]"
read
if [[ "$REPLY" =~ ^(yes|y|Y)$ ]]; then
echo "Reboot started..."
reboot
#else
echo
echo "Done"
fi
fi