[Arch] fix network, delete bar_scripts
[dotfiles_afify.git] / .scripts / network
blobed6cb01cae366227736f1c8c43370378807daa28
1 #!/usr/bin/env bash
3 wifi_icon="直"
4 eth_icon=""
5 other_icon="禍"
6 bpm=1048576 # 1024*1024
7 up_interfaces=$(ifconfig | grep "UP,BROADCAST,RUNNING" |\
8 sed 's/://' | awk '{print $1}')
9 up_type=
10 ssid_strength=
12 check_type(){
13 case $(uname) in
14 Linux) case $1 in
15 wlp*) up_type=wlan ;;
16 enp*) up_type=eth ;;
17 *) up_type=other ;;
18 esac ;;
19 OpenBSD) up_type=$(ifconfig $1 | grep "groups" | awk '{print $2}') ;;
20 esac
23 get_ssid_strength(){
24 if [[ "$up_type" == "wlan" ]]; then
25 case $(uname) in
26 Linux)
27 wifi_ssid=$(iw dev $1 link | grep SSID | cut -d " " -f 2-)
28 wifi_strength=$(grep "^\s*w" /proc/net/wireless |\
29 awk '{print int($3 * 100 / 70) "%"}')
30 ssid_strength='\n'$wifi_ssid' '$wifi_strength;;
32 OpenBSD) ssid_strength=$(echo "$int" | grep join |\
33 awk '{print "\n"$3"\t"int((-0.0154*$8*$8)-(0.3794*$8)+98.182)"%"}');;
34 esac
39 print_status(){
40 for each_interface in $up_interfaces; do
41 case $(uname) in
42 Linux) total_in=$(
43 cat /sys/class/net/$each_interface/statistics/rx_bytes);;
44 OpenBSD) total_in=$(netstat -b -I $each_interface |\
45 egrep "[0-9]{2}:" | awk '{print $5}');;
46 esac
47 check_type $each_interface
48 case $up_type in
49 egress) icon=$other_icon ;;
50 wlan) icon=$wifi_icon ;;
51 eth) icon=$eth_icon ;;
52 *) icon=$other_icon ;;
53 esac
54 in_sum=$(($total_in / $bpm))
55 result+=$icon' '$in_sum' '
56 done
57 echo $result
60 notify_status(){
61 for each_interface in $up_interfaces; do
62 int=$(ifconfig $each_interface)
63 ip=$(echo "$int" | grep 'inet ' | awk '{print $2}')
64 check_type $each_interface
65 get_ssid_strength $each_interface
66 result+="$up_type\t($each_interface)$ssid_strength\n$ip\n\n"
67 done
68 notify-send "Network details" "$result"
71 case $1 in
72 notify) notify_status ;;
73 *) print_status ;;
74 esac