logo

overlay

My (experimental) gentoo overlay

postgresql-9.6.11.ebuild (14727B)


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