Fix for PMS5003 ReadTimeoutError
[EVA-2020-02-2.git] / install.sh
1 #!/bin/bash
2
3 LIBRARY_VERSION=`cat library/setup.py | grep version | awk -F"'" '{print $2}'`
4 LIBRARY_NAME=`cat library/setup.py | grep name | awk -F"'" '{print $2}'`
5 CONFIG=/boot/config.txt
6 DATESTAMP=`date "+%Y-%M-%d-%H-%M-%S"`
7
8 printf "$LIBRARY_NAME $LIBRARY_VERSION Python Library: Installer\n\n"
9
10 if [ $(id -u) -ne 0 ]; then
11 printf "Script must be run as root. Try 'sudo ./install.sh'\n"
12 exit 1
13 fi
14
15 cd library
16
17 printf "Installing for Python 2..\n"
18 python setup.py install
19
20 if [ -f "/usr/bin/python3" ]; then
21 printf "Installing for Python 3..\n"
22 python3 setup.py install
23 fi
24
25 cd ..
26
27 printf "Backing up $CONFIG\n"
28 cp $CONFIG "config.preinstall-$DATESTAMP.txt"
29
30 printf "Setting up i2c and SPI..\n"
31 raspi-config nonint do_spi 0
32 raspi-config nonint do_i2c 0
33
34 printf "Setting up serial for PMS5003..\n"
35 # Disable serial terminal over /dev/ttyAMA0
36 raspi-config nonint do_serial 1
37 # Enable serial port
38 raspi-config nonint set_config_var enable_uart 1 $CONFIG
39 # Switch serial port to full UART for stability (may adversely affect bluetooth)
40 sed -i 's/^#dtoverlay=pi3-miniuart-bt/dtoverlay=pi3-miniuart-bt/' $CONFIG
41 if ! grep -q -E "^dtoverlay=pi3-miniuart-bt" $CONFIG; then
42 printf "dtoverlay=pi3-miniuart-bt\n" >> $CONFIG
43 fi
44
45 printf "Done!\n"