What if the hostname entry already exists? $sysconfdir instead of hard-coding etc.
I can't help but think a better solution would be to simply move /etc/hosts to base-files, so it can be updated at the same time as hostname. Ross On Mon, 26 Nov 2018 at 06:51, Chen Qi <qi.c...@windriver.com> wrote: > > We default hostname to ${MACHINE}, but it's not in /etc/hosts, > resulting in commands like `hostname -f' failing due to lack > of entry. > > So add entry to /etc/hosts according to /etc/hostname. We do > this via pkg_postinst because hostname is set in base-files > recipe. > > Signed-off-by: Chen Qi <qi.c...@windriver.com> > --- > meta/recipes-core/netbase/netbase_5.4.bb | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/meta/recipes-core/netbase/netbase_5.4.bb > b/meta/recipes-core/netbase/netbase_5.4.bb > index 5ab0c58..384c430 100644 > --- a/meta/recipes-core/netbase/netbase_5.4.bb > +++ b/meta/recipes-core/netbase/netbase_5.4.bb > @@ -23,3 +23,12 @@ do_install () { > } > > CONFFILES_${PN} = "${sysconfdir}/hosts" > + > +RDEPENDS_${PN} += "base-files" > + > +pkg_postinst_${PN} () { > + if [ -s $D/etc/hostname ]; then > + hostname=`cat $D/etc/hostname` > + echo "127.0.1.1 $hostname" >> $D/etc/hosts > + fi > +} > -- > 1.9.1 > > -- > _______________________________________________ > Openembedded-core mailing list > Openembedded-core@lists.openembedded.org > http://lists.openembedded.org/mailman/listinfo/openembedded-core -- _______________________________________________ Openembedded-core mailing list Openembedded-core@lists.openembedded.org http://lists.openembedded.org/mailman/listinfo/openembedded-core