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

Contents of /eclass/systemd.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (show annotations) (download)
Mon Aug 27 21:54:19 2012 UTC (2 years, 11 months ago) by mgorny
Branch: MAIN
Changes since 1.12: +9 -1 lines
tmpfiles.d: ensure .conf suffix when installing.

1 # Copyright 1999-2012 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/systemd.eclass,v 1.12 2012/08/27 21:53:04 mgorny Exp $
4
5 # @ECLASS: systemd.eclass
6 # @MAINTAINER:
7 # mgorny@gentoo.org
8 # @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 #
17 # 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 case ${EAPI:-0} in
29 0|1|2|3|4) ;;
30 *) die "${ECLASS}.eclass API in EAPI ${EAPI} not yet established."
31 esac
32
33 # Block systemd version without the migration helper.
34 DEPEND="!<sys-apps/systemd-29-r4
35 !=sys-apps/systemd-37-r1"
36
37 # @FUNCTION: _systemd_get_unitdir
38 # @INTERNAL
39 # @DESCRIPTION:
40 # Get unprefixed unitdir.
41 _systemd_get_unitdir() {
42 echo -n /usr/lib/systemd/system
43 }
44
45 # @FUNCTION: systemd_get_unitdir
46 # @DESCRIPTION:
47 # Output the path for the systemd unit directory (not including ${D}).
48 # This function always succeeds, even if systemd is not installed.
49 systemd_get_unitdir() {
50 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
51 debug-print-function ${FUNCNAME} "${@}"
52
53 echo -n "${EPREFIX}$(_systemd_get_unitdir)"
54 }
55
56 # @FUNCTION: systemd_dounit
57 # @USAGE: unit1 [...]
58 # @DESCRIPTION:
59 # Install systemd unit(s). Uses doins, thus it is fatal in EAPI 4
60 # and non-fatal in earlier EAPIs.
61 systemd_dounit() {
62 debug-print-function ${FUNCNAME} "${@}"
63
64 (
65 insinto "$(_systemd_get_unitdir)"
66 doins "${@}"
67 )
68 }
69
70 # @FUNCTION: systemd_newunit
71 # @USAGE: oldname newname
72 # @DESCRIPTION:
73 # Install systemd unit with a new name. Uses newins, thus it is fatal
74 # in EAPI 4 and non-fatal in earlier EAPIs.
75 systemd_newunit() {
76 debug-print-function ${FUNCNAME} "${@}"
77
78 (
79 insinto "$(_systemd_get_unitdir)"
80 newins "${@}"
81 )
82 }
83
84 # @FUNCTION: systemd_dotmpfilesd
85 # @USAGE: tmpfilesd1 [...]
86 # @DESCRIPTION:
87 # Install systemd tmpfiles.d files. Uses doins, thus it is fatal
88 # in EAPI 4 and non-fatal in earlier EAPIs.
89 systemd_dotmpfilesd() {
90 debug-print-function ${FUNCNAME} "${@}"
91
92 for f; do
93 [[ ${f} == *.conf ]] \
94 || die 'tmpfiles.d files need to have .conf suffix.'
95 done
96
97 (
98 insinto /usr/lib/tmpfiles.d/
99 doins "${@}"
100 )
101 }
102
103 # @FUNCTION: systemd_newtmpfilesd
104 # @USAGE: oldname newname.conf
105 # @DESCRIPTION:
106 # Install systemd tmpfiles.d file under a new name. Uses newins, thus it
107 # is fatal in EAPI 4 and non-fatal in earlier EAPIs.
108 systemd_newtmpfilesd() {
109 debug-print-function ${FUNCNAME} "${@}"
110
111 [[ ${2} == *.conf ]] \
112 || die 'tmpfiles.d files need to have .conf suffix.'
113
114 (
115 insinto /usr/lib/tmpfiles.d/
116 newins "${@}"
117 )
118 }
119
120 # @FUNCTION: systemd_enable_service
121 # @USAGE: target service
122 # @DESCRIPTION:
123 # Enable service in desired target, e.g. install a symlink for it.
124 # Uses dosym, thus it is fatal in EAPI 4 and non-fatal in earlier
125 # EAPIs.
126 systemd_enable_service() {
127 debug-print-function ${FUNCNAME} "${@}"
128
129 [[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service"
130
131 local target=${1}
132 local service=${2}
133 local ud=$(_systemd_get_unitdir)
134 local destname=$(basename "${service}")
135
136 dodir "${ud}"/"${target}".wants && \
137 dosym ../"${service}" "${ud}"/"${target}".wants/"${destname}"
138 }
139
140 # @FUNCTION: systemd_with_unitdir
141 # @USAGE: [configure option]
142 # @DESCRIPTION:
143 # Output '--with-systemdsystemunitdir' as expected by systemd-aware configure
144 # scripts. This function always succeeds. Its output may be quoted in order
145 # to preserve whitespace in paths. systemd_to_myeconfargs() is preferred over
146 # this function.
147 #
148 # If upstream does use invalid configure option to handle installing systemd
149 # units (e.g. `--with-systemdunitdir'), you can pass the 'suffix' as an optional
150 # argument to this function (`$(systemd_with_unitdir systemdunitdir)'). Please
151 # remember to report a bug upstream as well.
152 systemd_with_unitdir() {
153 debug-print-function ${FUNCNAME} "${@}"
154 local optname=${1:-systemdsystemunitdir}
155
156 echo -n --with-${optname}="$(systemd_get_unitdir)"
157 }
158
159 # @FUNCTION: systemd_to_myeconfargs
160 # @DESCRIPTION:
161 # Add '--with-systemdsystemunitdir' as expected by systemd-aware configure
162 # scripts to the myeconfargs variable used by autotools-utils eclass. Handles
163 # quoting automatically.
164 systemd_to_myeconfargs() {
165 debug-print-function ${FUNCNAME} "${@}"
166
167 myeconfargs=(
168 "${myeconfargs[@]}"
169 --with-systemdsystemunitdir="$(systemd_get_unitdir)"
170 )
171 }

  ViewVC Help
Powered by ViewVC 1.1.20