This comes from the following gentoo-dev thread:
http://www.gossamer-threads.com/lists/gentoo/dev/264888

Its usage will lead to the installation of a CONFIGURATION file
under /usr/share/doc/${PF} and show of elog messages with its content
first time package is installed, relying in doc file for future
installations or people simply going there to review configuration tips.

I also attach acpid ebuild as example.

Currently I have doubts about how to handle formatting, it is now using
"fmt" as kernel-2.eclass to format it and, then, you can set:
CONFIGURATION_INSTRUCTIONS="
        You may wish to read the Gentoo Linux Power Management Guide,
        which can be found online at:
        http://www.gentoo.org/doc/en/power-management-guide.xml";

and it will be properly formatted at the end. The problem is that I find
no way to force a jump to a new line (for example if somebody want to
show a command to run in a new line).

Other option would be to simply add quotes to:
echo ${CONFIGURATION_INSTRUCTIONS}

and drop "fmt" usage.

It will respect formatting specified in ebuild, but this needs to be
taken into account as, for example, acpid ebuild used as example should
be changed to use:
CONFIGURATION_INSTRUCTIONS="You may wish to read the Gentoo Linux Power
Management Guide,
        which can be found online at:
        http://www.gentoo.org/doc/en/power-management-guide.xml";

or people will get an empty line at the top of the messages.

Maybe an option to toggle fmt/formatting usage could be used, but I am
unsure about how to handle it at eclass level in a "short" way (I could
add some "ifs" running either variant (with quotes or without them and
fmt usage), but not sure if a shorter way could be used)


# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

# @ECLASS: configuration-doc
# @MAINTAINER:
# Pacho Ramos <pa...@gentoo.org>
# @AUTHOR:
# Author: Pacho Ramos <pa...@gentoo.org>
# @BLURB: An eclass for installing a CONFIGURATION doc file recording tips
# shown via elog messages. With this eclass, those elog messages will only be
# shown at first package installation and a file for later reviewing will be
# installed under /usr/share/doc/${PF}
# @DESCRIPTION:
# An eclass for installing a CONFIGURATION doc file recording tips           
# shown via elog messages. With this eclass, those elog messages will only be
# shown at first package installation and a file for later reviewing will be
# installed under /usr/share/doc/${PF}

if [[ ${___ECLASS_ONCE_CONFIGURATION_DOC} != "recur -_+^+_- spank" ]] ; then
___ECLASS_ONCE_CONFIGURATION_DOC="recur -_+^+_- spank"

inherit eutils

case "${EAPI:-0}" in
        0|1|2|3)
                die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
                ;;
        4|5)
                # EAPI>=4 is required for REPLACING_VERSIONS preventing us
                # from needing to export another pkg_preinst phase to save 
has_version
                # result. Also relies on EAPI >=4 default src_install phase.
                ;;
        *)
                die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
                ;;
esac

EXPORT_FUNCTIONS src_install pkg_postinst

# @FUNCTION: configuration_create_doc
# @DESCRIPTION:
# Create doc file with CONFIGURATION_INSTRUCTIONS contents.
# Usually called at src_install phase.
configuration_create_doc() {
        debug-print-function ${FUNCNAME} "${@}"

        if [[ -n "${CONFIGURATION_INSTRUCTIONS}" ]]; then
                eshopts_push
                set -f
                echo ${CONFIGURATION_INSTRUCTIONS} | fmt > CONFIGURATION
                eshopts_pop
                dodoc CONFIGURATION
        fi
}

# @FUNCTION: configuration_print_elog
# @DESCRIPTION:
# Print elog messages with CONFIGURATION_INSTRUCTIONS contents.
# Usually called at pkg_postinst phase.
configuration_print_elog() {
        debug-print-function ${FUNCNAME} "${@}"

        if [[ -n "${CONFIGURATION_INSTRUCTIONS}" ]]; then
                if ! [[ "${REPLACING_VERSIONS}" ]]; then
                        eshopts_push
                        set -f
                        echo ${CONFIGURATION_INSTRUCTIONS} | fmt | while read 
-r ELINE; do elog "${ELINE}"; done
                        eshopts_pop
                fi
        fi
}


# @FUNCTION: configuration-doc_src_install
# @DESCRIPTION:
# Show elog messages from CONFIGURATION_INSTRUCTIONS variable, that will be
# shared with /usr/share/doc/${PF}/CONFIGURATION content.
configuration-doc_src_install() {
        debug-print-function ${FUNCNAME} "${@}"

        default
        configuration_create_doc
}

# @FUNCTION: configuration-doc_pkg_postinst
# @DESCRIPTION:
# Show elog messages from CONFIGURATION_INSTRUCTIONS variable, that will be
# shared with /usr/share/doc/${PF}/CONFIGURATION content.
configuration-doc_pkg_postinst() {
        debug-print-function ${FUNCNAME} "${@}"
        configuration_print_elog
}

fi
# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-power/acpid/acpid-2.0.17.ebuild,v 1.6 
2012/11/25 18:59:25 armin76 Exp $

EAPI=4
inherit configuration-doc systemd

DESCRIPTION="Daemon for Advanced Configuration and Power Interface"
HOMEPAGE="http://tedfelix.com/linux/acpid-netlink.html";
SRC_URI="http://tedfelix.com/linux/${P}.tar.xz";

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="amd64 ia64 -ppc x86"
IUSE="selinux"

RDEPEND="selinux? ( sec-policy/selinux-apm )"
DEPEND="${RDEPEND}"

CONFIGURATION_INSTRUCTIONS="
        You may wish to read the Gentoo Linux Power Management Guide,
        which can be found online at:
        http://www.gentoo.org/doc/en/power-management-guide.xml";

src_configure() {
        econf --docdir=/usr/share/doc/${PF}
}

src_install() {
        emake DESTDIR="${D}" install

        newdoc kacpimon/README README.kacpimon
        dodoc -r samples
        rm -f "${D}"/usr/share/doc/${PF}/COPYING

        exeinto /etc/acpi
        newexe "${FILESDIR}"/${PN}-1.0.6-default.sh default.sh
        insinto /etc/acpi/events
        newins "${FILESDIR}"/${PN}-1.0.4-default default

        newinitd "${FILESDIR}"/${PN}-2.0.16-init.d ${PN}
        newconfd "${FILESDIR}"/${PN}-2.0.16-conf.d ${PN}

        systemd_dounit "${FILESDIR}"/systemd/${PN}.{service,socket}

        configuration_create_doc
}

pkg_postinst() {
        configuration_print_elog

        # files/systemd/acpid.socket -> ListenStream=/run/acpid.socket
        mkdir -p "${ROOT}"/run

        if ! grep -qs "^tmpfs.*/run " "${ROOT}"/proc/mounts ; then
                echo
                ewarn "You should reboot the system now to get /run mounted 
with tmpfs!"
        fi
}

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to