summaryrefslogtreecommitdiff
path: root/make/openrc.mk
blob: 47ddb7ff00e39c3faefe6a64280c39bb1338550f (plain)
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
is_openrc_module = $(filter $(COMPOSE_SERVICES),$(module))
openrc_module_target = $(if $(is_openrc_module),~/.config/rc/init.d/joeac.net.$(module))

define install_openrc_module_rule =
.PHONY: install_openrc_$(module)
install_openrc_$(module): $(if $(is_openrc_module),$(openrc_module_target) openrc_add_$(module) openrc_start_$(module))

~/.config/rc/init.d/joeac.net.$(module): ~/.config/rc/init.d/joeac.net ~/.config/rc/runlevels/default
	ln -s $(shell realpath ~)/.config/rc/init.d/joeac.net ~/.config/rc/init.d/joeac.net.$(module)
endef

define reinstall_openrc_module_rule =
.PHONY: reinstall_openrc_$(module)
reinstall_openrc_$(module): $(if $(is_openrc_module),$(openrc_module_target) openrc_restart_$(module))
endef

define uninstall_openrc_module_rule =
.PHONY: uninstall_openrc_$(module)
uninstall_openrc_$(module):
	$(if $(is_openrc_module),\
		rc-service -U joeac.net.$(module) stop; \
		rc-update -U del joeac.net.$(module) default; \
		rm ~/.config/rc/init.d/joeac.net.$(module); \
	)
endef

define openrc_add_rule =
.PHONY: openrc_add_$(module)
openrc_add_$(module):
	rc-update -U add joeac.net.$(module) default
endef

define openrc_start_rule =
.PHONY: openrc_start_$(module)
openrc_start_$(module):
	rc-service -U joeac.net.$(module) start
endef

define openrc_restart_rule =
.PHONY: openrc_restart_$(module)
openrc_restart_$(module):
	rc-service -U joeac.net.$(module) restart
endef

$(foreach module,$(MODULES),$(eval $(install_openrc_module_rule)))
$(foreach module,$(MODULES),$(eval $(reinstall_openrc_module_rule)))
$(foreach module,$(MODULES),$(eval $(uninstall_openrc_module_rule)))
$(foreach module,$(MODULES),$(eval $(openrc_add_rule)))
$(foreach module,$(MODULES),$(eval $(openrc_start_rule)))
$(foreach module,$(MODULES),$(eval $(openrc_restart_rule)))

~/.config/rc/init.d/joeac.net: openrc/init.d/joeac.net ~/.config/rc/init.d ~/.config/rc/runlevels/default /etc/init.d/user.$(shell whoami) /etc/conf.d/user.$(shell whoami)
	rm -f ~/.config/rc/init.d/joeac.net; \
	mkdir -p ~/.config/rc/init.d; \
	cp openrc/init.d/joeac.net ~/.config/rc/init.d/joeac.net

~/.config/rc/init.d:
	mkdir -p ~/.config/rc/init.d

~/.config/rc/runlevels/default:
	mkdir -p ~/.config/rc/runlevels/default

/etc/init.d/user.$(shell whoami):
	sudo ln -s /etc/init.d/user /etc/init.d/user.$(shell whoami)

/etc/conf.d/user.$(shell whoami): openrc/conf.d/user.$(shell whoami)
	sudo cp openrc/conf.d/user.$(shell whoami) /etc/conf.d/user.$(shell whoami)
	sudo rc-update add user.$(shell whoami) default

.PHONY: uninstall_joeac.net_service
	rm ~/.config/rc/joeac.net