ejabberd-16.08.ebuild 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. # Copyright 1999-2017 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=6
  4. SSL_CERT_MANDATORY=1
  5. inherit eutils pam rebar ssl-cert systemd
  6. DESCRIPTION="Robust, scalable and extensible XMPP server"
  7. HOMEPAGE="http://www.ejabberd.im/ https://github.com/processone/ejabberd/"
  8. SRC_URI="http://www.process-one.net/downloads/${PN}/${PV}/${P}.tgz
  9. -> ${P}.tar.gz"
  10. LICENSE="GPL-2"
  11. SLOT="0"
  12. KEYWORDS="~amd64 ~arm ~ia64 ~ppc ~sparc ~x86"
  13. REQUIRED_USE="mssql? ( odbc )"
  14. # TODO: Add 'tools' flag.
  15. IUSE="captcha debug full-xml hipe ldap mssql mysql nls odbc pam postgres redis
  16. riak roster-gw sqlite zlib"
  17. RESTRICT="test"
  18. # TODO: Add dependencies for 'tools' flag enabled.
  19. # TODO: tools? (
  20. # TODO: >=dev-erlang/meck-0.8.4
  21. # TODO: >=dev-erlang/moka-1.0.5b
  22. # TODO: )
  23. CDEPEND="
  24. >=dev-erlang/cache_tab-1.0.3
  25. >=dev-erlang/esip-1.0.7
  26. >=dev-erlang/fast_tls-1.0.6
  27. >=dev-erlang/fast_xml-1.1.14
  28. >=dev-erlang/fast_yaml-1.0.5
  29. >=dev-erlang/jiffy-0.14.7
  30. >=dev-erlang/lager-3.2.1
  31. >=dev-erlang/luerl-0.2
  32. >=dev-erlang/p1_oauth2-0.6.1
  33. >=dev-erlang/p1_utils-1.0.5
  34. >=dev-erlang/p1_xmlrpc-1.15.1
  35. >=dev-erlang/stringprep-1.0.5
  36. >=dev-erlang/stun-1.0.6
  37. >=dev-lang/erlang-17.1[hipe?,odbc?,ssl]
  38. >=net-im/jabber-base-0.01
  39. ldap? ( =net-nds/openldap-2* )
  40. mysql? ( >=dev-erlang/p1_mysql-1.0.1 )
  41. nls? ( >=dev-erlang/iconv-1.0.1 )
  42. odbc? ( dev-db/unixODBC )
  43. pam? ( >=dev-erlang/p1_pam-1.0.0 )
  44. postgres? ( >=dev-erlang/p1_pgsql-1.1.0 )
  45. redis? ( >=dev-erlang/eredis-1.0.8 )
  46. riak? (
  47. >=dev-erlang/hamcrest-0.1.0_p20150103
  48. >=dev-erlang/riakc-2.1.1_p20151111
  49. )
  50. sqlite? ( >=dev-erlang/sqlite3-1.1.5 )
  51. zlib? ( >=dev-erlang/ezlib-1.0.1 )"
  52. DEPEND="${CDEPEND}
  53. >=sys-apps/gawk-4.1"
  54. RDEPEND="${CDEPEND}
  55. captcha? ( media-gfx/imagemagick[truetype,png] )"
  56. DOCS=( README )
  57. PATCHES=( "${FILESDIR}/${P}-ejabberdctl.patch" )
  58. EJABBERD_CERT="${EPREFIX}/etc/ssl/ejabberd/server.pem"
  59. # Paths in net-im/jabber-base
  60. JABBER_ETC="${EPREFIX}/etc/jabber"
  61. JABBER_LOG="${EPREFIX}/var/log/jabber"
  62. JABBER_SPOOL="${EPREFIX}/var/spool/jabber"
  63. # Adjust example configuration file to Gentoo.
  64. # - Use our sample certificates.
  65. # - Correct PAM service name.
  66. adjust_config() {
  67. sed -e "s|\"/path/to/ssl.pem\"|\"${EJABBERD_CERT}\"|g" \
  68. -e "s|\"pamservicename\"|\"xmpp\"|" \
  69. -i "${S}/ejabberd.yml.example" \
  70. || die 'failed to adjust example config'
  71. }
  72. # Set paths to ejabberd lib directory consistently to point always to directory
  73. # suffixed with version.
  74. correct_ejabberd_paths() {
  75. sed -e "/^EJABBERDDIR[[:space:]]*=/{s:ejabberd:${P}:}" \
  76. -i "${S}/Makefile.in" \
  77. || die 'failed to set ejabberd path in Makefile.in'
  78. sed -e "/EJABBERD_BIN_PATH=/{s:ejabberd:${P}:}" \
  79. -i "${S}/ejabberdctl.template" \
  80. || die 'failed to set ejabberd path in ejabberdctl.template'
  81. sed -e 's|\(captcha_cmd:[[:space:]]*"\).\+"|\1'$(get_ejabberd_path)'/priv/bin/captcha.sh"|' \
  82. -i "${S}/ejabberd.yml.example" \
  83. || die 'failed to correct path to captcha.sh in example config'
  84. }
  85. # Get epam-wrapper from 'files' directory and correct path to lib directory in
  86. # it. epam-wrapper is placed into work directory. It is assumed no epam-wrapper
  87. # file exists there already.
  88. customize_epam_wrapper() {
  89. local epam_wrapper_src="$1"
  90. local epam_wrapper_dst="${S}/epam-wrapper"
  91. [[ -e ${epam_wrapper_dst} ]] && die 'epam-wrapper already exists'
  92. sed -r -e "s@^(ERL_LIBS=).*\$@\1${EPREFIX}$(get_erl_libs)@" \
  93. "${epam_wrapper_src}" >"${epam_wrapper_dst}" \
  94. || die 'failed to install epam-wrapper'
  95. }
  96. # Check if there already exists a certificate.
  97. ejabberd_cert_exists() {
  98. local cert
  99. for cert in $(gawk -- \
  100. 'match($0, /^[[:space:]]*certfile: "([^"]+)"/, m) {print m[1];}' \
  101. "${EROOT%/}${JABBER_ETC}/ejabberd.yml"); do
  102. [[ -f ${cert} ]] && return 0
  103. done
  104. return 1
  105. }
  106. # Generate and install sample ejabberd certificate. It's installed into
  107. # EJABBERD_CERT path.
  108. ejabberd_cert_install() {
  109. SSL_ORGANIZATION="${SSL_ORGANIZATION:-ejabberd XMPP Server}"
  110. install_cert "${EJABBERD_CERT%.*}"
  111. chown root:jabber "${EROOT%/}${EJABBERD_CERT}" || die
  112. chmod 0440 "${EROOT%/}${EJABBERD_CERT}" || die
  113. }
  114. # Get path to ejabberd lib directory.
  115. #
  116. # This is the path ./configure script Base for this path is path set in
  117. # ./configure script which is /usr/lib by default. If libdir is explicitely set
  118. # to something else than this should be adjusted here as well.
  119. get_ejabberd_path() {
  120. echo "/usr/$(get_libdir)/${P}"
  121. }
  122. # Make ejabberd.service for systemd from upstream provided template.
  123. make_ejabberd_service() {
  124. sed -r \
  125. -e 's!@ctlscriptpath@!/usr/sbin!' \
  126. -e 's!(User|Group)=(.*)!\1=jabber!' \
  127. "${PN}.service.template" >"${PN}.service" \
  128. || die 'failed to make ejabberd.service'
  129. }
  130. # Set paths to defined by net-im/jabber-base.
  131. set_jabberbase_paths() {
  132. sed -e "/^ETCDIR[[:space:]]*=/{s:@sysconfdir@/ejabberd:${JABBER_ETC}:}" \
  133. -e "/^LOGDIR[[:space:]]*=/{s:@localstatedir@/log/ejabberd:${JABBER_LOG}:}" \
  134. -e "/^SPOOLDIR[[:space:]]*=/{s:@localstatedir@/lib/ejabberd:${JABBER_SPOOL}:}" \
  135. -i "${S}/Makefile.in" \
  136. || die 'failed to set paths in Makefile.in'
  137. sed -e "s|\(ETC_DIR=\){{sysconfdir}}.*|\1${JABBER_ETC}|" \
  138. -e "s|\(LOGS_DIR=\){{localstatedir}}.*|\1${JABBER_LOG}|" \
  139. -e "s|\(SPOOL_DIR=\){{localstatedir}}.*|\1${JABBER_SPOOL}|" \
  140. -i "${S}/ejabberdctl.template" \
  141. || die 'failed to set paths ejabberdctl.template'
  142. }
  143. # Skip installing docs because it's only COPYING that's installed by Makefile.
  144. skip_docs() {
  145. gawk -i inplace '
  146. /# Documentation/, /^[[:space:]]*#?[[:space:]]*$/ {
  147. if ($0 ~ /^[[:space:]]*#?[[:space:]]*$/) {
  148. print $0;
  149. } else {
  150. next;
  151. }
  152. }
  153. 1
  154. ' "${S}/Makefile.in" || die 'failed to remove docs section from Makefile.in'
  155. }
  156. src_prepare() {
  157. default
  158. rebar_remove_deps
  159. correct_ejabberd_paths
  160. set_jabberbase_paths
  161. make_ejabberd_service
  162. skip_docs
  163. adjust_config
  164. customize_epam_wrapper "${FILESDIR}/epam-wrapper"
  165. # Fix bug #591862. ERL_LIBS should point directly to ejabberd directory
  166. # rather than its parent which is default. That way ejabberd directory
  167. # takes precedence is module lookup.
  168. local ejabberd_erl_libs="$(get_ejabberd_path):$(get_erl_libs)"
  169. sed -e "s|\(ERL_LIBS=\){{libdir}}.*|\1${ejabberd_erl_libs}|" \
  170. -i "${S}/ejabberdctl.template" \
  171. || die 'failed to set ERL_LIBS in ejabberdctl.template'
  172. }
  173. src_configure() {
  174. econf \
  175. --docdir="${EPREFIX}/usr/share/doc/${PF}/html" \
  176. --enable-user=jabber \
  177. $(use_enable debug) \
  178. $(use_enable full-xml) \
  179. $(use_enable hipe) \
  180. $(use_enable mssql) \
  181. $(use_enable mysql) \
  182. $(use_enable nls iconv) \
  183. $(use_enable odbc) \
  184. $(use_enable pam) \
  185. $(use_enable postgres pgsql) \
  186. $(use_enable redis) \
  187. $(use_enable riak) \
  188. $(use_enable roster-gw roster-gateway-workaround) \
  189. $(use_enable sqlite) \
  190. $(use_enable zlib)
  191. }
  192. src_compile() {
  193. emake REBAR='rebar -v' src
  194. }
  195. src_install() {
  196. default
  197. if use pam; then
  198. local epam_path="$(get_ejabberd_path)/priv/bin/epam"
  199. pamd_mimic_system xmpp auth account || die "cannot create pam.d file"
  200. into "$(get_ejabberd_path)/priv"
  201. newbin epam-wrapper epam
  202. # PAM helper module permissions
  203. # https://www.process-one.net/docs/ejabberd/guide_en.html#pam
  204. fowners root:jabber "${epam_path}"
  205. fperms 4750 "${epam_path}"
  206. fi
  207. newconfd "${FILESDIR}/${PN}.confd" "${PN}"
  208. newinitd "${FILESDIR}/${PN}.initd" "${PN}"
  209. systemd_dounit "${PN}.service"
  210. systemd_dotmpfilesd "${FILESDIR}/${PN}.tmpfiles.conf"
  211. insinto /etc/logrotate.d
  212. newins "${FILESDIR}/${PN}.logrotate" "${PN}"
  213. }
  214. pkg_postinst() {
  215. if [[ ! ${REPLACING_VERSIONS} ]]; then
  216. echo
  217. elog "For configuration instructions, please see"
  218. elog " http://www.process-one.net/en/ejabberd/docs/"
  219. echo
  220. if [[ " ${REPLACING_VERSIONS} " =~ \ 2\. ]]; then
  221. ewarn "If you have used pubsub in ejabberd-2.* you may encounter issues after"
  222. ewarn "migration to ${PV}. pubsub data may not be migrated automatically and"
  223. ewarn "you may need to run migration script manually, see:"
  224. ewarn
  225. ewarn " https://github.com/processone/ejabberd/issues/479#issuecomment-124497456"
  226. ewarn
  227. ewarn "In case you don't care about all stored moods, activities, geoinfo and you"
  228. ewarn "know you don't store in pubsub anything important, you can just remove"
  229. ewarn "pubsub tables:"
  230. ewarn
  231. ewarn " rm ${EROOT%/}${JABBER_SPOOL}/pubsub_*"
  232. ewarn
  233. ewarn "See also: https://bugs.gentoo.org/show_bug.cgi?id=588244"
  234. echo
  235. fi
  236. elif [[ -f ${EROOT}etc/jabber/ejabberd.cfg ]]; then
  237. elog "Ejabberd now defaults to using a YAML format for its config file."
  238. elog "The old ejabberd.cfg file can be converted using the following instructions:"
  239. echo
  240. elog "1. Make sure all processes related to the previous version of ejabberd aren't"
  241. elog " running. Usually this just means the ejabberd and epmd daemons and possibly"
  242. elog " the pam-related process (epam) if pam support is enabled."
  243. elog "2. Run \`ejabberdctl start\` with sufficient permissions. Note that this can"
  244. elog " fail to start ejabberd properly for various reasons. Check ejabberd's main"
  245. elog " log file at /var/log/jabber/ejabberd.log to confirm it started successfully."
  246. elog "3. Run"
  247. elog " \`ejabberdctl convert_to_yaml /etc/jabber/ejabberd.cfg /etc/jabber/ejabberd.yml.new\`"
  248. elog " with sufficient permissions, edit and rename /etc/jabber/ejabberd.yml.new to"
  249. elog " /etc/jabber/ejabberd.yml, and finally restart ejabberd with the new config"
  250. elog " file."
  251. echo
  252. fi
  253. if ! ejabberd_cert_exists; then
  254. ejabberd_cert_install
  255. fi
  256. if use pam; then
  257. # sfperms drops read bit from files with suid. Reapply it.
  258. # Fix bug #592218.
  259. local epam_path="$(get_ejabberd_path)/priv/bin/epam"
  260. chmod g+r "${EROOT%/}${epam_path}" \
  261. || die "failed to correct ${epam_path} permissions"
  262. fi
  263. }