forked from arnekaas/DSMR-P1-usb-logger
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall.sh
executable file
·88 lines (84 loc) · 3.97 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
82
83
84
85
86
87
88
#!/bin/bash
# Installation script for: disaggregation_logger-DSMR-P1-usb
# OS/HW: Raspbian / Raspberry Pi
# Path: /home/pi/disaggregation
# Get started:
# Download with: sudo wget https://raw.githubusercontent.com/disaggregation/logger-DSMR-P1-usb/master/install.sh
# Start with: sudo chmod +x install.sh && sudo ./install.sh
#***************************************************************************
printf "\e[33mInstallation - disaggregation_logger-DSMR-P1-usb v1.12\n\n"
#***************************************************************************
log_dir="/home/pi/disaggregation"
read -e -i "$log_dir" -p "Please enter your prefered directory: " input
log_dir="${input:-$name}"
printf "\e[96m* CHECK\n"
printf "\e[96m - Check if USB Serial port is found..."
#comment by Arne: I changed ttyUSB0 to ttyUSB, because serial does not have to be on usb port 0
if ls /dev | grep 'ttyUSB' >/dev/null 2>&1; then
printf "\e[92mOK\e[0m\n"
else
printf "\e[91mUSB NOT FOUND! Aborting installation!\e[0m\n"
exit
fi
#***************************************************************************
printf "\e[96m* GENERAL\n"
printf "\e[96m - Update apt-get lists..."
sudo apt-get update &>/dev/null
sudo apt-get install screen
printf "\e[92mOK\e[0m\n"
#***************************************************************************
printf "\e[96m - Set timezone..."
sudo sudo cp /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime
printf "\e[92mOK\e[0m\n"
#***************************************************************************
printf "\e[96m - Generate languages..."
sudo bash -c "echo 'nl_NL.UTF-8 UTF-8' >> /etc/locale.gen"
sudo bash -c "echo 'nl_NL ISO-8859-1' >> /etc/locale.gen"
sudo locale-gen &>/dev/null
printf "\e[92mOK\e[0m\n"
#***************************************************************************
printf "\e[96m* DSRM LOGGER FILES\n"
printf "\e[96m - Creating folder structure(s)..."
sudo mkdir $log_dir &>/dev/null
sudo mkdir $log_dir "/data" &>/dev/null
printf "\e[92mOK\e[0m\n"
#***************************************************************************
printf "\e[96m - Downloading files..."
sudo rm ${log_dir}/master.zip &>/dev/null
sudo wget -q https://github.com/disaggregation/logger-DSMR-P1-usb/archive/master.zip -O ${log_dir}/master.zip &>/dev/null
printf "\e[92mOK\e[0m\n"
#***************************************************************************
printf "\e[96m - Extracting files..."
sudo unzip -q -o ${log_dir}/master.zip -d ${log_dir} &>/dev/null
printf "\e[92mOK\e[0m\n"
#***************************************************************************
printf "\e[96m - Cleanup files..."
sudo rm ${log_dir}/master.zip &>/dev/null
sudo mv ${log_dir}/logger-DSMR-P1-usb-master/* .
sudo rm ${log_dir}/logger-DSMR-P1-usb-master
printf "\e[92mOK\e[0m\n"
#***************************************************************************
printf "\e[96m - Changing file permissions and rights to pi..."
sudo chmod -R 777 ${log_dir} &>/dev/null
sudo chown -R pi ${log_dir} &>/dev/null
printf "\e[92mOK\e[0m\n"
#***************************************************************************
printf "\e[96m* PYTHON DEPENDENCIES\n"
printf "\e[96m - Downloading and installing pyserial..."
pip install pyserial >/dev/null
printf "\e[92mOK\e[0m\n"
#***************************************************************************
printf "\e[96m* CONFIGURE\n"
printf "\e[96m - Set CRON-job..."
sudo cd ${log_dir}
echo "@reboot screen -dmS atboot_P1_logger /usr/bin/python ${log_dir}/schedule_p1_reader.py" >> tempcron
crontab tempcron
sudo rm tempcron
printf "\e[92mOK\e[0m\n"
#***************************************************************************
printf "\e[96m - Start DSMR P1 script..."
screen -dmS atboot_P1_logger /usr/bin/python ${log_dir}/schedule_p1_reader.py 2>&1 &>/dev/null
printf "\e[92m - OK\e[0m\n"
#***************************************************************************
printf "\n\e[33mEnd of installation - disaggregation_logger-DSMR-P1-usb\n"
#***************************************************************************