Building NRPE for OpenWRT

In the last article we restored nrpe from backups to a running OpenWRT installation. After another power outage we have to do this again, but let's actually build nrpe this time and only restore its configuration from the backup.

The build process will happen in a VM running Debian/jessie(amd64), so missing utilities or header files will have to be installed via apt-get:

sudo apt-get install autoconf binutils build-essential docbook gawk gettext git libncurses5-dev libssl-dev libz-dev ncurses-term openssl sharutils subversion unzip
We'll check out the source and switch to the v15.05.1 branch, because we'll need to build for the release that's currently running on the router. Since OpenWrt switched to musl last year, we cannot build trunk as the running Chaos Calmer is still linked against uClibc.
git clone https://github.com/openwrt/openwrt.git openwrt-git
cd $_
git checkout -b local v15.05.1
Note: the branch does no longer exist!

Fetch an appropriate .config (again, we cannot use trunk just yet) and enter the configuration menu:
wget https://downloads.openwrt.org/chaos_calmer/15.05.1/ar71xx/generic/config.diff -O .config
make defconfig
make menuconfig
Here, we'll select our target profile and disable the SDK:
  • Target Profile => NETGEAR WNDR3700/WNDR3800/WNDRMAC
  • [_] Build the OpenWrt SDK (disabled)
Let's also disable all modular packages from the build and run the prerequisite check to verfiy that the configuration is still valid:
sed 's/=m$/=n/' -i.bak .config
make prereq
With that, we're ready to build and install the toolchain:
script -c "time make -j4 V=s tools/install && date && time make -j4 V=s toolchain/install" ~/build.log 
This will need some time (and diskspace) to complete. Once completed (check the build.log!), we can finally build our packages:
wget https://github.com/ckujau/openwrt/archive/master.zip -O ~/openwrt_master.zip
(cd /tmp && unzip ~/openwrt_master.zip) && (cd /tmp/openwrt-master/ && tar -cf - package) | tar -xvf -
make oldconfig
script -c "time make -j4 V=s package/nrpe/compile" -a ~/build.log
script -c "time make -j4 V=s package/monitoring-plugins/compile" -a ~/build.log
Note: this will build all dependencies as well:
$ grep -h DEP package/network/utils/{monitoring-plugins,nrpe}/Makefile 
  DEPENDS:=+libopenssl +libpthread
  DEPENDS:=+libopenssl +libwrap
When everything is built correctly, we should have two package files:
$ ls -hgotr bin/ar71xx/packages/base/
total 1.1M
-rw-r--r-- 1  35K Oct  2 13:10 libgcc_5.3.0-1_ar71xx.ipk
-rw-r--r-- 1 268K Oct  2 13:10 libc_1.1.15-1_ar71xx.ipk
-rw-r--r-- 1  857 Oct  2 13:10 libpthread_1.1.15-1_ar71xx.ipk
-rw-r--r-- 1  36K Oct  2 13:11 zlib_1.2.8-1_ar71xx.ipk
-rw-r--r-- 1 741K Oct  2 13:16 libopenssl_1.0.2j-1_ar71xx.ipk
-rw-r--r-- 1  24K Oct  2 13:17 nrpe_3.0.1-1_ar71xx.ipk
-rw-r--r-- 1 768K Oct  2 13:32 monitoring-plugins_2.2-1_ar71xx.ipk

$ file build_dir/target-mips*/*/src/nrpe
build_dir/target-mips_34kc_uClibc-0.9.33.2/nrpe-3.0.1/src/nrpe: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked, interpreter /lib/ld-uClibc.so.0, not stripped
The installation should automatically install any dependencies, if needed:
router$ opkg install ./*.ipk
Installing monitoring-plugins (2.1.2-1) to root...
Installing nrpe (3.0.1-1) to root...

router$ /etc/init.d/nrpe enable
router$ /etc/init.d/nrpe start

router$ netstat -lnp | grep 5666
tcp 0 0 192.168.0.2:5666 0.0.0.0:* LISTEN 6771/nrpe
This was the easy part. The difficult part will be to get both packages upstream :-)