-
-
Save slavaaaaaaaaaa/5633066 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function dagd { | |
if [ $1 -eq '-6' ]; then | |
curl -m 2 -s "http://da.gd/$2" | |
else | |
curl -m 2 -s -4 "http://da.gd/$2?strip" | |
fi | |
} | |
function remote_network { | |
# set some magical temporary stuff | |
_IPV4_ADDRESS=$(dagd -4 ip) | |
_IPV6_ADDRESS=$(dagd -6 ip) | |
_IPV4_ISP=$(dagd -4 isp) | |
_IPV6_ISP=$(dagd -6 isp) | |
echo -e "\tRemote IP Addresses:" | |
if [ "$_IPV4_ADDRESS" ]; then | |
echo -e "\t\tExternal IPv4 Address: $_IPV4_ADDRESS ($_IPV4_ISP)" | |
else | |
echo -e "\t\tExternal Networking Offline" | |
fi | |
if [[ "$_IPV4_ADDRESS" != "$_IPV6_ADDRESS" ]]; then | |
echo -e "\t\tExternal IPv6 Address: $_IPV6_ADDRESS ($_IPV6_ISP)" | |
fi | |
} | |
function battery { | |
which upowerd > /dev/null 2>&1 | |
if [ $? -eq 0 ]; then | |
if upower -e|grep -q battery; then | |
echo -e "\\e[34;1mBattery:\\e[m" | |
export BATT=$(timeout 2.5s upower -i /org/freedesktop/UPower/devices/battery_BAT0|grep :|grep -E "^ "|awk 'BEGIN { FS = " "; ORS = "\\0" } { print $(1) " " $(2) " " $(3) " " $(4) " " $(5) }') | |
echo " "`echo -e $BATT|grep -z state|cut -d " " -f 2` at `echo -e $BATT|grep -z energy-rate|cut -d " " -f 2,3` | |
echo " "`echo -e $BATT|grep -z 'time to'|cut -d " " -f 4,5` `echo -e $BATT|grep -z 'time to'|cut -d " " -f 2,3|head -c -2` "("`echo -e $BATT|grep -z percentage|cut -d " " -f 2`")" | |
fi | |
else | |
which ioreg > /dev/null 2>&1 | |
if [ $? -eq 0 ]; then | |
export BATT=$(ioreg -l | grep -i capacity | tr '\n' ' | ' | awk '{printf("%.2f%%", $10/$5 * 100)}') | |
echo -e "\tBattery: Battery at $BATT" | |
else | |
echo -e "\tBattery: Not Detected..." | |
fi | |
fi | |
} | |
function userinfo { | |
echo -e "\tYou are `whoami` on `hostname`" | |
} | |
function local_network { | |
raw_interfaces=$(ifconfig | | |
perl -ane ' | |
END{print "\042", join("\042 \042", @a), "\042\n"} | |
$a[$c++] = $1 if /^(\w+)/; | |
') | |
interfaces=($raw_interfaces) | |
echo -e "\tLocal Network Interfaces:" | |
for interface in "${interfaces[@]}" | |
do | |
address=$(ifconfig `echo $interface | sed "s/\"//g"`|awk '{ if ( $1 == "inet" ) { print $2 } }') | |
if [ $address ]; then | |
echo -e "\t\tInterface $interface has address $address" | |
fi | |
done | |
} | |
function sysmem { | |
echo -e "\tSystem Memory:" | |
if [ "$OSTYPE" == "linux-gnu" ]; then | |
_MEMPERCENT=$((`free -m | grep '+' | awk {'print $3'}`*100/`free -m | grep 'Mem:' | awk {'print $2'}`))% | |
echo -e "\t\tMem: $((`free -m | grep '+' | awk {'print $3'}`*100/`free -m | grep 'Mem:' | awk {'print $2'}`))% (`free -m | grep '+' | awk {'print $3'}`MB) from `free -m | grep 'Mem:' | awk {'print $2'}`MB" | |
else | |
FREE_BLOCKS=$(vm_stat | grep free | awk '{ print $3 }' | sed 's/\.//') | |
INACTIVE_BLOCKS=$(vm_stat | grep inactive | awk '{ print $3 }' | sed 's/\.//') | |
SPECULATIVE_BLOCKS=$(vm_stat | grep speculative | awk '{ print $3 }' | sed 's/\.//') | |
FREE=$((($FREE_BLOCKS+SPECULATIVE_BLOCKS)*4096/1048576)) | |
INACTIVE=$(($INACTIVE_BLOCKS*4096/1048576)) | |
TOTAL=$((($FREE+$INACTIVE))) | |
MEMPERCENT=$(($FREE/$TOTAL)) | |
echo -e "\t\tCurrently using `echo $FREE $TOTAL | awk '{printf("%.f%%", $1/$2 * 100)}'` of RAM with $FREE MB of RAM free." | |
fi | |
} | |
function system_overview { | |
_LOAD=$(uptime | grep -ohe 'load average[s:][: ].*' | awk '{ print $3 }') | |
_UPTIME=$(uptime | grep -ohe 'up .*' | sed 's/,//g' | awk '{ print $2 }') | |
_PROCESSES=$(ps aux|wc -l) | |
_ARCH=$(uname -m) | |
_UNAME=$(uname -a) | |
_USERS=$(who | sort | wc -l) | |
if [ "$_UNAME" = *Linux* ]; then | |
_OS=$(uname -or) | |
else | |
_OS=$(uname -rs) | |
fi | |
echo -e "\tGeneral System Information:" | |
echo -e "\t\tOperating System: $_OS\t\tUsers: $_USERS\n\t\tProcesses: $_PROCESSES\t\t\tSystem Uptime: $_UPTIME\n\t\tSystem Load: $_LOAD\t\t\tArchitecture: $_ARCH" | |
} | |
userinfo | |
sysmem | |
system_overview | |
battery | |
local_network | |
remote_network |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment