[iface] refactoring
This commit is contained in:
parent
a2d8e3bf02
commit
b200c2cf3f
@ -87,8 +87,8 @@ interval=30
|
||||
# instance=eth0
|
||||
# instance=wlp2s0
|
||||
color=#00FF00
|
||||
# interval=10
|
||||
interval=once
|
||||
interval=10
|
||||
# interval=once
|
||||
separator=false
|
||||
|
||||
# [wifi]
|
||||
|
@ -19,11 +19,11 @@
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
# Use the provided interface, otherwise the device used for the default route.
|
||||
if [[ -z $IF ]] && [[ -n $BLOCK_INSTANCE ]]; then
|
||||
IF=$BLOCK_INSTANCE
|
||||
elif [[ -z $IF ]]; then
|
||||
IF=$(ip route | awk '/^default/ { print $5 ; exit }')
|
||||
fi
|
||||
IF="${IFACE:-$BLOCK_INSTANCE}"
|
||||
IF="${IF:-$(ip route | awk '/^default/ { print $5 ; exit }')}"
|
||||
|
||||
# Exit if there is no default route
|
||||
[[ -z "$IF" ]] && exit
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
@ -33,21 +33,30 @@ fi
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
if [[ "$(cat "/sys/class/net/$IF/operstate")" = 'down' ]]; then
|
||||
echo down # full text
|
||||
echo down # short text
|
||||
echo \#FF0000 # color
|
||||
exit
|
||||
fi
|
||||
AF=${ADDRESS_FAMILY:-inet6?}
|
||||
LABEL="${LABEL:-}"
|
||||
|
||||
case $1 in
|
||||
for flag in "$1" "$2"; do
|
||||
case "$flag" in
|
||||
-4)
|
||||
AF=inet ;;
|
||||
-6)
|
||||
AF=inet6 ;;
|
||||
*)
|
||||
AF=inet6? ;;
|
||||
-L)
|
||||
if [[ "$IF" = "" ]]; then
|
||||
LABEL="iface "
|
||||
else
|
||||
LABEL="$IF: "
|
||||
fi ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ "$IF" = "" ]] || [[ "$(cat "/sys/class/net/$IF/operstate")" = 'down' ]]; then
|
||||
echo "${LABEL}down" # full text
|
||||
echo "${LABEL}down" # short text
|
||||
echo \#FF0000 # color
|
||||
exit
|
||||
fi
|
||||
|
||||
# look for the vpn connection, if no interface is found, use the first device with a global scope
|
||||
if [[ $(ip addr show tun0) ]]; then
|
||||
@ -62,5 +71,5 @@ esac
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
echo "$IPADDR" # full text
|
||||
echo "$IPADDR" # short text
|
||||
echo "$LABEL$IPADDR" # full text
|
||||
echo "$LABEL$IPADDR" # short text
|
||||
|
Loading…
x
Reference in New Issue
Block a user