Postinst running on the make/building machine

Hello,

I am new to OpenWrt packaging and, I can't figure out why a postinst section which is meant to run after the installation of the package on the OpenWrt device. But it is running on my Linux machine where I am running the make and building the package. For reference, have posted postinst section of the Makefile. And the make log.

And the Make has a post install section like this

define Package/$(PKG_NAME)/postinst
#!/bin/sh
# Set dnsmasq to noresolv 
uci set dhcp.@dnsmasq[0].noresolv=0
uci commit
# to trigger the hotplug turing up the interface 
ifup lan
endef

Here is the make log. make -j1 V=sc

cp -fpR /home/saswata/git/openwrt/build_dir/target-mipsel_24kc_musl/root-ramips /home/saswata/git/openwrt/build_dir/target-mipsel_24kc_musl/root.orig-ramips
/home/saswata/git/openwrt/build_dir/target-mipsel_24kc_musl/root-ramips/usr/lib/opkg/info/some-pkg.postinst-pkg: line 3: uci: command not found
/home/saswata/git/openwrt/build_dir/target-mipsel_24kc_musl/root-ramips/usr/lib/opkg/info/some-pkg.postinst-pkg: line 4: uci: command not found
/home/saswata/git/openwrt/build_dir/target-mipsel_24kc_musl/root-ramips/usr/lib/opkg/info/some-pkg.postinst-pkg: line 6: ifup: command not found
postinst script ./usr/lib/opkg/info/some-pkg.postinst has failed with exit code 127
make[2]: *** [package/Makefile:73: package/install] Error 1
make[2]: Leaving directory '/home/saswata/git/openwrt'
make[1]: *** [package/Makefile:123: /home/saswata/git/openwrt/staging_dir/target-mipsel_24kc_musl/stamp/.package_install] Error 2
make[1]: Leaving directory '/home/saswata/git/openwrt'

And if there is a better way to do it other than making a UCI defaults file. Please let me know.

Thank you for your help...

isn't https://openwrt.org/docs/guide-developer/uci-defaults what you really want ?

1 Like

Hello, Thanks for replying.

As I said earlier, I have used UCI defaults and it is working fine. But It seems like some kind of hack to do it.
Few questions:-

  1. Does all packages does it this way?
  2. Is it the intended behavior of postint?

Yes it is intended, and documented.
https://openwrt.org/docs/techref/initscripts#enable_and_disable

! WARNING !
OpenWrt initscripts will be run while building OpenWrt images (when installing packages in what will become a ROM image) in the host system (right now, for actions “enable ” and “disable ”). They must not fail, or have undesired side-effects in that situation. When being run by the build system, environment variable ${IPKG_INSTROOT} will be set to the working directory being used. On the “target system”, that environment variable will be empty/unset. Refer to “/lib/functions.sh” and also to “/etc/rc.common” in package “base-files” for the nasty details.

In your postinst just wrap everything in

if [ -z “$${IPKG_INSTROOT}” ]
2 Likes

I think what you want is a package file, rather than the Makefile action, that contains the postinst code. One example I found is in the nfnetlink-log kmod, maybe look at its packaging and see how it's done there?

$ cat /usr/lib/opkg/info/kmod-nfnetlink-log.postinst
#!/bin/sh
[ "${IPKG_NO_SCRIPT}" = "1" ] && exit 0
[ -s ${IPKG_INSTROOT}/lib/functions.sh ] || exit 0
. ${IPKG_INSTROOT}/lib/functions.sh
default_postinst $0 $@
1 Like

This is exactly, what I wanted.

And thanks everybody for the help.