-
Notifications
You must be signed in to change notification settings - Fork 4
/
install.sh
81 lines (69 loc) · 1.77 KB
/
install.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
#!/bin/bash
ask() {
# http://djm.me/ask
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi
# Ask the question
read -p "$1 [$prompt] " REPLY
# Default?
if [ -z "$REPLY" ]; then
REPLY=$default
fi
# Check if the reply is valid
case "$REPLY" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac
done
}
install_overlay() {
echo "Enabling SPI overlay"
cd spi_overlay
sh compile-dtc
if ! grep -q 'dtoverlay=neuron-spi' /boot/config.txt ;then
echo -e "$(cat /boot/config.txt) \n\n#Enable UniPi Neuron SPI overlay\ndtoverlay=neuron-spi" > /boot/config.txt
fi
if ! grep -q '#dtparam=spi=on' /boot/config.txt ;then
sed -i '/dtparam=spi=on/s/^/#/g' /etc/modprobe.d/raspi-blacklist.conf
fi
cd ..
}
install_neuron_tcp_server() {
cd neuron_tcp_server
echo "Compiling neurontcp server..."
make
echo "Installing Neuron TCP server into /opt/neurontcp/"
make install
echo "Enabling neurontcp service for systemd"
cp neurontcp.service /lib/systemd/system/
cd ..
systemctl daemon-reload
systemctl enable neurontcp
}
install_prerequisites() {
echo "Installing libmodbus"
apt-get update
apt-get install -y libmodbus-dev
}
if [ "$EUID" -ne 0 ]; then
echo "Please run this script as root user"
exit
fi
install_prerequisites
install_overlay
install_neuron_tcp_server
if ask "Reboot is required. Is it OK to reboot now?"; then
reboot
else
echo 'Remember to reboot at earliest convenience'
fi
echo ' '