ampr-ripd: script improvements and add QA script
authorDan Srebnick <[email protected]>
Mon, 1 Sep 2025 15:45:15 +0000 (11:45 -0400)
committerGeorge Sapkin <[email protected]>
Thu, 11 Sep 2025 21:56:17 +0000 (00:56 +0300)
Added test.sh
Predetermine count used by for loops in Makefile postrm
Implemented extra_command in initscript
Resolved shellcheck issues
Bump release

Signed-off-by: Dan Srebnick <[email protected]>
net/ampr-ripd/Makefile
net/ampr-ripd/files/ampr-ripd-init
net/ampr-ripd/test.sh [new file with mode: 0644]

index 511fef29f536a53428ecefa0d5454604525ca7f0..27dce8a14566b022da567b633758e86682a0b950 100644 (file)
@@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=ampr-ripd
 PKG_VERSION:=2.4.2
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tgz
 PKG_SOURCE_URL:=https://yo2loj.ro/hamprojects
@@ -24,7 +24,8 @@ define Package/ampr-ripd
 endef
 
 define Package/ampr-ripd/description
-  Routing daemon written in C similar to Hessu's rip44d including optional resending of RIPv2 broadcasts for router injection.
+  Routing daemon written in C similar to Hessu's rip44d including
+  optional resending of RIPv2 broadcasts for router injection.
 endef
 
 CONFIGURE_VARS+= \
@@ -48,46 +49,43 @@ define Package/ampr-ripd/postrm
 [ -z "$${IPKG_INSTROOT}" ] || exit 0
 
 echo "Removing firewall rules..."
-for i in $$(seq 99 -1 0); do
-   if [ $$(uci -q get firewall.@rule[$$i]) ]; then
-      name=$$(uci get firewall.@rule[$$i].name)
-      if [ "$$name" = "Net 44 ICMP Echo Request" ] \
-         || [ "$$name" = "Net 44 Router ICMP" ]    \
-         || [ "$$name" = "ipip" ]; then
-         uci del firewall.@rule[$$i]
-      fi
+count=$$(( $$(uci show firewall | grep -c "=rule") - 1 ))
+for i in $$(seq "$$count" -1 0); do
+   name=$$(uci get firewall.@rule["$$i"].name)
+   if [ "$$name" = "Net 44 ICMP Echo Request" ] \
+      || [ "$$name" = "Net 44 Router ICMP" ]    \
+      || [ "$$name" = "ipip" ]; then
+      uci del firewall.@rule["$$i"]
    fi
 done
 uci commit firewall
 
 echo "Removing network rules..."
-for i in $$(seq 99 -1 0); do
-   if [ $$(uci -q get network.@rule[$$i]) ]; then
-      lookup=$$(uci get network.@rule[$$i].lookup)
-      if [ "$$lookup" = "44" ]; then
-         uci del network.@rule[$$i]
-      fi
+count=$$(( $$(uci show network | grep -c "=rule") - 1 ))
+for i in $$(seq "$$count" -1 0); do
+   lookup=$$(uci get network.@rule["$$i"].lookup)
+   if [ "$$lookup" = "44" ]; then
+      uci del network.@rule["$$i"]
    fi
 done
 uci commit network
 
 echo "Removing firewall zone forwarding rules..."
-for i in $$(seq 99 -1 0); do
-   if [ $$(uci -q get firewall.@forwarding[$$i]) ]; then
-      name=$$(uci get firewall.@forwarding[$$i].src)
-      if [ "$$name" = "amprlan" ] || [ "$$name" = "amprwan" ]; then
-         uci del firewall.@forwarding[$$i]
-      fi
+count=$$(( $$(uci show firewall | grep -c "=forwarding") -1 ))
+for i in $$(seq "$$count" -1 0); do
+   name=$$(uci get firewall.@forwarding["$$i"].src)
+   if [ "$$name" = "amprlan" ] || [ "$$name" = "amprwan" ]; then
+      uci del firewall.@forwarding["$$i"]
    fi
 done
+uci commit firewall
 
 echo "Removing firewall zones..."
-for i in $$(seq 99 -1 0); do
-   if [ $$(uci -q get firewall.@zone[$$i]) ]; then
-      name=$$(uci get firewall.@zone[$$i].name)
-      if [ "$$name" = "amprlan" ] || [ "$$name" = "amprwan" ]; then
-         uci del firewall.@zone[$$i]
-      fi
+count=$$(( $$(uci show firewall | grep -c "=zone") -1 ))
+for i in $$(seq "$$count" -1 0); do
+   name=$$(uci get firewall.@zone["$$i"].name)
+   if [ "$$name" = "amprlan" ] || [ "$$name" = "amprwan" ]; then
+      uci del firewall.@zone["$$i"]
    fi
 done
 uci commit firewall
index 6f1a8f426e4865ac3ca63b327c5a09632d253000..e1df78aca0244fb34d551473970d0baf7fc8d455 100755 (executable)
@@ -3,8 +3,7 @@
 START=95
 STOP=10
 
-EXTRA_COMMANDS="configure"
-EXTRA_HELP="        configure       Configure service parameters"
+extra_command "configure" "Configure service parameters"
 
 start() {
        default_addr="44.127.254.254"
@@ -66,12 +65,9 @@ configure() {
        uci set network.amprlan.netmask="$amprmask"
        uci set network.amprwan.ipaddr="$amprhost"
        uci set network.amprwan.netmask="$amprmask"
-       for i in $(seq 0 -1 -99); do
-               if [ ! -z $(uci -q get network.@rule[$i].src) ] && \
-                       [ "$(uci get network.@rule[$i].lookup)" = "44" ] && \
-                       [ "$(uci get network.@rule[$i].priority)" = "45" ]; then
-                               uci set network.@rule[$i].src="$tunnet"
-                               break
+       for i in $(uci show network | awk -F= "/@rule/ && /lookup='44'/ {split(\$1, conf, /[.=]/); print conf[2]}"); do
+               if [ "$(uci -q get "network.$i.priority")" = "45" ]; then
+                       uci set "network.$i.src=$tunnet"
                fi
        done
        uci commit network
diff --git a/net/ampr-ripd/test.sh b/net/ampr-ripd/test.sh
new file mode 100644 (file)
index 0000000..c8a730a
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+"$1" -h 2>&1 | grep "$PKG_VERSION"