forked from kobbejager/pimon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremote_install.sh
101 lines (85 loc) · 2.24 KB
/
remote_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
89
90
91
92
93
94
95
96
97
98
99
100
101
welcome(){
echo " This script will install if not installed: python-pip python -dev and python module paho-mqtt,"
echo " pyyaml, psutil and install service pimon."
read -r -p " Do you want to proceed? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
printf ""
else
exit
fi
}
install_python(){
sudo apt update -y
sudo apt install -y python3 python3-pip python3-venv git
}
printm(){
length=$(expr length "$1")
length=$(($length + 4))
printf "\n"
printf ":: $1 \n\n"
}
print_green(){
tput setaf 2; echo "$1"
tput sgr 0
}
print_yellow(){
tput setaf 3; printf "$1"
tput sgr 0
}
clone_create_venv(){
print_yellow "Cloning Repository"
sudo git clone https://github.com/ezhische/pimon /opt/pimon
print_yellow "Taking ownership"
sudo chown -R $USER /opt/pimon
print_yellow "Installing Virtual Enviroment"
python3 -m venv /opt/pimon/
}
install_requirements(){
print_yellow "Installing Python Modules"
/opt/pimon/bin/python3 -m pip install -r /opt/pimon/requirements.txt
}
update_config(){
print_green "+ Copy config.yaml.example to config.yaml"
cp /opt/pimon/config.yaml.example /opt/pimon/config.yaml
printm "MQTT settings"
printf "Enter mqtt_host: "
read HOST
sed -i "s/127.0.0.1/${HOST}/" /opt/pimon/config.yaml
printf "Enter mqtt_user: "
read USER
sed -i "s/mymqttusername/${USER}/" /opt/pimon/config.yaml
printf "Enter mqtt_password: "
read PASS
sed -i "s/mymqttpassword/${PASS}/" /opt/pimon/config.yaml
printf "Enter mqtt_port (default is 1883): "
read PORT
if [ -z "$PORT" ]; then
PORT=1883
fi
sed -i "s/1883/${PORT}/" /opt/pimon/config.yaml
printf "Enter mqtt_topic_prefix (default is pimon): "
read TOPIC
if [ -z "$TOPIC" ]; then
TOPIC=pimon
fi
sed -i "s/pimon/${TOPIC}/" /opt/pimon/config.yaml
print_green "+ config.yaml is updated with provided settings"
}
set_service(){
printm "Setting service"
sudo cp /opt/pimon/pimon.service /etc/systemd/system/pimon.service
sudo systemctl daemon-reload
sudo systemctl start pimon.service
sudo systemctl enable pimon.service
}
main(){
printm "Pimon Monitor installer"
welcome
install_python
clone_create_venv
install_requirements
update_config
set_service
printm "Done"
}
main