# [portage] epatch_user , commande introuvable (résolu)

## alcorel

Bonjour,

J'ai besoin d'inclure un patch dans un ebuild. La doc parle de epatch-user mais je n'arrive pas à le faire fonctionner.

Le patch est placé dans /etc/portage/patches/.../.patch et l'ebuild à modifié dans /usr/local/portage/.../.ebuild 

```
/etc/portage/make.conf

PORTDIR_OVERLAY="/usr/local/portage"

LOCALPATCH_OVERLAY="/etc/portage/patches"
```

Pour appeler epatch_user dans mon ebuild, j'ai repris l'exemple de celui de firefox: 

```
snort # nano snort-2.9.4.6.ebuild 

src_prepare() {

        # Apply our patches

        EPATCH_SUFFIX="patch" \

        EPATCH_FORCE="yes" \

        epatch "${WORKDIR}/snort"

        epatch "${FILESDIR}/${PN}snortsam.patch

        # Allow user to apply any additional patches without modifing ebuild

        epatch_user

......
```

ensuite je crée le manifest et prepare l'ebuild:

```
# ebuild snort-2.9.4.6.ebuild clean

# ebuild snort-2.9.4.6.ebuild prepare

 * snort-2.9.4.6.tar.gz SHA256 SHA512 WHIRLPOOL size ;-) ...                     [ ok ]

 * checking ebuild checksums ;-) ...                                             [ ok ]

>>> Unpacking source...

>>> Unpacking snort-2.9.4.6.tar.gz to /var/tmp/portage/net-analyzer/snort-2.9.4.6/work

>>> Source unpacked in /var/tmp/portage/net-analyzer/snort-2.9.4.6/work

>>> Preparing source in /var/tmp/portage/net-analyzer/snort-2.9.4.6/work/snort-2.9.4.6 ...

/var/tmp/portage/net-analyzer/snort-2.9.4.6/temp/environment: ligne1958: epatch : commande introuvable

/var/tmp/portage/net-analyzer/snort-2.9.4.6/temp/environment: ligne1959: epatch : commande introuvable

/var/tmp/portage/net-analyzer/snort-2.9.4.6/temp/environment: ligne1960: epatch_user : commande introuvable

 * Applying multilib fix ...                                                     [ ok ]

 * Running eautoreconf in '/var/tmp/portage/net-analyzer/snort-2.9.4.6/work/snort-2.9.4.6' ...

 * Running libtoolize --install --copy --force --automake ...                    [ ok ]

 * Running aclocal -I m4 ...                                                     [ ok ]

 * Running autoconf -I m4 ...                                                    [ ok ]

 * Running autoheader -I m4 ...                                                  [ ok ]

 * Running automake --add-missing --copy --foreign ...                           [ ok ]

 * Running elibtoolize in: snort-2.9.4.6/

 *   Applying portage/1.2.0 patch ...

 *   Applying sed/1.5.6 patch ...

 *   Applying as-needed/2.4.2 patch ...

 *   Applying target-nm/2.4.2 patch ...

>>> Source prepared.
```

Savez vous si il y a quelques chose à modifier dans /usr/portage/eclasse/ eutils.eclass ?Last edited by alcorel on Thu Nov 28, 2013 9:22 am; edited 1 time in total

----------

## xaviermiller

Hello,

Apparemment, tu dois aussi inclure la "eclass" qu s'occupe de patcher.

Il te faudra creuser dans la doc, je ne connais pas par coeur tout cela  :Wink: 

----------

## alcorel

Salut!

En fait, niveau doc, c'est un peu le désert!  :Smile: 

je n'ai aucune idée de la façon de renseigner le eclass utilisé. tu as vu cette info ou?  :Smile: 

un moyen de forcer epatch_user au moment de la phase prepare de l'ebuild: (résultat identique pour ma part)

```
/etc/portage/bashrc

if [ "${EBUILD_PHASE}" == "prepare" ]; then

    echo ":: Calling epatch_user";

    pushd "${S}"

    epatch_user

    popd

fi
```

