mirror of
https://github.com/flatcar/scripts.git
synced 2025-12-08 19:02:10 +01:00
eclass/systemd: Sync with gentoo
It's from gentoo commit b8f91fee6a8314dc58c1da011b65d9b857ef963f.
This commit is contained in:
parent
339298bd3e
commit
fd8030ea91
@ -1,10 +1,10 @@
|
|||||||
# Copyright 1999-2017 Gentoo Foundation
|
# Copyright 2011-2021 Gentoo Authors
|
||||||
# Distributed under the terms of the GNU General Public License v2
|
# Distributed under the terms of the GNU General Public License v2
|
||||||
|
|
||||||
# @ECLASS: systemd.eclass
|
# @ECLASS: systemd.eclass
|
||||||
# @MAINTAINER:
|
# @MAINTAINER:
|
||||||
# systemd@gentoo.org
|
# systemd@gentoo.org
|
||||||
# @SUPPORTED_EAPIS: 0 1 2 3 4 5 6 7
|
# @SUPPORTED_EAPIS: 5 6 7 8
|
||||||
# @BLURB: helper functions to install systemd units
|
# @BLURB: helper functions to install systemd units
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
# This eclass provides a set of functions to install unit files for
|
# This eclass provides a set of functions to install unit files for
|
||||||
@ -24,14 +24,14 @@
|
|||||||
# }
|
# }
|
||||||
# @CODE
|
# @CODE
|
||||||
|
|
||||||
inherit toolchain-funcs
|
case ${EAPI} in
|
||||||
|
5|6|7|8) ;;
|
||||||
case ${EAPI:-0} in
|
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
|
||||||
0|1|2|3|4|5|6|7) ;;
|
|
||||||
*) die "${ECLASS}.eclass API in EAPI ${EAPI} not yet established."
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [[ ${EAPI:-0} == [0123456] ]]; then
|
inherit toolchain-funcs
|
||||||
|
|
||||||
|
if [[ ${EAPI} == [56] ]]; then
|
||||||
DEPEND="virtual/pkgconfig"
|
DEPEND="virtual/pkgconfig"
|
||||||
else
|
else
|
||||||
BDEPEND="virtual/pkgconfig"
|
BDEPEND="virtual/pkgconfig"
|
||||||
@ -48,6 +48,9 @@ _systemd_get_dir() {
|
|||||||
[[ ${#} -eq 2 ]] || die "Usage: ${FUNCNAME} <variable-name> <fallback-directory>"
|
[[ ${#} -eq 2 ]] || die "Usage: ${FUNCNAME} <variable-name> <fallback-directory>"
|
||||||
local variable=${1} fallback=${2} d
|
local variable=${1} fallback=${2} d
|
||||||
|
|
||||||
|
# https://github.com/pkgconf/pkgconf/issues/205
|
||||||
|
local -x PKG_CONFIG_FDO_SYSROOT_RULES=1
|
||||||
|
|
||||||
if $(tc-getPKG_CONFIG) --exists systemd; then
|
if $(tc-getPKG_CONFIG) --exists systemd; then
|
||||||
d=$($(tc-getPKG_CONFIG) --variable="${variable}" systemd) || die
|
d=$($(tc-getPKG_CONFIG) --variable="${variable}" systemd) || die
|
||||||
d=${d#${EPREFIX}}
|
d=${d#${EPREFIX}}
|
||||||
@ -58,7 +61,7 @@ _systemd_get_dir() {
|
|||||||
echo "${d}"
|
echo "${d}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# @FUNCTION: _systemd_get_unitdir
|
# @FUNCTION: _systemd_get_systemunitdir
|
||||||
# @INTERNAL
|
# @INTERNAL
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
# Get unprefixed unitdir.
|
# Get unprefixed unitdir.
|
||||||
@ -72,7 +75,6 @@ _systemd_get_systemunitdir() {
|
|||||||
# ${D}). This function always succeeds, even if systemd is not
|
# ${D}). This function always succeeds, even if systemd is not
|
||||||
# installed.
|
# installed.
|
||||||
systemd_get_systemunitdir() {
|
systemd_get_systemunitdir() {
|
||||||
has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
|
|
||||||
debug-print-function ${FUNCNAME} "${@}"
|
debug-print-function ${FUNCNAME} "${@}"
|
||||||
|
|
||||||
echo "${EPREFIX}$(_systemd_get_systemunitdir)"
|
echo "${EPREFIX}$(_systemd_get_systemunitdir)"
|
||||||
@ -82,7 +84,7 @@ systemd_get_systemunitdir() {
|
|||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
# Deprecated alias for systemd_get_systemunitdir.
|
# Deprecated alias for systemd_get_systemunitdir.
|
||||||
systemd_get_unitdir() {
|
systemd_get_unitdir() {
|
||||||
[[ ${EAPI} == [012345] ]] || die "${FUNCNAME} is banned in EAPI 6, use systemd_get_systemunitdir instead"
|
[[ ${EAPI} == 5 ]] || die "${FUNCNAME} is banned in EAPI 6, use systemd_get_systemunitdir instead"
|
||||||
|
|
||||||
systemd_get_systemunitdir
|
systemd_get_systemunitdir
|
||||||
}
|
}
|
||||||
@ -101,7 +103,6 @@ _systemd_get_userunitdir() {
|
|||||||
# ${D}). This function always succeeds, even if systemd is not
|
# ${D}). This function always succeeds, even if systemd is not
|
||||||
# installed.
|
# installed.
|
||||||
systemd_get_userunitdir() {
|
systemd_get_userunitdir() {
|
||||||
has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
|
|
||||||
debug-print-function ${FUNCNAME} "${@}"
|
debug-print-function ${FUNCNAME} "${@}"
|
||||||
|
|
||||||
echo "${EPREFIX}$(_systemd_get_userunitdir)"
|
echo "${EPREFIX}$(_systemd_get_userunitdir)"
|
||||||
@ -121,7 +122,6 @@ _systemd_get_utildir() {
|
|||||||
# ${D}). This function always succeeds, even if systemd is not
|
# ${D}). This function always succeeds, even if systemd is not
|
||||||
# installed.
|
# installed.
|
||||||
systemd_get_utildir() {
|
systemd_get_utildir() {
|
||||||
has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
|
|
||||||
debug-print-function ${FUNCNAME} "${@}"
|
debug-print-function ${FUNCNAME} "${@}"
|
||||||
|
|
||||||
echo "${EPREFIX}$(_systemd_get_utildir)"
|
echo "${EPREFIX}$(_systemd_get_utildir)"
|
||||||
@ -138,20 +138,35 @@ _systemd_get_systemgeneratordir() {
|
|||||||
# @FUNCTION: systemd_get_systemgeneratordir
|
# @FUNCTION: systemd_get_systemgeneratordir
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
# Output the path for the systemd system generator directory (not including
|
# Output the path for the systemd system generator directory (not including
|
||||||
# ${D}). This function always succeeds, even if systemd is not
|
# ${D}). This function always succeeds, even if systemd is not installed.
|
||||||
# installed.
|
|
||||||
systemd_get_systemgeneratordir() {
|
systemd_get_systemgeneratordir() {
|
||||||
has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
|
|
||||||
debug-print-function ${FUNCNAME} "${@}"
|
debug-print-function ${FUNCNAME} "${@}"
|
||||||
|
|
||||||
echo "${EPREFIX}$(_systemd_get_systemgeneratordir)"
|
echo "${EPREFIX}$(_systemd_get_systemgeneratordir)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# @FUNCTION: _systemd_get_systempresetdir
|
||||||
|
# @INTERNAL
|
||||||
|
# @DESCRIPTION:
|
||||||
|
# Get unprefixed systempresetdir.
|
||||||
|
_systemd_get_systempresetdir() {
|
||||||
|
_systemd_get_dir systemdsystempresetdir /lib/systemd/system-preset
|
||||||
|
}
|
||||||
|
|
||||||
|
# @FUNCTION: systemd_get_systempresetdir
|
||||||
|
# @DESCRIPTION:
|
||||||
|
# Output the path for the systemd system preset directory (not including
|
||||||
|
# ${D}). This function always succeeds, even if systemd is not installed.
|
||||||
|
systemd_get_systempresetdir() {
|
||||||
|
debug-print-function ${FUNCNAME} "${@}"
|
||||||
|
|
||||||
|
echo "${EPREFIX}$(_systemd_get_systempresetdir)"
|
||||||
|
}
|
||||||
|
|
||||||
# @FUNCTION: systemd_dounit
|
# @FUNCTION: systemd_dounit
|
||||||
# @USAGE: <unit>...
|
# @USAGE: <unit>...
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
# Install systemd unit(s). Uses doins, thus it is fatal in EAPI 4
|
# Install systemd unit(s). Uses doins, thus it is fatal.
|
||||||
# and non-fatal in earlier EAPIs.
|
|
||||||
systemd_dounit() {
|
systemd_dounit() {
|
||||||
debug-print-function ${FUNCNAME} "${@}"
|
debug-print-function ${FUNCNAME} "${@}"
|
||||||
|
|
||||||
@ -165,8 +180,7 @@ systemd_dounit() {
|
|||||||
# @FUNCTION: systemd_newunit
|
# @FUNCTION: systemd_newunit
|
||||||
# @USAGE: <old-name> <new-name>
|
# @USAGE: <old-name> <new-name>
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
# Install systemd unit with a new name. Uses newins, thus it is fatal
|
# Install systemd unit with a new name. Uses newins, thus it is fatal.
|
||||||
# in EAPI 4 and non-fatal in earlier EAPIs.
|
|
||||||
systemd_newunit() {
|
systemd_newunit() {
|
||||||
debug-print-function ${FUNCNAME} "${@}"
|
debug-print-function ${FUNCNAME} "${@}"
|
||||||
|
|
||||||
@ -180,8 +194,7 @@ systemd_newunit() {
|
|||||||
# @FUNCTION: systemd_douserunit
|
# @FUNCTION: systemd_douserunit
|
||||||
# @USAGE: <unit>...
|
# @USAGE: <unit>...
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
# Install systemd user unit(s). Uses doins, thus it is fatal in EAPI 4
|
# Install systemd user unit(s). Uses doins, thus it is fatal.
|
||||||
# and non-fatal in earlier EAPIs.
|
|
||||||
systemd_douserunit() {
|
systemd_douserunit() {
|
||||||
debug-print-function ${FUNCNAME} "${@}"
|
debug-print-function ${FUNCNAME} "${@}"
|
||||||
|
|
||||||
@ -196,7 +209,7 @@ systemd_douserunit() {
|
|||||||
# @USAGE: <old-name> <new-name>
|
# @USAGE: <old-name> <new-name>
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
# Install systemd user unit with a new name. Uses newins, thus it
|
# Install systemd user unit with a new name. Uses newins, thus it
|
||||||
# is fatal in EAPI 4 and non-fatal in earlier EAPIs.
|
# is fatal.
|
||||||
systemd_newuserunit() {
|
systemd_newuserunit() {
|
||||||
debug-print-function ${FUNCNAME} "${@}"
|
debug-print-function ${FUNCNAME} "${@}"
|
||||||
|
|
||||||
@ -237,54 +250,11 @@ systemd_install_serviced() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
# @FUNCTION: systemd_dotmpfilesd
|
|
||||||
# @USAGE: <tmpfilesd>...
|
|
||||||
# @DESCRIPTION:
|
|
||||||
# Deprecated in favor of tmpfiles.eclass.
|
|
||||||
#
|
|
||||||
# Install systemd tmpfiles.d files. Uses doins, thus it is fatal
|
|
||||||
# in EAPI 4 and non-fatal in earlier EAPIs.
|
|
||||||
systemd_dotmpfilesd() {
|
|
||||||
debug-print-function ${FUNCNAME} "${@}"
|
|
||||||
|
|
||||||
for f; do
|
|
||||||
[[ ${f} == *.conf ]] \
|
|
||||||
|| die 'tmpfiles.d files need to have .conf suffix.'
|
|
||||||
done
|
|
||||||
|
|
||||||
(
|
|
||||||
insopts -m 0644
|
|
||||||
insinto /usr/lib/tmpfiles.d/
|
|
||||||
doins "${@}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
# @FUNCTION: systemd_newtmpfilesd
|
|
||||||
# @USAGE: <old-name> <new-name>.conf
|
|
||||||
# @DESCRIPTION:
|
|
||||||
# Deprecated in favor of tmpfiles.eclass.
|
|
||||||
#
|
|
||||||
# Install systemd tmpfiles.d file under a new name. Uses newins, thus it
|
|
||||||
# is fatal in EAPI 4 and non-fatal in earlier EAPIs.
|
|
||||||
systemd_newtmpfilesd() {
|
|
||||||
debug-print-function ${FUNCNAME} "${@}"
|
|
||||||
|
|
||||||
[[ ${2} == *.conf ]] \
|
|
||||||
|| die 'tmpfiles.d files need to have .conf suffix.'
|
|
||||||
|
|
||||||
(
|
|
||||||
insopts -m 0644
|
|
||||||
insinto /usr/lib/tmpfiles.d/
|
|
||||||
newins "${@}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
# @FUNCTION: systemd_enable_service
|
# @FUNCTION: systemd_enable_service
|
||||||
# @USAGE: <target> <service>
|
# @USAGE: <target> <service>
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
# Enable service in desired target, e.g. install a symlink for it.
|
# Enable service in desired target, e.g. install a symlink for it.
|
||||||
# Uses dosym, thus it is fatal in EAPI 4 and non-fatal in earlier
|
# Uses dosym, thus it is fatal.
|
||||||
# EAPIs.
|
|
||||||
systemd_enable_service() {
|
systemd_enable_service() {
|
||||||
debug-print-function ${FUNCNAME} "${@}"
|
debug-print-function ${FUNCNAME} "${@}"
|
||||||
|
|
||||||
@ -307,8 +277,7 @@ systemd_enable_service() {
|
|||||||
# and name, while the remaining arguments list service units that will
|
# and name, while the remaining arguments list service units that will
|
||||||
# be added to that file.
|
# be added to that file.
|
||||||
#
|
#
|
||||||
# Uses doins, thus it is fatal in EAPI 4 and non-fatal in earlier
|
# Uses doins, thus it is fatal.
|
||||||
# EAPIs.
|
|
||||||
#
|
#
|
||||||
# Doc: https://www.freedesktop.org/wiki/Software/systemd/timedated/
|
# Doc: https://www.freedesktop.org/wiki/Software/systemd/timedated/
|
||||||
systemd_enable_ntpunit() {
|
systemd_enable_ntpunit() {
|
||||||
@ -363,7 +332,7 @@ systemd_enable_ntpunit() {
|
|||||||
# argument to this function (`$(systemd_with_unitdir systemdunitdir)'). Please
|
# argument to this function (`$(systemd_with_unitdir systemdunitdir)'). Please
|
||||||
# remember to report a bug upstream as well.
|
# remember to report a bug upstream as well.
|
||||||
systemd_with_unitdir() {
|
systemd_with_unitdir() {
|
||||||
[[ ${EAPI:-0} != [012345] ]] && die "${FUNCNAME} is banned in EAPI ${EAPI}, use --with-${1:-systemdsystemunitdir}=\"\$(systemd_get_systemunitdir)\" instead"
|
[[ ${EAPI} == 5 ]] || die "${FUNCNAME} is banned in EAPI ${EAPI}, use --with-${1:-systemdsystemunitdir}=\"\$(systemd_get_systemunitdir)\" instead"
|
||||||
|
|
||||||
debug-print-function ${FUNCNAME} "${@}"
|
debug-print-function ${FUNCNAME} "${@}"
|
||||||
local optname=${1:-systemdsystemunitdir}
|
local optname=${1:-systemdsystemunitdir}
|
||||||
@ -380,7 +349,7 @@ systemd_with_unitdir() {
|
|||||||
# systemd helpers. This function always succeeds. Its output may be quoted
|
# systemd helpers. This function always succeeds. Its output may be quoted
|
||||||
# in order to preserve whitespace in paths.
|
# in order to preserve whitespace in paths.
|
||||||
systemd_with_utildir() {
|
systemd_with_utildir() {
|
||||||
[[ ${EAPI:-0} != [012345] ]] && die "${FUNCNAME} is banned in EAPI ${EAPI}, use --with-systemdutildir=\"\$(systemd_get_utildir)\" instead"
|
[[ ${EAPI} == 5 ]] || die "${FUNCNAME} is banned in EAPI ${EAPI}, use --with-systemdutildir=\"\$(systemd_get_utildir)\" instead"
|
||||||
|
|
||||||
debug-print-function ${FUNCNAME} "${@}"
|
debug-print-function ${FUNCNAME} "${@}"
|
||||||
|
|
||||||
@ -436,29 +405,6 @@ systemd_is_booted() {
|
|||||||
return ${ret}
|
return ${ret}
|
||||||
}
|
}
|
||||||
|
|
||||||
# @FUNCTION: systemd_tmpfiles_create
|
|
||||||
# @USAGE: <tmpfilesd> ...
|
|
||||||
# @DESCRIPTION:
|
|
||||||
# Deprecated in favor of tmpfiles.eclass.
|
|
||||||
#
|
|
||||||
# Invokes systemd-tmpfiles --create with given arguments.
|
|
||||||
# Does nothing if ROOT != / or systemd-tmpfiles is not in PATH.
|
|
||||||
# This function should be called from pkg_postinst.
|
|
||||||
#
|
|
||||||
# Generally, this function should be called with the names of any tmpfiles
|
|
||||||
# fragments which have been installed, either by the build system or by a
|
|
||||||
# previous call to systemd_dotmpfilesd. This ensures that any tmpfiles are
|
|
||||||
# created without the need to reboot the system.
|
|
||||||
systemd_tmpfiles_create() {
|
|
||||||
debug-print-function ${FUNCNAME} "${@}"
|
|
||||||
|
|
||||||
[[ ${EBUILD_PHASE} == postinst ]] || die "${FUNCNAME}: Only valid in pkg_postinst"
|
|
||||||
[[ ${#} -gt 0 ]] || die "${FUNCNAME}: Must specify at least one filename"
|
|
||||||
[[ ${ROOT:-/} == / ]] || return 0
|
|
||||||
type systemd-tmpfiles &> /dev/null || return 0
|
|
||||||
systemd-tmpfiles --create "${@}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# @FUNCTION: systemd_reenable
|
# @FUNCTION: systemd_reenable
|
||||||
# @USAGE: <unit> ...
|
# @USAGE: <unit> ...
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user