bump to 2.8.2

This commit is contained in:
fatalerrors
2022-07-29 15:45:09 +02:00
parent c3b875cb88
commit 541932d7f1

View File

@@ -30,6 +30,8 @@
# 21/06/2022 v2.7.0 : added isipv4 and isipv6, use it in rmhost as an improvement # 21/06/2022 v2.7.0 : added isipv4 and isipv6, use it in rmhost as an improvement
# 22/06/2022 v2.7.1 : [bugfix] few minor corrections, added help command # 22/06/2022 v2.7.1 : [bugfix] few minor corrections, added help command
# 24/06/2022 v2.8.0 : Added backtrace, error and settrace, corrected showinfo # 24/06/2022 v2.8.0 : Added backtrace, error and settrace, corrected showinfo
# 19/07/2022 v2.8.1 : few cleanup, fixes and optimizations
# 29/07/2022 v2.8.2 : added warning for non bash users
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org> # Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# Protected by the BSD3 license. Please read bellow for details. # Protected by the BSD3 license. Please read bellow for details.
@@ -65,10 +67,16 @@
# * OF SUCH DAMAGE. # * OF SUCH DAMAGE.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
export PROFVERSION="2.8.0" export PROFVERSION="2.8.2"
export DEFAULT_CITY="Toulouse" export DEFAULT_CITY="Toulouse"
if [[ ! $(echo $SHELL | grep bash) ]]; then
echo "That script is designed to be used with bash as being the shell."
echo "Please consider using bash instead, or patch me ;) !"
return 1
fi
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# path* : private functions for PATH variable management # path* : private functions for PATH variable management
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -229,23 +237,17 @@ isipv4 ()
ip=($ip) ip=($ip)
IFS=$old_ifs IFS=$old_ifs
if [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \ if [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]; then && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]; then
if [[ -t 1 ]]; then if [[ -t 1 ]]; then
echo "The given IPv4 is valid." echo "The given IPv4 is valid."
fi fi
return 0 return 0
else
if [[ -t 1 ]]; then
echo "The given parameter is NOT a valid IPv4."
fi
return 1
fi fi
else
if [[ -t 1 ]]; then
echo "The given parameter is NOT a valid IPv4."
fi
return 1
fi fi
if [[ -t 1 ]]; then
echo "The given parameter is NOT a valid IPv4."
fi
return 1
} }
export -f isipv4 export -f isipv4
@@ -261,12 +263,11 @@ isipv6 ()
echo "The given IPv6 is valid." echo "The given IPv6 is valid."
fi fi
return 0 return 0
else
if [[ -t 1 ]]; then
echo "The given parameter is not a valid IPv6."
fi
return 1
fi fi
if [[ -t 1 ]]; then
echo "The given parameter is not a valid IPv6."
fi
return 1
} }
export -f isipv6 export -f isipv6
@@ -482,13 +483,14 @@ export -f mcd
# Get PID list of the given process name # Get PID list of the given process name
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
gpid () { gpid () {
[[ $UID -eq 0 ]] && local psopt="-A"
[[ $# -eq 1 ]] && local single=1 [[ $# -eq 1 ]] && local single=1
for pid in $@; do for pid in $@; do
local result=$(ps -A | grep $pid | awk '{print $1}') local result=$(ps $psopt | grep $pid | awk '{print $1}' | sed "s/\n/ /")
if [[ $single ]]; then if [[ $single ]]; then
[[ $result ]] && echo "$result" [[ $result ]] && echo "${result//$'\n'/ }"
else else
[[ $result ]] && echo "$pid: $result" [[ $result ]] && echo "$pid: ${result//$'\n'/ }"
fi fi
done done
[[ $result ]] || return 1 [[ $result ]] || return 1
@@ -944,11 +946,25 @@ export -f taz
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
showinfo() { showinfo() {
echo -e "\n" echo -e "\n"
command -v figlet >/dev/null 2>&1 && if command -v figlet >/dev/null 2>&1; then
figlet -k $(hostname) figlet -k $(hostname)
else
echo "$(hostname -f)"
fi
echo "" echo ""
command -v neofetch >/dev/null 2>&1 && if command -v neofetch >/dev/null 2>&1; then
neofetch neofetch
else
(
if [[ -s /etc/os-release ]]; then
. /etc/os-release
echo "$NAME $VERSION"
else
cat /proc/version
fi
echo "Uptime: $(uptime)"
)
fi
} }
export -f showinfo export -f showinfo
@@ -1019,6 +1035,9 @@ function error ()
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
settrace () settrace ()
{ {
local status="off"
[[ $(trap -p ERR) ]] && status="on"
trap -p ERR
for opt in $@ ; do for opt in $@ ; do
case $opt in case $opt in
"-h"|"--help") "-h"|"--help")
@@ -1033,13 +1052,23 @@ settrace ()
echo echo
;; ;;
"--on") "--on")
if [[ $status == "on" ]]; then
echo "Warning: ERR signal trap is already set, replacing previous trap!"
fi
trap "error" ERR trap "error" ERR
;; ;;
"--off") "--off")
if [[ $status != "on" ]]; then
echo "Warning: ERR signal trap is already unset!"
fi
trap - ERR trap - ERR
;; ;;
"--status")
echo "ERR trap signal is ${status}."
;;
esac esac
done done
unset status
} }