Browse Source

Add Joy Bonnet installer

Phillip Burgess 2 years ago
parent
commit
d9219c3f4f
2 changed files with 182 additions and 2 deletions
  1. 0
    2
      arcade-bonnet.sh
  2. 182
    0
      joy-bonnet.sh

+ 0
- 2
arcade-bonnet.sh View File

@@ -1,7 +1,5 @@
1 1
 #!/bin/bash
2 2
 
3
-##### SET UP UDEV
4
-
5 3
 if [ $(id -u) -ne 0 ]; then
6 4
 	echo "Installer must be run as root."
7 5
 	echo "Try 'sudo bash $0'"

+ 182
- 0
joy-bonnet.sh View File

@@ -0,0 +1,182 @@
1
+#!/bin/bash
2
+
3
+if [ $(id -u) -ne 0 ]; then
4
+	echo "Installer must be run as root."
5
+	echo "Try 'sudo bash $0'"
6
+	exit 1
7
+fi
8
+
9
+clear
10
+
11
+echo "This script installs software for the Adafruit"
12
+echo "Joy Bonnet for Raspberry Pi. Steps include:"
13
+echo "- Update package index files (apt-get update)."
14
+echo "- Install Python libraries: smbus, evdev."
15
+echo "- Install joyBonnet.py in /boot and"
16
+echo "  configure /etc/rc.local to auto-start script."
17
+echo "- Enable I2C bus."
18
+echo "- OPTIONAL: disable overscan."
19
+echo "Run time ~10 minutes. Reboot required."
20
+echo "EXISTING INSTALLATION, IF ANY, WILL BE OVERWRITTEN."
21
+echo
22
+echo -n "CONTINUE? [y/N] "
23
+read
24
+if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
25
+	echo "Canceled."
26
+	exit 0
27
+fi
28
+
29
+# FEATURE PROMPTS ----------------------------------------------------------
30
+# Installation doesn't begin until after all user input is taken.
31
+
32
+DISABLE_OVERSCAN=0
33
+INSTALL_HALT=0
34
+
35
+# Given a list of strings representing options, display each option
36
+# preceded by a number (1 to N), display a prompt, check input until
37
+# a valid number within the selection range is entered.
38
+selectN() {
39
+	for ((i=1; i<=$#; i++)); do
40
+		echo $i. ${!i}
41
+	done
42
+	echo
43
+	REPLY=""
44
+	while :
45
+	do
46
+		echo -n "SELECT 1-$#: "
47
+		read
48
+		if [[ $REPLY -ge 1 ]] && [[ $REPLY -le $# ]]; then
49
+			return $REPLY
50
+		fi
51
+	done
52
+}
53
+
54
+echo -n "Disable overscan? [y/N] "
55
+read
56
+if [[ "$REPLY" =~ (yes|y|Y)$ ]]; then
57
+	DISABLE_OVERSCAN=1
58
+fi
59
+
60
+echo -n "Install GPIO-halt utility? [y/N] "
61
+read
62
+if [[ "$REPLY" =~ (yes|y|Y)$ ]]; then
63
+	INSTALL_HALT=1
64
+	echo -n "GPIO pin for halt: "
65
+	read
66
+	HALT_PIN=$REPLY
67
+fi
68
+
69
+echo
70
+if [ $DISABLE_OVERSCAN -eq 1 ]; then
71
+	echo "Overscan: disable."
72
+else
73
+	echo "Overscan: keep current setting."
74
+fi
75
+if [ $INSTALL_HALT -eq 1 ]; then
76
+        echo "Install GPIO-halt: YES (GPIO$HALT_PIN)"
77
+else
78
+        echo "Install GPIO-halt: NO"
79
+fi
80
+echo
81
+echo -n "CONTINUE? [y/N] "
82
+read
83
+if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
84
+	echo "Canceled."
85
+	exit 0
86
+fi
87
+
88
+# START INSTALL ------------------------------------------------------------
89
+# All selections are validated at this point...
90
+
91
+# Given a filename, a regex pattern to match and a replacement string,
92
+# perform replacement if found, else append replacement to end of file.
93
+# (# $1 = filename, $2 = pattern to match, $3 = replacement)
94
+reconfig() {
95
+	grep $2 $1 >/dev/null
96
+	if [ $? -eq 0 ]; then
97
+		# Pattern found; replace in file
98
+		sed -i "s/$2/$3/g" $1 >/dev/null
99
+	else
100
+		# Not found; append (silently)
101
+		echo $3 | sudo tee -a $1 >/dev/null
102
+	fi
103
+}
104
+
105
+echo
106
+echo "Starting installation..."
107
+echo "Updating package index files..."
108
+apt-get update
109
+
110
+echo "Installing Python libraries..."
111
+apt-get install -y --force-yes python-pip python-dev python-smbus
112
+pip install evdev
113
+
114
+echo "Installing Adafruit code in /boot..."
115
+cd /tmp
116
+curl -LO https://raw.githubusercontent.com/adafruit/Adafruit-Retrogame/master/joyBonnet.py
117
+# Moving between filesystems requires copy-and-delete:
118
+cp -r joyBonnet.py /boot
119
+rm -f joyBonnet.py
120
+if [ $INSTALL_HALT -ne 0 ]; then
121
+	echo "Installing gpio-halt in /usr/local/bin..."
122
+	curl -LO https://github.com/adafruit/Adafruit-GPIO-Halt/archive/master.zip
123
+	unzip master.zip
124
+	cd Adafruit-GPIO-Halt-master
125
+	make
126
+	mv gpio-halt /usr/local/bin
127
+	cd ..
128
+	rm -rf Adafruit-GPIO-Halt-master
129
+fi
130
+
131
+# CONFIG -------------------------------------------------------------------
132
+
133
+echo "Configuring system..."
134
+
135
+# Enable I2C using raspi-config
136
+raspi-config nonint do_i2c 0
137
+
138
+# Disable overscan compensation (use full screen):
139
+if [ $DISABLE_OVERSCAN -eq 1 ]; then
140
+	raspi-config nonint do_overscan 1
141
+fi
142
+
143
+if [ $INSTALL_HALT -ne 0 ]; then
144
+	# Add gpio-halt to /rc.local:
145
+	grep gpio-halt /etc/rc.local >/dev/null
146
+	if [ $? -eq 0 ]; then
147
+		# gpio-halt already in rc.local, but make sure correct:
148
+		sed -i "s/^.*gpio-halt.*$/\/usr\/local\/bin\/gpio-halt $HALT_PIN \&/g" /etc/rc.local >/dev/null
149
+	else
150
+		# Insert gpio-halt into rc.local before final 'exit 0'
151
+		sed -i "s/^exit 0/\/usr\/local\/bin\/gpio-halt $HALT_PIN \&\\nexit 0/g" /etc/rc.local >/dev/null
152
+	fi
153
+fi
154
+
155
+# Auto-start joyBonnet.py on boot
156
+grep joyBonnet.py /etc/rc.local >/dev/null
157
+if [ $? -eq 0 ]; then
158
+	# joyBonnet.py already in rc.local, but make sure correct:
159
+	sed -i "s/^.*joyBonnet.py.*$/cd \/boot;python joyBonnet.py \&/g" /etc/rc.local >/dev/null
160
+else
161
+	# Insert joyBonnet.py into rc.local before final 'exit 0'
162
+sed -i "s/^exit 0/cd \/boot;python joyBonnet.py \&\\nexit 0/g" /etc/rc.local >/dev/null
163
+fi
164
+
165
+# Add udev rule (will overwrite if present)
166
+echo "SUBSYSTEM==\"input\", ATTRS{name}==\"retrogame\", ENV{ID_INPUT_KEYBOARD}=\"1\"" > /etc/udev/rules.d/10-retrogame.rules
167
+
168
+# PROMPT FOR REBOOT --------------------------------------------------------
169
+
170
+echo "Done."
171
+echo
172
+echo "Settings take effect on next boot."
173
+echo
174
+echo -n "REBOOT NOW? [y/N] "
175
+read
176
+if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
177
+	echo "Exiting without reboot."
178
+	exit 0
179
+fi
180
+echo "Reboot started..."
181
+reboot
182
+exit 0

Loading…
Cancel
Save