Merge pull request #6909 from neheb/patch-34
authorTed Hess <thess@kitschensync.net>
Fri, 31 Aug 2018 19:15:00 +0000 (15:15 -0400)
committerGitHub <noreply@github.com>
Fri, 31 Aug 2018 19:15:00 +0000 (15:15 -0400)
crelay: Update to 0.13

20 files changed:
README.md
net/mwan3/Makefile
net/mwan3/files/etc/config/mwan3
net/mwan3/files/etc/hotplug.d/iface/16-mwan3 [new file with mode: 0644]
net/mwan3/files/lib/mwan3/mwan3.sh
net/mwan3/files/usr/sbin/mwan3
net/mwan3/files/usr/sbin/mwan3rtmon [new file with mode: 0755]
net/nfs-kernel-server/Makefile
net/nut/Makefile
net/nut/files/30-libhid-ups.head [new file with mode: 0755]
net/nut/files/30-libhid-ups.tail [new file with mode: 0644]
net/nut/files/nut-cgi.init
net/nut/files/nut-monitor.init
net/nut/files/nut-server.init
net/nut/files/nut_cgi
net/nut/files/nut_monitor
net/nut/files/nut_server
net/nut/files/nutshutdown [new file with mode: 0755]
net/socat/Makefile
utils/yunbridge/Makefile

index d908a86abb121e7ad338c357b9f0283a028d48ae..373f74e24eefe6b110b05ee98f5e41c204b7f09d 100644 (file)
--- a/README.md
+++ b/README.md
@@ -4,11 +4,11 @@
 
 This is the OpenWrt "packages"-feed containing community-maintained build scripts, options and patches for applications, modules and libraries used within OpenWrt.
 
