OpenWRT/Build
Preparation
Install prerequisites:[1]
sudo apt install subversion g++ zlib1g-dev build-essential git python python3 python3-distutils libncurses5-dev gawk gettext \ # Debian unzip file libssl-dev wget libelf-dev ecj fastjar java-propose-classpath sudo dnf install @c-development @development-tools @development-libs zlib-static elfutils-libelf-devel gawk unzip file wget python3 # Fedora
Checkout their source, maybe switch to a stable release:
umask 0022 git clone https://git.openwrt.org/openwrt/openwrt.git openwrt-git cd openwrt-git git checkout -b local v19.07.3
Update feeds and generate a minimal configuration:
./scripts/feeds update -a ./scripts/feeds install -a make menuconfig
- Select the correct
Target System
, e.g.Atheros ATH79 (DTS)
- Select the correct
Subtarget
, e.g.Generic
- Select the correct
Target Profile
, i.e. your router where OpenWRT is installed. - If needed, a newer compiler can be selected as well:
Advanced configuration options
=>Toolchain Options
=>GCC compiler Version
.
Before we can build packages, we need to build our toolchain:[2]
make -j$(nproc) tools/install make -j$(nproc) toolchain/install
If something goes wrong, we can add V=s
to our make options [3] to gather more details.
Packages
NRPE
As an example, let's build NRPE for OpenWRT. We need a Makefile
and maybe some patches and auxillary files[4] too:
$ find package/network/utils/nrpe/ package/network/utils/nrpe/ package/network/utils/nrpe/files package/network/utils/nrpe/files/openwrt-init package/network/utils/nrpe/files/openwrt-procd package/network/utils/nrpe/patches package/network/utils/nrpe/patches/100-nrpe.patch package/network/utils/nrpe/Makefile $ cat package/network/utils/nrpe/Makefile include $(TOPDIR)/rules.mk PKG_NAME:=nrpe PKG_VERSION:=4.0.0 PKG_RELEASE:=1 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=@GITHUB/NagiosEnterprises/nrpe.git PKG_LICENSE:=GPL-2.0 PKG_HASH:=a3d0a7ac5385421dfcc29afce7eeade13ca10d8d9115ca5c2962b72946c88a1e PKG_INSTALL:=1 PKG_BUILD_PARALLEL:=1 include $(INCLUDE_DIR)/package.mk define Package/nrpe SECTION:=net CATEGORY:=Network TITLE:=Nagios Remote Plugin Executor Server URL:=https://github.com/NagiosEnterprises/nrpe DEPENDS:=+libopenssl +libwrap USERID:=nagios:nagios MAINTAINER:=John Doe <jdoe@example.org> endef define Package/nrpe/description This program runs as a background process on the remote host and processes command execution requests from the check_nrpe plugin on the Nagios host. endef CONFIGURE_ARGS += \ --disable-ssl define Build/Compile $(MAKE) -C $(PKG_BUILD_DIR) nrpe endef define Package/nrpe/install $(INSTALL_DIR) $(1)/usr/sbin $(INSTALL_DIR) $(1)/etc $(INSTALL_DIR) $(1)/etc/init.d $(INSTALL_BIN) ./files/openwrt-init $(1)/etc/init.d/$(PKG_NAME) $(CP) $(PKG_BUILD_DIR)/src/nrpe $(1)/usr/sbin $(CP) $(PKG_BUILD_DIR)/sample-config/nrpe.cfg $(1)/etc/nrpe.cfg $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/nrpe $(1)/usr/sbin endef define Package/nrpe/conffiles /etc/nrpe.cfg endef $(eval $(call BuildPackage,nrpe))
Generate a new .config
and select either m
or y
:
$ make oldconfig nrpe................................ Nagios Remote Plugin Executor Server (PACKAGE_nrpe) [M/n/y/?] m
Build with:
make -j$(nproc) package/nrpe/compile make -j$(nproc) package/nrpe/install make -j$(nproc) package/index
If all goes well, the (stripped[5]) binary and package will be available in our build_dir
:
$ tar -tvzf bin/packages/mips_24kc/base/nrpe*mips_24kc.ipk && ls -go build_dir/target-mips_24kc_musl/nrpe*/ipkg-mips_24kc/nrpe/usr/sbin/nrpe -rw-r--r-- root/root 4 2020-01-29 08:05 ./debian-binary -rw-r--r-- root/root 21956 2020-01-29 08:05 ./data.tar.gz -rw-r--r-- root/root 588 2020-01-29 08:05 ./control.tar.gz -rwxr-xr-x. 1 39445 Mar 7 12:48 build_dir/target-mips_24kc_musl/nrpe-4.0.0/ipkg-mips_24kc/nrpe/usr/sbin/nrpe
monitoring-plugins
NRPE alone won't do much, let's install monitoring-plugins as well.
$ find package/network/utils/monitoring-plugins/ package/network/utils/monitoring-plugins/ package/network/utils/monitoring-plugins/Makefile $ cat package/network/utils/monitoring-plugins/Makefile include $(TOPDIR)/rules.mk PKG_NAME:=monitoring-plugins PKG_VERSION:=2.2 PKG_RELEASE:=1 PKG_SOURCE_PROTO:=git PKG_SOURCE_URL:=https://github.com/monitoring-plugins/monitoring-plugins.git PKG_SOURCE_VERSION:=db93deea319e54aea52618108adfebdfab1f1a26 PKG_MIRROR_HASH:=d3b100ed6077dabd30ec6846ef7cd80c0d911a7e738d99742b6af2ea2c8d005b PKG_LICENSE:=GPL-3.0 include $(INCLUDE_DIR)/package.mk define Package/monitoring-plugins SECTION:=net CATEGORY:=Network TITLE:=Monitoring Plugins URL:=https://www.monitoring-plugins.org DEPENDS:= # DEPENDS:=+libopenssl +libpthread MAINTAINER:=Jane Doe <janedoe@example.org> endef define Package/nrpe/description Plugins for Nagios compatible monitoring systems like Naemon or Icinga. endef define Build/Prepare $(Build/Prepare/Default) (cd $(PKG_BUILD_DIR) && ./tools/setup) endef CONFIGURE_ARGS += \ --disable-extra-opts \ --disable-largefile \ --disable-maintainer-mode \ --disable-nls \ --disable-threads \ --without-cgiurl \ --without-dbi \ --without-ldap \ --without-mysql \ --without-openssl \ --without-pgsql \ --without-radius \ --with-ping-command="/bin/ping -w %d -c %d %s" \ --with-ping6-command="/bin/ping6 -w %d -c %d %s" \ --with-ps-command="/bin/ps w" \ --with-ps-cols="6" \ --with-ps-format="%d %s %d %s %s %n" \ --with-ps-varlist="&procpid$(comma)&procuid$(comma)&procvsz$(comma)procstat$(comma)procprog$(comma)&pos" \ --with-uptime-command="/usr/bin/uptime" \ --with-ssh-command="/usr/bin/ssh" \ --with-nslookup-command="/usr/bin/nslookup" define Package/monitoring-plugins/install $(INSTALL_DIR) $(1)/usr/libexec/nagios $(INSTALL_BIN) $(PKG_BUILD_DIR)/plugins/check_* $(1)/usr/libexec/nagios/ $(INSTALL_BIN) $(PKG_BUILD_DIR)/plugins/negate $(1)/usr/libexec/nagios/ $(INSTALL_BIN) $(PKG_BUILD_DIR)/plugins/urlize $(1)/usr/libexec/nagios/ $(INSTALL_BIN) $(PKG_BUILD_DIR)/plugins-scripts/utils.sh $(1)/usr/libexec/nagios/ $(RM) $(1)/usr/libexec/nagios/*.c $(1)/usr/libexec/nagios/*.h $(1)/usr/libexec/nagios/*.o endef $(eval $(call BuildPackage,monitoring-plugins))
Generate a new .config
and select either m
or y
for monitoring-plugins
.
$ make oldconfig
Build with:
make -j$(nproc) package/monitoring-plugins/compile make -j$(nproc) package/monitoring-plugins/install make -j$(nproc) package/index
If all goes well, the (stripped[5]) binary and package will be available in our build_dir
:
$ tar -tvzf bin/packages/mips_24kc/base/monitoring-plugins*mips_24kc.ipk && ls -go build_dir/target-mips_24kc_musl/monitoring-plugins*/ipkg-mips_24kc/monitoring-plugins/usr/libexec/nagios/ | tail -5 -rw-r--r-- root/root 4 2020-01-29 08:05 ./debian-binary -rw-r--r-- root/root 639426 2020-01-29 08:05 ./data.tar.gz -rw-r--r-- root/root 507 2020-01-29 08:05 ./control.tar.gz -rwxr-xr-x. 1 33285 Mar 7 23:57 check_udp -rwxr-xr-x. 1 33029 Mar 7 23:57 check_ups -rwxr-xr-x. 1 24725 Mar 7 23:57 check_users -rwxr-xr-x. 1 28917 Mar 7 23:57 negate -rwxr-xr-x. 1 28805 Mar 7 23:57 urlize