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

Diff of /eclass/systemd.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.18

  ViewVC Help
Powered by ViewVC 1.1.20