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

Diff of /eclass/systemd.eclass

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

Revision 1.4 Revision 1.25
1# Copyright 1999-2011 Gentoo Foundation 1# Copyright 1999-2013 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.4 2011/06/16 16:39:18 mgorny Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/systemd.eclass,v 1.25 2013/04/13 22:49:21 floppym Exp $
4 4
5# @ECLASS: systemd.eclass 5# @ECLASS: systemd.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# mgorny@gentoo.org 7# systemd@gentoo.org
8# @BLURB: helper functions to install systemd units 8# @BLURB: helper functions to install systemd units
9# @DESCRIPTION: 9# @DESCRIPTION:
10# This eclass provides a set of functions to install unit files for 10# This eclass provides a set of functions to install unit files for
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# )
23# systemd_to_myeconfargs 23# systemd_to_myeconfargs
24# autotools-utils_src_configure 24# autotools-utils_src_configure
25# } 25# }
26# @CODE 26# @CODE
27 27
28inherit toolchain-funcs
29
28case ${EAPI:-0} in 30case ${EAPI:-0} in
29 0|1|2|3|4) ;; 31 0|1|2|3|4|5) ;;
30 *) die "${ECLASS}.eclass API in EAPI ${EAPI} not yet established." 32 *) die "${ECLASS}.eclass API in EAPI ${EAPI} not yet established."
31esac 33esac
34
35DEPEND="virtual/pkgconfig"
36
37# @FUNCTION: _systemd_get_unitdir
38# @INTERNAL
39# @DESCRIPTION:
40# Get unprefixed unitdir.
41_systemd_get_unitdir() {
42 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}
32 48
33# @FUNCTION: systemd_get_unitdir 49# @FUNCTION: systemd_get_unitdir
34# @DESCRIPTION: 50# @DESCRIPTION:
35# Output the path for the systemd unit directory (not including ${D}). 51# Output the path for the systemd unit directory (not including ${D}).
36# This function always succeeds, even if systemd is not installed. 52# This function always succeeds, even if systemd is not installed.
37systemd_get_unitdir() { 53systemd_get_unitdir() {
54 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
38 debug-print-function ${FUNCNAME} "${@}" 55 debug-print-function ${FUNCNAME} "${@}"
39 56
57 echo "${EPREFIX}$(_systemd_get_unitdir)"
58}
59
60# @FUNCTION: _systemd_get_userunitdir
61# @INTERNAL
62# @DESCRIPTION:
63# Get unprefixed userunitdir.
64_systemd_get_userunitdir() {
65 if $(tc-getPKG_CONFIG) --exists systemd; then
66 echo "$($(tc-getPKG_CONFIG) --variable=systemduserunitdir systemd)"
67 else
40 echo -n /lib/systemd/system 68 echo /usr/lib/systemd/user
69 fi
70}
71
72# @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.
77systemd_get_userunitdir() {
78 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
79 debug-print-function ${FUNCNAME} "${@}"
80
81 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 if $(tc-getPKG_CONFIG) --exists systemd; then
90 echo "$($(tc-getPKG_CONFIG) --variable=systemdutildir systemd)"
91 else
92 echo /usr/lib/systemd
93 fi
94}
95
96# @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.
101systemd_get_utildir() {
102 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
103 debug-print-function ${FUNCNAME} "${@}"
104
105 echo "${EPREFIX}$(_systemd_get_utildir)"
41} 106}
42 107
43# @FUNCTION: systemd_dounit 108# @FUNCTION: systemd_dounit
44# @USAGE: unit1 [...] 109# @USAGE: unit1 [...]
45# @DESCRIPTION: 110# @DESCRIPTION:
46# Install systemd unit(s). Uses doins, thus it is fatal in EAPI 4 111# Install systemd unit(s). Uses doins, thus it is fatal in EAPI 4
47# and non-fatal in earlier EAPIs. 112# and non-fatal in earlier EAPIs.
48systemd_dounit() { 113systemd_dounit() {
49 debug-print-function ${FUNCNAME} "${@}" 114 debug-print-function ${FUNCNAME} "${@}"
50 115
51 ( 116 local INSDESTTREE
52 insinto "$(systemd_get_unitdir)" 117 insinto "$(_systemd_get_unitdir)"
53 doins "${@}" 118 doins "${@}"
54 ) 119}
120
121# @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.
126systemd_newunit() {
127 debug-print-function ${FUNCNAME} "${@}"
128
129 local INSDESTTREE
130 insinto "$(_systemd_get_unitdir)"
131 newins "${@}"
55} 132}
56 133
57# @FUNCTION: systemd_dotmpfilesd 134# @FUNCTION: systemd_dotmpfilesd
58# @USAGE: tmpfilesd1 [...] 135# @USAGE: tmpfilesd1 [...]
59# @DESCRIPTION: 136# @DESCRIPTION:
60# Install systemd tmpfiles.d files. Uses doins, thus it is fatal 137# Install systemd tmpfiles.d files. Uses doins, thus it is fatal
61# in EAPI 4 and non-fatal in earlier EAPIs. 138# in EAPI 4 and non-fatal in earlier EAPIs.
62systemd_dotmpfilesd() { 139systemd_dotmpfilesd() {
63 debug-print-function ${FUNCNAME} "${@}" 140 debug-print-function ${FUNCNAME} "${@}"
64 141
65 ( 142 for f; do
143 [[ ${f} == *.conf ]] \
144 || die 'tmpfiles.d files need to have .conf suffix.'
145 done
146
147 local INSDESTTREE
66 insinto /usr/lib/tmpfiles.d/ 148 insinto /usr/lib/tmpfiles.d/
67 doins "${@}" 149 doins "${@}"
68 ) 150}
151
152# @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.
157systemd_newtmpfilesd() {
158 debug-print-function ${FUNCNAME} "${@}"
159
160 [[ ${2} == *.conf ]] \
161 || die 'tmpfiles.d files need to have .conf suffix.'
162
163 local INSDESTTREE
164 insinto /usr/lib/tmpfiles.d/
165 newins "${@}"
69} 166}
70 167
71# @FUNCTION: systemd_enable_service 168# @FUNCTION: systemd_enable_service
72# @USAGE: target service 169# @USAGE: target service
73# @DESCRIPTION: 170# @DESCRIPTION:
79 176
80 [[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service" 177 [[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service"
81 178
82 local target=${1} 179 local target=${1}
83 local service=${2} 180 local service=${2}
84 local ud=$(systemd_get_unitdir) 181 local ud=$(_systemd_get_unitdir)
182 local destname=${service##*/}
85 183
86 dodir "${ud}"/"${target}".wants && \ 184 dodir "${ud}"/"${target}".wants && \
87 dosym ../"${service}" "${ud}"/"${target}".wants 185 dosym ../"${service}" "${ud}"/"${target}".wants/"${destname}"
88} 186}
89 187
90# @FUNCTION: systemd_with_unitdir 188# @FUNCTION: systemd_with_unitdir
91# @USAGE: [configure option] 189# @USAGE: [configure option]
92# @DESCRIPTION: 190# @DESCRIPTION:
101# remember to report a bug upstream as well. 199# remember to report a bug upstream as well.
102systemd_with_unitdir() { 200systemd_with_unitdir() {
103 debug-print-function ${FUNCNAME} "${@}" 201 debug-print-function ${FUNCNAME} "${@}"
104 local optname=${1:-systemdsystemunitdir} 202 local optname=${1:-systemdsystemunitdir}
105 203
106 echo -n --with-${optname}="$(systemd_get_unitdir)" 204 echo --with-${optname}="$(systemd_get_unitdir)"
205}
206
207# @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.
212systemd_with_utildir() {
213 debug-print-function ${FUNCNAME} "${@}"
214
215 echo --with-systemdutildir="$(systemd_get_utildir)"
107} 216}
108 217
109# @FUNCTION: systemd_to_myeconfargs 218# @FUNCTION: systemd_to_myeconfargs
110# @DESCRIPTION: 219# @DESCRIPTION:
111# Add '--with-systemdsystemunitdir' as expected by systemd-aware configure 220# Add '--with-systemdsystemunitdir' as expected by systemd-aware configure
117 myeconfargs=( 226 myeconfargs=(
118 "${myeconfargs[@]}" 227 "${myeconfargs[@]}"
119 --with-systemdsystemunitdir="$(systemd_get_unitdir)" 228 --with-systemdsystemunitdir="$(systemd_get_unitdir)"
120 ) 229 )
121} 230}
231
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
241systemd_update_catalog() {
242 debug-print-function ${FUNCNAME} "${@}"
243
244 # Make sure to work on the correct system.
245
246 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}

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.25

  ViewVC Help
Powered by ViewVC 1.1.20