splitted main file, added rain, bump to v3.0.0

This commit is contained in:
2022-08-27 23:36:01 +02:00
parent 98afeed28d
commit 011e657e49
13 changed files with 1097 additions and 1104 deletions

72
profile.d/debug.sh Normal file
View File

@@ -0,0 +1,72 @@
# ------------------------------------------------------------------------------
# Display a backtrace
# ------------------------------------------------------------------------------
function backtrace ()
{
echo "========= Call stack ========="
typeset -i i=0
local func=
for func in "${FUNCNAME[@]}"; do
if [[ $i -ne 0 ]]; then
printf '%15s() %s:%d\n' \
"$func" "${BASH_SOURCE[$i]}" "${BASH_LINENO[ (( $i - 1)) ]}"
fi
let i++ || true
done
unset func i
echo "=============================="
}
# ------------------------------------------------------------------------------
# Function to be trapped for errors investigation
# ------------------------------------------------------------------------------
function error ()
{
local errcode=$?
backtrace
exit $errcode
}
# ------------------------------------------------------------------------------
# Activate or deactivate error trapping to display backtrace
# ------------------------------------------------------------------------------
settrace ()
{
local status="off"
[[ $(trap -p ERR) ]] && status="on"
trap -p ERR
for opt in $@ ; do
case $opt in
"-h"|"--help")
echo "Try to activate backtrace display for script debugging."
echo
echo "Options:"
echo " --on Activate backtrace generation"
echo " --off Deactivate backtrace generation"
echo
echo "That function active a trap event on error. If the script you want to"
echo "debug overload the ERR bash trap, it will not work."
echo
;;
"--on")
if [[ $status == "on" ]]; then
echo "Warning: ERR signal trap is already set, replacing previous trap!"
fi
trap "error" ERR
;;
"--off")
if [[ $status != "on" ]]; then
echo "Warning: ERR signal trap is already unset!"
fi
trap - ERR
;;
"--status")
echo "ERR trap signal is ${status}."
;;
esac
done
unset status
}
export -f settrace