Le plus surprenant, c'est que, si je joue un peu avec l'ebuild de firefox, je n'ai aucun message d'erreur venant de epatch_user lors la phase prepare.

----------

## xaviermiller

Google...

http://wiki.gentoo.org/wiki//etc/portage/patches

----------

## xaviermiller

et la doc complète: http://devmanual.gentoo.org/ebuild-writing/functions/src_prepare/epatch/index.html

----------

## alcorel

ça fonctionne:

En créant  un script dans /etc/portage/env/epatch.sh contenant une bonne partie de eclass.eutils et un bashrc pointant vers epatch.sh

la solution ici: https://forums.gentoo.org/viewtopic-t-912200-start-0.html dernier post

```

snort # ebuild snort-2.9.4.6.ebuild prepare

 * snort-2.9.4.6.tar.gz SHA256 SHA512 WHIRLPOOL size ;-) ...                                                                                          [ ok ]

 * checking ebuild checksums ;-) ...                                                                                                                  [ ok ]

>>> Unpacking source...

>>> Unpacking snort-2.9.4.6.tar.gz to /var/tmp/portage/net-analyzer/snort-2.9.4.6/work

>>> Source unpacked in /var/tmp/portage/net-analyzer/snort-2.9.4.6/work

 * Applying user patches from /etc/portage/patches//net-analyzer/snort ...

 *  snort.patch ...

```

merci  :Smile: 

----------

## xaviermiller

Perso, j'aurais repris l'ebuild dans un overlay local, ajouté "inherit eutils", et "epatch" dans 'src_prepare()'

----------

## alcorel

en fait j'ai essayé mais j'ai eu un tas d'erreurs:

```
# ebuild snort-2.9.4.6.ebuild prepare

 * snort-2.9.4.6.tar.gz SHA256 SHA512 WHIRLPOOL size ;-) ...                                                              [ ok ]

 * checking ebuild checksums ;-) ...                                                                                      [ ok ]

>>> Unpacking source...

>>> Unpacking snort-2.9.4.6.tar.gz to /var/tmp/portage/net-analyzer/snort-2.9.4.6/work

>>> Source unpacked in /var/tmp/portage/net-analyzer/snort-2.9.4.6/work

>>> Preparing source in /var/tmp/portage/net-analyzer/snort-2.9.4.6/work/snort-2.9.4.6 ...

 * QA Notice: ECLASS 'eutils' inherited illegally in net-analyzer/snort-2.9.4.6 prepare

/usr/lib64/portage/bin/ebuild.sh: ligne 273 : unset: IUSE : « unset » impossible : variable est en lecture seule

/usr/lib64/portage/bin/ebuild.sh: ligne 273 : unset: REQUIRED_USE : « unset » impossible : variable est en lecture seule

/usr/lib64/portage/bin/ebuild.sh: ligne 273 : unset: DEPEND : « unset » impossible : variable est en lecture seule

/usr/lib64/portage/bin/ebuild.sh: ligne 273 : unset: RDEPEND : « unset » impossible : variable est en lecture seule

/usr/lib64/portage/bin/ebuild.sh: ligne 273 : unset: PDEPEND : « unset » impossible : variable est en lecture seule

/usr/lib64/portage/bin/ebuild.sh: ligne 273 : unset: HDEPEND : « unset » impossible : variable est en lecture seule

/usr/lib64/portage/bin/ebuild.sh: ligne 273 : unset: IUSE : « unset » impossible : variable est en lecture seule

/usr/lib64/portage/bin/ebuild.sh: ligne 273 : unset: REQUIRED_USE : « unset » impossible : variable est en lecture seule

/usr/lib64/portage/bin/ebuild.sh: ligne 273 : unset: DEPEND : « unset » impossible : variable est en lecture seule

/usr/lib64/portage/bin/ebuild.sh: ligne 273 : unset: RDEPEND : « unset » impossible : variable est en lecture seule

/usr/lib64/portage/bin/ebuild.sh: ligne 273 : unset: PDEPEND : « unset » impossible : variable est en lecture seule

/usr/lib64/portage/bin/ebuild.sh: ligne 273 : unset: HDEPEND : « unset » impossible : variable est en lecture seule

/usr/lib64/portage/bin/ebuild.sh: ligne291: IUSE : variable en lecture seule

 * The ebuild phase 'prepare' has exited unexpectedly. This type of

 * behavior is known to be triggered by things such as failed variable

 * assignments (bug #190128) or bad substitution errors (bug #200313).

 * Normally, before exiting, bash should have displayed an error message

 * above. If bash did not produce an error message above, it's possible

 * that the ebuild has called `exit` when it should have called `die`

 * instead. This behavior may also be triggered by a corrupt bash binary or

 * a hardware problem such as memory or cpu malfunction. If the problem is

 * not reproducible or it appears to occur randomly, then it is likely to

 * be triggered by a hardware problem. If you suspect a hardware problem

 * then you should try some basic hardware diagnostics such as memtest.

 * Please do not report this as a bug unless it is consistently

 * reproducible and you are sure that your bash binary and hardware are

 * functioning properly.
```

