| 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.13 2012/08/27 21:54:19 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 |
# @FUNCTION: _systemd_get_unitdir
|
| 34 |
# @INTERNAL
|
| 35 |
# @DESCRIPTION:
|
| 36 |
# Get unprefixed unitdir.
|
| 37 |
_systemd_get_unitdir() {
|
| 38 |
echo -n /usr/lib/systemd/system
|
| 39 |
}
|
| 40 |
|
| 41 |
# @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 |
has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
|
| 47 |
debug-print-function ${FUNCNAME} "${@}"
|
| 48 |
|
| 49 |
echo -n "${EPREFIX}$(_systemd_get_unitdir)"
|
| 50 |
}
|
| 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 |
insinto "$(_systemd_get_unitdir)"
|
| 62 |
doins "${@}"
|
| 63 |
)
|
| 64 |
}
|
| 65 |
|
| 66 |
# @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 |
insinto "$(_systemd_get_unitdir)"
|
| 76 |
newins "${@}"
|
| 77 |
)
|
| 78 |
}
|
| 79 |
|
| 80 |
# @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 |
for f; do
|
| 89 |
[[ ${f} == *.conf ]] \
|
| 90 |
|| die 'tmpfiles.d files need to have .conf suffix.'
|
| 91 |
done
|
| 92 |
|
| 93 |
(
|
| 94 |
insinto /usr/lib/tmpfiles.d/
|
| 95 |
doins "${@}"
|
| 96 |
)
|
| 97 |
}
|
| 98 |
|
| 99 |
# @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 |
[[ ${2} == *.conf ]] \
|
| 108 |
|| die 'tmpfiles.d files need to have .conf suffix.'
|
| 109 |
|
| 110 |
(
|
| 111 |
insinto /usr/lib/tmpfiles.d/
|
| 112 |
newins "${@}"
|
| 113 |
)
|
| 114 |
}
|
| 115 |
|
| 116 |
# @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 |
local ud=$(_systemd_get_unitdir)
|
| 130 |
local destname=$(basename "${service}")
|
| 131 |
|
| 132 |
dodir "${ud}"/"${target}".wants && \
|
| 133 |
dosym ../"${service}" "${ud}"/"${target}".wants/"${destname}"
|
| 134 |
}
|
| 135 |
|
| 136 |
# @FUNCTION: systemd_with_unitdir
|
| 137 |
# @USAGE: [configure option]
|
| 138 |
# @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 |
#
|
| 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 |
systemd_with_unitdir() {
|
| 149 |
debug-print-function ${FUNCNAME} "${@}"
|
| 150 |
local optname=${1:-systemdsystemunitdir}
|
| 151 |
|
| 152 |
echo -n --with-${optname}="$(systemd_get_unitdir)"
|
| 153 |
}
|
| 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 |
}
|