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

Contents of /eclass/systemd.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (hide annotations) (download)
Mon Aug 27 21:53:04 2012 UTC (19 months, 2 weeks ago) by mgorny
Branch: MAIN
Changes since 1.11: +15 -1 lines
Add systemd_newtmpfilesd().

1 mgorny 1.10 # Copyright 1999-2012 Gentoo Foundation
2 mgorny 1.1 # Distributed under the terms of the GNU General Public License v2
3 mgorny 1.12 # $Header: /var/cvsroot/gentoo-x86/eclass/systemd.eclass,v 1.11 2012/01/07 17:53:47 mgorny Exp $
4 mgorny 1.1
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 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     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 mgorny 1.11 # Block systemd version without the migration helper.
34     DEPEND="!<sys-apps/systemd-29-r4
35     !=sys-apps/systemd-37-r1"
36    
37 mgorny 1.9 # @FUNCTION: _systemd_get_unitdir
38     # @INTERNAL
39     # @DESCRIPTION:
40     # Get unprefixed unitdir.
41     _systemd_get_unitdir() {
42 mgorny 1.11 echo -n /usr/lib/systemd/system
43 mgorny 1.9 }
44    
45 mgorny 1.1 # @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 darkside 1.6 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
51 mgorny 1.1 debug-print-function ${FUNCNAME} "${@}"
52    
53 mgorny 1.9 echo -n "${EPREFIX}$(_systemd_get_unitdir)"
54 mgorny 1.1 }
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 mgorny 1.9 insinto "$(_systemd_get_unitdir)"
66 mgorny 1.1 doins "${@}"
67     )
68     }
69    
70 mgorny 1.5 # @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 mgorny 1.9 insinto "$(_systemd_get_unitdir)"
80 mgorny 1.5 newins "${@}"
81     )
82     }
83    
84 mgorny 1.3 # @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     (
93     insinto /usr/lib/tmpfiles.d/
94     doins "${@}"
95     )
96     }
97    
98 mgorny 1.12 # @FUNCTION: systemd_newtmpfilesd
99     # @USAGE: oldname newname.conf
100     # @DESCRIPTION:
101     # Install systemd tmpfiles.d file under a new name. Uses newins, thus it
102     # is fatal in EAPI 4 and non-fatal in earlier EAPIs.
103     systemd_newtmpfilesd() {
104     debug-print-function ${FUNCNAME} "${@}"
105    
106     (
107     insinto /usr/lib/tmpfiles.d/
108     newins "${@}"
109     )
110     }
111    
112 mgorny 1.1 # @FUNCTION: systemd_enable_service
113     # @USAGE: target service
114     # @DESCRIPTION:
115     # Enable service in desired target, e.g. install a symlink for it.
116     # Uses dosym, thus it is fatal in EAPI 4 and non-fatal in earlier
117     # EAPIs.
118     systemd_enable_service() {
119     debug-print-function ${FUNCNAME} "${@}"
120    
121     [[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service"
122    
123     local target=${1}
124     local service=${2}
125 mgorny 1.9 local ud=$(_systemd_get_unitdir)
126 mgorny 1.10 local destname=$(basename "${service}")
127 mgorny 1.1
128     dodir "${ud}"/"${target}".wants && \
129 mgorny 1.10 dosym ../"${service}" "${ud}"/"${target}".wants/"${destname}"
130 mgorny 1.1 }
131    
132     # @FUNCTION: systemd_with_unitdir
133 mgorny 1.4 # @USAGE: [configure option]
134 mgorny 1.1 # @DESCRIPTION:
135     # Output '--with-systemdsystemunitdir' as expected by systemd-aware configure
136     # scripts. This function always succeeds. Its output may be quoted in order
137     # to preserve whitespace in paths. systemd_to_myeconfargs() is preferred over
138     # this function.
139 mgorny 1.4 #
140     # If upstream does use invalid configure option to handle installing systemd
141     # units (e.g. `--with-systemdunitdir'), you can pass the 'suffix' as an optional
142     # argument to this function (`$(systemd_with_unitdir systemdunitdir)'). Please
143     # remember to report a bug upstream as well.
144 mgorny 1.1 systemd_with_unitdir() {
145     debug-print-function ${FUNCNAME} "${@}"
146 mgorny 1.4 local optname=${1:-systemdsystemunitdir}
147 mgorny 1.1
148 mgorny 1.4 echo -n --with-${optname}="$(systemd_get_unitdir)"
149 mgorny 1.1 }
150    
151     # @FUNCTION: systemd_to_myeconfargs
152     # @DESCRIPTION:
153     # Add '--with-systemdsystemunitdir' as expected by systemd-aware configure
154     # scripts to the myeconfargs variable used by autotools-utils eclass. Handles
155     # quoting automatically.
156     systemd_to_myeconfargs() {
157     debug-print-function ${FUNCNAME} "${@}"
158    
159     myeconfargs=(
160     "${myeconfargs[@]}"
161     --with-systemdsystemunitdir="$(systemd_get_unitdir)"
162     )
163     }

  ViewVC Help
Powered by ViewVC 1.1.20