# # This is an example /etc/portage/bashrc which can be used for # "hook" functions. # # Created by Wolfram Schlich , # licensed under the GNU GPLv2. # # Available "hook" functions: # # pre_src_unpack() # post_src_unpack() # # pre_src_compile() # post_src_compile() # # pre_src_test() # post_src_test() # # pre_src_install() # post_src_install() # # pre_pkg_setup() # post_pkg_setup() # # pre_pkg_preinst() # post_pkg_preinst() # # pre_pkg_postinst() # post_pkg_postinst() # # pre_pkg_prerm() # post_pkg_prerm() # # pre_pkg_postrm() # post_pkg_postrm() # # pre_pkg_config() # post_pkg_config() # ## ## this can be used to stop daemons before their files are actually overwritten, ## which can cause their stopping/restarting to actually fail ## post_pkg_preinst() { return # remove this line to enable this function einfo "--8<-- ${FUNCNAME}() started --8<--" case ${CATEGORY}/${PN} in ## ## Example for OpenSSH ## net-misc/openssh) if /etc/init.d/sshd --quiet status; then einfo "Stopping sshd" /etc/init.d/sshd stop fi ;; ## ## Example for Apache version 2 ## net-www/apache) case ${PV} in 2*) if /etc/init.d/apache2 --quiet status; then einfo "Stopping apache2" /etc/init.d/apache2 stop fi ;; *) ;; esac ;; ## ## Example for fcron ## sys-process/fcron) if /etc/init.d/fcron --quiet status; then einfo "Stopping fcron" /etc/init.d/fcron stop fi ;; ## ## Example for Squid ## net-proxy/squid) if /etc/init.d/squid --quiet status; then einfo "Starting squid" /etc/init.d/squid stop fi ;; ## ## Example for postfix ## sys-process/postfix) if /etc/init.d/postfix --quiet status; then einfo "Stopping postfix" /etc/init.d/postfix stop fi ;; ## ## Example for antivir-mailgate ## sys-process/antivir-mailgate) if /etc/init.d/antivir-mailgate --quiet status; then einfo "Starting antivir-mailgate" /etc/init.d/antivir-mailgate start fi ;; ## ## Default ## *) ## Nothing to be done ;; esac einfo "--8<-- ${FUNCNAME}() finished --8<--" return 0 } ## ## this is ideal to do things to the live system, e.g. automatically/forcibly ## update configuration, (re)start daemons or similar ## post_pkg_postinst() { return # remove this line to enable this function einfo "--8<-- ${FUNCNAME}() started --8<--" case ${CATEGORY}/${PN} in ## ## Remerge libtool after gcc has been merged ## See http://www.gentoo.org/doc/en/gcc-upgrading.xml#doc_chap2 ## sys-devel/gcc) einfo "Remerging libtool after gcc has been merged" set -x set -- $(gcc-config -S $(gcc-config -c 2>/dev/null) 2>/dev/null) gcc_ver_old=${2} gcc_ver_new=${PV} if [[ -z "${gcc_ver_old}" ]]; then eerror "Failed to determine version of currently selected gcc profile" return 1 fi gcc-config ${CHOST}-${PV} env-update && . /etc/profile fix_libtool_files.sh ${gcc_ver_old} if ! emerge --oneshot libtool; then eerror "Remerging libtool failed" return 1 fi set +x ;; ## ## Disable PaX flags on JAVA (JDK/JRE) binaries ## See http://www.gentoo.org/proj/en/hardened/hardenedfaq.xml#paxjava ## Use paxctl instead of chpax (which is obsolete). ## dev-java/*-jre|dev-java/*-jre-bin|dev-java/*-jdk|dev-java/*-jdk-bin) einfo "Disabling PaX flags on java binaries" local java_bindir="/opt/${P}/bin" if [[ ! -d "${java_bindir}" ]]; then eerror "JAVA bindir '${java_bindir}' does not exist" elif [[ ! -x "$(type -p scanelf)" ]]; then eerror "Cannot execute scanelf, please install app-misc/pax-utils" elif [[ ! -x "$(type -p paxctl)" ]]; then eerror "Cannot execute paxctl, please install sys-apps/paxctl" else scanelf -BRy -F %F "${java_bindir}" | while read bin; do paxctl -C -pemrxs "${bin}" \ || eerror "Failed to set PaX flags on '${bin}'" done fi ;; ## ## Disable PaX flags on the Unison binary ## See http://www.gentoo.org/proj/en/hardened/hardenedfaq.xml#paxnoelf ## Use paxctl instead of chpax (which is obsolete). ## net-misc/unison) einfo "Disabling PaX flags on the Unison binary" local bin='/usr/bin/unison' if [[ ! -e "${bin}" ]]; then eerror "Unison binary '${bin}' does not exist" elif [[ ! -x "$(type -p paxctl)" ]]; then eerror "Cannot execute paxctl, please install sys-apps/paxctl" else paxctl -C -m "${bin}" \ || eerror "Failed to set PaX flags on '${bin}'" fi ;; ## ## Example for nVidia Drivers ## x11-drivers/nvidia-drivers) einfo "Activating nVidia OpenGL interface" eselect opengl set nvidia ;; ## ## Example for OpenSSH ## net-misc/openssh) if [ ! -e /etc/runlevels/default/sshd ]; then einfo "Making sshd start at boot (runlevel: default)" rc-update add sshd default fi if ! /etc/init.d/sshd --quiet status; then einfo "Starting sshd" /etc/init.d/sshd start else einfo "Restarting sshd" /etc/init.d/sshd restart fi ;; ## ## Example for Apache version 2 ## net-www/apache) case ${PV} in 2*) if [ ! -e /etc/runlevels/default/apache2 ]; then einfo "Making apache2 start at boot (runlevel: default)" rc-update add apache2 default fi if ! /etc/init.d/apache2 --quiet status; then einfo "Starting apache2" /etc/init.d/apache2 start else einfo "Restarting apache2" /etc/init.d/apache2 restart fi ;; *) ;; esac ;; ## ## Example for fcron ## sys-process/fcron) if [ ! -e /etc/runlevels/default/fcron ]; then einfo "Making fcron start at boot (runlevel: default)" rc-update add fcron default fi if ! /etc/init.d/fcron --quiet status; then einfo "Starting fcron" /etc/init.d/fcron start else einfo "Restarting fcron" /etc/init.d/fcron restart fi einfo "Generating system crontab" check_system_crontabs -v -i -f ;; ## ## Example for Squid ## net-proxy/squid) if [ ! -e /etc/runlevels/default/squid ]; then einfo "Making squid start at boot (runlevel: default)" rc-update add squid default fi if ! /etc/init.d/squid --quiet status; then einfo "Starting squid" /etc/init.d/squid start else einfo "Restarting squid" /etc/init.d/squid restart fi ;; ## ## Example for postfix ## sys-process/postfix) if [ ! -e /etc/runlevels/default/postfix ]; then einfo "Making postfix start at boot (runlevel: default)" rc-update add postfix default fi if ! /etc/init.d/postfix --quiet status; then einfo "Starting postfix" /etc/init.d/postfix start else einfo "Restarting postfix" /etc/init.d/postfix restart fi ;; ## ## Example for antivir-mailgate ## sys-process/antivir-mailgate) if [ ! -e /etc/runlevels/default/antivir-mailgate ]; then einfo "Making antivir-mailgate start at boot (runlevel: default)" rc-update add antivir-mailgate default fi if ! /etc/init.d/antivir-mailgate --quiet status; then einfo "Starting antivir-mailgate" /etc/init.d/antivir-mailgate start else einfo "Restarting antivir-mailgate" /etc/init.d/antivir-mailgate restart fi einfo "Updating AntiVir" antivir --update ;; ## ## Default ## *) ## Nothing to be done ;; esac einfo "--8<-- ${FUNCNAME}() finished --8<--" return 0 } ## ## this is ideal to apply custom patches or similar ## post_src_unpack() { return # remove this line to enable this function einfo "--8<-- ${FUNCNAME}() started --8<--" ## ## Apply local patches ## ## Example search order for app-foo/bar-1.0_rc1-r2: ## /local/portage/patches/app-foo/bar/bar-1.0_rc1-r2.patch ## /local/portage/patches/app-foo/bar/bar-1.0_rc1.patch ## /local/portage/patches/app-foo/bar/bar.patch ## local patchdir="/local/portage/patches" for i in "${PF}" "${P}" "${PN}"; do patchfile="${patchdir}/${CATEGORY}/${PN}/${i}.patch" if [ -e "${patchfile}" ]; then ## Apply patchfile pushd "${S}" >/dev/null epatch "${patchfile}" popd >/dev/null ## Stop on first patch that was found break fi done ## ## Other actions, by category/packagename ## case ${CATEGORY}/${PN} in app-portage/layman) einfo "Replacing storage directory in /etc/layman.cfg" sed -i -e 's#^storage[[:space:]]*:.*$#storage: /local/portage/layman#' "${S}/etc/layman.cfg" ;; esac einfo "--8<-- ${FUNCNAME}() finished --8<--" return 0 }