xdg-utils.eclass 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # Copyright 1999-2017 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: xdg-utils.eclass
  4. # @MAINTAINER:
  5. # gnome@gentoo.org
  6. # @AUTHOR:
  7. # Original author: Gilles Dartiguelongue <eva@gentoo.org>
  8. # @BLURB: Auxiliary functions commonly used by XDG compliant packages.
  9. # @DESCRIPTION:
  10. # This eclass provides a set of auxiliary functions needed by most XDG
  11. # compliant packages.
  12. # It provides XDG stack related functions such as:
  13. # * XDG .desktop files cache management
  14. # * XDG mime information database management
  15. case "${EAPI:-0}" in
  16. 0|1|2|3|4|5|6) ;;
  17. *) die "EAPI=${EAPI} is not supported" ;;
  18. esac
  19. # @ECLASS-VARIABLE: DESKTOP_DATABASE_UPDATE_BIN
  20. # @INTERNAL
  21. # @DESCRIPTION:
  22. # Path to update-desktop-database
  23. : ${DESKTOP_DATABASE_UPDATE_BIN:="/usr/bin/update-desktop-database"}
  24. # @ECLASS-VARIABLE: DESKTOP_DATABASE_DIR
  25. # @INTERNAL
  26. # @DESCRIPTION:
  27. # Directory where .desktop files database is stored
  28. : ${DESKTOP_DATABASE_DIR="/usr/share/applications"}
  29. # @ECLASS-VARIABLE: MIMEINFO_DATABASE_UPDATE_BIN
  30. # @INTERNAL
  31. # @DESCRIPTION:
  32. # Path to update-mime-database
  33. : ${MIMEINFO_DATABASE_UPDATE_BIN:="/usr/bin/update-mime-database"}
  34. # @ECLASS-VARIABLE: MIMEINFO_DATABASE_DIR
  35. # @INTERNAL
  36. # @DESCRIPTION:
  37. # Directory where .desktop files database is stored
  38. : ${MIMEINFO_DATABASE_DIR:="/usr/share/mime"}
  39. # @FUNCTION: xdg_environment_reset
  40. # @DESCRIPTION:
  41. # Clean up environment for clean builds.
  42. xdg_environment_reset() {
  43. # Prepare XDG base directories
  44. export XDG_DATA_HOME="${HOME}/.local/share"
  45. export XDG_CONFIG_HOME="${HOME}/.config"
  46. export XDG_CACHE_HOME="${HOME}/.cache"
  47. export XDG_RUNTIME_DIR="${T}/run"
  48. mkdir -p "${XDG_DATA_HOME}" "${XDG_CONFIG_HOME}" "${XDG_CACHE_HOME}" \
  49. "${XDG_RUNTIME_DIR}" || die
  50. # This directory needs to be owned by the user, and chmod 0700
  51. # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
  52. chmod 0700 "${XDG_RUNTIME_DIR}" || die
  53. unset DBUS_SESSION_BUS_ADDRESS
  54. }
  55. # @FUNCTION: fdo-xdg_desktop_database_update
  56. # @DESCRIPTION:
  57. # Updates the .desktop files database.
  58. # Generates a list of mimetypes linked to applications that can handle them
  59. xdg_desktop_database_update() {
  60. local updater="${EROOT}${DESKTOP_DATABASE_UPDATE_BIN}"
  61. if [[ ${EBUILD_PHASE} != post* ]] ; then
  62. die "xdg_desktop_database_update must be used in pkg_post* phases."
  63. fi
  64. if [[ ! -x "${updater}" ]] ; then
  65. debug-print "${updater} is not executable"
  66. return
  67. fi
  68. ebegin "Updating .desktop files database"
  69. "${updater}" -q "${EROOT}${DESKTOP_DATABASE_DIR}"
  70. eend $?
  71. }
  72. # @FUNCTION: xdg_mimeinfo_database_update
  73. # @DESCRIPTION:
  74. # Update the mime database.
  75. # Creates a general list of mime types from several sources
  76. xdg_mimeinfo_database_update() {
  77. local updater="${EROOT}${MIMEINFO_DATABASE_UPDATE_BIN}"
  78. if [[ ${EBUILD_PHASE} != post* ]] ; then
  79. die "xdg_mimeinfo_database_update must be used in pkg_post* phases."
  80. fi
  81. if [[ ! -x "${updater}" ]] ; then
  82. debug-print "${updater} is not executable"
  83. return
  84. fi
  85. ebegin "Updating shared mime info database"
  86. "${updater}" "${EROOT}${MIMEINFO_DATABASE_DIR}"
  87. eend $?
  88. }