#/bin/bash
# stats.sh by n1x4 <https://github.com/n1x4/bin/blob/master/stats.sh>

clear
declare -rx BC="/usr/bin/bc"

if test -f $HOME/.gtkrc-2.0;then
    GTK=$HOME/.gtkrc-2.0
else
    GTK=$HOME/.gtkrc-3.0
fi

if test ! -x $BC; then
    echo -e "\e[0;5;31m$BC is not available, please install before continuing."
    exit 192
fi

host=`cat /proc/sys/kernel/hostname`
mem_total=`free -m | grep "Mem" | awk '{print $2}'`
mem_used=`free -m | grep "buffers/" | awk '{print $3}'`
hd_used=`df | grep "sda" | awk '{print $3}'`
hd_total=`df | grep "sda" | awk '{print $2}'`
type=`df -T | grep "sda" | awk '{print $2}'`
idle=`cat /proc/uptime | awk '{print $2}'`
kernel=`cat /proc/version | awk '{print $3}'`
cpu=`cat /proc/cpuinfo | grep "model name" | awk '{print $4,$5,$6, $7}'`
theme=`cat $GTK | grep "gtk-theme-name" | cut -d= -f2 | tr -d '"'`
icon=`cat $GTK | grep "gtk-icon-theme-name" | cut -d= -f2 | tr -d '"'`
font=`cat $GTK | grep "gtk-font-name" | cut -d= -f2 | tr -d '"'`

function uptime() {
	uptime=$(</proc/uptime)
    uptime=${uptime%%.*}

    seconds=$(( uptime%60 ))
    minutes=$(( uptime/60%60 ))
    hours=$(( uptime/60/60%24 ))
    days=$(( uptime/60/60/24 ))
    echo -e $days"-days", $hours"-hrs" $minutes"-mins" $seconds"-s"
}

echo -e "\e[1;33mUptime\e[0m:   $(uptime)"
echo -e "\e[1;33mKernel\e[0m:   $kernel"
echo -e "\e[1;33mHostname\e[0m: $host"
echo -e "\e[1;33mCPU\e[0m:      $cpu"
echo -e "\e[1;33mRAM\e[0m:      $mem_used Mb / $mem_total Mb (\e[0;31m$(($mem_used*100/$mem_total))\e[0m%)"
echo -e "\e[1;33mROOT\e[0m:     $(echo "scale=3; $hd_used/1000000" | bc) Gb / $(echo "scale=3; $hd_total/1000000" | bc) Gb (\e[0;31m$(($hd_used*100/$hd_total))\e[0m%) ($type)"
echo -e "\e[1;33mTheme\e[0m:    $theme"
echo -e "\e[1;33mIcons\e[0m:    $icon"
echo -e "\e[1;33mFont\e[0m:     $font"
echo -e "\n"
echo -e "Colors:\n\e[0;30m###### \e[0;31m###### \e[0;32m###### \e[0;33m###### \e[0;34m###### \e[0;35m###### \e[0;36m###### \e[0;37m######\e[0m"
echo -e "\e[1;30m###### \e[1;31m###### \e[1;32m###### \e[1;33m###### \e[1;34m###### \e[1;35m###### \e[1;36m###### \e[1;37m######\e[0m\n"
exit 0