/[gentoo-x86]/eclass/systemd.eclass
Gentoo

Contents of /eclass/systemd.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.24 - (hide annotations) (download)
Sat Apr 13 22:36:51 2013 UTC (17 months, 2 weeks ago) by mgorny
Branch: MAIN
Changes since 1.23: +3 -3 lines
Fix unnecessary $().

1 mgorny 1.22 # Copyright 1999-2013 Gentoo Foundation
2 mgorny 1.1 # Distributed under the terms of the GNU General Public License v2
3 mgorny 1.24 # $Header: /var/cvsroot/gentoo-x86/eclass/systemd.eclass,v 1.23 2013/04/13 22:35:53 mgorny Exp $
4 mgorny 1.1
5     # @ECLASS: systemd.eclass
6     # @MAINTAINER:
7 mgorny 1.22 # systemd@gentoo.org
8 mgorny 1.1 # @BLURB: helper functions to install systemd units
9     # @DESCRIPTION:
10     # This eclass provides a set of functions to install unit files for
11     # sys-apps/systemd within ebuilds.
12     # @EXAMPLE:
13     #
14     # @CODE
15     # inherit autotools-utils systemd
16 vapier 1.8 #
17 mgorny 1.1 # src_configure() {
18     # local myeconfargs=(
19     # --enable-foo
20     # --disable-bar
21     # )
22     #
23     # systemd_to_myeconfargs
24     # autotools-utils_src_configure
25     # }
26     # @CODE
27    
28 mgorny 1.23 inherit toolchain-funcs
29    
30 mgorny 1.1 case ${EAPI:-0} in
31 axs 1.15 0|1|2|3|4|5) ;;
32 mgorny 1.1 *) die "${ECLASS}.eclass API in EAPI ${EAPI} not yet established."
33     esac
34    
35 mgorny 1.23 DEPEND="virtual/pkgconfig"
36    
37 mgorny 1.9 # @FUNCTION: _systemd_get_unitdir
38     # @INTERNAL
39     # @DESCRIPTION:
40     # Get unprefixed unitdir.
41     _systemd_get_unitdir() {
42 mgorny 1.23 if $(tc-getPKG_CONFIG) --exists systemd; then
43     echo "$($(tc-getPKG_CONFIG) --variable=systemdsystemunitdir systemd)"
44     else
45     echo /usr/lib/systemd/system
46     fi
47 mgorny 1.9 }
48    
49 mgorny 1.1 # @FUNCTION: systemd_get_unitdir
50     # @DESCRIPTION:
51     # Output the path for the systemd unit directory (not including ${D}).
52     # This function always succeeds, even if systemd is not installed.
53     systemd_get_unitdir() {
54 darkside 1.6 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
55 mgorny 1.1 debug-print-function ${FUNCNAME} "${@}"
56    
57 mgorny 1.16 echo "${EPREFIX}$(_systemd_get_unitdir)"
58 mgorny 1.1 }
59    
60 mgorny 1.23 # @FUNCTION: _systemd_get_userunitdir
61     # @INTERNAL
62     # @DESCRIPTION:
63     # Get unprefixed userunitdir.
64     _systemd_get_userunitdir() {
65 mgorny 1.24 if $(tc-getPKG_CONFIG) --exists systemd; then
66 mgorny 1.23 echo "$($(tc-getPKG_CONFIG) --variable=systemduserunitdir systemd)"
67     else
68     echo /usr/lib/systemd/user
69     fi
70     }
71    
72 mgorny 1.21 # @FUNCTION: systemd_get_userunitdir
73     # @DESCRIPTION:
74     # Output the path for the systemd user unit directory (not including
75     # ${D}). This function always succeeds, even if systemd is not
76     # installed.
77     systemd_get_userunitdir() {
78     has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
79     debug-print-function ${FUNCNAME} "${@}"
80    
81 mgorny 1.23 echo "${EPREFIX}$(_systemd_get_userunitdir)"
82     }
83    
84     # @FUNCTION: _systemd_get_utildir
85     # @INTERNAL
86     # @DESCRIPTION:
87     # Get unprefixed utildir.
88     _systemd_get_utildir() {
89 mgorny 1.24 if $(tc-getPKG_CONFIG) --exists systemd; then
90 mgorny 1.23 echo "$($(tc-getPKG_CONFIG) --variable=systemdutildir systemd)"
91     else
92     echo /usr/lib/systemd
93     fi
94 mgorny 1.21 }
95    
96 mgorny 1.17 # @FUNCTION: systemd_get_utildir
97     # @DESCRIPTION:
98     # Output the path for the systemd utility directory (not including
99     # ${D}). This function always succeeds, even if systemd is not
100     # installed.
101     systemd_get_utildir() {
102     has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
103     debug-print-function ${FUNCNAME} "${@}"
104    
105 mgorny 1.23 echo "${EPREFIX}$(_systemd_get_utildir)"
106 mgorny 1.17 }
107    
108 mgorny 1.1 # @FUNCTION: systemd_dounit
109     # @USAGE: unit1 [...]
110     # @DESCRIPTION:
111     # Install systemd unit(s). Uses doins, thus it is fatal in EAPI 4
112     # and non-fatal in earlier EAPIs.
113     systemd_dounit() {
114     debug-print-function ${FUNCNAME} "${@}"
115    
116 mgorny 1.19 local INSDESTTREE
117     insinto "$(_systemd_get_unitdir)"
118     doins "${@}"
119 mgorny 1.1 }
120    
121 mgorny 1.5 # @FUNCTION: systemd_newunit
122     # @USAGE: oldname newname
123     # @DESCRIPTION:
124     # Install systemd unit with a new name. Uses newins, thus it is fatal
125     # in EAPI 4 and non-fatal in earlier EAPIs.
126     systemd_newunit() {
127     debug-print-function ${FUNCNAME} "${@}"
128    
129 mgorny 1.19 local INSDESTTREE
130     insinto "$(_systemd_get_unitdir)"
131     newins "${@}"
132 mgorny 1.5 }
133    
134 mgorny 1.3 # @FUNCTION: systemd_dotmpfilesd
135     # @USAGE: tmpfilesd1 [...]
136     # @DESCRIPTION:
137     # Install systemd tmpfiles.d files. Uses doins, thus it is fatal
138     # in EAPI 4 and non-fatal in earlier EAPIs.
139     systemd_dotmpfilesd() {
140     debug-print-function ${FUNCNAME} "${@}"
141    
142 mgorny 1.13 for f; do
143     [[ ${f} == *.conf ]] \
144     || die 'tmpfiles.d files need to have .conf suffix.'
145     done
146    
147 mgorny 1.19 local INSDESTTREE
148     insinto /usr/lib/tmpfiles.d/
149     doins "${@}"
150 mgorny 1.3 }
151    
152 mgorny 1.12 # @FUNCTION: systemd_newtmpfilesd
153     # @USAGE: oldname newname.conf
154     # @DESCRIPTION:
155     # Install systemd tmpfiles.d file under a new name. Uses newins, thus it
156     # is fatal in EAPI 4 and non-fatal in earlier EAPIs.
157     systemd_newtmpfilesd() {
158     debug-print-function ${FUNCNAME} "${@}"
159    
160 mgorny 1.13 [[ ${2} == *.conf ]] \
161     || die 'tmpfiles.d files need to have .conf suffix.'
162    
163 mgorny 1.19 local INSDESTTREE
164     insinto /usr/lib/tmpfiles.d/
165     newins "${@}"
166 mgorny 1.12 }
167    
168 mgorny 1.1 # @FUNCTION: systemd_enable_service
169     # @USAGE: target service
170     # @DESCRIPTION:
171     # Enable service in desired target, e.g. install a symlink for it.
172     # Uses dosym, thus it is fatal in EAPI 4 and non-fatal in earlier
173     # EAPIs.
174     systemd_enable_service() {
175     debug-print-function ${FUNCNAME} "${@}"
176    
177     [[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service"
178    
179     local target=${1}
180     local service=${2}
181 mgorny 1.9 local ud=$(_systemd_get_unitdir)
182 mgorny 1.10 local destname=$(basename "${service}")
183 mgorny 1.1
184     dodir "${ud}"/"${target}".wants && \
185 mgorny 1.10 dosym ../"${service}" "${ud}"/"${target}".wants/"${destname}"
186 mgorny 1.1 }
187    
188     # @FUNCTION: systemd_with_unitdir
189 mgorny 1.4 # @USAGE: [configure option]
190 mgorny 1.1 # @DESCRIPTION:
191     # Output '--with-systemdsystemunitdir' as expected by systemd-aware configure
192     # scripts. This function always succeeds. Its output may be quoted in order
193     # to preserve whitespace in paths. systemd_to_myeconfargs() is preferred over
194     # this function.
195 mgorny 1.4 #
196     # If upstream does use invalid configure option to handle installing systemd
197     # units (e.g. `--with-systemdunitdir'), you can pass the 'suffix' as an optional
198     # argument to this function (`$(systemd_with_unitdir systemdunitdir)'). Please
199     # remember to report a bug upstream as well.
200 mgorny 1.1 systemd_with_unitdir() {
201     debug-print-function ${FUNCNAME} "${@}"
202 mgorny 1.4 local optname=${1:-systemdsystemunitdir}
203 mgorny 1.1
204 mgorny 1.16 echo --with-${optname}="$(systemd_get_unitdir)"
205 mgorny 1.1 }
206    
207 mgorny 1.18 # @FUNCTION: systemd_with_utildir
208     # @DESCRIPTION:
209     # Output '--with-systemdsystemutildir' as used by some packages to install
210     # systemd helpers. This function always succeeds. Its output may be quoted
211     # in order to preserve whitespace in paths.
212     systemd_with_utildir() {
213     debug-print-function ${FUNCNAME} "${@}"
214    
215     echo --with-systemdutildir="$(systemd_get_utildir)"
216     }
217    
218 mgorny 1.1 # @FUNCTION: systemd_to_myeconfargs
219     # @DESCRIPTION:
220     # Add '--with-systemdsystemunitdir' as expected by systemd-aware configure
221     # scripts to the myeconfargs variable used by autotools-utils eclass. Handles
222     # quoting automatically.
223     systemd_to_myeconfargs() {
224     debug-print-function ${FUNCNAME} "${@}"
225    
226     myeconfargs=(
227     "${myeconfargs[@]}"
228     --with-systemdsystemunitdir="$(systemd_get_unitdir)"
229     )
230     }
231 mgorny 1.20
232     # @FUNCTION: systemd_update_catalog
233     # @DESCRIPTION:
234     # Update the journald catalog. This needs to be called after installing
235     # or removing catalog files.
236     #
237     # If systemd is not installed, no operation will be done. The catalog
238     # will be (re)built once systemd is installed.
239     #
240     # See: http://www.freedesktop.org/wiki/Software/systemd/catalog
241     systemd_update_catalog() {
242     debug-print-function ${FUNCNAME} "${@}"
243    
244     # Make sure to work on the correct system.
245 mgorny 1.23
246 mgorny 1.20 local journalctl=${EPREFIX}/usr/bin/journalctl
247     if [[ -x ${journalctl} ]]; then
248     ebegin "Updating systemd journal catalogs"
249     journalctl --update-catalog
250     eend $?
251     else
252     debug-print "${FUNCNAME}: journalctl not found."
253     fi
254     }

  ViewVC Help
Powered by ViewVC 1.1.20