How to leave the init service disabled after package installation?

Hi folks,

So I (finally) succeeded at making my package, and it even works. Now one issue I'm encountering is that the init script I'm installing gets automatically enabled, however it can not and should not work before the user configures the app. So log errors ensue. Is there a way to install the init script but leave it in a disabled state? I could, of course, simply not install it and then only install it after the user configures the app but I thought I'd ask if there is a more elegant method (plus I want the init script to get automatically removed by opkg when uninstalling).

I tried to disable it in postinst but that doesn't work - the script is enabled after installation anyway.

You can have an "enabled=0" option in the config, then have the init script check the value.

Several packages use this.

2 Likes

You mean in the makefile? Where do I insert it?

Here's the makefile:

include $(TOPDIR)/rules.mk

PKG_NAME:=geoip-shell
PKG_VERSION:=0.3.5
PKG_RELEASE:=1
PKG_LICENSE:=GPL-3.0-or-later

include $(INCLUDE_DIR)/package.mk

define Package/geoip-shell
	SECTION:=net
	CATEGORY:=Network
	TITLE:=geoip-shell
	DEPENDS:=+firewall4 +ca-bundle
	PKGARCH:=all
endef

define Package/geoip-shell/description
	Flexible geoip blocker with a user-friendly command line interface (currently no LuCi interface).
	For readme, please see
	https://github.com/friendly-bits/geoip-shell/README.md
	and
	https://github.com/friendly-bits/geoip-shell/OpenWrt/README.md
endef

define Package/geoip-shell/postinst
	#!/bin/sh
	/etc/init.d/geoip-shell-init disable
	rm "/usr/bin/geoip-shell" 2>/dev/null
	ln -s "/usr/bin/geoip-shell-manage.sh" "/usr/bin/geoip-shell"
	exit 0
endef

define Package/geoip-shell/prerm
	#!/bin/sh
	sh /usr/bin/geoip-shell-owrt-uninstall.sh
	exit 0
endef

define Package/geoip-shell/postrm
	#!/bin/sh
	sleep 1
	echo "Restarting the firewall..."
	fw4 -q restart
	exit 0
endef

define Build/Prepare
endef

define Build/Configure
endef

define Build/Compile
endef

define Package/geoip-shell/install

	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_BIN) ./files/etc/init.d/geoip-shell-init $(1)/etc/init.d

	$(INSTALL_DIR) $(1)/etc/geoip-shell
	$(INSTALL_CONF) ./files/etc/geoip-shell/geoip-shell.conf $(1)/etc/geoip-shell
	$(INSTALL_CONF) ./files/etc/geoip-shell/cca2.list $(1)/etc/geoip-shell
	$(INSTALL_CONF) ./files/etc/geoip-shell/geoip-shell-constants $(1)/etc/geoip-shell

	$(INSTALL_DIR) $(1)/usr/bin
	$(INSTALL_BIN) ./files/usr/bin/geoip-shell-fetch.sh $(1)/usr/bin
	$(INSTALL_BIN) ./files/usr/bin/geoip-shell-fw-include.sh $(1)/usr/bin
	$(INSTALL_BIN) ./files/usr/bin/geoip-shell-backup.sh $(1)/usr/bin
	$(INSTALL_BIN) ./files/usr/bin/geoip-shell-geoinit.sh $(1)/usr/bin
	$(INSTALL_BIN) ./files/usr/bin/geoip-shell-run.sh $(1)/usr/bin
	$(INSTALL_BIN) ./files/usr/bin/geoip-shell-owrt-uninstall.sh $(1)/usr/bin
	$(INSTALL_BIN) ./files/usr/bin/geoip-shell-mk-fw-include.sh $(1)/usr/bin
	$(INSTALL_BIN) ./files/usr/bin/geoip-shell-manage.sh $(1)/usr/bin
	$(INSTALL_BIN) ./files/usr/bin/geoip-shell-apply.sh $(1)/usr/bin
	$(INSTALL_BIN) ./files/usr/bin/geoip-shell-detect-lan.sh $(1)/usr/bin
	$(INSTALL_BIN) ./files/usr/bin/geoip-shell-cronsetup.sh $(1)/usr/bin

	$(INSTALL_DIR) $(1)/usr/lib
	$(INSTALL_CONF) ./files/usr/lib/geoip-shell-lib-status.sh $(1)/usr/lib
	$(INSTALL_CONF) ./files/usr/lib/geoip-shell-lib-backup-nft.sh $(1)/usr/lib
	$(INSTALL_CONF) ./files/usr/lib/geoip-shell-lib-ip-regex.sh $(1)/usr/lib
	$(INSTALL_CONF) ./files/usr/lib/geoip-shell-lib-apply-nft.sh $(1)/usr/lib
	$(INSTALL_CONF) ./files/usr/lib/geoip-shell-lib-status-nft.sh $(1)/usr/lib
	$(INSTALL_CONF) ./files/usr/lib/geoip-shell-lib-owrt-common.sh $(1)/usr/lib
	$(INSTALL_CONF) ./files/usr/lib/geoip-shell-lib-common.sh $(1)/usr/lib
	$(INSTALL_CONF) ./files/usr/lib/geoip-shell-lib-arrays.sh $(1)/usr/lib
	$(INSTALL_CONF) ./files/usr/lib/geoip-shell-lib-setup.sh $(1)/usr/lib
	$(INSTALL_CONF) ./files/usr/lib/geoip-shell-lib-uninstall.sh $(1)/usr/lib
	$(INSTALL_CONF) ./files/usr/lib/geoip-shell-lib-nft.sh $(1)/usr/lib

endef

$(eval $(call BuildPackage,geoip-shell))


Or do you mean add some logic to the init script which will check if it's supposed to be disabled? I'd like a more elegant solution if possible.

Yes

If it's good enough for mysql/mariadb on Openwrt, it should be good enough for you ,)

2 Likes

One can not argue with mariadb (sigh).

And a followup question: do you happen to know an up-to-date enough guide for submitting a pull request for my package to OpenWrt? I'm getting slightly tired of wasting a ton of time reading documentation which in the end turns out to be outdated/irrelevant.

Sorry, but no.

Have a look in https://github.com/openwrt/packages, and some of the commits, perhaps.

Might want to look at the ticket regarding package manager switch, too.

1 Like

As @frollic says, yes. Well that is one way.
The other common way is to have the package itself check if the config has enabled='1' and if it does not, terminate without doing anything ( exit 0 ). This will also work for non-openwrt/generic Linux too.

Again as @frollic says, look at openwrt packages in his link.
It is very instructive to read the process of review in merged PRs.

1 Like