1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
6 PYTHON_COMPAT=( python{2_7,3_4} )
8 inherit eutils flag-o-matic linux-info multilib pam prefix python-single-r1 \
9 systemd user versionator
11 KEYWORDS="alpha amd64 arm ~hppa ia64 ~mips ppc ppc64 ~s390 ~sh sparc x86 ~amd64-fbsd ~sparc-fbsd ~x86-fbsd ~ppc-macos ~x86-solaris"
13 SLOT="$(get_version_component_range 1-2)"
15 SRC_URI="mirror://postgresql/source/v${PV}/postgresql-${PV}.tar.bz2"
17 LICENSE="POSTGRESQL GPL-2"
18 DESCRIPTION="PostgreSQL RDBMS"
19 HOMEPAGE="http://www.postgresql.org/"
21 LINGUAS="af cs de en es fa fr hr hu it ko nb pl pt_BR ro ru sk sl sv tr
23 IUSE="doc kerberos kernel_linux ldap libressl nls pam perl -pg_legacytimestamp python
24 +readline selinux +server ssl static-libs tcl threads uuid xml zlib"
26 for lingua in ${LINGUAS}; do
27 IUSE+=" linguas_${lingua}"
29 REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
34 for lingua in ${LINGUAS} ; do
35 use linguas_${lingua} && enable_langs+="${lingua} "
38 echo -n ${enable_langs}
42 >=app-eselect/eselect-postgresql-2.0
45 kerberos? ( virtual/krb5 )
46 ldap? ( net-nds/openldap )
48 perl? ( >=dev-lang/perl-5.8:= )
49 python? ( ${PYTHON_DEPS} )
50 readline? ( sys-libs/readline:0= )
52 !libressl? ( >=dev-libs/openssl-0.9.6-r1:0= )
53 libressl? ( dev-libs/libressl:= )
55 tcl? ( >=dev-lang/tcl-8:0= )
56 uuid? ( dev-libs/ossp-uuid )
57 xml? ( dev-libs/libxml2 dev-libs/libxslt )
58 zlib? ( sys-libs/zlib )
62 !!<sys-apps/sandbox-2.0
65 nls? ( sys-devel/gettext )
66 xml? ( virtual/pkgconfig )
70 !dev-db/postgresql-docs:${SLOT}
71 !dev-db/postgresql-base:${SLOT}
72 !dev-db/postgresql-server:${SLOT}
73 selinux? ( sec-policy/selinux-postgresql )
77 use server && CONFIG_CHECK="~SYSVIPC" linux-info_pkg_setup
80 enewuser postgres 70 /bin/sh /var/lib/postgresql postgres
82 use python && python-single-r1_pkg_setup
86 # Work around PPC{,64} compilation bug where bool is already defined
87 sed '/#ifndef __cplusplus/a #undef bool' -i src/include/c.h || die
89 # Set proper run directory
90 sed "s|\(PGSOCKET_DIR\s\+\)\"/tmp\"|\1\"${EPREFIX}/run/postgresql\"|" \
91 -i src/include/pg_config_manual.h || die
93 use server || epatch "${FILESDIR}/${PN}-${SLOT}-no-server.patch"
95 # Fix bug 486556 where the server would crash at start up because of
96 # an infinite loop caused by a self-referencing symlink.
97 epatch "${FILESDIR}/postgresql-9.2-9.4-tz-dir-overflow.patch"
100 sed -e "s/\(#define PGSQL_PAM_SERVICE \"postgresql\)/\1-${SLOT}/" \
101 -i src/backend/libpq/auth.c || \
102 die 'PGSQL_PAM_SERVICE rename failed.'
110 *-darwin*|*-solaris*)
111 use nls && append-libs intl
115 export LDFLAGS_SL="${LDFLAGS}"
116 export LDFLAGS_EX="${LDFLAGS}"
118 local PO="${EPREFIX%/}"
121 --prefix="${PO}/usr/$(get_libdir)/postgresql-${SLOT}" \
122 --datadir="${PO}/usr/share/postgresql-${SLOT}" \
123 --docdir="${PO}/usr/share/doc/${PF}" \
124 --includedir="${PO}/usr/include/postgresql-${SLOT}" \
125 --mandir="${PO}/usr/share/postgresql-${SLOT}/man" \
126 --sysconfdir="${PO}/etc/postgresql-${SLOT}" \
127 --with-system-tzdata="${PO}/usr/share/zoneinfo" \
128 $(use_enable !pg_legacytimestamp integer-datetimes) \
129 $(use_enable threads thread-safety) \
130 $(use_with kerberos gssapi) \
131 $(use_with kerberos krb5) \
136 $(use_with readline) \
137 $(use_with ssl openssl) \
139 $(use_with uuid ossp-uuid) \
140 $(use_with xml libxml) \
141 $(use_with xml libxslt) \
143 "$(use_enable nls nls "$(wanted_languages)")"
152 emake DESTDIR="${D}" install
153 emake DESTDIR="${D}" install -C contrib
155 dodoc README HISTORY doc/{TODO,bug.template}
157 # man pages are already built, but if we have the target make them,
158 # they'll be generated from source before being installed so we
159 # manually install man pages.
160 # We use ${SLOT} instead of doman for postgresql.eselect
161 insinto /usr/share/postgresql-${SLOT}/man/
162 doins -r doc/src/sgml/man{1,3,7}
163 if ! use server; then
164 # Remove man pages for non-existent binaries
165 for m in {initdb,pg_{controldata,ctl,resetxlog},post{gres,master}}; do
166 rm "${ED}/usr/share/postgresql-${SLOT}/man/man1/${m}.1"
169 docompress /usr/share/postgresql-${SLOT}/man/man{1,3,7}
171 insinto /etc/postgresql-${SLOT}
172 newins src/bin/psql/psqlrc.sample psqlrc
174 use static-libs || find "${ED}" -name '*.a' -delete
177 for f in $(find "${ED}/usr/$(get_libdir)/postgresql-${SLOT}/bin" \
178 -mindepth 1 -maxdepth 1)
180 bn=$(basename "${f}")
181 # Temporarily tack on tmp to workaround a file collision
182 # issue. This is only necessary for 9.7 and earlier. 10 never
184 dosym "../$(get_libdir)/postgresql-${SLOT}/bin/${bn}" \
185 "/usr/bin/${bn}${SLOT/.}tmp"
188 local linkname mansec
189 for mansec in {1,3,7} ; do
190 for f in "${ED}"/usr/share/postgresql-${SLOT}/man/man${mansec}/* ; do
191 bn=$(basename "${f}")
192 linkname=${bn/%.${mansec}/${SLOT/.}.${mansec}}
193 dosym ../../postgresql-${SLOT}/man/man${mansec}/$bn \
194 /usr/share/man/man${mansec}/${linkname}
200 dodoc doc/src/sgml/html/*
203 dodoc doc/src/sgml/*.{sgml,dsl}
207 sed -e "s|@SLOT@|${SLOT}|g" -e "s|@LIBDIR@|$(get_libdir)|g" \
208 "${FILESDIR}/${PN}.confd-9.2" | newconfd - ${PN}-${SLOT}
210 sed -e "s|@SLOT@|${SLOT}|g" -e "s|@LIBDIR@|$(get_libdir)|g" \
211 "${FILESDIR}/${PN}.init-9.2" | newinitd - ${PN}-${SLOT}
213 sed -e "s|@SLOT@|${SLOT}|g" -e "s|@LIBDIR@|$(get_libdir)|g" \
214 "${FILESDIR}/${PN}.service" | \
215 systemd_newunit - ${PN}-${SLOT}.service
217 newbin "${FILESDIR}"/${PN}-check-db-dir ${PN}-${SLOT}-check-db-dir
219 use pam && pamd_mimic system-auth ${PN}-${SLOT} auth account session
222 keepdir /run/postgresql
223 fperms 0775 /run/postgresql
229 # Find all of the slot-specific symlinks, if any, in /usr/bin (e.g.,
230 # /usr/bin/psql96). They may have been created by the
231 # postgresql.eselect module, but they're handled within this ebuild
232 # now. It's alright if we momentarily delete /usr/bin/psql as it
233 # will be recreated by the eselect module in pkg_ppostinst(). This
234 # is only necessary for 9.7 and earlier. 10 and later were never
235 # handled in this manner.
237 if type -p realpath > /dev/null; then
238 canonicalise=realpath
239 elif type -p readlink > /dev/null; then
240 canonicalise='readlink -f'
242 # can't die, subshell
243 die "No readlink nor realpath found, cannot canonicalise"
247 # First remove any symlinks in /usr/bin that may have been created
249 for l in $(find "${ROOT%/}/usr/bin" -mindepth 1 -maxdepth 1 -type l) ; do
250 if [[ $(${canonicalise} "${l}") == *postgresql-${SLOT}* ]] ; then
251 rm "${l}" || ewarn "Couldn't remove ${l}"
255 # Then move the symlinks created by the ebuild to their proper place.
256 for l in "${ED}"/usr/bin/*tmp ; do
257 mv "${l}" "${l%tmp}" \
258 || ewarn "Couldn't rename $(basename ${l}) to $(basename ${l%tmp})"
263 postgresql-config update
265 elog "If you need a global psqlrc-file, you can place it in:"
266 elog " ${EROOT%/}/etc/postgresql-${SLOT}/"
270 elog "Gentoo specific documentation:"
271 elog "https://wiki.gentoo.org/wiki/PostgreSQL"
273 elog "Official documentation:"
274 elog "http://www.postgresql.org/docs/${SLOT}/static/index.html"
276 elog "The default location of the Unix-domain socket is:"
277 elog " ${EROOT%/}/run/postgresql/"
279 elog "Before initializing the database, you may want to edit PG_INITDB_OPTS"
280 elog "so that it contains your preferred locale in:"
281 elog " ${EROOT%/}/etc/conf.d/postgresql-${SLOT}"
283 elog "Then, execute the following command to setup the initial database"
285 elog " emerge --config =${CATEGORY}/${PF}"
290 if use server && [[ -z ${REPLACED_BY_VERSION} ]] ; then
291 ewarn "Have you dumped and/or migrated the ${SLOT} database cluster?"
292 ewarn "\thttps://wiki.gentoo.org/wiki/PostgreSQL/QuickStart#Migrating_PostgreSQL"
294 ebegin "Resuming removal in 10 seconds (Control-C to cancel)"
301 postgresql-config update
305 use server || die "USE flag 'server' not enabled. Nothing to configure."
307 [[ -f "${EROOT%/}/etc/conf.d/postgresql-${SLOT}" ]] \
308 && source "${EROOT%/}/etc/conf.d/postgresql-${SLOT}"
309 [[ -z "${PGDATA}" ]] && PGDATA="${EROOT%/}/etc/postgresql-${SLOT}/"
310 [[ -z "${DATA_DIR}" ]] \
311 && DATA_DIR="${EROOT%/}/var/lib/postgresql/${SLOT}/data"
313 # environment.bz2 may not contain the same locale as the current system
314 # locale. Unset and source from the current system locale.
315 if [ -f "${EROOT%/}/etc/env.d/02locale" ]; then
324 source "${EROOT%/}/etc/env.d/02locale"
325 [ -n "${LANG}" ] && export LANG
326 [ -n "${LC_CTYPE}" ] && export LC_CTYPE
327 [ -n "${LC_NUMERIC}" ] && export LC_NUMERIC
328 [ -n "${LC_TIME}" ] && export LC_TIME
329 [ -n "${LC_COLLATE}" ] && export LC_COLLATE
330 [ -n "${LC_MONETARY}" ] && export LC_MONETARY
331 [ -n "${LC_MESSAGES}" ] && export LC_MESSAGES
332 [ -n "${LC_ALL}" ] && export LC_ALL
335 einfo "You can modify the paths and options passed to initdb by editing:"
336 einfo " ${EROOT%/}/etc/conf.d/postgresql-${SLOT}"
338 einfo "Information on options that can be passed to initdb are found at:"
339 einfo " http://www.postgresql.org/docs/${SLOT}/static/creating-cluster.html"
340 einfo " http://www.postgresql.org/docs/${SLOT}/static/app-initdb.html"
342 einfo "PG_INITDB_OPTS is currently set to:"
343 if [[ -z "${PG_INITDB_OPTS}" ]] ; then
346 einfo " ${PG_INITDB_OPTS}"
349 einfo "Configuration files will be installed to:"
352 einfo "The database cluster will be created in:"
356 ebegin "Continuing initialization in 5 seconds (Control-C to cancel)"
360 if [ -n "$(ls -A ${DATA_DIR} 2> /dev/null)" ] ; then
361 eerror "The given directory, '${DATA_DIR}', is not empty."
362 eerror "Modify DATA_DIR to point to an empty directory."
363 die "${DATA_DIR} is not empty."
366 einfo "Creating the data directory ..."
367 if [[ ${EUID} == 0 ]] ; then
368 mkdir -p "${DATA_DIR}"
369 chown -Rf postgres:postgres "${DATA_DIR}"
370 chmod 0700 "${DATA_DIR}"
373 einfo "Initializing the database ..."
375 if [[ ${EUID} == 0 ]] ; then
376 su postgres -c "${EROOT%/}/usr/$(get_libdir)/postgresql-${SLOT}/bin/initdb -D \"${DATA_DIR}\" ${PG_INITDB_OPTS}"
378 "${EROOT%/}"/usr/$(get_libdir)/postgresql-${SLOT}/bin/initdb -U postgres -D "${DATA_DIR}" ${PG_INITDB_OPTS}
381 if [[ "${DATA_DIR%/}" != "${PGDATA%/}" ]] ; then
382 mv "${DATA_DIR%/}"/{pg_{hba,ident},postgresql}.conf "${PGDATA}"
383 ln -s "${PGDATA%/}"/{pg_{hba,ident},postgresql}.conf "${DATA_DIR%/}"
386 # unix_socket_directory has no effect in postgresql.conf as it's
387 # overridden in the initscript
388 sed '/^#unix_socket_directory/d' -i "${PGDATA%/}"/postgresql.conf
390 cat <<- EOF >> "${PGDATA%/}"/postgresql.conf
391 # This is here because of https://bugs.gentoo.org/show_bug.cgi?id=518522
392 # On the off-chance that you might need to work with UTF-8 encoded
393 # characters in PL/Perl
394 plperl.on_init = 'use utf8; use re; package utf8; require "utf8_heavy.pl";'
397 einfo "The autovacuum function, which was in contrib, has been moved to the main"
398 einfo "PostgreSQL functions starting with 8.1, and starting with 8.4 is now enabled"
399 einfo "by default. You can disable it in the cluster's:"
400 einfo " ${PGDATA%/}/postgresql.conf"
402 einfo "The PostgreSQL server, by default, will log events to:"
403 einfo " ${DATA_DIR%/}/postmaster.log"
406 einfo "The location of the configuration files have moved to:"
408 einfo "To start the server:"
409 einfo " pg_ctl start -D ${DATA_DIR} -o '-D ${PGDATA} --data-directory=${DATA_DIR}'"
411 einfo " pg_ctl stop -D ${DATA_DIR}"
413 einfo "Or move the configuration files back:"
414 einfo "mv ${PGDATA}*.conf ${DATA_DIR}"
416 einfo "You should use the '${EROOT%/}/etc/init.d/postgresql-${SLOT}' script to run PostgreSQL"
417 einfo "instead of 'pg_ctl'."
422 if use server && [[ ${UID} -ne 0 ]] ; then
425 einfo "If you think other tests besides the regression tests are necessary, please"
426 einfo "submit a bug including a patch for this ebuild to enable them."
429 ewarn 'Tests cannot be run without the "server" use flag enabled.'
430 [[ ${UID} -eq 0 ]] || \
431 ewarn 'Tests cannot be run as root. Enable "userpriv" in FEATURES.'