| 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.17 2012/10/30 21:29:32 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|5) ;; |
| 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 /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 "${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. |
| 57 |
systemd_get_utildir() { |
| 58 |
has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX= |
| 59 |
debug-print-function ${FUNCNAME} "${@}" |
| 60 |
|
| 61 |
echo "${EPREFIX}/usr/lib/systemd" |
| 62 |
} |
| 63 |
|
| 64 |
# @FUNCTION: systemd_dounit |
| 65 |
# @USAGE: unit1 [...] |
| 66 |
# @DESCRIPTION: |
| 67 |
# Install systemd unit(s). Uses doins, thus it is fatal in EAPI 4 |
| 68 |
# and non-fatal in earlier EAPIs. |
| 69 |
systemd_dounit() { |
| 70 |
debug-print-function ${FUNCNAME} "${@}" |
| 71 |
|
| 72 |
( |
| 73 |
insinto "$(_systemd_get_unitdir)" |
| 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. |
| 83 |
systemd_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. |
| 97 |
systemd_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. |
| 116 |
systemd_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 "${@}" |
| 125 |
) |
| 126 |
} |
| 127 |
|
| 128 |
# @FUNCTION: systemd_enable_service |
| 129 |
# @USAGE: target service |
| 130 |
# @DESCRIPTION: |
| 131 |
# Enable service in desired target, e.g. install a symlink for it. |
| 132 |
# Uses dosym, thus it is fatal in EAPI 4 and non-fatal in earlier |
| 133 |
# EAPIs. |
| 134 |
systemd_enable_service() { |
| 135 |
debug-print-function ${FUNCNAME} "${@}" |
| 136 |
|
| 137 |
[[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service" |
| 138 |
|
| 139 |
local target=${1} |
| 140 |
local service=${2} |
| 141 |
local ud=$(_systemd_get_unitdir) |
| 142 |
local destname=$(basename "${service}") |
| 143 |
|
| 144 |
dodir "${ud}"/"${target}".wants && \ |
| 145 |
dosym ../"${service}" "${ud}"/"${target}".wants/"${destname}" |
| 146 |
} |
| 147 |
|
| 148 |
# @FUNCTION: systemd_with_unitdir |
| 149 |
# @USAGE: [configure option] |
| 150 |
# @DESCRIPTION: |
| 151 |
# Output '--with-systemdsystemunitdir' as expected by systemd-aware configure |
| 152 |
# scripts. This function always succeeds. Its output may be quoted in order |
| 153 |
# to preserve whitespace in paths. systemd_to_myeconfargs() is preferred over |
| 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. |
| 160 |
systemd_with_unitdir() { |
| 161 |
debug-print-function ${FUNCNAME} "${@}" |
| 162 |
local optname=${1:-systemdsystemunitdir} |
| 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. |
| 172 |
systemd_with_utildir() { |
| 173 |
debug-print-function ${FUNCNAME} "${@}" |
| 174 |
|
| 175 |
echo --with-systemdutildir="$(systemd_get_utildir)" |
| 176 |
} |
| 177 |
|
| 178 |
# @FUNCTION: systemd_to_myeconfargs |
| 179 |
# @DESCRIPTION: |
| 180 |
# Add '--with-systemdsystemunitdir' as expected by systemd-aware configure |
| 181 |
# scripts to the myeconfargs variable used by autotools-utils eclass. Handles |
| 182 |
# quoting automatically. |
| 183 |
systemd_to_myeconfargs() { |
| 184 |
debug-print-function ${FUNCNAME} "${@}" |
| 185 |
|
| 186 |
myeconfargs=( |
| 187 |
"${myeconfargs[@]}" |
| 188 |
--with-systemdsystemunitdir="$(systemd_get_unitdir)" |
| 189 |
) |
| 190 |
} |