postgresql-10.7.ebuild (13843B)
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI="6"
5
6 PYTHON_COMPAT=( python2_7 python3_{5,6} )
7
8 PLOCALES="af cs de en es fa fr hr hu it ko nb pl pt_BR ro ru sk sl sv tr zh_CN
9 zh_TW"
10
11 inherit flag-o-matic l10n linux-info multilib pam prefix python-single-r1 \
12 systemd user versionator
13
14 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~amd64-fbsd ~x86-fbsd ~ppc-macos ~x86-solaris"
15
16 SLOT=$(get_major_version)
17
18 MY_PV=${PV/_/}
19 S="${WORKDIR}/${PN}-${MY_PV}"
20
21 SRC_URI="mirror://postgresql/source/v${MY_PV}/postgresql-${MY_PV}.tar.bz2"
22
23 LICENSE="POSTGRESQL GPL-2"
24 DESCRIPTION="PostgreSQL RDBMS"
25 HOMEPAGE="https://www.postgresql.org/"
26
27 IUSE="doc kerberos kernel_linux ldap libressl nls pam perl python +readline
28 selinux +server systemd ssl static-libs tcl threads uuid xml zlib"
29
30 REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
31
32 CDEPEND="
33 >=app-eselect/eselect-postgresql-2.0
34 virtual/pager
35 app-misc/editor-wrapper
36 virtual/libintl
37 kerberos? ( virtual/krb5 )
38 ldap? ( net-nds/openldap )
39 pam? ( virtual/pam )
40 perl? ( >=dev-lang/perl-5.8:= )
41 python? ( ${PYTHON_DEPS} )
42 readline? ( sys-libs/readline:0= )
43 server? ( systemd? ( sys-apps/systemd ) )
44 ssl? (
45 !libressl? ( >=dev-libs/openssl-0.9.6-r1:0= )
46 libressl? ( dev-libs/libressl:= )
47 )
48 tcl? ( >=dev-lang/tcl-8:0= )
49 xml? ( dev-libs/libxml2 dev-libs/libxslt )
50 zlib? ( sys-libs/zlib )
51 "
52
53 # uuid flags -- depend on sys-apps/util-linux for Linux libcs, or if no
54 # supported libc in use depend on dev-libs/ossp-uuid. For BSD systems,
55 # the libc includes UUID functions.
56 UTIL_LINUX_LIBC=( elibc_{glibc,uclibc,musl} )
57 BSD_LIBC=( elibc_{Free,Net,Open}BSD )
58
59 nest_usedep() {
60 local front back
61 while [[ ${#} -gt 1 ]]; do
62 front+="${1}? ( "
63 back+=" )"
64 shift
65 done
66 echo "${front}${1}${back}"
67 }
68
69 IUSE+=" ${UTIL_LINUX_LIBC[@]} ${BSD_LIBC[@]}"
70 CDEPEND+="
71 uuid? (
72 ${UTIL_LINUX_LIBC[@]/%/? ( sys-apps/util-linux )}
73 $(nest_usedep ${UTIL_LINUX_LIBC[@]/#/!} ${BSD_LIBC[@]/#/!} dev-libs/ossp-uuid)
74 )"
75
76 DEPEND="${CDEPEND}
77 !!<sys-apps/sandbox-2.0
78 sys-devel/bison
79 sys-devel/flex
80 nls? ( sys-devel/gettext )
81 xml? ( virtual/pkgconfig )
82 "
83
84 RDEPEND="${CDEPEND}
85 !dev-db/postgresql-docs:${SLOT}
86 !dev-db/postgresql-base:${SLOT}
87 !dev-db/postgresql-server:${SLOT}
88 selinux? ( sec-policy/selinux-postgresql )
89 "
90
91 pkg_setup() {
92 use server && CONFIG_CHECK="~SYSVIPC" linux-info_pkg_setup
93
94 enewgroup postgres 70
95 enewuser postgres 70 /bin/sh /var/lib/postgresql postgres
96
97 use python && python-single-r1_pkg_setup
98 }
99
100 src_prepare() {
101 # Work around PPC{,64} compilation bug where bool is already defined
102 sed '/#ifndef __cplusplus/a #undef bool' -i src/include/c.h || die
103
104 # Set proper run directory
105 sed "s|\(PGSOCKET_DIR\s\+\)\"/tmp\"|\1\"${EPREFIX}/run/postgresql\"|" \
106 -i src/include/pg_config_manual.h || die
107
108 # Rely on $PATH being in the proper order so that the correct
109 # install program is used for modules utilizing PGXS in both
110 # hardened and non-hardened environments. (Bug #528786)
111 sed 's/@install_bin@/install -c/' -i src/Makefile.global.in || die
112
113 use server || eapply "${FILESDIR}/${PN}-10.2-no-server.patch"
114
115 if use pam ; then
116 sed -e "s/\(#define PGSQL_PAM_SERVICE \"postgresql\)/\1-${SLOT}/" \
117 -i src/backend/libpq/auth.c || \
118 die 'PGSQL_PAM_SERVICE rename failed.'
119 fi
120
121 eapply_user
122 }
123
124 src_configure() {
125 case ${CHOST} in
126 *-darwin*|*-solaris*)
127 use nls && append-libs intl
128 ;;
129 esac
130
131 export LDFLAGS_SL="${LDFLAGS}"
132 export LDFLAGS_EX="${LDFLAGS}"
133
134 local PO="${EPREFIX%/}"
135
136 local i uuid_config=""
137 if use uuid; then
138 for i in ${UTIL_LINUX_LIBC[@]}; do
139 use ${i} && uuid_config="--with-uuid=e2fs"
140 done
141 for i in ${BSD_LIBC[@]}; do
142 use ${i} && uuid_config="--with-uuid=bsd"
143 done
144 [[ -z $uuid_config ]] && uuid_config="--with-uuid=ossp"
145 fi
146
147 econf \
148 --prefix="${PO}/usr/$(get_libdir)/postgresql-${SLOT}" \
149 --datadir="${PO}/usr/share/postgresql-${SLOT}" \
150 --docdir="${PO}/usr/share/doc/${PF}" \
151 --includedir="${PO}/usr/include/postgresql-${SLOT}" \
152 --mandir="${PO}/usr/share/postgresql-${SLOT}/man" \
153 --sysconfdir="${PO}/etc/postgresql-${SLOT}" \
154 --with-system-tzdata="${PO}/usr/share/zoneinfo" \
155 $(use_enable !alpha spinlocks) \
156 $(use_enable threads thread-safety) \
157 $(use_with kerberos gssapi) \
158 $(use_with ldap) \
159 $(use_with pam) \
160 $(use_with perl) \
161 $(use_with python) \
162 $(use_with readline) \
163 $(use_with ssl openssl) \
164 $(usex server "$(use_with systemd)" '--without-systemd') \
165 $(use_with tcl) \
166 ${uuid_config} \
167 $(use_with xml libxml) \
168 $(use_with xml libxslt) \
169 $(use_with zlib) \
170 $(use_enable nls nls "'$(l10n_get_locales)'")
171 }
172
173 src_compile() {
174 emake
175 emake -C contrib
176 }
177
178 src_install() {
179 emake DESTDIR="${D}" install
180 emake DESTDIR="${D}" install -C contrib
181
182 dodoc README HISTORY doc/{TODO,bug.template}
183
184 # man pages are already built, but if we have the target make them,
185 # they'll be generated from source before being installed so we
186 # manually install man pages.
187 # We use ${SLOT} instead of doman for postgresql.eselect
188 insinto /usr/share/postgresql-${SLOT}/man/
189 doins -r doc/src/sgml/man{1,3,7}
190 if ! use server; then
191 # Remove man pages for non-existent binaries
192 serverman=(
193 initdb
194 pg_{archivecleanup,controldata,ctl,resetwal,rewind,standby}
195 pg_{test_{fsync,timing},upgrade,waldump}
196 post{gres,master}
197 )
198 for m in ${serverman[@]} ; do
199 rm "${ED}/usr/share/postgresql-${SLOT}/man/man1/${m}.1"
200 done
201 fi
202 docompress /usr/share/postgresql-${SLOT}/man/man{1,3,7}
203
204 # Create slot specific man pages
205 local bn f mansec slotted_name
206 for mansec in 1 3 7 ; do
207 local rel_manpath="../../postgresql-${SLOT}/man/man${mansec}"
208
209 mkdir -p "${ED}"/usr/share/man/man${mansec} || die "making man dir"
210 pushd "${ED}"/usr/share/man/man${mansec} > /dev/null || die "pushd failed"
211
212 for f in "${ED}/usr/share/postgresql-${SLOT}/man/man${mansec}"/* ; do
213 bn=$(basename "${f}")
214 slotted_name=${bn%.${mansec}}${SLOT}.${mansec}
215 case ${bn} in
216 TABLE.7|WITH.7)
217 echo ".so ${rel_manpath}/SELECT.7" > ${slotted_name}
218 ;;
219 *)
220 echo ".so ${rel_manpath}/${bn}" > ${slotted_name}
221 ;;
222 esac
223 done
224
225 popd > /dev/null
226 done
227
228 insinto /etc/postgresql-${SLOT}
229 newins src/bin/psql/psqlrc.sample psqlrc
230
231 use static-libs || find "${ED}" -name '*.a' -delete
232
233 local f bn
234 for f in $(find "${ED}/usr/$(get_libdir)/postgresql-${SLOT}/bin" \
235 -mindepth 1 -maxdepth 1)
236 do
237 bn=$(basename "${f}")
238 # Temporarily tack on tmp to workaround a file collision
239 # issue. This is only necessary for 9.7 and earlier. 10 never
240 # had this issue.
241 dosym "../$(get_libdir)/postgresql-${SLOT}/bin/${bn}" \
242 "/usr/bin/${bn}${SLOT/.}"
243 done
244
245 if use doc ; then
246 docinto html
247 dodoc doc/src/sgml/html/*
248 fi
249
250 if use server; then
251 sed -e "s|@SLOT@|${SLOT}|g" -e "s|@LIBDIR@|$(get_libdir)|g" \
252 "${FILESDIR}/${PN}.confd-9.3" | newconfd - ${PN}-${SLOT}
253
254 sed -e "s|@SLOT@|${SLOT}|g" -e "s|@LIBDIR@|$(get_libdir)|g" \
255 "${FILESDIR}/${PN}.init-9.3-r1" | newinitd - ${PN}-${SLOT}
256
257 if use systemd; then
258 sed -e "s|@SLOT@|${SLOT}|g" -e "s|@LIBDIR@|$(get_libdir)|g" \
259 "${FILESDIR}/${PN}.service-9.6-r1" | \
260 systemd_newunit - ${PN}-${SLOT}.service
261 newbin "${FILESDIR}"/${PN}-check-db-dir ${PN}-${SLOT}-check-db-dir
262 systemd_newtmpfilesd "${FILESDIR}"/${PN}.tmpfiles ${PN}-${SLOT}.conf
263 fi
264
265 use pam && pamd_mimic system-auth ${PN}-${SLOT} auth account session
266
267 if use prefix ; then
268 keepdir /run/postgresql
269 fperms 1775 /run/postgresql
270 fi
271 fi
272 }
273
274 pkg_postinst() {
275 use server && use systemd && systemd_tmpfiles_create ${PN}-${SLOT}.conf
276 postgresql-config update
277
278 elog "If you need a global psqlrc-file, you can place it in:"
279 elog " ${EROOT%/}/etc/postgresql-${SLOT}/"
280
281 if use server ; then
282 elog
283 elog "Gentoo specific documentation:"
284 elog "https://wiki.gentoo.org/wiki/PostgreSQL"
285 elog
286 elog "Official documentation:"
287 elog "https://www.postgresql.org/docs/${SLOT}/static/index.html"
288 elog
289 elog "The default location of the Unix-domain socket is:"
290 elog " ${EROOT%/}/run/postgresql/"
291 elog
292 elog "Before initializing the database, you may want to edit PG_INITDB_OPTS"
293 elog "so that it contains your preferred locale in:"
294 elog " ${EROOT%/}/etc/conf.d/postgresql-${SLOT}"
295 elog
296 elog "Then, execute the following command to setup the initial database"
297 elog "environment:"
298 elog " emerge --config =${CATEGORY}/${PF}"
299
300 if [[ -n ${REPLACING_VERSIONS} ]] ; then
301 ewarn "If your system is using 'pg_stat_statements' and you are running a"
302 ewarn "version of PostgreSQL ${SLOT}, we advise that you execute"
303 ewarn "the following command after upgrading:"
304 ewarn
305 ewarn "ALTER EXTENSION pg_stat_statements UPDATE;"
306 fi
307 fi
308 }
309
310 pkg_prerm() {
311 if use server && [[ -z ${REPLACED_BY_VERSION} ]] ; then
312 ewarn "Have you dumped and/or migrated the ${SLOT} database cluster?"
313 ewarn "\thttps://wiki.gentoo.org/wiki/PostgreSQL/QuickStart#Migrating_PostgreSQL"
314
315 ebegin "Resuming removal in 10 seconds (Control-C to cancel)"
316 sleep 10
317 eend 0
318 fi
319 }
320
321 pkg_postrm() {
322 postgresql-config update
323 }
324
325 pkg_config() {
326 use server || die "USE flag 'server' not enabled. Nothing to configure."
327
328 [[ -f "${EROOT%/}/etc/conf.d/postgresql-${SLOT}" ]] \
329 && source "${EROOT%/}/etc/conf.d/postgresql-${SLOT}"
330 [[ -z "${PGDATA}" ]] && PGDATA="${EROOT%/}/etc/postgresql-${SLOT}/"
331 [[ -z "${DATA_DIR}" ]] \
332 && DATA_DIR="${EROOT%/}/var/lib/postgresql/${SLOT}/data"
333
334 # environment.bz2 may not contain the same locale as the current system
335 # locale. Unset and source from the current system locale.
336 if [ -f "${EROOT%/}/etc/env.d/02locale" ]; then
337 unset LANG
338 unset LC_CTYPE
339 unset LC_NUMERIC
340 unset LC_TIME
341 unset LC_COLLATE
342 unset LC_MONETARY
343 unset LC_MESSAGES
344 unset LC_ALL
345 source "${EROOT%/}/etc/env.d/02locale"
346 [ -n "${LANG}" ] && export LANG
347 [ -n "${LC_CTYPE}" ] && export LC_CTYPE
348 [ -n "${LC_NUMERIC}" ] && export LC_NUMERIC
349 [ -n "${LC_TIME}" ] && export LC_TIME
350 [ -n "${LC_COLLATE}" ] && export LC_COLLATE
351 [ -n "${LC_MONETARY}" ] && export LC_MONETARY
352 [ -n "${LC_MESSAGES}" ] && export LC_MESSAGES
353 [ -n "${LC_ALL}" ] && export LC_ALL
354 fi
355
356 einfo "You can modify the paths and options passed to initdb by editing:"
357 einfo " ${EROOT%/}/etc/conf.d/postgresql-${SLOT}"
358 einfo
359 einfo "Information on options that can be passed to initdb are found at:"
360 einfo " https://www.postgresql.org/docs/${SLOT}/static/creating-cluster.html"
361 einfo " https://www.postgresql.org/docs/${SLOT}/static/app-initdb.html"
362 einfo
363 einfo "PG_INITDB_OPTS is currently set to:"
364 if [[ -z "${PG_INITDB_OPTS}" ]] ; then
365 einfo " (none)"
366 else
367 einfo " ${PG_INITDB_OPTS}"
368 fi
369 einfo
370 einfo "Configuration files will be installed to:"
371 einfo " ${PGDATA}"
372 einfo
373 einfo "The database cluster will be created in:"
374 einfo " ${DATA_DIR}"
375 einfo
376
377 ebegin "Continuing initialization in 5 seconds (Control-C to cancel)"
378 sleep 5
379 eend 0
380
381 if [ -n "$(ls -A ${DATA_DIR} 2> /dev/null)" ] ; then
382 eerror "The given directory, '${DATA_DIR}', is not empty."
383 eerror "Modify DATA_DIR to point to an empty directory."
384 die "${DATA_DIR} is not empty."
385 fi
386
387 einfo "Creating the data directory ..."
388 if [[ ${EUID} == 0 ]] ; then
389 mkdir -p "${DATA_DIR}"
390 chown -Rf postgres:postgres "${DATA_DIR}"
391 chmod 0700 "${DATA_DIR}"
392 fi
393
394 einfo "Initializing the database ..."
395
396 if [[ ${EUID} == 0 ]] ; then
397 su postgres -c "${EROOT%/}/usr/$(get_libdir)/postgresql-${SLOT}/bin/initdb -D \"${DATA_DIR}\" ${PG_INITDB_OPTS}"
398 else
399 "${EROOT%/}"/usr/$(get_libdir)/postgresql-${SLOT}/bin/initdb -U postgres -D "${DATA_DIR}" ${PG_INITDB_OPTS}
400 fi
401
402 if [[ "${DATA_DIR%/}" != "${PGDATA%/}" ]] ; then
403 mv "${DATA_DIR%/}"/{pg_{hba,ident},postgresql}.conf "${PGDATA}"
404 ln -s "${PGDATA%/}"/{pg_{hba,ident},postgresql}.conf "${DATA_DIR%/}"
405 fi
406
407 # unix_socket_directory has no effect in postgresql.conf as it's
408 # overridden in the initscript
409 sed '/^#unix_socket_directories/,+1d' -i "${PGDATA%/}"/postgresql.conf
410
411 cat <<- EOF >> "${PGDATA%/}"/postgresql.conf
412 # This is here because of https://bugs.gentoo.org/show_bug.cgi?id=518522
413 # On the off-chance that you might need to work with UTF-8 encoded
414 # characters in PL/Perl
415 plperl.on_init = 'use utf8; use re; package utf8; require "utf8_heavy.pl";'
416 EOF
417
418 einfo "The autovacuum function, which was in contrib, has been moved to the main"
419 einfo "PostgreSQL functions starting with 8.1, and starting with 8.4 is now enabled"
420 einfo "by default. You can disable it in the cluster's:"
421 einfo " ${PGDATA%/}/postgresql.conf"
422 einfo
423 if ! use systemd; then
424 einfo "The PostgreSQL server, by default, will log events to:"
425 einfo " ${DATA_DIR%/}/postmaster.log"
426 einfo
427 fi
428 if use prefix ; then
429 einfo "The location of the configuration files have moved to:"
430 einfo " ${PGDATA}"
431 einfo "To start the server:"
432 einfo " pg_ctl start -D ${DATA_DIR} -o '-D ${PGDATA} --data-directory=${DATA_DIR}'"
433 einfo "To stop:"
434 einfo " pg_ctl stop -D ${DATA_DIR}"
435 einfo
436 einfo "Or move the configuration files back:"
437 einfo "mv ${PGDATA}*.conf ${DATA_DIR}"
438 elif use systemd; then
439 einfo "You should use the 'postgresql-${SLOT}.service' unit to run PostgreSQL"
440 einfo "instead of 'pg_ctl'."
441 else
442 einfo "You should use the '${EROOT%/}/etc/init.d/postgresql-${SLOT}' script to run PostgreSQL"
443 einfo "instead of 'pg_ctl'."
444 fi
445 }
446
447 src_test() {
448 if use server && [[ ${UID} -ne 0 ]] ; then
449 emake check
450
451 einfo "If you think other tests besides the regression tests are necessary, please"
452 einfo "submit a bug including a patch for this ebuild to enable them."
453 else
454 use server || \
455 ewarn 'Tests cannot be run without the "server" use flag enabled.'
456 [[ ${UID} -eq 0 ]] || \
457 ewarn 'Tests cannot be run as root. Enable "userpriv" in FEATURES.'
458
459 ewarn 'Skipping.'
460 fi
461 }