Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·134 lines (105 loc) · 3.35 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·134 lines (105 loc) · 3.35 KB
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
#!/bin/bash
#
# Mycodo install script
#
# Usage: sudo ./setup.sh
#
if [ "$EUID" -ne 0 ]; then
printf "Please run as root with \"sudo ./setup.sh\"\n";
exit
fi
INSTALL_DIRECTORY=$( cd "$( dirname "${BASH_SOURCE[0]}" )/" && pwd -P )
cd $INSTALL_DIRECTORY
LOG_LOCATION=$INSTALL_DIRECTORY/setup.log
exec > >(tee -i $LOG_LOCATION)
exec 2>&1
abort()
{
echo >&2 '
***************
*** ABORTED ***
***************
'
echo "An error occurred. Exiting..." >&2
exit 1
}
trap 'abort' 0
set -e
NOW=$(date +"%m-%d-%Y %H:%M:%S")
printf "### Mycodo installation began at $NOW\n\n"
printf "#### Uninstall current version of pip\n"
apt-get update -y
apt-get purge -y python-pip
printf "#### Install latest pip\n"
apt-get upgrade -y
apt-get install -y libav-tools libffi-dev libi2c-dev python-dev python-setuptools python-smbus sqlite3
easy_install pip
pip install -U pip
# printf "#### Uninstalling specific prerequisites\n"
# pip uninstall -y Adafruit_ADS1x15
# pip uninstall -y Adafruit_BMP
# pip uninstall -y Adafruit_DHT
# pip uninstall -y Adafruit_GPIO
# pip uninstall -y Adafruit_Python_DHT
# pip uninstall -y Adafruit_TMP
# pip uninstall -y MCP342x
printf "#### Installing prerequisites\n"
wget --quiet --show-progress -P $INSTALL_DIRECTORY/ abyz.co.uk/rpi/pigpio/pigpio.zip
unzip pigpio.zip
cd $INSTALL_DIRECTORY/PIGPIO
make -j4
make install
git clone git://git.drogon.net/wiringPi $INSTALL_DIRECTORY/wiringPi
cd $INSTALL_DIRECTORY/wiringPi
./build
wget --quiet --show-progress -P $INSTALL_DIRECTORY/ https://dl.influxdata.com/influxdb/releases/influxdb_1.0.0_armhf.deb
dpkg -i $INSTALL_DIRECTORY/influxdb_1.0.0_armhf.deb
service influxdb start
cd $INSTALL_DIRECTORY
pip install -r requirements.txt --upgrade
rm -rf ./PIGPIO ./pigpio.zip ./wiringPi ./influxdb_0.13.0_armhf.deb
printf "#### Creating InfluxDB database and user\n"
influx -execute "CREATE DATABASE mycodo_db"
influx -database mycodo_db -execute "CREATE USER mycodo WITH PASSWORD 'mmdu77sj3nIoiajjs'"
printf "#### Creating cron entry to start pigpiod at boot\n"
$INSTALL_DIRECTORY/mycodo/scripts/crontab.sh mycodo
printf "#### Installing and configuring apache2 web server\n"
apt-get install -y apache2 libapache2-mod-wsgi
a2enmod wsgi ssl
ln -sf $INSTALL_DIRECTORY/mycodo_flask_apache.conf /etc/apache2/sites-enabled/000-default.conf
printf "#### Creating SSL certificates at $INSTALL_DIRECTORY/mycodo/frontend/ssl_certs (replace with your own if desired)\n"
mkdir -p $INSTALL_DIRECTORY/mycodo/frontend/ssl_certs
cd $INSTALL_DIRECTORY/mycodo/frontend/ssl_certs/
openssl req \
-new \
-x509 \
-sha512 \
-days 365 \
-nodes \
-out cert.pem \
-keyout privkey.pem\
-subj "/C=US/ST=Georgia/L=Atlanta/O=mycodo/OU=mycodo/CN=mycodo"
openssl genrsa -out certificate.key 1024
openssl req \
-new \
-key certificate.key \
-out certificate.csr \
-subj "/C=US/ST=Georgia/L=Atlanta/O=mycodo/OU=mycodo/CN=mycodo"
openssl x509 -req \
-days 365 \
-in certificate.csr -CA cert.pem \
-CAkey privkey.pem \
-set_serial $RANDOM \
-out chain.pem
rm -f certificate.csr
printf "#### Enabling mycodo startup script\n"
systemctl enable $INSTALL_DIRECTORY/mycodo/scripts/mycodo.service
printf "#### Creating SQLite databases\n"
$INSTALL_DIRECTORY/init_databases.py -i all
$INSTALL_DIRECTORY/mycodo/scripts/update_mycodo.sh initialize
trap : 0
echo >&2 '
************
*** DONE ***
************
'