forked from pimoroni/hyperpixel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·266 lines (212 loc) · 6.48 KB
/
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
#!/bin/bash
: <<'DISCLAIMER'
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
This script is licensed under the terms of the MIT license.
Unless otherwise noted, code reproduced herein
was written for this script.
- The Pimoroni Crew -
DISCLAIMER
# script control variables
productname="Hyperpixel" # the name of the product to install
scriptname="setup.sh" # the name of this script
spacereq=20 # minimum size required on root partition in MB
debugmode="no" # whether the script should use debug routines
debuguser="none" # optional test git user to use in debug mode
debugpoint="none" # optional git repo branch or tag to checkout
forcesudo="no" # whether the script requires to be ran with root privileges
promptreboot="yes" # whether the script should always prompt user to reboot
mininstall="no" # whether the script enforces minimum install routine
customcmd="yes" # whether to execute commands specified before exit
armhfonly="yes" # whether the script is allowed to run on other arch
armv6="yes" # whether armv6 processors are supported
armv7="yes" # whether armv7 processors are supported
armv8="yes" # whether armv8 processors are supported
raspbianonly="no" # whether the script is allowed to run on other OSes
pkgdeplist=( "python-rpi.gpio" "python-smbus" ) # list of dependencies
FORCE=""
ASK_TO_REBOOT=false
CURRENT_SETTING=false
MIN_INSTALL=false
FAILED_PKG=false
REMOVE_PKG=false
UPDATE_DB=false
AUTOSTART=~/.config/lxsession/LXDE-pi/autostart
BOOTCMD=/boot/cmdline.txt
CONFIG=/boot/config.txt
APTSRC=/etc/apt/sources.list
INITABCONF=/etc/inittab
BLACKLIST=/etc/modprobe.d/raspi-blacklist.conf
LOADMOD=/etc/modules
# function define
confirm() {
if [ "$FORCE" == '-y' ]; then
true
else
read -r -p "$1 [y/N] " response < /dev/tty
if [[ $response =~ ^(yes|y|Y)$ ]]; then
true
else
false
fi
fi
}
prompt() {
read -r -p "$1 [y/N] " response < /dev/tty
if [[ $response =~ ^(yes|y|Y)$ ]]; then
true
else
false
fi
}
success() {
echo -e "$(tput setaf 2)$1$(tput sgr0)"
}
inform() {
echo -e "$(tput setaf 6)$1$(tput sgr0)"
}
warning() {
echo -e "$(tput setaf 1)$1$(tput sgr0)"
}
newline() {
echo ""
}
progress() {
count=0
until [ $count -eq 7 ]; do
echo -n "..." && sleep 1
((count++))
done;
if ps -C $1 > /dev/null; then
echo -en "\r\e[K" && progress $1
fi
}
sudocheck() {
if [ $(id -u) -ne 0 ]; then
echo -e "Install must be run as root. Try 'sudo ./$scriptname'\n"
exit 1
fi
}
sysclean() {
sudo apt-get clean && sudo apt-get autoclean
sudo apt-get -y autoremove &> /dev/null
}
sysupdate() {
if ! $UPDATE_DB; then
echo "Updating apt indexes..." && progress apt-get &
sudo apt-get update 1> /dev/null || { warning "Apt failed to update indexes!" && exit 1; }
sleep 3 && UPDATE_DB=true
fi
}
sysupgrade() {
sudo apt-get upgrade
sudo apt-get clean && sudo apt-get autoclean
sudo apt-get -y autoremove &> /dev/null
}
sysreboot() {
warning "Some changes made to your system require"
warning "your computer to reboot to take effect."
echo
if prompt "Would you like to reboot now?"; then
sync && sudo reboot
fi
}
apt_pkg_req() {
APT_CHK=$(dpkg-query -W -f='${Status}\n' "$1" 2> /dev/null | grep "install ok installed")
if [ "" == "$APT_CHK" ]; then
echo "$1 is required"
true
else
echo "$1 is already installed"
false
fi
}
apt_pkg_install() {
echo "Installing $1..."
sudo apt-get --yes install "$1" 1> /dev/null || { inform "Apt failed to install $1!\nFalling back on pypi..." && return 1; }
}
config_set() {
if [ -n $defaultconf ]; then
sudo sed -i "s|$1=.*$|$1=$2|" $defaultconf
else
sudo sed -i "s|$1=.*$|$1=$2|" $3
fi
}
: <<'MAINSTART'
Perform all global variables declarations as well as function definition
above this section for clarity, thanks!
MAINSTART
# checks and init
if [ $forcesudo == "yes" ]; then
sudocheck
fi
# main routine
echo -e "Installing dependencies..."
if ! [ -f "$(which python2)" ] && ! [ -f "$(which python3)" ]; then
echo "Python is not installed. Installing, this may take a while..."
progress apt-get &
apt_pkg_install "python"
fi
if apt_pkg_req "python-evdev" &> /dev/null; then
sudo dpkg -i ./dependencies/python-evdev_0.6.4-1_armhf.deb
fi
for pkgdep in ${pkgdeplist[@]}; do
if apt_pkg_req "$pkgdep"; then
sysupdate && apt_pkg_install "$pkgdep"
fi
done
echo -e "\nInstalling Requirements..."
dtbolist=( "hyperpixel" "hyperpixel-gpio-backlight" )
for dtbofile in ${dtbolist[@]}; do
sudo cp ./requirements/boot/overlays/$dtbofile.dtbo /boot/overlays/ &> /dev/null
done
binlist=( "hyperpixel-init" "hyperpixel-touch" )
for binfile in ${binlist[@]}; do
sudo cp ./requirements/usr/bin/$binfile /usr/bin/ &> /dev/null
sudo chmod +x /usr/bin/$binfile
done
echo -e "\nInstalling init script..."
sudo rm /etc/init.d/hyperpixel-touch.sh &> /dev/null # remove old init script
sudo mkdir -p /usr/lib/systemd/system
initlist=( "hyperpixel-init" "hyperpixel-touch" )
for initfile in ${initlist[@]}; do
sudo cp ./requirements/usr/lib/systemd/system/$initfile.service /usr/lib/systemd/system/ &> /dev/null
sudo systemctl enable $initfile
done
if [ $(grep -c "hyperpixel" $CONFIG) == 0 ]; then
echo -e "\nWriting settings to $CONFIG..."
sudo bash -c "cat <<EOT >> $CONFIG
# HyperPixel LCD Settings
dtoverlay=hyperpixel
overscan_left=0
overscan_right=0
overscan_top=0
overscan_bottom=0
framebuffer_width=800
framebuffer_height=480
enable_dpi_lcd=1
display_default_lcd=1
dpi_group=2
dpi_mode=87
dpi_output_format=0x6f016
display_rotate=2
hdmi_timings=800 0 50 20 50 480 1 3 2 3 0 0 0 60 0 32000000 6
# Use a basic GPIO backlight driver with on/off support
dtoverlay=hyperpixel-gpio-backlight
EOT"
fi
if ! grep -q "^i2c[-_]dev" $LOADMOD; then
echo "i2c-dev" | sudo tee -a $LOADMOD &> /dev/null
sudo modprobe -a i2c-dev
fi
success "\nAll done!\n"
if [ "$FORCE" != '-y' ]; then
sysreboot
fi; echo
exit 0