-Installation of pre-built packages is handled directly by the **opkg** utility within your running OpenWrt system or by using the [OpenWrt SDK](http://wiki.openwrt.org/doc/howto/obtain.firmware.sdk) on a build system.
+Installation of pre-built packages is handled directly by the **opkg** utility within your running OpenWrt system or by using the [OpenWrt SDK](https://openwrt.org/docs/guide-developer/obtain.firmware.sdk) on a build system.
 
 ## Usage
 
-This repository is intended to be layered on-top of an OpenWrt buildroot. If you do not have an OpenWrt buildroot installed, see the documentation at: [OpenWrt Buildroot – Installation](http://wiki.openwrt.org/doc/howto/buildroot.exigence) on the OpenWrt support site.
+This repository is intended to be layered on-top of an OpenWrt buildroot. If you do not have an OpenWrt buildroot installed, see the documentation at: [OpenWrt Buildroot – Installation](https://openwrt.org/docs/guide-developer/build-system/install-buildsystem) on the OpenWrt support site.
 
 This feed is enabled by default. To install all its package definitions, run:
 ```
index adb54b24ae08cc29ca7b73a52022eac00d057bcc..741c92ce72707e0781c86b9b25196259a78bbe7b 100644 (file)
@@ -8,7 +8,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=mwan3
-PKG_VERSION:=2.6.18
+PKG_VERSION:=2.7.0
 PKG_RELEASE:=1
 PKG_MAINTAINER:=Florian Eckert <fe@dev.tdt.de>
 PKG_LICENSE:=GPLv2
index b7f6c2c11ba27b86629444b0cd9ed458f85cdf80..966601eee2dd1e78ad0051e6613cb5ede01cc6cc 100644 (file)
@@ -1,7 +1,8 @@
 
 config globals 'globals'
        option mmx_mask '0x3F00'
-       option local_source 'lan'
+       option local_source 'none'
+       option rtmon_interval '5'
 
 config interface 'wan'
        option enabled '1'
diff --git a/net/mwan3/files/etc/hotplug.d/iface/16-mwan3 b/net/mwan3/files/etc/hotplug.d/iface/16-mwan3
new file mode 100644 (file)
index 0000000..d2d148b
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+. /lib/functions.sh
+. /lib/functions/network.sh
+. /lib/mwan3/mwan3.sh
+
+config_load mwan3
+config_get_bool enabled globals 'enabled' '0'
+[ ${enabled} -gt 0 ] || exit 0
+
+if [ "$ACTION" == "ifup" ]; then
+       mwan3_lock
+       mwan3_rtmon
+       mwan3_unlock
+fi
+
+exit 0
index 2c5bbf3c126e9a10e5f7122dbc41916b46c30245..f252cb26bac8a2a77e82456de614b7b80eb3b686 100644 (file)
@@ -20,6 +20,63 @@ MM_BLACKHOLE=""
 MMX_UNREACHABLE=""
 MM_UNREACHABLE=""
 
+mwan3_rtmon_ipv4()
+{
+       local tid=1
+       local idx=0
+       local ret=1
+       main_tbsum=$($IP4 route list table main  | grep -v ^default | md5sum | head -c32)
+       while uci get mwan3.@interface[$idx] >/dev/null 2>&1 ; do
+               idx=$((idx+1))
+               tid=$idx
+               [ "$(uci get mwan3.@interface[$((idx-1))].family)" = "ipv4" ] && {
+                       if $IP4 route list table $tid | grep -q ^default; then
+                               tbsum=$($IP4 route list table $tid  | grep -v ^default | md5sum | head -c32)
+                               if [ "$tbsum" != "$main_tbsum" ]; then
+                                       $IP4 route list table $tid | grep -v ^default | while read line; do
+                                               $IP4 route del table $tid $line
+                                       done
+                                       $IP4 route list table main  | grep -v ^default | while read line; do
+                                               $IP4 route add table $tid $line
+                                       done
+                               fi
+                       fi
+               }
+               if [ "$(uci get mwan3.@interface[$((idx-1))].enabled)" = "1" ]; then
+                       ret=0
+               fi
+       done
+       return $ret
+}
+
+mwan3_rtmon_ipv6()
+{
+       local tid=1
+       local idx=0
+       local ret=1
+       main_tbsum=$($IP6 route list table main  | grep -v "^default\|^::/" | md5sum | head -c32)
+       while uci get mwan3.@interface[$idx] >/dev/null 2>&1 ; do
+               idx=$((idx+1))
+               tid=$idx
+               [ "$(uci get mwan3.@interface[$((idx-1))].family)" = "ipv6" ] && {
+                       if $IP6 route list table $tid | grep -q ^::/0; then
+                               tbsum=$($IP6 route list table $tid  | grep -v "^default\|^::/" | md5sum | head -c32)
+                               if [ "$tbsum" != "$main_tbsum" ]; then
+                                       $IP6 route list table $tid | grep -v "^default\|^::/" | while read line; do
+                                               $IP6 route del table $tid $line
+                                       done
+                                       $IP6 route list table main  | grep -v "^default\|^::/" | while read line; do
+                                               $IP6 route add table $tid $line
+                                       done
+                               fi
+                       fi
+               }
+               if [ "$(uci get mwan3.@interface[$((idx-1))].enabled)" = "1" ]; then
+                       ret=0
+               fi
+       done
+       return $ret
+}
 
 # counts how many bits are set to 1
 # n&(n-1) clears the lowest bit set to 1
@@ -188,10 +245,6 @@ mwan3_set_general_iptables()
                        $IPT -A mwan3_connected -m set --match-set mwan3_connected dst -j MARK --set-xmark $MMX_DEFAULT/$MMX_MASK
                fi
 
-               if ! $IPT -S mwan3_ifaces_out &> /dev/null; then
-                       $IPT -N mwan3_ifaces_out
-               fi
-
                if ! $IPT -S mwan3_rules &> /dev/null; then
                        $IPT -N mwan3_rules
                fi
@@ -209,7 +262,6 @@ mwan3_set_general_iptables()
                        $IPT -A mwan3_hook -j CONNMARK --restore-mark --nfmask $MMX_MASK --ctmask $MMX_MASK
                        $IPT -A mwan3_hook -m mark --mark 0x0/$MMX_MASK -j mwan3_ifaces_in
                        $IPT -A mwan3_hook -m mark --mark 0x0/$MMX_MASK -j mwan3_connected
-                       $IPT -A mwan3_hook -m mark --mark 0x0/$MMX_MASK -j mwan3_ifaces_out
                        $IPT -A mwan3_hook -m mark --mark 0x0/$MMX_MASK -j mwan3_rules
                        $IPT -A mwan3_hook -j CONNMARK --save-mark --nfmask $MMX_MASK --ctmask $MMX_MASK
                        $IPT -A mwan3_hook -m mark ! --mark $MMX_DEFAULT/$MMX_MASK -j mwan3_connected
@@ -241,30 +293,16 @@ mwan3_create_iface_iptables()
                        $IPT4 -N mwan3_ifaces_in
                fi
 
-               if ! $IPT4 -S mwan3_ifaces_out &> /dev/null; then
-                       $IPT4 -N mwan3_ifaces_out
-               fi
-
                if ! $IPT4 -S mwan3_iface_in_$1 &> /dev/null; then
                        $IPT4 -N mwan3_iface_in_$1
                fi
 
-               if ! $IPT4 -S mwan3_iface_out_$1 &> /dev/null; then
-                       $IPT4 -N mwan3_iface_out_$1
-               fi
-
                $IPT4 -F mwan3_iface_in_$1
                $IPT4 -A mwan3_iface_in_$1 -i $2 -m set --match-set mwan3_connected src -m mark --mark 0x0/$MMX_MASK -m comment --comment "default" -j MARK --set-xmark $MMX_DEFAULT/$MMX_MASK
                $IPT4 -A mwan3_iface_in_$1 -i $2 -m mark --mark 0x0/$MMX_MASK -m comment --comment "$1" -j MARK --set-xmark $(mwan3_id2mask id MMX_MASK)/$MMX_MASK
 
                $IPT4 -D mwan3_ifaces_in -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_in_$1 &> /dev/null
                $IPT4 -A mwan3_ifaces_in -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_in_$1
-
-               $IPT4 -F mwan3_iface_out_$1
-               $IPT4 -A mwan3_iface_out_$1 -o $2 -m mark --mark 0x0/$MMX_MASK -m comment --comment "$1" -j MARK --set-xmark $(mwan3_id2mask id MMX_MASK)/$MMX_MASK
-
-               $IPT4 -D mwan3_ifaces_out -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_out_$1 &> /dev/null
-               $IPT4 -A mwan3_ifaces_out -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_out_$1
        fi
 
        if [ "$family" == "ipv6" ]; then
@@ -274,30 +312,16 @@ mwan3_create_iface_iptables()
                        $IPT6 -N mwan3_ifaces_in
                fi
 
-               if ! $IPT6 -S mwan3_ifaces_out &> /dev/null; then
-                       $IPT6 -N mwan3_ifaces_out
-               fi
-
                if ! $IPT6 -S mwan3_iface_in_$1 &> /dev/null; then
                        $IPT6 -N mwan3_iface_in_$1
                fi
 
-               if ! $IPT6 -S mwan3_iface_out_$1 &> /dev/null; then
-                       $IPT6 -N mwan3_iface_out_$1
-               fi
-
                $IPT6 -F mwan3_iface_in_$1
                $IPT6 -A mwan3_iface_in_$1 -i $2 -m set --match-set mwan3_connected_v6 src -m mark --mark 0x0/$MMX_MASK -m comment --comment "default" -j MARK --set-xmark $MMX_DEFAULT/$MMX_MASK
                $IPT6 -A mwan3_iface_in_$1 -i $2 -m mark --mark 0x0/$MMX_MASK -m comment --comment "$1" -j MARK --set-xmark $(mwan3_id2mask id MMX_MASK)/$MMX_MASK
 
                $IPT6 -D mwan3_ifaces_in -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_in_$1 &> /dev/null
                $IPT6 -A mwan3_ifaces_in -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_in_$1
-
-               $IPT6 -F mwan3_iface_out_$1
-               $IPT6 -A mwan3_iface_out_$1 -o $2 -m mark --mark 0x0/$MMX_MASK -m comment --comment "$1" -j MARK --set-xmark $(mwan3_id2mask id MMX_MASK)/$MMX_MASK
-
-               $IPT6 -D mwan3_ifaces_out -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_out_$1 &> /dev/null
-               $IPT6 -A mwan3_ifaces_out -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_out_$1
        fi
 }
 
@@ -310,10 +334,6 @@ mwan3_delete_iface_iptables()
                $IPT4 -D mwan3_ifaces_in -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_in_$1 &> /dev/null
                $IPT4 -F mwan3_iface_in_$1 &> /dev/null
                $IPT4 -X mwan3_iface_in_$1 &> /dev/null
-
-               $IPT4 -D mwan3_ifaces_out -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_out_$1 &> /dev/null
-               $IPT4 -F mwan3_iface_out_$1 &> /dev/null
-               $IPT4 -X mwan3_iface_out_$1 &> /dev/null
        fi
 
        if [ "$family" == "ipv6" ]; then
@@ -321,10 +341,6 @@ mwan3_delete_iface_iptables()
                $IPT6 -D mwan3_ifaces_in -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_in_$1 &> /dev/null
                $IPT6 -F mwan3_iface_in_$1 &> /dev/null
                $IPT6 -X mwan3_iface_in_$1 &> /dev/null
-
-               $IPT6 -D mwan3_ifaces_out -m mark --mark 0x0/$MMX_MASK -j mwan3_iface_out_$1 &> /dev/null
-               $IPT6 -F mwan3_iface_out_$1 &> /dev/null
-               $IPT6 -X mwan3_iface_out_$1 &> /dev/null
        fi
 }
 
@@ -352,6 +368,7 @@ mwan3_create_iface_route()
 
                $IP4 route flush table $id
                $IP4 route add table $id default $route_args dev $2
+               mwan3_rtmon_ipv4
        fi
 
        if [ "$family" == "ipv6" ]; then
@@ -369,6 +386,7 @@ mwan3_create_iface_route()
 
                $IP6 route flush table $id
                $IP6 route add table $id default $route_args dev $2
+               mwan3_rtmon_ipv6
        fi
 }
 
@@ -409,7 +427,7 @@ mwan3_create_iface_rules()
                        $IP4 rule del pref $(($id+2000))
                done
 
-               $IP4 rule add pref $(($id+1000)) iif $2 lookup main
+               $IP4 rule add pref $(($id+1000)) iif $2 lookup $id
                $IP4 rule add pref $(($id+2000)) fwmark $(mwan3_id2mask id MMX_MASK)/$MMX_MASK lookup $id
        fi
 
@@ -423,7 +441,7 @@ mwan3_create_iface_rules()
                        $IP6 rule del pref $(($id+2000))
                done
 
-               $IP6 rule add pref $(($id+1000)) iif $2 lookup main
+               $IP6 rule add pref $(($id+1000)) iif $2 lookup $id
                $IP6 rule add pref $(($id+2000)) fwmark $(mwan3_id2mask id MMX_MASK)/$MMX_MASK lookup $id
        fi
 }
@@ -475,6 +493,16 @@ mwan3_delete_iface_ipset_entries()
        done
 }
 
+mwan3_rtmon()
+{
+       pid="$(pgrep -f mwan3rtmon)"
+       if [ "${pid}" != "" ]; then
+               kill -USR1 "${pid}"
+       else
+               [ -x /usr/sbin/mwan3rtmon ] && /usr/sbin/mwan3rtmon &
+       fi
+}
+
 mwan3_track()
 {
        local track_ip track_ips pid
@@ -507,13 +535,14 @@ mwan3_track_signal()
 
 mwan3_set_policy()
 {
-       local iface_count id iface family metric probability weight
+       local iface_count id iface family metric probability weight device
 
        config_get iface $1 interface
        config_get metric $1 metric 1
        config_get weight $1 weight 1
 
        [ -n "$iface" ] || return 0
+       network_get_device device $iface
        [ "$metric" -gt $DEFAULT_LOWEST_METRIC ] && $LOG warn "Member interface $iface has >$DEFAULT_LOWEST_METRIC metric. Not appending to policy" && return 0
 
        mwan3_get_iface_id id $iface
@@ -552,6 +581,11 @@ mwan3_set_policy()
 
                                $IPT4 -I mwan3_policy_$policy -m mark --mark 0x0/$MMX_MASK $probability -m comment --comment "$iface $weight $total_weight_v4" -j MARK --set-xmark $(mwan3_id2mask id MMX_MASK)/$MMX_MASK
                        fi
+               else
+                       [ -n "$device" ] && {
+                               $IPT4 -S mwan3_policy_$policy | grep -q '.*--comment ".* [0-9]* [0-9]*"' || \
+                                       $IPT4 -I mwan3_policy_$policy -o $device -m mark --mark 0x0/$MMX_MASK -m comment --comment "out $iface $device" -j MARK --set-xmark $MMX_DEFAULT/$MMX_MASK
+                       }
                fi
        fi
 
@@ -585,6 +619,11 @@ mwan3_set_policy()
 
                                $IPT6 -I mwan3_policy_$policy -m mark --mark 0x0/$MMX_MASK $probability -m comment --comment "$iface $weight $total_weight_v6" -j MARK --set-xmark $(mwan3_id2mask id MMX_MASK)/$MMX_MASK
                        fi
+               else
+                       [ -n "$device" ] && {
+                               $IPT6 -S mwan3_policy_$policy | grep -q '.*--comment ".* [0-9]* [0-9]*"' || \
+                                       $IPT6 -I mwan3_policy_$policy -o $device -m mark --mark 0x0/$MMX_MASK -m comment --comment "out $iface $device" -j MARK --set-xmark $MMX_DEFAULT/$MMX_MASK
+                       }
                fi
        fi
 }
@@ -649,7 +688,7 @@ mwan3_set_sticky_iptables()
                        [ -n "$id" ] || return 0
 
                        for IPT in "$IPT4" "$IPT6"; do
-                               if [ -n "$($IPT -S mwan3_iface_in_$1 2> /dev/null)" -a -n "$($IPT -S mwan3_iface_out_$1 2> /dev/null)" ]; then
+                               if [ -n "$($IPT -S mwan3_iface_in_$1 2> /dev/null)" ]; then
                                        $IPT -I mwan3_rule_$rule -m mark --mark $(mwan3_id2mask id MMX_MASK)/$MMX_MASK -m set ! --match-set mwan3_sticky_$rule src,src -j MARK --set-xmark 0x0/$MMX_MASK
                                        $IPT -I mwan3_rule_$rule -m mark --mark 0/$MMX_MASK -j MARK --set-xmark $(mwan3_id2mask id MMX_MASK)/$MMX_MASK
                                fi
@@ -822,9 +861,9 @@ mwan3_report_iface_status()
 
        if [ -z "$id" -o -z "$device" ]; then
                result="unknown"
-       elif [ -n "$($IP rule | awk '$1 == "'$(($id+1000)):'"')" -a -n "$($IP rule | awk '$1 == "'$(($id+2000)):'"')" -a -n "$($IPT -S mwan3_iface_in_$1 2> /dev/null)" -a -n "$($IPT -S mwan3_iface_out_$1 2> /dev/null)" -a -n "$($IP route list table $id default dev $device 2> /dev/null)" ]; then
+       elif [ -n "$($IP rule | awk '$1 == "'$(($id+1000)):'"')" -a -n "$($IP rule | awk '$1 == "'$(($id+2000)):'"')" -a -n "$($IPT -S mwan3_iface_in_$1 2> /dev/null)" -a -n "$($IP route list table $id default dev $device 2> /dev/null)" ]; then
                result="$(mwan3_get_iface_hotplug_state $1)"
-       elif [ -n "$($IP rule | awk '$1 == "'$(($id+1000)):'"')" -o -n "$($IP rule | awk '$1 == "'$(($id+2000)):'"')" -o -n "$($IPT -S mwan3_iface_in_$1 2> /dev/null)" -o -n "$($IPT -S mwan3_iface_out_$1 2> /dev/null)" -o -n "$($IP route list table $id default dev $device 2> /dev/null)" ]; then
+       elif [ -n "$($IP rule | awk '$1 == "'$(($id+1000)):'"')" -o -n "$($IP rule | awk '$1 == "'$(($id+2000)):'"')" -o -n "$($IPT -S mwan3_iface_in_$1 2> /dev/null)" -o -n "$($IP route list table $id default dev $device 2> /dev/null)" ]; then
                result="error"
        elif [ "$enabled" == "1" ]; then
                result="offline"
@@ -858,16 +897,16 @@ mwan3_report_policies_v4()
        for policy in $($IPT4 -S | awk '{print $2}' | grep mwan3_policy_ | sort -u); do
                echo "$policy:" | sed 's/mwan3_policy_//'
 
-               [ -n "$total_weight" ] || total_weight=$($IPT4 -S $policy | cut -s -d'"' -f2 | head -1 | awk '{print $3}')
+               [ -n "$total_weight" ] || total_weight=$($IPT4 -S $policy | grep -v '.*--comment "out .*" .*$' | cut -s -d'"' -f2 | head -1 | awk '{print $3}')
 
                if [ ! -z "${total_weight##*[!0-9]*}" ]; then
-                       for iface in $($IPT4 -S $policy | cut -s -d'"' -f2 | awk '{print $1}'); do
-                               weight=$($IPT4 -S $policy | cut -s -d'"' -f2 | awk '$1 == "'$iface'"' | awk '{print $2}')
+                       for iface in $($IPT4 -S $policy | grep -v '.*--comment "out .*" .*$' | cut -s -d'"' -f2 | awk '{print $1}'); do
+                               weight=$($IPT4 -S $policy | grep -v '.*--comment "out .*" .*$' | cut -s -d'"' -f2 | awk '$1 == "'$iface'"' | awk '{print $2}')
                                percent=$(($weight*100/$total_weight))
                                echo " $iface ($percent%)"
                        done
                else
-                       echo " $($IPT4 -S $policy | sed '/.*--comment \([^ ]*\) .*$/!d;s//\1/;q')"
+                       echo " $($IPT4 -S $policy | grep -v '.*--comment "out .*" .*$' | sed '/.*--comment \([^ ]*\) .*$/!d;s//\1/;q')"
                fi
 
                unset total_weight
@@ -883,16 +922,16 @@ mwan3_report_policies_v6()
        for policy in $($IPT6 -S | awk '{print $2}' | grep mwan3_policy_ | sort -u); do
                echo "$policy:" | sed 's/mwan3_policy_//'
 
-               [ -n "$total_weight" ] || total_weight=$($IPT6 -S $policy | cut -s -d'"' -f2 | head -1 | awk '{print $3}')
+               [ -n "$total_weight" ] || total_weight=$($IPT6 -S $policy | grep -v '.*--comment "out .*" .*$' | cut -s -d'"' -f2 | head -1 | awk '{print $3}')
 
                if [ ! -z "${total_weight##*[!0-9]*}" ]; then
-                       for iface in $($IPT6 -S $policy | cut -s -d'"' -f2 | awk '{print $1}'); do
-                               weight=$($IPT6 -S $policy | cut -s -d'"' -f2 | awk '$1 == "'$iface'"' | awk '{print $2}')
+                       for iface in $($IPT6 -S $policy | grep -v '.*--comment "out .*" .*$' | cut -s -d'"' -f2 | awk '{print $1}'); do
+                               weight=$($IPT6 -S $policy | grep -v '.*--comment "out .*" .*$' | cut -s -d'"' -f2 | awk '$1 == "'$iface'"' | awk '{print $2}')
                                percent=$(($weight*100/$total_weight))
                                echo " $iface ($percent%)"
                        done
                else
-                       echo " $($IPT6 -S $policy | sed '/.*--comment \([^ ]*\) .*$/!d;s//\1/;q')"
+                       echo " $($IPT6 -S $policy | grep -v '.*--comment "out .*" .*$' | sed '/.*--comment \([^ ]*\) .*$/!d;s//\1/;q')"
                fi
 
                unset total_weight
index a0c296f18e2bc0ea2acce0787163a596723a044f..c10ffa8a53a6d9542cba2d5c1bbaa996d482907b 100755 (executable)
@@ -155,6 +155,12 @@ stop()
 {
        local ipset route rule table IP IPT pid src_ip
 
+       for pid in $(pgrep -f "mwan3rtmon"); do
+               kill -TERM "$pid" > /dev/null 2>&1
+               sleep 1
+               kill -KILL "$pid" > /dev/null 2>&1
+       done
+
        for pid in $(pgrep -f "mwan3track"); do
                kill -TERM "$pid" > /dev/null 2>&1
                sleep 1
diff --git a/net/mwan3/files/usr/sbin/mwan3rtmon b/net/mwan3/files/usr/sbin/mwan3rtmon
new file mode 100755 (executable)
index 0000000..667d0cc
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+. /lib/functions.sh
+. /lib/mwan3/mwan3.sh
+
+LOG="logger -t $(basename "$0")[$$] -p"
+
+clean_up() {
+       $LOG notice "Stopping mwan3rtmon..."
+       exit 0
+}
+
+rtchange() {
+       $LOG info "Detect rtchange event."
+}
+
+main() {
+       local rtmon_interval
+       trap clean_up TERM
+       trap rtchange USR1
+
+       config_load mwan3
+       config_get rtmon_interval globals rtmon_interval '5'
+
+       sleep 3
+       while mwan3_rtmon_ipv4 || mwan3_rtmon_ipv6; do
+               [ "$rtmon_interval" = "0" ] && break
+               sleep $rtmon_interval
+       done
+}
+
+main "$@"
index de88938f28501829721555147a8a050ee13db418..3eee8cc51b0d45d244f9aece8eba0a67c8ffc90c 100644 (file)
@@ -9,10 +9,10 @@ include $(TOPDIR)/rules.mk
 PKG_NAME:=nfs-kernel-server
 PKG_VERSION:=2.3.2
 PKG_RELEASE:=2
-PKG_HASH:=1748a046e452ceb2285cc07b61ec0f85af7c92ac443e111a6c8a1061254ca717
+PKG_HASH:=a6418fc6b80e39a360a236d1a575e2e3258dc5582808e524b19f716b3cd66224
 
 PKG_SOURCE_URL:=@SF/nfs
-PKG_SOURCE:=nfs-utils-$(PKG_VERSION).tar.bz2
+PKG_SOURCE:=nfs-utils-$(PKG_VERSION).tar.xz
 
 HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/nfs-utils-$(PKG_VERSION)
 PKG_BUILD_DIR:=$(BUILD_DIR)/nfs-utils-$(PKG_VERSION)
index 2a253f8c0849b76dde0d6120801c161d8b0ed60a..6108e27056b058b2d615b2abce5f4e8333387ff2 100644 (file)
@@ -9,14 +9,14 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=nut
 PKG_VERSION:=2.7.4
-PKG_RELEASE:=7
+PKG_RELEASE:=8
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=http://www.networkupstools.org/source/2.7/
 PKG_HASH:=980e82918c52d364605c0703a5dcf01f74ad2ef06e3d365949e43b7d406d25a7
 PKG_MAINTAINER:=Daniel Dickinson <cshored@thecshore.com>
-PKG_LICENSE:=GPL-2.0
-PKG_LICENSE_FILES:=LICENSE-GPL2
+PKG_LICENSE:=GPL-2.0+ GPL-3.0+ GPL-1.0+ Artistic-1.0-Perl
+PKG_LICENSE_FILES:=LICENSE-GPL2 LICENSE-GPL3 COPYING
 PKG_FIXUP:=autoreconf
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
@@ -63,22 +63,32 @@ define Package/nut/install
 endef
 
 define Package/nut-server/install
+       # Server portion
        $(INSTALL_DIR) $(1)/etc/nut
        $(INSTALL_DIR) $(1)/usr/sbin
        $(INSTALL_DIR) $(1)/etc/init.d
        $(INSTALL_DIR) $(1)/usr/share/nut
-       $(INSTALL_DIR) $(1)/etc/init.d
        $(INSTALL_BIN) ./files/nut-server.init $(1)/etc/init.d/nut-server
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/upsd $(1)/usr/sbin
-       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/upsdrvctl $(1)/usr/sbin
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/share/nut/cmdvartab $(1)/usr/share/nut/
-       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/share/nut/driver.list $(1)/usr/share/nut/
        $(INSTALL_DIR) $(1)/etc/config
        $(INSTALL_CONF) ./files/nut_server $(1)/etc/config/nut_server
-       ln -sf /var/etc/nut/nut.conf $(1)/etc/nut/nut.conf
-       ln -sf /var/etc/nut/ups.conf $(1)/etc/nut/ups.conf
        ln -sf /var/etc/nut/upsd.users  $(1)/etc/nut/upsd.users
        ln -sf /var/etc/nut/upsd.conf $(1)/etc/nut/upsd.conf
+       # Driver common portion
+       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/upsdrvctl $(1)/usr/sbin
+       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/share/nut/driver.list $(1)/usr/share/nut/
+       ln -sf /var/etc/nut/ups.conf $(1)/etc/nut/ups.conf
+       # Mangle libhid.usermap into a format (hotplug shell script) useful for OpenWrt
+       $(INSTALL_DIR) $(1)/etc/hotplug.d/usb
+       $(INSTALL_BIN) ./files/30-libhid-ups.head $(1)/etc/hotplug.d/usb/30-libhid-ups
+       $(CP) $(PKG_INSTALL_DIR)/etc/hotplug/usb/libhid.usermap $(PKG_BUILD_DIR)/30-libhid-ups.middle
+       $(SED) '/^$$$$/d' \
+               -e '/^#/d' \
+               -E -e 's:^[^ ][^ ]*  *0x0003  *0x0{0,3}([^ ][^ ]*)  *0x{0,3}*([^ ][^ ]*).*:\1/\2/* | \\:' \
+               $(PKG_BUILD_DIR)/30-libhid-ups.middle
+       tail -n+2 $(PKG_BUILD_DIR)/30-libhid-ups.middle >>$(1)/etc/hotplug.d/usb/30-libhid-ups
+       cat ./files/30-libhid-ups.tail >>$(1)/etc/hotplug.d/usb/30-libhid-ups
 endef
 
 define Package/nut-common
@@ -87,8 +97,7 @@ define Package/nut-common
        DEPENDS:= nut \
                +NUT_DRIVER_SNMP:libnetsnmp \
                +NUT_DRIVER_USB:libusb-compat \
-               +NUT_SSL:libopenssl \
-               +PACKAGE_libwrap:libwrap
+               +NUT_SSL:libopenssl
 endef
 
 define Package/nut-common/description
@@ -96,6 +105,10 @@ $(call Package/nut/description/Default)
 This package contains the common files.
 endef
 
+define Package/nut-common/conffiles
+/etc/nut/nut.conf
+endef
+
 define Package/nut-common/install
        $(INSTALL_DIR) $(1)/etc/nut
        $(INSTALL_DIR) $(1)/usr/lib
@@ -107,6 +120,7 @@ define Package/nut-server
        $(call Package/nut/Default)
        TITLE+= (server)
        DEPENDS:=nut +nut-common
+       USERID:=nut=113:nut=113
 endef
 
 define Package/nut-server/description
@@ -120,13 +134,16 @@ endef
 
 define Package/nut-server/conffiles
 /etc/config/nut_server
+/etc/nut/upsd.conf
+/etc/nut/upsd.users
+/etc/nut/ups.conf
 endef
 
 define Package/nut-upsmon
   $(call Package/nut/Default)
        TITLE+= (monitor)
        DEPENDS:=nut +nut-common
-       USERID:=nut=113:nut=113
+       USERID:=nutmon=114:nutmon=114
 endef
 
 define Package/nut-upsmon/description
@@ -141,6 +158,7 @@ endef
 
 define Package/nut-upsmon/conffiles
 /etc/config/nut_monitor
+/etc/nut/upsmon.conf
 endef
 
 define Package/nut-upsmon/install
@@ -149,6 +167,7 @@ define Package/nut-upsmon/install
        $(INSTALL_DIR) $(1)/etc/init.d
        $(INSTALL_BIN) ./files/nut-monitor.init $(1)/etc/init.d/nut-monitor
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/upsmon $(1)/usr/sbin/
+       $(INSTALL_BIN) ./files/nutshutdown $(1)/usr/sbin/nutshutdown
        $(INSTALL_DIR) $(1)/etc/config
        $(INSTALL_CONF) ./files/nut_monitor $(1)/etc/config/nut_monitor
        ln -sf /var/etc/nut/upsmon.conf $(1)/etc/nut/upsmon.conf
@@ -182,7 +201,7 @@ define Package/nut-upsc/description
 $(call Package/nut/description/Default)
 upsc is provided as a quick way to poll the status of a UPS server. It
 can be used inside shell scripts and other programs that need UPS data
-but don not want to include the full interface.
+but do not want to include the full interface.
 endef
 
 define Package/nut-upsc/install
@@ -308,12 +327,15 @@ define Package/nut-web-cgi/install
        $(INSTALL_CONF) ./files/add_nut_httpd_conf $(1)/etc/uci-defaults/add_nut_httpd_conf
        $(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/nut/upsstats.html.sample $(1)/etc/nut/upsstats.html
        $(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/nut/upsstats-single.html.sample $(1)/etc/nut/upsstats-single.html
-       $(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/nut/upsset.conf.sample $(1)/etc/nut/upsset.conf
+       $(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/nut/upsset.conf.sample $(1)/etc/nut/upsset.conf.disable
+       $(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/nut/upsset.conf.sample $(1)/etc/nut/upsset.conf.enable
+       $(SED) 's/### \?//' $(1)/etc/nut/upsset.conf.enable
        $(INSTALL_DIR) $(1)/etc/config
        $(INSTALL_CONF) ./files/nut_cgi $(1)/etc/config/nut_cgi
        $(INSTALL_DIR) $(1)/etc/init.d
        $(INSTALL_BIN) ./files/nut-cgi.init $(1)/etc/init.d/nut-cgi
        ln -sf /var/etc/nut/hosts.conf $(1)/etc/nut/hosts.conf
+       ln -sf /var/etc/nut/upsset.conf $(1)/etc/nut/upsset.conf
 endef
 
 define Package/nut-avahi-service
@@ -342,7 +364,7 @@ define DriverPackage
         define Package/nut-driver-$(2)
                $(call Package/nut/Default)
                TITLE:=$(2) (NUT $(1) driver)
-               DEPENDS:=nut +nut-common
+               DEPENDS:=nut +nut-server
                $(if $(filter $(1),snmp),DEPENDS+= @NUT_DRIVER_SNMP)
                $(if $(filter $(1),usb),DEPENDS+= @NUT_DRIVER_USB)
                $(if $(filter $(1),serial),DEPENDS+= @NUT_DRIVER_SERIAL)
@@ -502,9 +524,11 @@ CONFIGURE_ARGS += \
        --without-avahi \
        --$(if $(CONFIG_NUT_DRIVER_SNMP),with,without)-snmp \
        --$(if $(CONFIG_NUT_DRIVER_SERIAL),with,without)-serial \
+       --without-doc \
        --without-neon \
        --without-powerman \
        --without-wrap \
+       --with-hotplug-dir=/etc/hotplug \
        --with-cgi \
        --without-ipmi \
        --without-freeipmi \
diff --git a/net/nut/files/30-libhid-ups.head b/net/nut/files/30-libhid-ups.head
new file mode 100755 (executable)
index 0000000..efcbcf6
--- /dev/null
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+. /lib/functions.sh
+
+nut_driver_config() {
+       local cfg="$1"
+       local nomatch="$2"
+
+       config_get runas "$cfg" runas "nut"
+       config_get vendorid "$cfg" vendorid
+       config_get productid "$cfg" productid
+
+       [ "$ACTION" = "add" ] &&[ -n "$DEVNAME" ] && {
+               chmod 0660 /dev/"$DEVNAME"
+               chown ${runas:-root}:$(id -gn "${runas:-root}") /dev/"$DEVNAME"
+       }
+
+       if [ "$(printf "%04x" 0x"$pvendid")" = "$vendorid" ] && \
+               [ "$(printf "%04x" 0x"$pprodid")" = "$productid" ]; then
+                       [ "$ACTION" = "add" ] && {
+                               /etc/init.d/nut-server start "$cfg"
+                       }
+                       [ "$ACTION" = "remove" ] && {
+                               /etc/init.d/nut-server stop "$cfg"
+                       }
+                       found=1
+       elif [ "$nomatch" = "1" ]; then
+               [ "$ACTION" = "add" ] && {
+                       /etc/init.d/nut-server start "$cfg"
+               }
+               [ "$ACTION" = "remove" ] && {
+                       /etc/init.d/nut-server stop "$cfg"
+               }
+       fi
+}
+
+perform_libhid_action() {
+       local vendorid productid runas
+       local pvendid pprodid found
+
+       pvendid=${PRODUCT%/*}
+       pvendid=${pvendid%/*}
+       pprodid=${PRODUCT%/*}
+       pprodid=${pprodid##*/}
+
+       config_load nut_server
+       config_foreach nut_driver_config driver 0
+       [ "$found" != "1" ] && config_foreach nut_driver_config driver 1
+}
+
+[ -n "$PRODUCT" ] && case "$PRODUCT" in
diff --git a/net/nut/files/30-libhid-ups.tail b/net/nut/files/30-libhid-ups.tail
new file mode 100644 (file)
index 0000000..24c2a96
--- /dev/null
@@ -0,0 +1,5 @@
+"")
+       [ -d /var/run/nut ] && [ ! -f /var/run/nut/disable-hotplug ] && \
+               /etc/init.d/nut-server enabled &&  perform_libhid_action
+       ;;
+esac
index d63d98ba95d4618ae036337d95579054dc61bc83..ceb7cce2266cdda9ee89829492d1c771216acf9b 100755 (executable)
@@ -5,9 +5,24 @@
 # See /LICENSE for more information.
 #
 START=51
+USE_PROCD=1
 
 DEFAULT=/etc/default/nut
 UPSCGI_C=/var/etc/nut/hosts.conf
+UPSCGI_S=/var/etc/nut/upsset.conf
+
+nut_upscgi_upsset() {
+       local cfg="$1"
+       local enable
+
+       config_get_bool enable "$cfg" enable 0
+
+       [ $enable -eq 1 ] && {
+               ln -sf /etc/nut/upsset.conf.enable "$UPSCGI_S"
+       } || {
+               ln -sf /etc/nut/upsset.conf.disable "$UPSCGI_S"
+       }
+}
 
 nut_upscgi_add() {
        local cfg="$1"
@@ -25,20 +40,32 @@ nut_upscgi_add() {
            system="$system:$port";
        fi
        config_get displayname "$cfg" displayname
-       echo "MONITOR $system \"$displayname\"" >> $UPSCGI_C
+       echo "MONITOR $system \"$displayname\"" >> "$UPSCGI_C"
 }
 
-start() {
-       rm -f $UPSCGI_C
+service_reload() {
+       mkdir -m 0755 -p "$(dirname "$UPSCGI_C")"
+       rm -f "$UPSCGI_C"
+       rm -f "$UPSCGI_S"
 
        config_load nut_cgi
 
        config_foreach nut_upscgi_add host
+       config_foreach nut_upscgi_upsset upsset
 
        chmod 640 /var/etc/nut/hosts.conf
 }
 
-stop() {
-       rm -f $UPSCGI_C
+start_service() {
+       service_reload
+}
+
+stop_service() {
+       rm -f "$UPSCGI_C"
+       rm -f "$UPSCGI_S"
+       ln -sf /etc/nut/upsset.conf.disable "$UPSCGI_S"
 }
 
+service_triggers() {
+       procd_add_reload_trigger "nut_cgi"
+}
index af814078106534f4848d8be2fae67175f397aebd..513d703058b27ebe64f8a5c59213fd8726843f57 100755 (executable)
@@ -6,56 +6,57 @@ UPSMON_C=/var/etc/nut/upsmon.conf
 
 nut_upsmon_conf() {
        local cfg="$1"
+       local RUNAS val optval
 
-       echo "# Config file automatically generated from UCI config" > $UPSMON_C
+       echo "# Config file automatically generated from UCI config" > "$UPSMON_C"
 
-       config_get runas "$cfg" runas "nut"
-       [ -n "$runas" ] && echo "RUN_AS_USER $runas" >> $UPSMON_C
+       config_get RUNAS "$cfg" runas "nutmon"
+       [ -n "$RUNAS" ] && echo "RUN_AS_USER $RUNAS" >> "$UPSMON_C"
+       runas=$RUNAS
 
        config_get val "$cfg" minsupplies 1
-       echo "MINSUPPLIES $val" >> $UPSMON_C
+       echo "MINSUPPLIES $val" >> "$UPSMON_C"
 
-       config_get val "$cfg" shutdowncmd "/sbin/halt"
-       echo "SHUTDOWNCMD \"$val\"" >> $UPSMON_C
+       config_get val "$cfg" shutdowncmd "/usr/sbin/nutshutdown"
+       echo "SHUTDOWNCMD \"$val\"" >> "$UPSMON_C"
 
        config_get val "$cfg" notifycmd
-       [ -n "$val" ] && echo "NOTIFYCMD \"$val\"" >> $UPSMON_C
+       [ -n "$val" ] && echo "NOTIFYCMD \"$val\"" >> "$UPSMON_C"
 
        config_get val "$cfg" pollfreq 5
-       echo "POLLFREQ $val" >> $UPSMON_C
+       echo "POLLFREQ $val" >> "$UPSMON_C"
 
        config_get val "$cfg" pollfreqalert 5
-       echo "POLLFREQALERT $val" >> $UPSMON_C
+       echo "POLLFREQALERT $val" >> "$UPSMON_C"
 
        config_get val "$cfg" hostsync 15
-       echo "HOSTSYNC $val" >> $UPSMON_C
+       echo "HOSTSYNC $val" >> "$UPSMON_C"
 
        config_get val "$cfg" deadtime 15
-       echo "DEADTIME $val" >> $UPSMON_C
+       echo "DEADTIME $val" >> "$UPSMON_C"
 
-       config_get val "$cfg" powerdownflag /var/run/killpower
-       echo "POWERDOWNFLAG $val" >> $UPSMON_C
+       echo "POWERDOWNFLAG /var/run/killpower" >> "$UPSMON_C"
 
        config_get val "$cfg" onlinemsg
-       [ -n "$val" ] && echo "NOTIFYMSG ONLINE \"$val\"" >> $UPSMON_C
+       [ -n "$val" ] && echo "NOTIFYMSG ONLINE \"$val\"" >> "$UPSMON_C"
        config_get val "$cfg" onbattmsg
-       [ -n "$val" ] && echo "NOTIFYMSG ONBATT \"$val\"" >> $UPSMON_C
+       [ -n "$val" ] && echo "NOTIFYMSG ONBATT \"$val\"" >> "$UPSMON_C"
        config_get val "$cfg" lowbattmsg
-       [ -n "$val" ] && echo "NOTIFYMSG LOWBATT \"$val\"" >> $UPSMON_C
+       [ -n "$val" ] && echo "NOTIFYMSG LOWBATT \"$val\"" >> "$UPSMON_C"
        config_get val "$cfg" fsdmsg
-       [ -n "$val" ] && echo "NOTIFYMSG FSD \"$val\"" >> $UPSMON_C
+       [ -n "$val" ] && echo "NOTIFYMSG FSD \"$val\"" >> "$UPSMON_C"
        config_get val "$cfg" commokmsg
-       [ -n "$val" ] && echo "NOTIFYMSG COMMOK \"$val\"" >> $UPSMON_C
+       [ -n "$val" ] && echo "NOTIFYMSG COMMOK \"$val\"" >> "$UPSMON_C"
        config_get val "$cfg" commbadmsg
-       [ -n "$val" ] && echo "NOTIFYMSG COMMBAD \"$val\"" >> $UPSMON_C
+       [ -n "$val" ] && echo "NOTIFYMSG COMMBAD \"$val\"" >> "$UPSMON_C"
        config_get val "$cfg" shutdownmsg
-       [ -n "$val" ] && echo "NOTIFYMSG SHUTDOWN \"$val\"" >> $UPSMON_C
+       [ -n "$val" ] && echo "NOTIFYMSG SHUTDOWN \"$val\"" >> "$UPSMON_C"
        config_get val "$cfg" replbattmsg
-       [ -n "$val" ] && echo "NOTIFYMSG REPLBATT \"$val\"" >> $UPSMON_C
+       [ -n "$val" ] && echo "NOTIFYMSG REPLBATT \"$val\"" >> "$UPSMON_C"
        config_get val "$cfg" nocommmsg
-       [ -n "$val" ] && echo "NOTIFYMSG NOCOMM \"$val\"" >> $UPSMON_C
+       [ -n "$val" ] && echo "NOTIFYMSG NOCOMM \"$val\"" >> "$UPSMON_C"
        config_get val "$cfg" noparentmsg
-       [ -n "$val" ] && echo "NOTIFYMSG NOPARENT \"$val\"" >> $UPSMON_C
+       [ -n "$val" ] && echo "NOTIFYMSG NOPARENT \"$val\"" >> "$UPSMON_C"
 
        notifylist() {
                local value="$1"
@@ -85,34 +86,34 @@ nut_upsmon_conf() {
        val=""
        config_list_foreach "$cfg" defaultnotify notifylist
        default="$optval"
-       echo "NOTIFYFLAG ONLINE $(setnotify "$cfg" onlinenotify)" >> $UPSMON_C
-       echo "NOTIFYFLAG ONBATT $(setnotify "$cfg" onbattnotify)" >> $UPSMON_C
-       echo "NOTIFYFLAG LOWBATT $(setnotify "$cfg" lowbatnotify)" >> $UPSMON_C
-       echo "NOTIFYFLAG FSD $(setnotify "$cfg" fsdnotify)" >> $UPSMON_C
-       echo "NOTIFYFLAG COMMOK $(setnotify "$cfg" commoknotify)" >> $UPSMON_C
-       echo "NOTIFYFLAG COMMBAD $(setnotify "$cfg" commbadnotify)" >> $UPSMON_C
-       echo "NOTIFYFLAG SHUTDOWN $(setnotify "$cfg" shutdownnotify)" >> $UPSMON_C
-       echo "NOTIFYFLAG REPLBATT $(setnotify "$cfg" repolbattnotify)" >> $UPSMON_C
-       echo "NOTIFYFLAG NOCOMM $(setnotify "$cfg" nocommnotify)" >> $UPSMON_C
-       echo "NOTIFYFLAG NOPARENT $(setnotify "$cfg" noparentnotify)" >> $UPSMON_C
+       echo "NOTIFYFLAG ONLINE $(setnotify "$cfg" onlinenotify)" >> "$UPSMON_C"
+       echo "NOTIFYFLAG ONBATT $(setnotify "$cfg" onbattnotify)" >> "$UPSMON_C"
+       echo "NOTIFYFLAG LOWBATT $(setnotify "$cfg" lowbatnotify)" >> "$UPSMON_C"
+       echo "NOTIFYFLAG FSD $(setnotify "$cfg" fsdnotify)" >> "$UPSMON_C"
+       echo "NOTIFYFLAG COMMOK $(setnotify "$cfg" commoknotify)" >> "$UPSMON_C"
+       echo "NOTIFYFLAG COMMBAD $(setnotify "$cfg" commbadnotify)" >> "$UPSMON_C"
+       echo "NOTIFYFLAG SHUTDOWN $(setnotify "$cfg" shutdownnotify)" >> "$UPSMON_C"
+       echo "NOTIFYFLAG REPLBATT $(setnotify "$cfg" repolbattnotify)" >> "$UPSMON_C"
+       echo "NOTIFYFLAG NOCOMM $(setnotify "$cfg" nocommnotify)" >> "$UPSMON_C"
+       echo "NOTIFYFLAG NOPARENT $(setnotify "$cfg" noparentnotify)" >> "$UPSMON_C"
 
        config_get val "$cfg" rbwarntime 43200
-       echo "RBWARNTIME $val" >> $UPSMON_C
+       echo "RBWARNTIME $val" >> "$UPSMON_C"
 
        config_get val "$cfg" nocommwarntime 300
-       echo "NOCOMMWARNTIME $val" >> $UPSMON_C
+       echo "NOCOMMWARNTIME $val" >> "$UPSMON_C"
 
        config_get val "$cfg" finaldelay 5
-       echo "FINALDELAY $val" >> $UPSMON_C
+       echo "FINALDELAY $val" >> "$UPSMON_C"
 
        config_get val "$cfg" certpath
-       if [ -n "$val" ]; then echo "CERTPATH $val" >> $UPSMON_C; fi
+       if [ -n "$val" ]; then echo "CERTPATH $val" >> "$UPSMON_C"; fi
 
        config_get_bool val "$cfg" certverify 0
-       if [ -n "$val" ]; then echo "CERTVERIFY $val" >> $UPSMON_C; fi
+       if [ -n "$val" ]; then echo "CERTVERIFY $val" >> "$UPSMON_C"; fi
 
        config_get_bool val "$cfg" forcessl 0
-       if [ -n "$val" ]; then echo "FORCESSL $val" >> $UPSMON_C; fi
+       if [ -n "$val" ]; then echo "FORCESSL $val" >> "$UPSMON_C"; fi
 }
 
 nut_upsmon_add() {
@@ -126,12 +127,6 @@ nut_upsmon_add() {
        local password
        local system
 
-       # if UPSMON_C is a symlink we're only doing generated config
-       [ -L $UPSMON_C ] && {
-               rm -f $UPSMON_C
-               nut_upsmon_conf ""
-       }
-
        config_get upsname "$cfg" upsname
        config_get hostname "$cfg" hostname localhost
        config_get port "$cfg" port
@@ -142,40 +137,49 @@ nut_upsmon_add() {
        if [ -n "$port" ]; then
            system="$system:$port";
        fi
-       echo "MONITOR $system $powervalue $username $password $type" >> $UPSMON_C
+       echo "MONITOR $system $powervalue $username $password $type" >> "$UPSMON_C"
 }
 
-start_service() {
-       mkdir -p "$(dirname "$UPSMON_C")"
-       chmod 750 "$(dirname "$UPSMON_C")"
+build_config() {
+       local runas
+       mkdir -m 0750 -p "$(dirname "$UPSMON_C")"
 
        config_load nut_monitor
-
        config_foreach nut_upsmon_conf upsmon
        config_foreach nut_upsmon_add master master
        config_foreach nut_upsmon_add slave slave
 
-       [ -z "$(cat /var/etc/nut/nut.conf)" ] && echo "MODE=netclient" >>/var/etc/nut/nut.conf
-
-       chmod 640 $UPSMON_C
-       chmod 640 /var/etc/nut/nut.conf
-
-       chown ${runas:-root}:$(id -gn ${runas:-root}) /var/etc/nut
-       chown ${runas:-root}:$(id -gn ${runas:-root}) /var/etc/nut/nut.conf
-       chown ${runas:-root}:$(id -gn ${runas:-root}) $UPSMON_C
-
-       [ -d /var/run/nut ] || {
-               mkdir -m 0750 -p /var/run/nut
-               chown ${runas:-root}:$(id -gn ${runas:-root}) /var/run/nut
+       [ -z "$(cat /var/etc/nut/nut.conf)" ] && {
+               echo "MODE=netclient" >>/var/etc/nut/nut.conf
+               chmod 640 /var/etc/nut/nut.conf
+               chgrp $(id -gn ${runas:-root}) /var/etc/nut/nut.conf
        }
 
-       exec $DEBUG /usr/sbin/upsmon $UPSMON_OPTIONS
+       chmod 640 "$UPSMON_C"
+       chgrp $(id -gn ${runas:-root}) "$UPSMON_C"
 }
 
-stop_service() {
-       exec /usr/sbin/upsmon -c stop
+start_service() {
+       build_config
+       procd_open_instance
+       procd_set_param respawn
+       procd_set_param stderr 0
+       procd_set_param stdout 1
+       procd_set_param command /usr/sbin/upsmon -D
+       procd_close_instance
 }
 
 reload_service() {
-       exec /usr/sbin/upsmon -c reload
+       if pgrep upsmon >/dev/null 2>/dev/null; then
+               build_config
+               upsmon -c reload
+       else
+               stop
+               sleep 1
+               start
+       fi
+}
+
+service_triggers() {
+       procd_add_reload_trigger nut_monitor
 }
index e064dd721358bb31681fca75f8ccb4146e31e9a6..73bf30ea183410fad316cb754dab013ba4546d03 100755 (executable)
@@ -6,47 +6,70 @@
 #
 START=50
 
-RUN_D=/var/run
-PID_F=$RUN_D/upsd.pid
-UPS_C=/var/etc/nut/ups.conf
 USERS_C=/var/etc/nut/upsd.users
 UPSD_C=/var/etc/nut/upsd.conf
+UPS_C=/var/etc/nut/ups.conf
 
 USE_PROCD=1
 
-listen_address() {
-    local cfg="$1"
+get_write_driver_config() {
+       local cfg="$1"
+       local var="$2"
+       local def="$3"
+       local flag="$4"
+       local val
 
-    config_get address "$cfg" address "::1"
-    config_get port "$cfg" port
-    echo "LISTEN $address $port" >>$UPSD_C
+       [ -z "$flag" ] && {
+               config_get val "$cfg" "$var" "$def"
+               [ -n "$val" ] && [ "$val" != "0" ] && echo "$var = $val" >>"$UPS_C"
+       }
+
+       [ -n "$flag" ] && {
+               config_get_bool val "$cfg" "$var" "$def"
+               [ "$val" = 1 ] && echo "$var" >>"$UPS_C"
+       }
 }
 
 upsd_statepath() {
+       local cfg="$1"
+       local statepath
+
+       config_get statepath "$cfg" statepath "/var/run/nut"
+       STATEPATH="$statepath"
+}
+
+listen_address() {
     local cfg="$1"
-    config_get statepath "$cfg" statepath
+
+    config_get address "$cfg" address "::1"
+    config_get port "$cfg" port
+    echo "LISTEN $address $port" >>"$UPSD_C"
 }
 
 upsd_config() {
     local cfg="$1"
-    local maxage maxconn certfile
+    local maxage maxconn certfile runas statepath
 
     # Note runas support requires you make sure USB device file is readable by
     # the runas user
-    config_get runas "$cfg" runas
+    config_get runas "$cfg" runas "nut"
+    RUNAS="$runas"
+
+    config_get statepath "$cfg" statepath "/var/run/nut"
+    STATEPATH="$statepath"
 
     config_get maxage "$cfg" maxage
-    [ -n "$maxage" ] && echo "MAXAGE $maxage" >>$UPSD_C
+    [ -n "$maxage" ] && echo "MAXAGE $maxage" >>"$UPSD_C"
 
     config_get statepath "$cfg" statepath
-    [ -n "$statepath" ] && echo "STATEPATH $statepath" >>$UPSD_C
+    [ -n "$statepath" ] && echo "STATEPATH $statepath" >>"$UPSD_C"
 
     config_get maxconn "$cfg" maxconn
-    [ -n "$maxconn" ] && echo "MAXCONN $maxconn" >>$UPSD_C
+    [ -n "$maxconn" ] && echo "MAXCONN $maxconn" >>"$UPSD_C"
 
     #NOTE: certs only apply to SSL-enabled version
     config_get certfile "$cfg" certfile
-    [ -n "$certfile" ] && echo "CERTFILE $certfile" >>$UPSD_C
+    [ -n "$certfile" ] && echo "CERTFILE $certfile" >>"$UPSD_C"
 }
 
 nut_user_add() {
@@ -55,104 +78,180 @@ nut_user_add() {
        local val
 
        config_get val "$cfg" username "$1"
-       echo "[$val]" >> $USERS_C
+       echo "[$val]" >> "$USERS_C"
 
        config_get val "$cfg" password
-       echo "  password = $val" >> $USERS_C
+       echo "  password = $val" >> "$USERS_C"
 
        config_get val "$cfg" actions
        for a in $val; do
-           echo "  actions = $a" >> $USERS_C
+           echo "  actions = $a" >> "$USERS_C"
        done
 
        instcmd() {
                local val="$1"
-               echo "  instcmds = $val" >> $USERS_C
+               echo "  instcmds = $val" >> "$USERS_C"
        }
 
        config_list_foreach "$cfg" instcmd instcmd
 
        config_get val "$cfg" upsmon
        if [ -n "$val" ]; then
-           echo "  upsmon $val" >> $USERS_C
+           echo "  upsmon $val" >> "$USERS_C"
        fi
 }
 
-start_service() {
-       local runas statepath
-
-        mkdir -p /var/etc/nut
-       chmod -R 750 /var/etc/nut
-
-       rm -f $UPSD_C
-       rm -f $USERS_C
-       rm -f $UPSD_C
+build_server_config() {
+        mkdir -m 0755 -p "$(dirname "$UPSD_C")"
+       rm -f "$USERS_C"
+       rm -f "$UPSD_C"
        rm -f /var/etc/nut/nut.conf
 
-       echo "# Config file automatically generated from UCI config" > $UPS_C
-       echo "# Config file automatically generated from UCI config" > $USERS_C
-       echo "# Config file automatically generated from UCI config" > $UPSD_C
-
-        local in_driver have_drivers
-       config_cb() {
-           if [ "$1" != "driver" ]; then
-               in_driver=
-           else
-               echo "[$2]" >> $UPS_C
-               in_driver=true
-               have_drivers=true
-           fi
-       }
-       option_cb() {
-           if [ "$in_driver" = "true" ]; then
-               echo " $1 = $2" >> $UPS_C
-           fi
-       }
-
-       config_load nut_server
+       echo "# Config file automatically generated from UCI config" > "$USERS_C"
+       echo "# Config file automatically generated from UCI config" > "$UPSD_C"
 
        config_foreach nut_user_add user
-       config_foreach upsd_config upsd
        config_foreach listen_address listen_address
-
+       config_foreach upsd_config upsd
        echo "MODE=netserver" >>/var/etc/nut/nut.conf
 
-       chmod 0640 $USERS_C
-       chmod 0640 $UPS_C
-       chmod 0640 $UPSD_C
+       chmod 0640 "$USERS_C"
+       chmod 0640 "$UPSD_C"
        chmod 0640 /var/etc/nut/nut.conf
-       [ -d "${statepath:-/var/run/nut}" ] || {
-               mkdir -m 0750 -p "${statepath:-/var/run/nut}"
-               chown $runas:$(id -gn $runas) "${statepath:-/var/run/nut}"
+
+       [ -d "${STATEPATH}" ] || {
+               mkdir -m 0750 -p "${STATEPATH}"
        }
 
-       if [ -n "$runas" ]; then
-               chown -R $runas:$(id -gn $runas) /var/etc/nut
+       if [ -n "$RUNAS" ]; then
+               chown $RUNAS:$(id -gn $RUNAS) "${STATEPATH}"
+               chgrp $(id -gn $RUNAS) "$USERS_C"
+               chgrp $(id -gn $RUNAS) "$UPSD_C"
        fi
+}
 
-       if [ "$have_drivers" = "true" ]; then
-           $DEBUG /usr/sbin/upsd ${runas:+-u $runas} $OPTIONS
-           $DEBUG /usr/sbin/upsdrvctl ${runas:+-u $runas} start
-       fi
+build_driver_config() {
+       local cfg="$1"
+       local runas
+
+       echo "[$cfg]" >>"$UPS_C"
+
+       config_get runas "$cfg" runas "nut"
+       RUNAS="$runas"
+
+       get_write_driver_config "$cfg" driver "usbhid-ups"
+       get_write_driver_config "$cfg" port "auto"
+       get_write_driver_config "$cfg" mfr
+       get_write_driver_config "$cfg" model
+       get_write_driver_config "$cfg" serial
+       get_write_driver_config "$cfg" sdtime
+       get_write_driver_config "$cfg" offdelay 20
+       get_write_driver_config "$cfg" ondelay 30
+       get_write_driver_config "$cfg" pollfreq 30
+       get_write_driver_config "$cfg" vendor
+       get_write_driver_config "$cfg" product
+       get_write_driver_config "$cfg" bus
+       get_write_driver_config "$cfg" interruptonly 0 1
+       get_write_driver_config "$cfg" interruptsize 0
+       get_write_driver_config "$cfg" maxreport
+       get_write_driver_config "$cfg" vendorid
+       get_write_driver_config "$cfg" productid
+       get_write_driver_config "$cfg" community
+       get_write_driver_config "$cfg" snmp_version
+       get_write_driver_config "$cfg" snmp_retries 0
+       get_write_driver_config "$cfg" snmp_timeout 0
+       get_write_driver_config "$cfg" notransferoids 0 1
+       get_write_driver_config "$cfg" other
+       echo "" >>$UPS_C
 }
 
+build_config() {
+        mkdir -m 0755 -p "$(dirname "$UPS_C")"
+       rm -f "$UPS_C"
+       echo "# Config file automatically generated from UCI config" > "$UPS_C"
+       chmod 0640 "$UPS_C"
+
+       config_load nut_server
+       config_foreach build_driver_config driver
+       [ -n "$RUNAS" ] && chgrp $(id -gn $RUNAS) "$UPS_C"
 
-nut_driver_stop() {
+       build_server_config
+}
+
+start_driver_instance() {
        local cfg="$1"
+       local requested="$2"
+       local RUNAS=nut
        local driver
 
-       config_get driver "$cfg" driver
+       # If wanting a specific instance, only start it
+       [ "$requested" != "$cfg" ] && [ x"$requested" != x"" ] && return 0
+
+       mkdir -m 0755 -p "$(dirname "$UPS_C")"
+
+       [ ! -s "$UPS_C" ] && build_config
+
 
-       [ -r ${statepath:-/var/run/nut}/$driver-$cfg ] && /usr/sbin/upsdrvctl stop $cfg
+       # Avoid hotplug inadvertenly restarting driver during
+       # forced shutdown
+       [ -f /var/run/killpower ] && return 0
+       [ -d /var/run/nut ] && [ -f /var/run/nut/disable-hotplug ] && return 0
+
+
+       if [ -n "$RUNAS" ]; then
+               chown $RUNAS:$(id -gn $RUNAS) "${STATEPATH}"
+               chown $RUNAS:$(id -gn $RUNAS) "$(dirname "$UPS_C")"
+       fi
+
+       config_get driver "$cfg" driver "usbhid-ups"
+       procd_open_instance "$cfg"
+       procd_set_param respawn
+       procd_set_param stderr 0
+       procd_set_param stdout 1
+       procd_set_param command /lib/nut/${driver} -D -a "$cfg" ${RUNAS:+-u $RUNAS}
+       procd_close_instance
+}
+
+start_server_instance() {
+       local RUNAS STATEPATH
+       build_config
+
+       procd_open_instance "upsd"
+       procd_set_param respawn
+       procd_set_param stderr 0
+       procd_set_param stdout 1
+       procd_set_param command /usr/sbin/upsd -D ${RUNAS:+-u $RUNAS}
+       procd_close_instance
 }
 
-stop_service() {
-       [ -r $PID_F ] && /usr/sbin/upsd -c stop
-       config_load ups
+start_service() {
+       local STATEPATH=/var/run/nut
+
+       # Avoid hotplug inadvertenly restarting driver during
+       # forced shutdown
+       [ -f /var/run/killpower ] && return 0
+       [ -d /var/run/nut ] && [ -f /var/run/nut/disable-hotplug ] && return 0
+
+       config_load nut_server
        config_foreach upsd_statepath upsd
-       config_foreach nut_driver_stop driver
+
+       [ -d "${STATEPATH}" ] || {
+               mkdir -m 0750 -p "${STATEPATH}"
+       }
+
+       build_config
+       config_foreach start_driver_instance driver "$@"
+
+       [ "$1" != "upsd" ] && [ x"$1" != x"" ] && return 0
+       start_server_instance "upsd"
 }
 
 reload_service() {
-       upsd -c reload
+       stop
+       sleep 2
+       start
+}
+
+service_triggers() {
+       procd_add_reload_trigger "nut_server"
 }
index 9f0bed6fc10f42370651b2c450c8ce6b25bad7e0..dca5de07cc645d5ceedd17bbc26f24c4a70a3bbc 100644 (file)
@@ -4,3 +4,5 @@
 #      option port # optional port number
 #      option displayname "Display Name"
 
+config upsset
+       option enable 0
index 0b71e95cf05b46da7be6bac3046bdac46b696bf4..59e0f360daeeb02b342feaecee12293d7f268522 100644 (file)
@@ -1,14 +1,13 @@
 #config upsmon 'upsmon'
-#      option runas run-as-user
+#      option runas nutmon
 #      option minsupplies 1
-#      option shutdowncmd /sbin/halt
+#      option shutdowncmd '/usr/sbin/nutshutdown'
 #      option notifycmd /path/to/cmd
 #      list defaultnotify SYSLOG
 #      option pollfreq 5
 #      option pollfreqalert 5
 #      option hostsync 15
 #      option deadtime 15
-#      option powerdownflags /var/run/killpower
 #      option onlinemsg "online message"
 #      option onbattmsg "on battery message"
 #      option lowbattmsg "low battery message"
@@ -51,4 +50,3 @@
 #      option powervalue 1
 #      option username upsuser
 #      option password upspassword
-
index bebd169db61756adaaceb6889005c0abdfdb4521..464d56303be09e87fd9484b79c7012a203f684db 100644 (file)
@@ -19,5 +19,6 @@
 #      option maxage 15
 #      option statepath /var/run/nut
 #      option maxconn 1024
+#      option runas nut
 # NB: certificates only apply to SSL-enabled version
 #       option certfile /usr/local/etc/upsd.pem
diff --git a/net/nut/files/nutshutdown b/net/nut/files/nutshutdown
new file mode 100755 (executable)
index 0000000..e4fd962
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/sh
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+. /lib/functions.sh
+
+mount -o remount,ro /overlay /overlay
+mount -o remount,ro / /
+
+stop_instance() {
+       /etc/init.d/nut-server stop "$1"
+}
+
+shutdown_instance() {
+       local cfg="$1"
+       config_get driver "$cfg" driver "usbhid-ups"
+       /lib/nut/${driver} -a "$cfg" -k
+}
+
+[ -f /var/run/killpower ] && {
+       [ -f /etc/config/nut_server ] && {
+               config_load nut_server
+
+               # Can't FSD unless drivers are stopped
+               config_foreach stop_instance driver
+               # Driver will  wait 'offdelay' before shutting down
+               config_foreach shutdown_instance driver
+               # So this can happen
+               poweroff
+               # And just in case
+               sleep 120
+               # Uh-oh failed to poweroff UPS
+               reboot -f
+       } || {
+               poweroff
+       }
+} || {
+       poweroff
+}
index 3885e15813a846c6c1bb0b16deb9c4ed4074380d..be57601071994202428f126834a9e15735b953b2 100644 (file)
@@ -1,6 +1,4 @@
 #
-# Copyright (C) 2006-2015 OpenWrt.org
-#
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
 #
@@ -9,7 +7,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=socat
 PKG_VERSION:=1.7.3.2
-PKG_RELEASE:=2
+PKG_RELEASE:=3
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
 PKG_SOURCE_URL:=http://www.dest-unreach.org/socat/download
@@ -63,11 +61,21 @@ ifneq ($(CONFIG_SOCAT_SSL),y)
   CONFIGURE_ARGS+= --disable-openssl
 endif
 
+# PowerPC has different TERMIOS bits
+ifneq ($(findstring powerpc,$(CONFIG_ARCH)),)
+  CONFIGURE_VARS += \
+         sc_cv_sys_crdly_shift=12 \
+         sc_cv_sys_tabdly_shift=10 \
+         sc_cv_sys_csize_shift=8
+else
+  CONFIGURE_VARS += \
+         sc_cv_sys_crdly_shift=9 \
+         sc_cv_sys_tabdly_shift=11 \
+         sc_cv_sys_csize_shift=4
+endif
+
 CONFIGURE_VARS += \
        sc_cv_termios_ispeed="no" \
-       sc_cv_sys_crdly_shift=9 \
-       sc_cv_sys_tabdly_shift=11 \
-       sc_cv_sys_csize_shift=4 \
        ac_cv_header_bsd_libutil_h=no \
        ac_cv_lib_bsd_openpty=no \
        BUILD_DATE=$(SOURCE_DATE_EPOCH)
index a6827e207df2d0b464bdbdc6cf0a3b9a79407654..24dbc9c736b576e92263690594c216dbd20db326 100644 (file)
@@ -14,7 +14,7 @@ PKG_RELEASE:=1
 PKG_SOURCE_URL:=https://codeload.github.com/arduino/YunBridge/tar.gz/$(PKG_VERSION)?
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_HASH:=9e5ffc7a0d0cc2c92e972e425adcc49b77cf39da075d31728e7755d316d910d8
-PKG_BUILD_DIR:=YunBridge-$(PKG_VERSION)
+PKG_BUILD_DIR:=$(BUILD_DIR)/YunBridge-$(PKG_VERSION)
 
 PKG_MAINTAINER:=John Crispin <blogic@openwrt.org>
 PKG_LICENSE:=GPL-2.0