improve and fix issues shellcheck
This commit is contained in:
parent
1c9a6121ab
commit
557015eaa0
@ -1,6 +1,7 @@
|
||||
#!/bin/bash
|
||||
# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
|
||||
# Copyright (C) 2014 Alexander Keller <github@nycroth.com>
|
||||
# Copyright (C) 2019 Jesús E. <heckyel@hyperbola.info>
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@ -18,10 +19,10 @@
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
# Use the provided interface, otherwise the device used for the default route.
|
||||
if [[ -n $BLOCK_INSTANCE ]]; then
|
||||
IF=$BLOCK_INSTANCE
|
||||
else
|
||||
IF=$(ip route | awk '/^default/ { print $5 ; exit }')
|
||||
if [[ -z $IF ]] && [[ -n $BLOCK_INSTANCE ]]; then
|
||||
IF=$BLOCK_INSTANCE
|
||||
elif [[ -z $IF ]]; then
|
||||
IF=$(ip route | awk '/^default/ { print $5 ; exit }')
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
@ -32,27 +33,27 @@ fi
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
if [[ "$(cat /sys/class/net/$IF/operstate)" = 'down' ]]; then
|
||||
echo down # full text
|
||||
echo down # short text
|
||||
echo \#FF0000 # color
|
||||
exit
|
||||
if [[ "$(cat "/sys/class/net/$IF/operstate")" = 'down' ]]; then
|
||||
echo down # full text
|
||||
echo down # short text
|
||||
echo \#FF0000 # color
|
||||
exit
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
-4)
|
||||
AF=inet ;;
|
||||
-6)
|
||||
AF=inet6 ;;
|
||||
*)
|
||||
AF=inet6? ;;
|
||||
-4)
|
||||
AF=inet ;;
|
||||
-6)
|
||||
AF=inet6 ;;
|
||||
*)
|
||||
AF=inet6? ;;
|
||||
esac
|
||||
|
||||
# if no interface is found, use the first device with a global scope
|
||||
IPADDR=$(ip addr show $IF | perl -n -e "/$AF ([^\/]+).* scope global/ && print \$1 and exit")
|
||||
IPADDR=$(ip addr show "$IF" | perl -n -e "/$AF ([^\/]+).* scope global/ && print \$1 and exit")
|
||||
|
||||
case $BLOCK_BUTTON in
|
||||
3) echo -n "$IPADDR" | xclip -q -se c ;;
|
||||
3) echo -n "$IPADDR" | xclip -q -se c ;;
|
||||
esac
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user