tmpfiles.eclass 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # Copyright 1999-2016 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: tmpfiles.eclass
  4. # @MAINTAINER:
  5. # Gentoo systemd project <systemd@gentoo.org>
  6. # William Hubbs <williamh@gentoo.org>
  7. # @AUTHOR:
  8. # Mike Gilbert <floppym@gentoo.org>
  9. # William Hubbs <williamh@gentoo.org>
  10. # @BLURB: Functions related to tmpfiles.d files
  11. # @DESCRIPTION:
  12. # This eclass provides functionality related to installing and
  13. # creating volatile and temporary files based on configuration files$and
  14. # locations defined at this URL:
  15. #
  16. # https://www.freedesktop.org/software/systemd/man/tmpfiles.d.html
  17. #
  18. # The dotmpfiles and newtmpfiles functions are used to install
  19. # configuration files into /usr/lib/tmpfiles.d, then in pkg_postinst, the
  20. # tmpfiles_process function can be called to process the newly
  21. # installed tmpfiles.d entries.
  22. #
  23. # @EXAMPLE:
  24. # Typical usage of this eclass:
  25. #
  26. # @CODE
  27. # EAPI=6
  28. # inherit tmpfiles
  29. #
  30. # ...
  31. #
  32. # src_install() {
  33. # ...
  34. # dotmpfiles "${FILESDIR}"/file1.conf "${FILESDIR}"/file2.conf
  35. # newtmpfiles "${FILESDIR}"/file3.conf-${PV} file3.conf
  36. # ...
  37. # }
  38. #
  39. # pkg_postinst() {
  40. # ...
  41. # tmpfiles_process file1.conf file2.conf file3.conf
  42. # ...
  43. # }
  44. #
  45. # @CODE
  46. if [[ -z ${TMPFILES_ECLASS} ]]; then
  47. TMPFILES_ECLASS=1
  48. case "${EAPI}" in
  49. 6) ;;
  50. *) die "API is undefined for EAPI ${EAPI}" ;;
  51. esac
  52. RDEPEND="kernel_linux? ( virtual/tmpfiles )"
  53. # @FUNCTION: dotmpfiles
  54. # @USAGE: dotmpfiles <tmpfiles.d_file> ...
  55. # @DESCRIPTION:
  56. # Install one or more tmpfiles.d files into /usr/lib/tmpfiles.d.
  57. dotmpfiles() {
  58. debug-print-function "${FUNCNAME}" "$@"
  59. use kernel_linux || return 0
  60. local f
  61. for f; do
  62. if [[ ${f} != *.conf ]]; then
  63. die "tmpfiles.d files must end with .conf"
  64. fi
  65. done
  66. (
  67. insinto /usr/lib/tmpfiles.d
  68. doins "$@"
  69. )
  70. }
  71. # @FUNCTION: newtmpfiles
  72. # @USAGE: newtmpfiles <old-name> <new-name>.conf
  73. # @DESCRIPTION:
  74. # Install a tmpfiles.d file in /usr/lib/tmpfiles.d under a new name.
  75. newtmpfiles() {
  76. debug-print-function "${FUNCNAME}" "$@"
  77. use kernel_linux || return 0
  78. if [[ $2 != *.conf ]]; then
  79. die "tmpfiles.d files must end with .conf"
  80. fi
  81. (
  82. insinto /usr/lib/tmpfiles.d
  83. newins "$@"
  84. )
  85. }
  86. # @FUNCTION: tmpfiles_process
  87. # @USAGE: tmpfiles_process <filename> <filename> ...
  88. # @DESCRIPTION:
  89. # Call a tmpfiles.d implementation to create new volatile and temporary
  90. # files and directories.
  91. tmpfiles_process() {
  92. debug-print-function "${FUNCNAME}" "$@"
  93. use kernel_linux || return 0
  94. [[ ${EBUILD_PHASE} == postinst ]] || die "${FUNCNAME}: Only valid in pkg_postinst"
  95. [[ ${#} -gt 0 ]] || die "${FUNCNAME}: Must specify at least one filename"
  96. # Only process tmpfiles for the currently running system
  97. [[ ${ROOT} == / ]] || return 0
  98. if type systemd-tmpfiles &> /dev/null; then
  99. systemd-tmpfiles --create "$@"
  100. elif type tmpfiles &> /dev/null; then
  101. tmpfiles --create "$@"
  102. fi
  103. if [[ $? -ne 0 ]]; then
  104. ewarn "The tmpfiles processor exited with a non-zero exit code"
  105. fi
  106. }
  107. fi