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

Contents of /eclass/systemd.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16 - (hide annotations) (download)
Tue Oct 30 20:24:09 2012 UTC (2 years, 1 month ago) by mgorny
Branch: MAIN
Changes since 1.15: +4 -4 lines
Replace "echo -n" with "echo", bash removes trailing newline in subshells anyway.

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

  ViewVC Help
Powered by ViewVC 1.1.20