summaryrefslogtreecommitdiff
path: root/spec/macros.inc
blob: d4e99e6ae0a19cd17726709957cf980494a47840 (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
72
73
74
75
76
77
78
79
80
81
82
83
%global _default_pid_dir /run
%global _default_dm_run_dir /run
%global _default_run_dir /run/lvm
%global _default_locking_dir /run/lock/lvm
%global _udevbasedir %{_prefix}/lib/udev
%global _udevdir %{_udevbasedir}/rules.d
%global _tmpfilesdir %{_prefix}/lib/tmpfiles.d

%if !0%{?fedora}
%global fedora 0
%endif

%if !0%{?rhel}
%global rhel 0
%endif

%global enableif() \
%%global configure_flags %%{?configure_flags} --%%(if test %%1 -gt 0; then echo enable-%%2; else echo disable-%%2; fi)

%global with() \
%%global configure_flags %%(echo -n "%%{?configure_flags} " | sed -e "s,--with-%%1=[^ ]*,,"; test -n "%%{?2}" && echo --with-%%1=%%2) \
%%global with_flags %%(echo -n "%%{?with_flags} " | sed -e "s,%%1,,"; test -n "%%{?2}" && test "%%{?2}" != none && echo %%1)

%global services monitor
%global service() \
%%global services %%(echo -n "%%{?services} " | sed -e s,%%1,,; test "%%2" = 1 && echo %%1)

%global maybe() \
%%if %%(test -n "%%{?2}" && echo 1 || echo 0) \
%%* \
%%endif

%global have_with() %%(if echo %%{with_flags} | grep -q %%1; then echo 1; else echo 0; fi)
%global have_service() %%(if echo %%{services} | grep -q %%1; then echo 1; else echo 0; fi)

%global daemon_reload \
%%if %%{enable_systemd} \
systemctl daemon-reload > /dev/null 2>&1 || : \
%%endif \
: \
%%{nil}

%global enable(s:t:) \
%%if %%{have_service %%{-s*}} \
%%if %%{enable_systemd} \
if [ $1 = 1 ]; then \
	systemctl preset lvm2-%%{-s*}.%%{-t*} > /dev/null 2>&1 || : \
fi \
%%else \
/sbin/chkconfig --add lvm2-%%{-s*} \
%%endif \
%%endif \
: \
%%{nil}

%global disable(s:t:) \
%%if %%{have_service %%{-s*}} \
%%if %%{enable_systemd} \
if [ $1 = 0 ]; then \
	systemctl --no-reload disable lvm2-%%{-s*}.%%{-t*} > /dev/null 2>&1 || : \
	%%if "%%{-t*}" == "socket" \
	systemctl --no-reload disable lvm2-%%{-s*}.service > /dev/null 2>&1 || : \
	%%endif \
	systemctl stop lvm2-%%{-s*}.%%{-t*} > /dev/null 2>&1 || : \
	%%if "%%{-t*}" == "socket" \
	systemctl stop lvm2-%%{-s*}.service > /dev/null 2>&1 || : \
	%%endif \
fi \
%%else \
/sbin/chkconfig --del lvm2-%%{-s*} \
%%endif \
%%endif \
: \
%%{nil}

%global try_restart(s:t:) \
%%if %%{have_service %%{-s*}} && %%{enable_systemd} \
if [ $1 = 1 ]; then \
	systemctl try-restart lvm2-%%{-s*}.%%{-t*} > /dev/null 2>&1 || : \
fi \
%%endif \
: \
%%{nil}