2016-03-31 02:06:44 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
|
|
|
|
# Copyright (C) 2014 Alexander Keller <github@nycroth.com>
|
|
|
|
|
|
|
|
# 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
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Use the provided interface, otherwise the device used for the default route.
|
|
|
|
if [[ -n $BLOCK_INSTANCE ]]; then
|
2016-04-17 22:33:20 +00:00
|
|
|
IF=$BLOCK_INSTANCE
|
2016-03-31 02:06:44 +00:00
|
|
|
else
|
2016-04-17 22:33:20 +00:00
|
|
|
IF=$(ip route | awk '/^default/ { print $5 ; exit }')
|
2016-03-31 02:06:44 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# As per #36 -- It is transparent: e.g. if the machine has no battery or wireless
|
|
|
|
# connection (think desktop), the corresponding block should not be displayed.
|
|
|
|
[[ ! -d /sys/class/net/${IF} ]] && exit
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
|
2016-10-04 12:57:35 +00:00
|
|
|
if [[ -z $IF ]] || [[ "$(cat /sys/class/net/$IF/operstate)" = 'down' ]]; then
|
2016-04-17 22:33:20 +00:00
|
|
|
echo down # full text
|
|
|
|
echo down # short text
|
|
|
|
echo \#FF0000 # color
|
|
|
|
exit
|
2016-03-31 02:06:44 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
case $1 in
|
2016-04-17 22:33:20 +00:00
|
|
|
-4) AF=inet ;;
|
|
|
|
-6) AF=inet6 ;;
|
|
|
|
*) AF=inet6? ;;
|
2016-03-31 02:06:44 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
# if no interface is found, use the first device with a global scope
|
|
|
|
LOCIP=$(ip addr show $IF | perl -n -e "/$AF ([^\/]+).* scope global/ && print \$1 and exit")
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
|
|
|
|
case $BLOCK_BUTTON in
|
2018-03-29 10:53:27 +00:00
|
|
|
1) curl -s https://api.ipify.org;
|
|
|
|
break;;
|
|
|
|
2) curl -s https://api.ipify.org | tee >(xclip -i);
|
|
|
|
break;;
|
2018-03-29 14:59:41 +00:00
|
|
|
0|3) echo "$LOCIP" | tee >(xclip -i);
|
|
|
|
break;;
|
|
|
|
*) echo "$LOCIP"
|
2018-03-29 10:53:27 +00:00
|
|
|
break;;
|
2016-03-31 02:06:44 +00:00
|
|
|
esac
|