-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
223 lines (161 loc) · 6.31 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
config ?= config.json
SHELL := /bin/bash # for curly-brace expansion
HOME_ASSISTANT_CONFIG := ~/network/home-assistant/config
DEV_SYSTEMD_CONFIG_DIR := ~/.config/systemd/user
LIVE_SYSTEMD_CONFIG_DIR := /etc/systemd/system
LIVE_NGINX_CONFIG_DIR := /etc/nginx/sites-available
VENV := .venv
SYSTEMCTL_USER ?=
ALL_HOSTS := \
study \
kitchen \
library \
lounge \
ballroom \
ballroom-patio \
outside \
bedroom-mark \
ALL_LOGICAL := \
announcer \
everywhere \
ALL_ZONES := \
$(ALL_HOSTS) \
$(ALL_LOGICAL) \
EXP_SERVICES := {snapclient,mopidy}
DEV_UNITS := \
$(DEV_SYSTEMD_CONFIG_DIR)/snapserver.service \
$(DEV_SYSTEMD_CONFIG_DIR)/snapclient@.service \
$(DEV_SYSTEMD_CONFIG_DIR)/mopidy@.service \
$(DEV_SYSTEMD_CONFIG_DIR)/multizone-audio-control.service \
DEBIAN_UNITS := \
$(LIVE_SYSTEMD_CONFIG_DIR)/mopidy@.service \
$(LIVE_SYSTEMD_CONFIG_DIR)/multizone-audio-control.service \
ALL_MOPIDY := $(patsubst %, mopidy.%.conf, $(ALL_ZONES))
ALL_AIRPLAY := $(patsubst %, shairport-sync.%.conf, $(ALL_HOSTS))
ALL_SNAPCLIENTS := $(patsubst %, snapclient.%.conf, $(ALL_HOSTS))
ALL_SPOTIFY := $(patsubst %, librespot.%.toml, $(ALL_ZONES))
ALL_NGINX := $(patsubst %, iris.%.conf, $(ALL_HOSTS))
ALL_HOME_ASSISTANT := $(patsubst %, home-assistant.%.yaml, $(ALL_ZONES))
ALL_HOME_ASSISTANT_INSTALL := \
$(patsubst %, $(HOME_ASSISTANT_CONFIG)/packages/%/media.yaml, $(ALL_HOSTS)) \
$(patsubst %, $(HOME_ASSISTANT_CONFIG)/packages/multizone-audio-%.yaml, $(ALL_LOGICAL))
ALL_CONFIGS := \
../snapserver.conf \
snapcast-autoconfig.yaml \
$(ALL_MOPIDY) \
$(ALL_AIRPLAY) \
$(ALL_NGINX) \
$(ALL_HOME_ASSISTANT) \
$(ALL_SPOTIFY) \
$(ALL_SNAPCLIENTS) \
DEV_CONFIGS := \
dev/snapserver.service \
dev/snapclient@.service \
dev/mopidy@.service \
dev/multizone-audio-control.service \
LIVE_CONFIGS := \
debian/mopidy@.service \
debian/multizone-audio-control.service \
ALL_SERVICES := \
$(patsubst %, ${EXP_SERVICES}@%, $(ALL_HOSTS)) \
$(patsubst %, mopidy@%, $(ALL_LOGICAL))
all: $(ALL_CONFIGS)
# Find chevron or create a venv and install it
SYS_CHEVRON := $(shell which chevron)
ifeq (, $(SYS_CHEVRON))
CHEVRON := $(VENV)/bin/chevron
$(CHEVRON): venv
else
CHEVRON := $(SYS_CHEVRON)
endif
RENDER := render.py
$(VENV):
$(info "No chevron in $(PATH). Installing in $(VENV)")
python3 -m venv $(VENV)
$(VENV)/bin/pip install chevron
venv: $(VENV)
nginx: $(ALL_NGINX)
home-assistant: $(ALL_HOME_ASSISTANT)
$(HOME_ASSISTANT_CONFIG)/packages/%/media.yaml: home-assistant.%.yaml
install -T $^ $@
$(HOME_ASSISTANT_CONFIG)/packages/multizone-audio-%.yaml: home-assistant.%.yaml
install -T $^ $@
ha-install: $(ALL_HOME_ASSISTANT_INSTALL)
dietpi/%.service: templates/dietpi/%.service.template $(config) $(RENDER)
python $(RENDER) -d $(config) $< > $@
dev/%.service: templates/dev/%.service.template $(config) $(RENDER)
-@mkdir -p dev
python $(RENDER) -d $(config) $< > $@
dev/%.service: templates/%.service.template $(config) $(RENDER)
-@mkdir -p dev
python $(RENDER) -d $(config) $< > $@
debian/%.service: templates/debian/%.service.template $(config) $(RENDER)
-@mkdir -p debian
python $(RENDER) -d $(config) $< > $@
debian/%.service: templates/%.service.template $(config) $(RENDER)
-@mkdir -p debian
python $(RENDER) -d $(config) $< > $@
../snapserver.conf: templates/snapserver.template $(config) $(RENDER)
python $(RENDER) -d $(config) $< > $@
snapcast-autoconfig.yaml: templates/snapcast-autoconfig.yaml.template $(config) $(RENDER)
python $(RENDER) -d $(config) $< > $@
mopidy.%.conf: $(config) templates/mopidy.template $(RENDER)
python $(RENDER) -z $* -d $< templates/mopidy.template > $@
snapclient.%.conf: $(config) templates/snapclient.template $(RENDER)
python $(RENDER) -z $* -d $< templates/snapclient.template > $@
shairport-sync.%.conf: $(config) templates/shairport-sync.template $(RENDER)
python $(RENDER) -z $* -d $< templates/shairport-sync.template | grep -v '^//\|^$$' > $@
librespot.%.toml: $(config) templates/librespot.template $(RENDER)
python $(RENDER) -z $* -d $< templates/librespot.template > $@
iris.%.conf: $(config) templates/iris.template $(RENDER)
python $(RENDER) -z $* -d $< templates/iris.template > $@
home-assistant.%.yaml: $(config) templates/home-assistant.yaml.template
python $(RENDER) -z $* -d $< templates/home-assistant.yaml.template > $@
snapserver: ../snapserver.conf
systemctl $(SYSTEMCTL_USER) restart snapserver
controller: controller/multizone-control.py
systemctl $(SYSTEMCTL_USER) restart multizone-audio-control
restart: $(ALL_CONFIGS) $(ALL_SNAPCLIENTS)
systemctl $(SYSTEMCTL_USER) restart $(ALL_SERVICES)
restart-host:
systemctl $(SYSTEMCTL_USER) restart $(EXP_SERVICES)@$(HOST)
start: restart snapserver controller
start-host: restart-host
status:
systemctl $(SYSTEMCTL_USER) status $(ALL_SERVICES)
status-host:
systemctl $(SYSTEMCTL_USER) status $(EXP_SERVICES)@$(HOST)
stop: $(ALL_CONFIGS) $(ALL_SNAPCLIENTS)
systemctl $(SYSTEMCTL_USER) stop $(ALL_SERVICES)
stop-host: $(ALL_CONFIGS) $(ALL_SNAPCLIENTS)
systemctl $(SYSTEMCTL_USER) stop $(EXP_SERVICES)@$(HOST)
# install the systemd unit files in the appropriate place
$(DEV_SYSTEMD_CONFIG_DIR)/%.service: dev/%.service
install -t $(DEV_SYSTEMD_CONFIG_DIR) $^
$(DEV_SYSTEMD_CONFIG_DIR)/%.service: controller/%.service
install -t $(DEV_SYSTEMD_CONFIG_DIR) $^
$(LIVE_SYSTEMD_CONFIG_DIR)/%.service: debian/%.service
install -t $(LIVE_SYSTEMD_CONFIG_DIR) $^
$(LIVE_SYSTEMD_CONFIG_DIR)/%.service: controller/%.service
install -t $(LIVE_SYSTEMD_CONFIG_DIR) $^
dev: $(ALL_CONFIGS) $(DEV_CONFIGS)
dev-install: dev $(DEV_UNITS)
systemctl $(SYSTEMCTL_USER) daemon-reload
debian: $(ALL_CONFIGS) $(LIVE_CONFIGS)
live-install: debian $(DEBIAN_UNITS)
systemctl $(SYSTEMCTL_USER) daemon-reload
# Player install
#
debian-%-install: debian iris.%.conf debian/nginx.override.conf
install -t $(LIVE_NGINX_CONFIG_DIR) iris.$*.conf
install -T -D debian/nginx.override.conf $(LIVE_SYSTEMD_CONFIG_DIR)/nginx.service.d/override.conf
dietpi-%-install: dietpi iris.%.conf dietpi/nginx.override.conf
install -t $(LIVE_NGINX_CONFIG_DIR) iris.$*.conf
install -T -D dietpi/nginx.override.conf $(LIVE_SYSTEMD_CONFIG_DIR)/nginx.service.d/override.conf
clean:
-rm $(ALL_CONFIGS)
# Documentation
%.html: %.md Makefile
pandoc -d multizone-audio --self-contained -f gfm+attributes -t html5 -o $@ $<
doc: doc/demo-001.html
.PHONY: clean install status stop controller debian dev