1#  -*- Mode: rpm-spec; indent-tabs-mode: nil -*- */
2#  SPDX-License-Identifier: LGPL-2.1-or-later
3#
4#  This file is part of systemd.
5
6# RPM macros for packages installing systemd unit files
7
8%_systemd_util_dir {{ROOTLIBEXECDIR}}
9%_unitdir {{SYSTEM_DATA_UNIT_DIR}}
10%_userunitdir {{USER_DATA_UNIT_DIR}}
11%_presetdir {{SYSTEM_PRESET_DIR}}
12%_userpresetdir {{USER_PRESET_DIR}}
13%_udevhwdbdir {{UDEV_HWDB_DIR}}
14%_udevrulesdir {{UDEV_RULES_DIR}}
15%_journalcatalogdir {{SYSTEMD_CATALOG_DIR}}
16%_binfmtdir {{BINFMT_DIR}}
17%_sysctldir {{SYSCTL_DIR}}
18%_sysusersdir {{SYSUSERS_DIR}}
19%_tmpfilesdir {{TMPFILES_DIR}}
20%_environmentdir {{ENVIRONMENT_DIR}}
21%_modulesloaddir {{MODULESLOAD_DIR}}
22%_modprobedir {{MODPROBE_DIR}}
23%_systemdgeneratordir {{SYSTEM_GENERATOR_DIR}}
24%_systemdusergeneratordir {{USER_GENERATOR_DIR}}
25%_systemd_system_env_generator_dir {{SYSTEM_ENV_GENERATOR_DIR}}
26%_systemd_user_env_generator_dir {{USER_ENV_GENERATOR_DIR}}
27
28# Because we had one release with a typo...
29# This is temporary (Remove after systemd 240 is released)
30%_environmnentdir %{warn:Use %%_environmentdir instead}%_environmentdir
31
32%systemd_requires \
33Requires(post): systemd \
34Requires(preun): systemd \
35Requires(postun): systemd \
36%{nil}
37
38%systemd_ordering \
39OrderWithRequires(post): systemd \
40OrderWithRequires(preun): systemd \
41OrderWithRequires(postun): systemd \
42%{nil}
43
44%__systemd_someargs_0(:) %{error:The %%%1 macro requires some arguments}
45%__systemd_twoargs_2() %{nil}
46
47%systemd_post() \
48%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_post}} \
49if [ $1 -eq 1 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \
50    # Initial installation \
51    {{SYSTEMD_UPDATE_HELPER_PATH}} install-system-units %{?*} || : \
52fi \
53%{nil}
54
55%systemd_user_post() \
56%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_user_post}} \
57if [ $1 -eq 1 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \
58    # Initial installation \
59    {{SYSTEMD_UPDATE_HELPER_PATH}} install-user-units %{?*} || : \
60fi \
61%{nil}
62
63%systemd_preun() \
64%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_preun}} \
65if [ $1 -eq 0 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \
66    # Package removal, not upgrade \
67    {{SYSTEMD_UPDATE_HELPER_PATH}} remove-system-units %{?*} || : \
68fi \
69%{nil}
70
71%systemd_user_preun() \
72%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_user_preun}} \
73if [ $1 -eq 0 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \
74    # Package removal, not upgrade \
75    {{SYSTEMD_UPDATE_HELPER_PATH}} remove-user-units %{?*} || : \
76fi \
77%{nil}
78
79%systemd_postun() \
80%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_postun}} \
81%{nil}
82
83%systemd_user_postun() \
84%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_user_postun}} \
85%{nil}
86
87%systemd_postun_with_restart() \
88%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_postun_with_restart}} \
89if [ $1 -ge 1 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \
90    # Package upgrade, not uninstall \
91    {{SYSTEMD_UPDATE_HELPER_PATH}} mark-restart-system-units %{?*} || : \
92fi \
93%{nil}
94
95%systemd_user_postun_with_restart() \
96%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_user_postun_with_restart}} \
97if [ $1 -ge 1 ] && [ -x "{{SYSTEMD_UPDATE_HELPER_PATH}}" ]; then \
98    # Package upgrade, not uninstall \
99    {{SYSTEMD_UPDATE_HELPER_PATH}} mark-restart-user-units %{?*} || : \
100fi \
101%{nil}
102
103%udev_hwdb_update() %{nil}
104
105%udev_rules_update() %{nil}
106
107%journal_catalog_update() %{nil}
108
109# Deprecated. Use %tmpfiles_create_package instead
110%tmpfiles_create() \
111%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# tmpfiles_create}} \
112command -v systemd-tmpfiles >/dev/null && systemd-tmpfiles --create %{?*} || : \
113%{nil}
114
115# Deprecated. Use %sysusers_create_package instead
116%sysusers_create() \
117%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# sysusers_create}} \
118command -v systemd-sysusers >/dev/null && systemd-sysusers %{?*} || : \
119%{nil}
120
121%sysusers_create_inline() \
122command -v systemd-sysusers >/dev/null && systemd-sysusers - <<SYSTEMD_INLINE_EOF || : \
123%{?*} \
124SYSTEMD_INLINE_EOF\
125%{nil}
126
127# This should be used by package installation scripts which require users or
128# groups to be present before the files installed by the package are present on
129# disk (for example because some files are owned by those users or groups).
130#
131# Example:
132#   Source1: %{name}-sysusers.conf
133#   ...
134#   %install
135#   install -D %SOURCE1 %{buildroot}%{_sysusersdir}/%{name}.conf
136#   %pre
137#   %sysusers_create_package %{name} %SOURCE1
138#   %files
139#   %{_sysusersdir}/%{name}.conf
140%sysusers_create_package() \
141%{expand:%%{?!__systemd_twoargs_%#:%%{error:The %%%%sysusers_create_package macro requires two arguments}}} \
142systemd-sysusers --replace=%_sysusersdir/%1.conf - <<SYSTEMD_INLINE_EOF || : \
143%(cat %2) \
144SYSTEMD_INLINE_EOF\
145%{nil}
146
147# This may be used by package installation scripts to create files according to
148# their tmpfiles configuration from a package installation script, even before
149# the files of that package are installed on disk.
150#
151# Example:
152#   Source1: %{name}-tmpfiles.conf
153#   ...
154#   %install
155#   install -D %SOURCE1 %{buildroot}%{_tmpfilesdir}/%{name}.conf
156#   %pre
157#   %tmpfiles_create_package %{name} %SOURCE1
158#   %files
159#   %{_tmpfilesdir}/%{name}.conf
160%tmpfiles_create_package() \
161%{expand:%%{?!__systemd_twoargs_%#:%%{error:The %%%%tmpfiles_create_package macro requires two arguments}}} \
162systemd-tmpfiles --replace=%_tmpfilesdir/%1.conf --create - <<SYSTEMD_INLINE_EOF || : \
163%(cat %2) \
164SYSTEMD_INLINE_EOF\
165%{nil}
166
167%sysctl_apply() \
168%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# sysctl_apply}} \
169[ -x {{ROOTLIBEXECDIR}}/systemd-sysctl ] && {{ROOTLIBEXECDIR}}/systemd-sysctl %{?*} || : \
170%{nil}
171
172%binfmt_apply() \
173%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# binfmt_apply}} \
174[ -x {{ROOTLIBEXECDIR}}/systemd-binfmt ] && {{ROOTLIBEXECDIR}}/systemd-binfmt %{?*} || : \
175%{nil}
176