-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
150 lines (134 loc) · 5.11 KB
/
Makefile
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
BINDIR ?=/usr/local/bin/
CONFIGDIR ?=/etc
DJANGODIR ?=/usr/local/django/
CONFIGURE ?=./configure
MAKE_INSTALL ?=sudo make install
DOW :=$(shell date +%a)
AUTOMAKE ?= automake --add-missing
ACLOCAL ?= aclocal
MAKE ?=make
.PHONY: install raspi433 i2c osd daemons binaries django
i2c:
@echo "Allowing I2C"
sudo utilities/add_i2c.sh
os:
@echo "Installing prereqs"
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get install -y redis-server python3-redis weather-util apache2 libapache2-mod-wsgi-py3 sqlite3 python3-bs4 python3-dateutil python-dev-is-python3 python3-smbus python3-pip
@echo "Modifying redis-server to listen on all ports"
sudo sed -i "s/^bind/#bind/g" /etc/redis/redis.conf
sudo sed -i "s/^protected-mode yes/protected-mode no/g" /etc/redis/redis.conf
sudo service redis-server restart
@echo "Initialized redis queues"
utilities/setup_keys.sh
@echo "Adding cron job"
(crontab -u $(USER) -l; cat utilities/crontab) | crontab -u $(USER) -
@echo "Copying apache2 configuration"
sudo cp -rp etc/apache2/* /etc/apache2/
sudo cp -rp etc/apache2/.htpasswd /etc/apache2/
sudo chmod 600 /etc/apache2/.htpasswd
sudo chown www-data:www-data /etc/apache2/.htpasswd
@echo "Modifying KeepAlive Off"
sudo sed -i "s/^KeepAlive On/KeepAlive Off/g" /etc/apache2/apache2.conf
binaries:
@echo "Installing into $(BINDIR)"
sudo cp bin/relay_state.py $(BINDIR)
sudo cp bin/calculate_temps.py $(BINDIR)
sudo cp bin/heating_water_cal.py $(BINDIR)
sudo cp bin/process_temperatures.py $(BINDIR)
sudo cp bin/read_redis.py $(BINDIR)
sudo cp utilities/temp_stats.py $(BINDIR)
sudo cp utilities/redis_sensor.py $(BINDIR)
sudo cp utilities/retrieve_weather.sh $(BINDIR)
sudo cp utilities/parse_weather.py $(BINDIR)
sudo cp utilities/mean_outsidetemp.py $(BINDIR)
@echo "Setting executable permissions"
sudo chmod 755 $(BINDIR)/*.py
sudo chmod 755 $(BINDIR)/*.sh
@echo "Copying systemd script"
sudo cp systemd/*.service /etc/systemd/system/
sudo python3 -m pip install bmp280 --break-system-packages
locale:
@echo "Copying configuration file"
sudo cp etc/pithermostat.conf /etc
sudo mkdir -p $(DJANGODIR)/hotf
sudo cp django_db/db.sqlite3 $(DJANGODIR)hotf/
sudo chmod 666 $(DJANGODIR)/hotf/db.sqlite3
sudo chown www-data:www-data $(DJANGODIR)
@echo "Modifying hosts file"
sudo hostnamectl set-hostname hotf
sudo utilities/edit_file.sh /etc/hosts 127.0.0.1 433board 433host hotf
django:
@echo "Installing Django"
sudo apt -y install python3-bs4 python3-django python3-redis python3-pytzdata python3-evdev python3-urllib3
sudo python3 -m pip install django-scheduler --break-system-packages
sudo python3 -m pip install apiclient --break-system-packages
sudo mkdir -p /usr/local/django
sudo cp -rp django/* $(DJANGODIR)
sudo python3 $(DJANGODIR)hotf/manage.py migrate
sudo chmod 666 $(DJANGODIR)/hotf/db.sqlite3
sudo chown www-data:www-data $(DJANGODIR)
sudo chmod g+w $(DJANGODIR)
daemons:
@echo "Starting processes"
sudo systemctl daemon-reload
sudo chown www-data:www-data /etc/apache2/.htpasswd
sudo systemctl enable apache2 --now
sudo systemctl enable murunner --now
sudo systemctl enable redis_sensor --now
sudo systemctl enable thermostat --now
restart_daemons:
@echo "Restarting processes"
sudo systemctl daemon-reload
sudo systemctl restart apache2
sudo systemctl restart murunner
sudo systemctl restart redis_sensor
sudo systemctl restart thermostat
tradfri:
@echo "Building tradfri"
sudo cp utilities/switch_tradfri.sh $(BINDIR)
git clone --recursive https://github.com/obgm/libcoap.git
cd libcoap
git checkout dtls
git submodule update --init --recursive
./autogen.sh
./configure --disable-documentation --disable-shared
make
sudo make install
test:
sudo bin/unit_test.py
backup:
sudo tar zvcf /var/tmp/backup_$(DOW).tgz $(BINDIR) /etc/pithermostat.conf $(DJANGODIR) /etc/apache2/
sudo cp $(DJANGODIR)hotf/hotf/settings.py /var/tmp/
upgrade: backup binaries django test restart_daemons
sudo cp /var/tmp/settings.py $(DJANGODIR)/hotf/hotf/
sudo chown -R www-data:www-data $(DJANGODIR)
@echo "Upgrade done"
install: os i2c binaries locale django daemons upgrade
@echo "Install complete"
@echo "Remember to set tradfri Pass in $(BINDIR)/switch_tradfri.sh"
clean:
sudo rm -f $(BINDIR)/relay_state.py
sudo rm -f $(BINDIR)/calculate_temps.py
sudo rm -f $(BINDIR)/heating_water_cal.py
sudo rm -f $(BINDIR)/process_temperatures.py
sudo rm -f $(BINDIR)/temp_stats.py
sudo rm -f $(BINDIR)/read_redis.py
sudo rm -f $(BINDIR)/redis_sensor.py
sudo rm -f $(BINDIR)/retrieve_weather.sh
sudo rm -f $(BINDIR)/parse_weather.py
sudo rm -f $(BINDIR)/switch_tradfri.sh
sudo rm -f $(BINDIR)/mean_outsidetemp.py
sudo rm -f /etc/pithermostat.conf
sudo rm -rf $(DJANGODIR)
sudo systemctl disable --now thermostat.service
sudo systemctl disable --now murunner.service
sudo systemctl disable --now redis_sensor.service
sudo rm -f /etc/systemd/system/murunner.service
sudo rm -f /etc/systemd/system/thermostat.service
sudo rm -f /etc/systemd/system/redis_sensor.service
sudo rm -f /etc/init.d/murunner.sh
sudo rm -f /etc/init.d/thermostat.sh
sudo rm -f /etc/init.d/redis_sensor.sh
@echo "Removal complete"