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