privoxy: correctly format /etc/services additions
authorJosh Powers <powersj@fastmail.com>
Wed, 26 Oct 2022 01:54:43 +0000 (19:54 -0600)
committerRosen Penev <rosenp@gmail.com>
Fri, 11 Nov 2022 23:16:45 +0000 (15:16 -0800)
This adds the missing protocol (e.g. /tcp and /udp) to the entry in
/etc/services. If the entry already exists, it will add the /tcp to it.
Otherwise, it will look and add the tcp and udp entries if either is
missing.

fixes: openwrt#19665

Signed-off-by: Josh Powers <powersj@fastmail.com>
net/privoxy/Makefile

index 1f8e72a0901b2eb1aaf3f2a29d46ad7e0a7fdb62..6ce0574afb5e56c2f6f2b37c527155545cac2c37 100644 (file)
@@ -157,8 +157,15 @@ endef
 
 define Package/privoxy/postinst
        #!/bin/sh
-       grep -i privoxy $${IPKG_INSTROOT}/etc/services >/dev/null 2>&1 || \
-               echo -e "privoxy\t8118" >> $${IPKG_INSTROOT}/etc/services
+       # if exists, update previous version entry missing protocol
+       (grep -E "privoxy.*8118$" $${IPKG_INSTROOT}/etc/services) > /dev/null \
+               && sed -i "s/privoxy.*8118/privoxy\t\t8118\/tcp/" $${IPKG_INSTROOT}/etc/services
+
+       # add missing tcp and udp entries
+       (grep -E "privoxy.*8118\/tcp" $${IPKG_INSTROOT}/etc/services) > /dev/null \
+               || echo -e "privoxy\t\t8118/tcp" >> $${IPKG_INSTROOT}/etc/services
+       (grep -E "privoxy.*8118\/udp" $${IPKG_INSTROOT}/etc/services) > /dev/null \
+               || echo -e "privoxy\t\t8118/udp" >> $${IPKG_INSTROOT}/etc/services
 endef
 
 $(eval $(call BuildPackage,privoxy))