Added Some Tools. New Readme

This commit is contained in:
Cyrille L 2022-03-14 16:19:42 +01:00
parent f2a6d12423
commit 8355a6ffa3
3 changed files with 304 additions and 1 deletions

View File

@ -19,10 +19,16 @@ As bash scripts, you will have to manually edit /etc/bash.bashrc and
add - according to your needs - a load script line
```
# Change Prompt with this one
# Getting Tools...
[[ -f /etc/profile.d/echolib/tools.sh ]] && . /etc/profile.d/echolib/tools.sh
# To Change Prompt with this one
[[ -f /etc/profile.d/echolib/prompt.sh ]] && . /etc/profile.d/echolib/prompt.sh
```
# How lo list tools ?
```
echolib
```
# ToDo ?
There will be a lot more to come soon. Maybe then, i will create a setup
to help you install what you need.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View File

@ -0,0 +1,297 @@
#!/bin/bash
# file: tools.sh
# Folder: /etc/profile.d/echolib/
# By echolib
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
#======================================================================
# Main
#======================================================================
echolib() {
# Helps for echolib in function
echolib__help() {
clear
cat << EOHELP
# Tools in /etc/profile.d/echolib/tools.sh
# Commands available
$ cpul : Check CPU load, load average, and highest process
$ isadmin : Check $USER sudo rights
$ isco : Check if connected. See isco --help
$ dlup : Show Internal IP + DL/UP Speed
EOHELP
}
case "$1" in
--help|-h|help|*)
echolib__help
;;
esac
}
#======================================================================
# ---------------------------------
# Usefull Tools for echolib scripts
# ---------------------------------
#======================================================================
#======================================================================
# Set Colors
#======================================================================
NC="\e[0m"
C_Blue="\e[34m"
C_Cyan="\e[36m"
C_Green="\e[32m"
C_Grey="\e[2m"
C_Pink="\e[35m"
C_Red="\e[31m"
C_White="\e[1m"
C_Yellow="\e[33m"
#======================================================================
# Set Separators / Markers Colors
#======================================================================
I_Blue="\e[34m#\e[0m"
I_Cyan="\e[36m#\e[0m"
I_Green="\e[32m#\e[0m"
I_Grey="\e[2m#\e[0m"
I_Pink="\e[35m#\e[0m"
I_Red="\e[31m!\e[0m"
I_White="\e[1m#\e[0m"
I_Yellow="\e[33m#\e[0m"
#======================================================================
# Set Other markers colors
#======================================================================
P_Grey="\e[2m%\e[0m"
Bo_Grey="\e[2m(\e[0m"
Bc_Grey="\e[2m)\e[0m"
Pp_Grey="\e[2m|\e[0m"
Dp_Grey="\e[2m:\e[0m"
#======================================================================
# Set linuxè_pkg : Which System in use
#======================================================================
linux__pkg() {
[[ `command -v pacman` ]] \
&& linux_pkg="pacman" \
&& return
[[ `command -v apt-get` ]] \
&& linux_pkg="apt" \
&& return
}
#======================================================================
# Set : Is user Root or Sudo
#======================================================================
isadmin() {
is__admin_show() {
echo -e "$isa_c $USER ${C_Grey}is$NC $user_admin"
}
if_admin=`id -u`
if (( $if_admin )) && (( $if_admin == 0 ));then
is_admin="${C_Red}root$NC"
user_admin=$is_admin
isa_c="$I_Red"
is__admin_show
return
fi
if ! [[ `command -v sudo` ]];then
is_admin="user"
user_admin="${C_Cyan}a simple user$NC"
isa_c="$I_Cyan"
is__admin_show
return
fi
user_prompt=`sudo -nv 2>&1`
code_return="$?"
if (( $code_return == 1 ));then
is_admin="sudo-1"
user_admin="${C_Green}not in sudo mode$NC"
isa_c="$I_Green"
else
is_admin="sudo-0"
user_admin="${C_Yellow}in sudo mode$NC"
isa_c="$I_Yellow"
fi
is__admin_show
}
#======================================================================
# Check CPU Load
#======================================================================
cpul() {
cpu__set_colors() {
if (( $1 <= 10 ));then
cpu_ic="$I_White"
cpu_sc="$C_White"
elif (( $1 > 10 && $1 <= 19 ));then
cpu_ic="$I_Cyan"
cpu_sc="$C_Cyan"
elif (( $1 >= 20 && $1 <= 39 ));then
cpu_ic="$I_Green"
cpu_sc="$C_Green"
elif (( $1 >= 40 && $1 <= 69 ));then
cpu_ic="$I_Yellow"
cpu_sc="$C_Yellow"
elif (( $1 >= 70 ));then
cpu_ic="$I_Red"
cpu_sc="$C_Red"
fi
}
# CPU Usage
cpu_raw=`
grep 'cpu ' /proc/stat \
| awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage}'`
cpul=(${cpu_raw%.*})
cpu__set_colors $cpul
cpu_show="$cpu_ic CPU: ${cpu_sc}$cpul$NC$P_Grey $Pp_Grey "
# CPU Load Average
cpu_lav=(`awk '{print $1,$2,$3}' /proc/loadavg`)
cpu_la0=`awk -v l0="${cpu_lav[0]}" 'BEGIN{print l0 * 100}'`
cpu_la1=`awk -v l1="${cpu_lav[1]}" 'BEGIN{print l1 * 100}'`
cpu_la2=`awk -v l2="${cpu_lav[2]}" 'BEGIN{print l2 * 100}'`
cpu__set_colors $cpu_la0
cpul0="$cpu_sc$cpu_la0$NC"
cpu__set_colors $cpu_la1
cpul1="$cpu_sc$cpu_la1$NC"
cpu__set_colors $cpu_la2
cpul2="$cpu_sc$cpu_la2$NC"
cpu_show+="Load: $cpul0$P_Grey $cpul1$P_Grey $cpul2$P_Grey $Pp_Grey"
# CPU Higher App
cpu_app=(`
command ps aux --no-header \
| sort -k 3 \
| tail -1 \
| awk '{print $11,$3}'`)
cpu_app_raw=(${cpu_app[1]%.*})
cpu__set_colors $cpu_app_raw
cpu_app_c="$cpu_sc${cpu_app[1]}$NC$P_Grey"
# Show
echo -e "$cpu_show ${cpu_app[0]}$Dp_Grey $cpu_app_c"
# Can unset
unset ${!cpu_@}
}
#======================================================================
# is Internet reachable
#======================================================================
isco() {
# Helps for echolib in function
isco__help() {
cat << EOHELP
--help : This help
ip : Show my external IP
net : Show if Internet is not reachable
EOHELP
}
case "$1" in
ip)
dig +short myip.opendns.com @resolver1.opendns.com
;;
lip)
isco_device=`ip r | awk 'NR==2 {print $3}'`
isco_lip=`ip -4 address show dev ${isco_device} \
| grep "inet" \
| awk '{print $2}'`
isco_lip="${isco_lip//\/*/}"
;;
net)
isco_net=`timeout .3 getent ahosts debian.org &>/dev/null`
isco_return="$?"
if ! (( "$isco_return" == 0 ));then
isco_net=`timeout .3 getent ahosts archlinux.org &>/dev/null` \
isco_return="$?"
fi
if ! (( $isco_return == 0 ));then
isco_c="$I_Red"
isco_s="Internet not reachable ?"
else
isco_c="$I_Green"
fi
;;
--help|help|-h|*)
;;
esac
}
#======================================================================
# Check Download / Upload speed
#======================================================================
dlup() {
isco__show() {
echo -e "$isco_c $isco_device $Bo_Grey$isco_lip$C_Grey) |$NC $isco_s"
unset ${!isco_@}
}
isco net &>/dev/null
isco lip
! (( $isco_return == 0 )) \
&& isco__show \
&& return
isco_s=`
awk '
{
if (l1)
{
dlspeed = int(($2-l1)/1024*2);
if (dlspeed > 1000)
{
dlspeed=((dlspeed/1000));
dlval="\033[0;02mMB/s";
}
else
if (dlspeed < 1)
dlval = "\033[0;02m..";
else
dlval = "\033[0;02mkB/s"
upspeed = int(($10-l2)/1024*2);
if (upspeed > 1000)
{
upspeed = ((upspeed/1000));
upval = "\033[0;02mMB/s";
}
else
if (upspeed < 1)
upval = "\033[0;02m..";
else
upval = "\033[0;02mkB/s"
print "\033[0;02mD:\033[0;32m"\
dlspeed\
"\033[0;02"\
dlval,\
"U:\033[0;33m"\
upspeed\
upval\
"\033[0m"
}
else
{
l1=$2; l2=$10;
}
}' <(grep ${isco_device} /proc/net/dev) \
<(sleep .7;grep ${isco_device} /proc/net/dev)`
isco__show
}