----------

## xaviermiller

montre-nous l'ebuild steplé  :Wink: 

----------

## alcorel

j'ai modifié ça dans la partie prepare

```
nano snort-2.9.4.6.ebuild 

 

src_prepare() {

inherit eutils

epatch

epatch_user

```

----------

## boozo

Pardonnez-moi, je crois que je n'ai sans doute pas bien compris le problème car de mémoire "epatch_user" est une feature qui permet à l'utilsateur de patcher simplement un prog sans rien devoir modifier dans l'ebuild   :Shocked: 

Me semble qu'il suffisait juste de créer un repertoire dans /etc/portage/patches/<arb>/<apps>-<version> et d'y coller le patch à appliquer avant de relancer un --oneshot sur le prog en question

Aurais-je loupé qqch ?

----------

## xaviermiller

@alcorel

il faut mettre inherit hors de src_prepare()

regarde la doc que j'ai donnée.

@boozo: tous les ebuilds ne sont pas "user-friendly", et il faut les adapter.

----------

## alcorel

c'est effectivement le cas si d'origine, ton ebuild est déjà préparé pour la fonction epatch_user

----------

## alcorel

 *XavierMiller wrote:*   

> @alcorel
> 
> il faut mettre inherit hors de src_prepare()
> 
> regarde la doc que j'ai donnée..

 

effectivement, ça va tout de suite mieux au début de l'ebuild : 

```
# Copyright 1999-2013 Gentoo Foundation

# Distributed under the terms of the GNU General Public License v2

# $Header: /var/cvsroot/gentoo-x86/net-analyzer/snort/snort-2.9.4.6.ebuild,v 1.$

EAPI="5"

inherit autotools multilib user

inherit eutils
```

```
 snort # ebuild snort-2.9.4.6.ebuild prepare

 * snort-2.9.4.6.tar.gz SHA256 SHA512 WHIRLPOOL size ;-) ...             [ ok ]

 * checking ebuild checksums ;-) ...                                     [ ok ]

>>> Unpacking source...

>>> Unpacking snort-2.9.4.6.tar.gz to /var/tmp/portage/net-analyzer/snort-2.9.4.6/work

>>> Source unpacked in /var/tmp/portage/net-analyzer/snort-2.9.4.6/work

>>> Preparing source in /var/tmp/portage/net-analyzer/snort-2.9.4.6/work/snort-2.9.4.6 ...

 * Cannot find $EPATCH_SOURCE!  Value for $EPATCH_SOURCE is:

 * 

 *   /var/tmp/portage/net-analyzer/snort-2.9.4.6/work/patch

 *   ( patch )

 * ERROR: net-analyzer/snort-2.9.4.6::x-portage failed (prepare phase):

 *   Cannot find $EPATCH_SOURCE!

 * 

 * Call stack:

 *     ebuild.sh, line   93:  Called src_prepare

 *   environment, line 3056:  Called epatch

 *   environment, line 1572:  Called die

 * The specific snippet of code:

 *                   die "Cannot find \$EPATCH_SOURCE!";

```

