1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
7 # Testing within Portage's environment is broken, and the patch no
8 # longer applies cleanly.
11 PYTHON_COMPAT=( python{2_7,3_4} )
13 inherit eutils flag-o-matic linux-info multilib pam prefix python-single-r1 \
14 systemd user versionator
16 KEYWORDS="~alpha amd64 ~arm ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~amd64-fbsd ~sparc-fbsd ~x86-fbsd ~ppc-macos ~x86-solaris"
18 SLOT="$(get_version_component_range 1-2)"
20 SRC_URI="mirror://postgresql/source/v${PV}/postgresql-${PV}.tar.bz2"
22 LICENSE="POSTGRESQL GPL-2"
23 DESCRIPTION="PostgreSQL RDBMS"
24 HOMEPAGE="http://www.postgresql.org/"
26 LINGUAS="af cs de en es fa fr hr hu it ko nb pl pt_BR ro ru sk sl sv tr
28 IUSE="doc kerberos kernel_linux ldap libressl nls pam perl -pg_legacytimestamp python
29 +readline selinux +server ssl static-libs tcl threads uuid xml zlib"
31 for lingua in ${LINGUAS}; do
32 IUSE+=" linguas_${lingua}"
38 for lingua in ${LINGUAS} ; do
39 use linguas_${lingua} && enable_langs+="${lingua} "
42 echo -n ${enable_langs}
46 >=app-eselect/eselect-postgresql-1.2.0
49 kerberos? ( virtual/krb5 )
50 ldap? ( net-nds/openldap )
52 perl? ( >=dev-lang/perl-5.8 )
53 python? ( ${PYTHON_DEPS} )
54 readline? ( sys-libs/readline:0= )
56 !libressl? ( >=dev-libs/openssl-0.9.6-r1:0= )
57 libressl? ( dev-libs/libressl:= )
59 tcl? ( >=dev-lang/tcl-8:0= )
60 uuid? ( dev-libs/ossp-uuid )
61 xml? ( dev-libs/libxml2 dev-libs/libxslt )
62 zlib? ( sys-libs/zlib )
66 !!<sys-apps/sandbox-2.0
69 nls? ( sys-devel/gettext )
70 xml? ( virtual/pkgconfig )
74 !dev-db/postgresql-docs:${SLOT}
75 !dev-db/postgresql-base:${SLOT}
76 !dev-db/postgresql-server:${SLOT}
77 selinux? ( sec-policy/selinux-postgresql )
81 use server && CONFIG_CHECK="~SYSVIPC" linux-info_pkg_setup
84 enewuser postgres 70 /bin/sh /var/lib/postgresql postgres
86 use python && python-single-r1_pkg_setup
90 # Work around PPC{,64} compilation bug where bool is already defined
91 sed '/#ifndef __cplusplus/a #undef bool' -i src/include/c.h || die
93 # Set proper run directory
94 sed "s|\(PGSOCKET_DIR\s\+\)\"/tmp\"|\1\"${EPREFIX}/run/postgresql\"|" \
95 -i src/include/pg_config_manual.h || die
97 epatch "${FILESDIR}/pg_ctl-exit-status.patch"
99 use server || epatch "${FILESDIR}/${PN}-${SLOT}-no-server.patch"
101 # Fix bug 486556 where the server would crash at start up because of
102 # an infinite loop caused by a self-referencing symlink.
103 epatch "${FILESDIR}/postgresql-9.1-tz-dir-overflow.patch"
106 sed -e "s/\(#define PGSQL_PAM_SERVICE \"postgresql\)/\1-${SLOT}/" \
107 -i src/backend/libpq/auth.c || \
108 die 'PGSQL_PAM_SERVICE rename failed.'
116 *-darwin*|*-solaris*)
117 use nls && append-libs intl
121 export LDFLAGS_SL="${LDFLAGS}"
122 export LDFLAGS_EX="${LDFLAGS}"
124 local PO="${EPREFIX%/}"
127 --prefix="${PO}/usr/$(get_libdir)/postgresql-${SLOT}" \
128 --datadir="${PO}/usr/share/postgresql-${SLOT}" \
129 --docdir="${PO}/usr/share/doc/${PF}" \
130 --includedir="${PO}/usr/include/postgresql-${SLOT}" \
131 --mandir="${PO}/usr/share/postgresql-${SLOT}/man" \
132 --sysconfdir="${PO}/etc/postgresql-${SLOT}" \
133 --with-system-tzdata="${PO}/usr/share/zoneinfo" \
134 $(use_enable !pg_legacytimestamp integer-datetimes) \
135 $(use_enable threads thread-safety) \
136 $(use_with kerberos gssapi) \
137 $(use_with kerberos krb5) \
142 $(use_with readline) \
143 $(use_with ssl openssl) \
145 $(use_with uuid ossp-uuid) \
146 $(use_with xml libxml) \
147 $(use_with xml libxslt) \
149 "$(use_enable nls nls "$(wanted_languages)")"
158 emake DESTDIR="${D}" install
159 emake DESTDIR="${D}" install -C contrib
161 dodoc README HISTORY doc/{TODO,bug.template}
163 # man pages are already built, but if we have the target make them,
164 # they'll be generated from source before being installed so we
165 # manually install man pages.
166 # We use ${SLOT} instead of doman for postgresql.eselect
167 insinto /usr/share/postgresql-${SLOT}/man/
168 doins -r doc/src/sgml/man{1,3,7}
169 if ! use server; then
170 # Remove man pages for non-existent binaries
171 for m in {initdb,pg_{controldata,ctl,resetxlog},post{gres,master}}; do
172 rm "${ED}/usr/share/postgresql-${SLOT}/man/man1/${m}.1"
175 docompress /usr/share/postgresql-${SLOT}/man/man{1,3,7}
177 insinto /etc/postgresql-${SLOT}
178 newins src/bin/psql/psqlrc.sample psqlrc
180 dodir /etc/eselect/postgresql/slots/${SLOT}
181 echo "postgres_ebuilds=\"\${postgres_ebuilds} ${PF}\"" > \
182 "${ED}/etc/eselect/postgresql/slots/${SLOT}/base"
184 use static-libs || find "${ED}" -name '*.a' -delete
188 dodoc doc/src/sgml/html/*
191 dodoc doc/src/sgml/*.{sgml,dsl}
195 sed -e "s|@SLOT@|${SLOT}|g" -e "s|@LIBDIR@|$(get_libdir)|g" \
196 "${FILESDIR}/${PN}.confd" | newconfd - ${PN}-${SLOT}
198 sed -e "s|@SLOT@|${SLOT}|g" -e "s|@LIBDIR@|$(get_libdir)|g" \
199 "${FILESDIR}/${PN}.init-pre_9.2" | newinitd - ${PN}-${SLOT}
201 sed -e "s|@SLOT@|${SLOT}|g" -e "s|@LIBDIR@|$(get_libdir)|g" \
202 "${FILESDIR}/${PN}.service" | \
203 systemd_newunit - ${PN}-${SLOT}.service
205 newbin "${FILESDIR}"/${PN}-check-db-dir ${PN}-${SLOT}-check-db-dir
207 use pam && pamd_mimic system-auth ${PN}-${SLOT} auth account session
210 keepdir /run/postgresql
211 fperms 0775 /run/postgresql
217 postgresql-config update
219 elog "If you need a global psqlrc-file, you can place it in:"
220 elog " ${EROOT%/}/etc/postgresql-${SLOT}/"
222 if [[ -z ${REPLACING_VERSIONS} ]] ; then
224 elog "It looks like this is your first time installing PostgreSQL. Run the"
225 elog "following command in all active shells to pick up changes to the default"
227 elog " source /etc/profile"
232 elog "Gentoo specific documentation:"
233 elog "https://wiki.gentoo.org/wiki/PostgreSQL"
235 elog "Official documentation:"
236 elog "http://www.postgresql.org/docs/${SLOT}/static/index.html"
238 elog "The default location of the Unix-domain socket is:"
239 elog " ${EROOT%/}/run/postgresql/"
241 elog "Before initializing the database, you may want to edit PG_INITDB_OPTS"
242 elog "so that it contains your preferred locale in:"
243 elog " ${EROOT%/}/etc/conf.d/postgresql-${SLOT}"
245 elog "Then, execute the following command to setup the initial database"
247 elog " emerge --config =${CATEGORY}/${PF}"
252 if use server && [[ -z ${REPLACED_BY_VERSION} ]] ; then
253 ewarn "Have you dumped and/or migrated the ${SLOT} database cluster?"
254 ewarn "\thttps://wiki.gentoo.org/wiki/PostgreSQL/QuickStart#Migrating_PostgreSQL"
256 ebegin "Resuming removal in 10 seconds (Control-C to cancel)"
263 postgresql-config update
267 use server || die "USE flag 'server' not enabled. Nothing to configure."
269 [[ -f "${EROOT%/}/etc/conf.d/postgresql-${SLOT}" ]] \
270 && source "${EROOT%/}/etc/conf.d/postgresql-${SLOT}"
271 [[ -z "${PGDATA}" ]] && PGDATA="${EROOT%/}/etc/postgresql-${SLOT}/"
272 [[ -z "${DATA_DIR}" ]] \
273 && DATA_DIR="${EROOT%/}/var/lib/postgresql/${SLOT}/data"
275 # environment.bz2 may not contain the same locale as the current system
276 # locale. Unset and source from the current system locale.
277 if [ -f "${EROOT%/}/etc/env.d/02locale" ]; then
286 source "${EROOT%/}/etc/env.d/02locale"
287 [ -n "${LANG}" ] && export LANG
288 [ -n "${LC_CTYPE}" ] && export LC_CTYPE
289 [ -n "${LC_NUMERIC}" ] && export LC_NUMERIC
290 [ -n "${LC_TIME}" ] && export LC_TIME
291 [ -n "${LC_COLLATE}" ] && export LC_COLLATE
292 [ -n "${LC_MONETARY}" ] && export LC_MONETARY
293 [ -n "${LC_MESSAGES}" ] && export LC_MESSAGES
294 [ -n "${LC_ALL}" ] && export LC_ALL
297 einfo "You can modify the paths and options passed to initdb by editing:"
298 einfo " ${EROOT%/}/etc/conf.d/postgresql-${SLOT}"
300 einfo "Information on options that can be passed to initdb are found at:"
301 einfo " http://www.postgresql.org/docs/${SLOT}/static/creating-cluster.html"
302 einfo " http://www.postgresql.org/docs/${SLOT}/static/app-initdb.html"
304 einfo "PG_INITDB_OPTS is currently set to:"
305 if [[ -z "${PG_INITDB_OPTS}" ]] ; then
308 einfo " ${PG_INITDB_OPTS}"
311 einfo "Configuration files will be installed to:"
314 einfo "The database cluster will be created in:"
317 while [ "$correct" != "true" ] ; do
318 einfo "Are you ready to continue? (y/n)"
320 if [[ $answer =~ ^[Yy]([Ee][Ss])?$ ]] ; then
322 elif [[ $answer =~ ^[Nn]([Oo])?$ ]] ; then
323 die "Aborting initialization."
325 echo "Answer not recognized"
329 if [ -n "$(ls -A ${DATA_DIR} 2> /dev/null)" ] ; then
330 eerror "The given directory, '${DATA_DIR}', is not empty."
331 eerror "Modify DATA_DIR to point to an empty directory."
332 die "${DATA_DIR} is not empty."
335 einfo "Creating the data directory ..."
336 if [[ ${EUID} == 0 ]] ; then
337 mkdir -p "${DATA_DIR}"
338 chown -Rf postgres:postgres "${DATA_DIR}"
339 chmod 0700 "${DATA_DIR}"
342 einfo "Initializing the database ..."
344 if [[ ${EUID} == 0 ]] ; then
345 su postgres -c "${EROOT%/}/usr/$(get_libdir)/postgresql-${SLOT}/bin/initdb -D \"${DATA_DIR}\" ${PG_INITDB_OPTS}"
347 "${EROOT%/}"/usr/$(get_libdir)/postgresql-${SLOT}/bin/initdb -U postgres -D "${DATA_DIR}" ${PG_INITDB_OPTS}
350 if [[ "${DATA_DIR%/}" != "${PGDATA%/}" ]] ; then
351 mv "${DATA_DIR%/}"/{pg_{hba,ident},postgresql}.conf "${PGDATA}"
352 ln -s "${PGDATA%/}"/{pg_{hba,ident},postgresql}.conf "${DATA_DIR%/}"
355 cat <<- EOF >> "${PGDATA%/}"/postgresql.conf
356 # This is here because of https://bugs.gentoo.org/show_bug.cgi?id=518522
357 # On the off-chance that you might need to work with UTF-8 encoded
358 # characters in PL/Perl
359 plperl.on_init = 'use utf8; use re; package utf8; require "utf8_heavy.pl";'
362 einfo "The autovacuum function, which was in contrib, has been moved to the main"
363 einfo "PostgreSQL functions starting with 8.1, and starting with 8.4 is now enabled"
364 einfo "by default. You can disable it in the cluster's:"
365 einfo " ${PGDATA%/}/postgresql.conf"
367 einfo "The PostgreSQL server, by default, will log events to:"
368 einfo " ${DATA_DIR%/}/postmaster.log"
371 einfo "The location of the configuration files have moved to:"
373 einfo "To start the server:"
374 einfo " pg_ctl start -D ${DATA_DIR} -o '-D ${PGDATA} --data-directory=${DATA_DIR}'"
376 einfo " pg_ctl stop -D ${DATA_DIR}"
378 einfo "Or move the configuration files back:"
379 einfo "mv ${PGDATA}*.conf ${DATA_DIR}"
381 einfo "You should use the '${EROOT%/}/etc/init.d/postgresql-${SLOT}' script to run PostgreSQL"
382 einfo "instead of 'pg_ctl'."