-
Notifications
You must be signed in to change notification settings - Fork 33
/
install-pi.sh
executable file
·172 lines (137 loc) · 4.52 KB
/
install-pi.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
#!/usr/bin/env bash
if [ `id -u` != 0 ] ; then
echo "Please run install-pi.sh using sudo (sudo ./install-pi.sh <model>)"
exit 1
fi
BIN=bin_pi
A314_USER=$SUDO_USER
A314_GROUP=`sudo -u $A314_USER id -gn`
A314_HOME=`sudo -u $A314_USER printenv HOME`
modinstall() {
sed -e s%##USER##%${A314_USER}%g -e s%##GROUP##%${A314_GROUP}%g -e s%##HOME##%${A314_HOME}%g $1 > $2/`basename $1`
}
install_common() {
install a314d/a314d.py /opt/a314
install picmd/picmd.py /opt/a314
install a314fs/a314fs.py /opt/a314
install piaudio/piaudio.py /opt/a314
install remotewb/remotewb.py /opt/a314
install disk/disk.py /opt/a314
install ethernet/ethernet.py /opt/a314
install hid/hid.py /opt/a314
install remote-mouse/remote-mouse.py /opt/a314
install videoplayer/videoplayer.py /opt/a314
# Write configuration files, but don't overwrite
[ -f /etc/opt/a314/a314d.conf ] || modinstall a314d/a314d.conf /etc/opt/a314
[ -f /etc/opt/a314/picmd.conf ] || modinstall picmd/picmd.conf /etc/opt/a314
[ -f /etc/opt/a314/a314fs.conf ] || modinstall a314fs/a314fs.conf /etc/opt/a314
[ -f /etc/opt/a314/disk.conf ] || modinstall disk/disk.conf /etc/opt/a314
# Add shared directory for a314fs
sudo -u $A314_USER mkdir -p ${A314_HOME}/a314shared
# Install Python packages in virtual environment
python3 -m virtualenv /opt/a314/venv
/opt/a314/venv/bin/pip install pyudev websockets python-pytun bpls2gif/
# Add tap0 interface
modinstall ethernet/pi-config/tap0 /etc/network/interfaces.d
# Enable IP forwarding
echo net.ipv4.ip_forward=1 > /etc/sysctl.d/a314eth.conf
# Add service that sets iptable rules
[ -f /lib/systemd/system/a314net.service ] || install -m644 ethernet/pi-config/a314net.service /lib/systemd/system
systemctl daemon-reload
systemctl enable a314d
systemctl enable a314net
echo
echo "Installation complete"
echo "Restart the Raspberry Pi (sudo reboot now) to automatically start a314 software"
}
install_trapdoor() {
sudo -u $A314_USER mkdir -p ${BIN}
sudo -u $A314_USER make ${BIN}/a314d-td
sudo -u $A314_USER make ${BIN}/spi-a314.dtbo
if [ -d /boot/firmware ]; then
BOOT_FW_DIR=/boot/firmware
else
BOOT_FW_DIR=/boot
fi
install -d /opt/a314
install -d /etc/opt/a314
install ${BIN}/a314d-td /opt/a314/a314d
install ${BIN}/spi-a314.dtbo $BOOT_FW_DIR/overlays
modinstall a314d/a314d-td.service /lib/systemd/system
mv /lib/systemd/system/a314d-td.service /lib/systemd/system/a314d.service
# Set dtparam=spi=on
CONFIG_FILE=$BOOT_FW_DIR/config.txt
PREV_DTPARAM_SPI=`grep ^dtparam=spi= $CONFIG_FILE`
case "$PREV_DTPARAM_SPI" in
"dtparam=spi=on"*)
;;
"dtparam=spi="*)
sed -i "s%${PREV_DTPARAM_SPI}%#${PREV_DTPARAM_SPI}%g" $CONFIG_FILE
printf "\ndtparam=spi=on\n" >> $CONFIG_FILE
;;
*)
printf "\ndtparam=spi=on\n" >> $CONFIG_FILE
;;
esac
# Set dtoverlay=spi-a314
if ! grep -q ^dtoverlay=spi-a314 $CONFIG_FILE
then
printf "\ndtoverlay=spi-a314\n" >> $CONFIG_FILE
fi
# Set force_turbo=1
PREV_FORCE_TURBO=`grep ^force_turbo= $CONFIG_FILE`
case "$PREV_FORCE_TURBO" in
"force_turbo=1"*)
;;
"force_turbo="*)
sed -i "s%${PREV_FORCE_TURBO}%#${PREV_FORCE_TURBO}%g" $CONFIG_FILE
printf "\nforce_turbo=1\n" >> $CONFIG_FILE
;;
*)
printf "\nforce_turbo=1\n" >> $CONFIG_FILE
;;
esac
# Add spidev.bufsiz=65536
CMDLINE_FILE=$BOOT_FW_DIR/cmdline.txt
if ! grep -q "spidev.bufsiz=65536" $CMDLINE_FILE
then
echo `cat $CMDLINE_FILE` spidev.bufsiz=65536 > $CMDLINE_FILE
fi
install_common
}
install_clockport() {
sudo -u $A314_USER mkdir -p ${BIN}
sudo -u $A314_USER make ${BIN}/a314d-cp
sudo -u $A314_USER make ${BIN}/start_gpclk
install -d /opt/a314
install -d /etc/opt/a314
install ${BIN}/a314d-cp /opt/a314/a314d
install ${BIN}/start_gpclk /opt/a314
modinstall a314d/a314d-cp.service /lib/systemd/system
mv /lib/systemd/system/a314d-cp.service /lib/systemd/system/a314d.service
install_common
}
install_frontexpansion() {
sudo -u $A314_USER mkdir -p ${BIN}
sudo -u $A314_USER make ${BIN}/a314d-fe
install -d /opt/a314
install -d /etc/opt/a314
install ${BIN}/a314d-fe /opt/a314/a314d
modinstall a314d/a314d-td.service /lib/systemd/system
mv /lib/systemd/system/a314d-td.service /lib/systemd/system/a314d.service
install_common
}
case "$1" in
td | TD) install_trapdoor
;;
cp | CP) install_clockport
;;
fe | FE) install_frontexpansion
;;
*) echo "Usage: sudo ./install-pi.sh <model>"
echo " <model> is one of:"
echo " td (trapdoor) A314-500, A314-600"
echo " cp (clockport) A314-cp"
echo " fe (front expansion) A314-1000"
;;
esac