-
-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathMakefile
More file actions
87 lines (74 loc) · 2.68 KB
/
Copy pathMakefile
File metadata and controls
87 lines (74 loc) · 2.68 KB
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
DESTDIR:=
prefix:=$(DESTDIR)/opt
REBAR3:=./rebar3
SERVICE:=$(DESTDIR)/etc/systemd/system/mtproto-proxy.service
EPMD_SERVICE:=$(DESTDIR)/etc/systemd/system/epmd.service
LOGDIR:=$(DESTDIR)/var/log/mtproto-proxy
USER:=mtproto-proxy
# ROLE selects which config templates are used.
# Values: both (default, single server), front (domestic), back (foreign).
# For split mode: run `make init-config ROLE=front` / `make init-config ROLE=back`
# on each server, edit the resulting config files, then run `make ROLE=front` etc.
ROLE ?= both
ifeq ($(ROLE),front)
SYS_CONFIG_SRC := config/sys.config.front.example
VM_ARGS_SRC := config/vm.args.front.example
else ifeq ($(ROLE),back)
SYS_CONFIG_SRC := config/sys.config.back.example
VM_ARGS_SRC := config/vm.args.back.example
else
SYS_CONFIG_SRC := config/sys.config.example
VM_ARGS_SRC := config/vm.args.example
endif
all: config/prod-sys.config config/prod-vm.args
$(REBAR3) as prod release
.PHONY: test
test:
$(REBAR3) xref
$(REBAR3) eunit -c
$(REBAR3) ct -c
$(REBAR3) proper -c -n 50
$(REBAR3) dialyzer
$(REBAR3) cover -v
config/prod-sys.config: $(SYS_CONFIG_SRC)
[ -f $@ ] && diff -u $@ $^ || true
cp -i -b $^ $@
config/prod-vm.args: $(VM_ARGS_SRC)
[ -f $@ ] && diff -u $@ $^ || true
cp -i -b $^ $@
@IP=$(shell curl -s -4 -m 10 http://ip.seriyps.com || curl -s -4 -m 10 https://digitalresistance.dog/myIp) \
&& sed -i s/@0\.0\.0\.0/@$${IP}/ $@
.PHONY: init-config
init-config:
cp $(SYS_CONFIG_SRC) config/prod-sys.config
cp $(VM_ARGS_SRC) config/prod-vm.args
@IP=$$(curl -s -4 -m 10 http://ip.seriyps.com || curl -s -4 -m 10 https://digitalresistance.dog/myIp) \
&& sed -i s/@0\.0\.0\.0/@$${IP}/ config/prod-vm.args; true
@echo ""
@echo "Config created from ROLE=$(ROLE) templates."
@echo "Edit config/prod-sys.config and config/prod-vm.args, then run: make [ROLE=$(ROLE)]"
user:
sudo useradd -r $(USER) || true
$(LOGDIR):
mkdir -p $(LOGDIR)/
chown $(USER) $(LOGDIR)/
install: user $(LOGDIR)
mkdir -p $(prefix)
cp -r _build/prod/rel/mtp_proxy $(prefix)/
mkdir -p $(prefix)/mtp_proxy/log/
chmod 777 $(prefix)/mtp_proxy/log/
install -D config/mtproto-proxy.service $(SERVICE)
# If there is no "epmd" service, install one
if [ -z "`systemctl show -p FragmentPath epmd | cut -d = -f 2`" ]; then \
install -D config/epmd.service $(EPMD_SERVICE); \
fi
systemctl daemon-reload
.PHONY: update-sysconfig
update-sysconfig: config/prod-sys.config $(prefix)/mtp_proxy
REL_VSN=$(shell cut -d " " -f 2 $(prefix)/mtp_proxy/releases/start_erl.data) && \
install -m 644 config/prod-sys.config "$(prefix)/mtp_proxy/releases/$${REL_VSN}/sys.config"
uninstall:
# TODO: ensure service is stopped
rm $(SERVICE)
rm -r $(prefix)/mtp_proxy/
systemctl daemon-reload