----------

## xaviermiller

donne-nous l'ebuild complet stp !

----------

## alcorel

```
# Copyright 1999-2013 Gentoo Foundation

# Distributed under the terms of the GNU General Public License v2

# $Header: /var/cvsroot/gentoo-x86/net-analyzer/snort/snort-2.9.4.6.ebuild,v 1.2 2013/08/18 03:06:45 patrick Exp $

EAPI="5"

inherit autotools multilib user 

inherit eutils

DESCRIPTION="The de facto standard for intrusion detection/prevention"

HOMEPAGE="http://www.snort.org/"

SRC_URI="http://snort.org/downloads/2320 -> ${P}.tar.gz"

LICENSE="GPL-2"

SLOT="0"

KEYWORDS="~amd64 ~arm ~mips ~ppc ~ppc64 ~sparc ~x86"

IUSE="static +dynamicplugin +zlib +gre +mpls +targetbased +decoder-preprocessor-rules

+ppm +perfprofiling linux-smp-stats inline-init-failopen +threads debug +active-response

+normalizer reload-error-restart +react +flexresp3 +paf large-pcap-64bit

aruba mysql odbc postgres selinux"

DEPEND=">=net-libs/libpcap-1.0.0

   >=net-libs/daq-0.6

   >=dev-libs/libpcre-6.0

   dev-libs/libdnet

   postgres? ( dev-db/postgresql-base )

   mysql? ( virtual/mysql )

   odbc? ( dev-db/unixODBC )

   zlib? ( sys-libs/zlib )"

RDEPEND="${DEPEND}

   selinux? ( sec-policy/selinux-snort )"

REQUIRED_USE="zlib? ( dynamicplugin )"

pkg_setup() {

   # pre_inst() is a better place to put this

   # but we need it here for the 'fowners' statements in src_install()

   enewgroup snort

   enewuser snort -1 -1 /dev/null snort

}

src_prepare() {

epatch

epatch_user

   #Multilib fix for the sf_engine

   ebegin "Applying multilib fix"

   sed -i -e 's|${exec_prefix}/lib|${exec_prefix}/'$(get_libdir)'|g' \

      "${WORKDIR}/${P}/src/dynamic-plugins/sf_engine/Makefile.am" \

      || die "sed for sf_engine failed"

   #Multilib fix for the curent set of dynamic-preprocessors

   for i in ftptelnet smtp ssh dns ssl dcerpc2 sdf imap pop rzb_saac sip reputation gtp modbus dnp3; do

      sed -i -e 's|${exec_prefix}/lib|${exec_prefix}/'$(get_libdir)'|g' \

         "${WORKDIR}/${P}/src/dynamic-preprocessors/$i/Makefile.am" \

         || die "sed for $i failed."

   done

   eend

   AT_M4DIR=m4 eautoreconf

}

src_configure() {

   econf \

      $(use_enable !static shared) \

      $(use_enable static) \

      $(use_enable static so-with-static-lib) \

      $(use_enable dynamicplugin) \

      $(use_enable zlib) \

      $(use_enable gre) \

      $(use_enable mpls) \

      $(use_enable targetbased) \

      $(use_enable decoder-preprocessor-rules) \

      $(use_enable ppm) \

      $(use_enable perfprofiling) \

      $(use_enable linux-smp-stats) \

      $(use_enable inline-init-failopen) \

      $(use_enable threads pthread) \

      $(use_enable debug) \

      $(use_enable debug debug-msgs) \

      $(use_enable debug corefiles) \

      $(use_enable !debug dlclose) \

      $(use_enable active-response) \

      $(use_enable normalizer) \

      $(use_enable reload-error-restart) \

      $(use_enable react) \

      $(use_enable flexresp3) \

      $(use_enable paf) \

      $(use_enable large-pcap-64bit large-pcap) \

      $(use_enable aruba) \

      $(use_with mysql) \

      $(use_with odbc) \

      $(use_with postgres postgresql) \

      --enable-ipv6 \

      --enable-reload \

      --disable-prelude \

      --disable-build-dynamic-examples \

      --disable-profile \

      --disable-ppm-test \

      --disable-intel-soft-cpm \

      --disable-static-daq \

      --disable-rzb-saac \

      --without-oracle

}

src_install() {

   emake DESTDIR="${D}" install

   dodir /var/log/snort \

      /var/run/snort \

      /etc/snort/rules \

      /etc/snort/so_rules \

      /usr/$(get_libdir)/snort_dynamicrules

   # config.log and build.log are needed by Sourcefire

   # to trouble shoot build problems and bug reports so we are

   # perserving them incase the user needs upstream support.

   dodoc RELEASE.NOTES ChangeLog \

      doc/* \

      tools/u2boat/README.u2boat

   insinto /etc/snort

   doins etc/attribute_table.dtd \

      etc/classification.config \

      etc/gen-msg.map \

      etc/reference.config \

      etc/threshold.conf \

      etc/unicode.map

   # We use snort.conf.distrib because the config file is complicated

   # and the one shipped with snort can change drastically between versions.

   # Users should migrate setting by hand and not with etc-update.

   newins etc/snort.conf snort.conf.distrib

   # config.log and build.log are needed by Sourcefire

   # to troubleshoot build problems and bug reports so we are

   # preserving them incase the user needs upstream support.

   if [ -f "${WORKDIR}/${PF}/config.log" ]; then

      dodoc "${WORKDIR}/${PF}/config.log"

   fi

   if [ -f "${T}/build.log" ]; then

      dodoc "${T}/build.log"

   fi

   insinto /etc/snort/preproc_rules

   doins preproc_rules/decoder.rules \

      preproc_rules/preprocessor.rules \

      preproc_rules/sensitive-data.rules

   fowners -R snort:snort \

      /var/log/snort \

      /var/run/snort \

      /etc/snort

   newinitd "${FILESDIR}/snort.rc12" snort

   newconfd "${FILESDIR}/snort.confd.2" snort

   # Sourcefire uses Makefiles to install docs causing Bug #297190.

   # This removes the unwanted doc directory and rogue Makefiles.

   rm -rf "${D}"usr/share/doc/snort || die "Failed to remove SF doc directories"

   rm "${D}"usr/share/doc/"${PF}"/Makefile* || die "Failed to remove doc make files"

   #Remove unneeded .la files (Bug #382863)

   rm "${D}"usr/$(get_libdir)/snort_dynamicengine/libsf_engine.la || die

   rm "${D}"usr/$(get_libdir)/snort_dynamicpreprocessor/libsf_*_preproc.la || die "Failed to remove libsf_?_preproc.la"

   # Set the correct lib path for dynamicengine, dynamicpreprocessor, and dynamicdetection

   sed -i -e 's|/usr/local/lib|/usr/'$(get_libdir)'|g' \

      "${D}etc/snort/snort.conf.distrib" || die

   # Set the correct rule location in the config

   sed -i -e 's|RULE_PATH ../rules|RULE_PATH /etc/snort/rules|g' \

      "${D}etc/snort/snort.conf.distrib" || die

   # Set the correct preprocessor/decoder rule location in the config

   sed -i -e 's|PREPROC_RULE_PATH ../preproc_rules|PREPROC_RULE_PATH /etc/snort/preproc_rules|g' \

      "${D}etc/snort/snort.conf.distrib" || die

   # Enable the preprocessor/decoder rules

   sed -i -e 's|^# include $PREPROC_RULE_PATH|include $PREPROC_RULE_PATH|g' \

      "${D}etc/snort/snort.conf.distrib" || die

   sed -i -e 's|^# dynamicdetection directory|dynamicdetection directory|g' \

      "${D}etc/snort/snort.conf.distrib" || die

   # Just some clean up of trailing /'s in the config

   sed -i -e 's|snort_dynamicpreprocessor/$|snort_dynamicpreprocessor|g' \

      "${D}etc/snort/snort.conf.distrib" || die

   # Make it clear in the config where these are...

   sed -i -e 's|^include classification.config|include /etc/snort/classification.config|g' \

      "${D}etc/snort/snort.conf.distrib" || die

   sed -i -e 's|^include reference.config|include /etc/snort/reference.config|g' \

      "${D}etc/snort/snort.conf.distrib" || die

   # Disable all rule files by default.

   sed -i -e 's|^include $RULE_PATH|# include $RULE_PATH|g' \

      "${D}etc/snort/snort.conf.distrib" || die

   # Disable normalizer preprocessor config if normalizer USE flag not set.

   if ! use normalizer; then

      sed -i -e 's|^preprocessor normalize|#preprocessor normalize|g' \

         "${D}etc/snort/snort.conf.distrib" || die

   fi

   # Set the configured DAQ to afpacket

   sed -i -e 's|^# config daq: <type>|config daq: afpacket|g' \

      "${D}etc/snort/snort.conf.distrib" || die

   # Set the location of the DAQ modules

   sed -i -e 's|^# config daq_dir: <dir>|config daq_dir: /usr/'$(get_libdir)'/daq|g' \

      "${D}etc/snort/snort.conf.distrib" || die

   # Set the DAQ mode to passive

   sed -i -e 's|^# config daq_mode: <mode>|config daq_mode: passive|g' \

      "${D}etc/snort/snort.conf.distrib" || die

   # Set snort to run as snort:snort

   sed -i -e 's|^# config set_gid:|config set_gid: snort|g' \

      "${D}etc/snort/snort.conf.distrib" || die

   sed -i -e 's|^# config set_uid:|config set_uid: snort|g' \

      "${D}etc/snort/snort.conf.distrib" || die

   # Set the default log dir

   sed -i -e 's|^# config logdir:|config logdir: /var/log/snort/|g' \

      "${D}etc/snort/snort.conf.distrib" || die

   # Set the correct so_rule location in the config

    sed -i -e 's|SO_RULE_PATH ../so_rules|SO_RULE_PATH /etc/snort/so_rules|g' \

       "${D}etc/snort/snort.conf.distrib" || die

}

pkg_postinst() {

   einfo "There have been a number of improvements and new features"

   einfo "added to ${P}. Please review the RELEASE.NOTES and"

   einfo "ChangLog located in /usr/share/doc/${PF}."

   einfo

   elog "The Sourcefire Vulnerability Research Team (VRT) recommends that"

   elog "users migrate their snort.conf customizations to the latest config"

   elog "file released by the VRT. You can find the latest version of the"

   elog "Snort config file in /etc/snort/snort.conf.distrib."

   elog

   elog "!! It is important that you migrate to this new snort.conf file !!"

   elog

   elog "This version of the ebuild includes an updated init.d file and"

   elog "conf.d file that rely on options found in the latest Snort"

   elog "config file provided by the VRT."

   if use debug; then

      elog "You have the 'debug' USE flag enabled. If this has been done to"

      elog "troubleshoot an issue by producing a core dump or a back trace,"

      elog "then you need to also ensure the FEATURES variable in make.conf"

      elog "contains the 'nostrip' option."

   fi

}
```

----------

## xaviermiller

non, l'ebuild modifiée qui pose problème...

----------

## alcorel

j'ai édité, désolé

----------

## xaviermiller

pourquoi mets-tu epatch tout seul ?

epatch demande un nom de fichier comme argument (un patch fourni par l'ebuild).

----------

## alcorel

désolé petite galère d'internet. 

en fait cela fonctionne parfaitement comme tu le disais plus haut 

epatch_user dans la partie prepare, inherit eutils en haut de l'ebuild.

----------

