-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.sh
executable file
·58 lines (52 loc) · 1.54 KB
/
setup.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
#!/bin/bash
function dependencyExists() {
package=$1
if command -v "$1" >/dev/null; then
return 0
else
return 1
fi
}
function createVirtualEnviroment {
if dependencyExists "python"; then
echo "Creating virtual enviroment";
python -m venv venv
echo "Installing dependecies";
source venv/bin/activate
pip install -r requirements.txt
else
echo "Python is not installed on your system";
fi
}
function migrations {
echo "Making migrations";
declare -a migrationsArr=("relays" "dht22")
echo "${migrationsArr[@]}"
python controlpanel/manage.py migrate
python controlpanel/manage.py makemigrations "${migrationsArr[@]}"
}
function addAdmin {
echo "Add admin user";
python controlpanel/manage.py createsuperuser
}
function configureMosquitto {
confFile="/etc/mosquitto/mosquitto.conf"
if dependencyExists "mosquitto"; then
echo "Starting mosquitto service";
sudo systemctl start mosquitto
echo "Enter mosquitto username ";
read username
sudo mosquitto_passwd -c /etc/mosquitto/passwd $username
echo "Configuring $confFile";
echo "allow_anonymous false" | sudo tee -a $confFile > /dev/null
echo "password_file /etc/mosquitto/passwd" | sudo tee -a $confFile > /dev/null
echo "Restarting mosquitto service"
sudo systemctl restart mosquitto
else
echo "Mosquitto is not installed on your system";
fi
}
createVirtualEnviroment
migrations
addAdmin
configureMosquitto