OSDN Git Service

luci-app-unblockneteasemusic: fix add firewall rules repeatedly
authorZiMing Mo <msylgj@immortalwrt.org>
Wed, 16 Mar 2022 17:47:10 +0000 (01:47 +0800)
committerZiMing Mo <msylgj@immortalwrt.org>
Wed, 16 Mar 2022 17:47:10 +0000 (01:47 +0800)
applications/luci-app-unblockneteasemusic/root/etc/init.d/unblockneteasemusic

index 31d3e45..23bba20 100755 (executable)
@@ -74,16 +74,18 @@ start_service()
        append_param "-p" "${http_port}":"${https_port}"
 
        if is_enabled "config" "pub_access"; then
-               uci -q batch <<-EOF
-                       add firewall rule
-                       set firewall.@rule[-1].name='unblockneteasemusic_pub_access'
-                       set firewall.@rule[-1].proto='tcp'
-                       set firewall.@rule[-1].src='wan'
-                       set firewall.@rule[-1].dest_port='${http_port}-${https_port}'
-                       set firewall.@rule[-1].target='ACCEPT'
-                       commit firewall
-               EOF
-               fw4 reload
+               local rule="$(uci show firewall | grep "name='unblockneteasemusic_pub_access'" | awk -F '.' '{ print $2}')"
+               [ -n "${rule}" ] || {
+                       uci -q batch <<-EOF
+                               add firewall rule
+                               set firewall.@rule[-1].name='unblockneteasemusic_pub_access'
+                               set firewall.@rule[-1].proto='tcp'
+                               set firewall.@rule[-1].src='wan'
+                               set firewall.@rule[-1].dest_port='${http_port}-${https_port}'
+                               set firewall.@rule[-1].target='ACCEPT'
+                               commit firewall
+                       EOF
+               }
        fi
 
        local music_source