diff mbox

[OpenWrt-Devel,2/5] package/utils/bzip2: Allow install/uninstall alongside busybox

Message ID 1453398885-102144-3-git-send-email-openwrt@daniel.thecshore.com
State Changes Requested
Headers show

Commit Message

Daniel Dickinson Jan. 21, 2016, 5:54 p.m. UTC
From: Daniel Dickinson <openwrt@daniel.thecshore.com>

Instead of installing to  /usr/bin, which conflicts with busybox
if bzip2 applet present, install to /bin and symlink from
/usr/bin (replacing symlink to busybox on install), and,
if busybox applet present, restore busybox symlink on
uninstall.

Also manage busybox vs. full version symlinks for
bunzip2 and bzcat (which exist by default and should
be pointed to bzip2 binary when bzip2 installed and
returned to busybox (if applets present) on uninstall.

This method avoid the need for opkg --force-overwrite
when installing the package, and also allows for
installing the package without breaking the system
(e.g. if bzunzip2 and bzcat links where not properly
managed, now that they're part of the install).

The biggest change for standard systems is that
means using the full versions of bunzip2 and
bzcat when they are present, while reverting
to busybox when uninstalled.

Signed-off-by: Daniel Dickinson <openwrt@daniel.thecshore.com>
---
 package/utils/bzip2/Makefile | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/package/utils/bzip2/Makefile b/package/utils/bzip2/Makefile
index 425173c..fb52c4a 100644
--- a/package/utils/bzip2/Makefile
+++ b/package/utils/bzip2/Makefile
@@ -9,7 +9,7 @@  include $(TOPDIR)/rules.mk
 
 PKG_NAME:=bzip2
 PKG_VERSION:=1.0.6
-PKG_RELEASE:=2
+PKG_RELEASE:=3
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=http://www.bzip.org/$(PKG_VERSION)
@@ -53,6 +53,22 @@  define Package/bzip2/description
 	data compressor. This package provides the binary.
 endef
 
+define Package/bzip2/postinst
+#!/bin/sh
+ln -sf /bin/bzip2 $${IPKG_INSTROOT}/usr/bin/bzip2
+ln -sf /bin/bzip2 $${IPKG_INSTROOT}/usr/bin/bunzip2
+ln -sf /bin/bzip2 $${IPKG_INSTROOT}/usr/bin/bzcat
+endef
+
+define Package/bzip2/postrm
+#!/bin/sh
+  #!/bin/sh
+  /bin/busybox bzip2 -h 2>&1 | grep -q BusyBox && ln -sf ../../bin/busybox /usr/bin/bzip2 || rm -f /usr/bin/bzip2
+  /bin/busybox bunzip2 -h 2>&1 | grep -q BusyBox && ln -sf ../../bin/busybox /usr/bin/bunzip2 || rm -f /usr/bin/bunzip2
+  /bin/busybox bzcat -h 2>&1 | grep -q BusyBox && ln -sf ../../bin/busybox /usr/bin/bzcat || rm -f /usr/bin/bzcat
+exit 0
+endef
+
 TARGET_CFLAGS += \
 	$(FPIC) \
 	$(TARGET_LDFLAGS)
@@ -80,8 +96,8 @@  define Package/libbz2/install
 endef
 
 define Package/bzip2/install
-	$(INSTALL_DIR) $(1)/usr/bin/
-	$(INSTALL_BIN) $(PKG_BUILD_DIR)/bzip2-shared $(1)/usr/bin/bzip2
+	$(INSTALL_DIR) $(1)/bin/
+	$(INSTALL_BIN) $(PKG_BUILD_DIR)/bzip2-shared $(1)/bin/bzip2
 endef
 
 HOST_CFLAGS += \