From c441afa9b28f16e661d11a494c277c5c75e0b755 Mon Sep 17 00:00:00 2001 From: pvincent Date: Sun, 5 Jul 2026 16:02:42 +0400 Subject: [PATCH] backtrace and raise_error --- install.sh | 63 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/install.sh b/install.sh index cda2ec9..bb31f06 100755 --- a/install.sh +++ b/install.sh @@ -6,6 +6,33 @@ BASEDIR=$(dirname $0) ## FUNCTIONS +function exit { + on_exit $1 true +} + +function on_exit { + local error_code bypass_last_call stack_lines + error_code=$1 + + bypass_last_call=${2:-false} + stack_lines=("${BASH_LINENO[@]}") + $bypass_last_call && stack_lines=("${stack_lines[@]:1}") + + # remove 1 on head list + [[ ${#stack_lines[@]} > 0 && ${stack_lines[0]} == 1 ]] && unset stack_lines[0] + + # remove 0 on tail list + [[ ${#stack_lines[@]} > 0 && ${stack_lines[-1]} == 0 ]] && unset stack_lines[-1] + + if [[ $error_code > 0 ]]; then + printf "\nEXIT #${error_code} due to error at line ${stack_lines[*]} : \n-----------------------------------------\n" + trap - ERR TERM INT EXIT + builtin exit "${error_code}" + else + echo SUCCESS + fi +} + function assert_debian13 { test -f /etc/debian_version && grep --quiet ^13\. /etc/debian_version || @@ -18,7 +45,6 @@ function assert_gnome_desktop { } function install_ghostty { - if ! command -v ghostty >/dev/null; then curl -sS https://debian.griffo.io/EA0F721D231FDD3A0A17B9AC7808B4DD62C41256.asc | sudo gpg --dearmor --yes -o /etc/apt/trusted.gpg.d/debian.griffo.io.gpg @@ -40,7 +66,12 @@ function install_ghostty { } function install_homebrew { - + # $nope + # exit 11 + # echo AAA + raise_error 'BBB' + false + echo BBB bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" } @@ -48,7 +79,12 @@ function raise_error { message=${1:-an undefined error has occured!} code=${2:-1} echo "error ${code}: ${message}" >&2 - exit "${code}" + echo "FUNCNAME: ${FUNCNAME[@]}" >&2 # inner outer main + echo "BASH_SOURCE: ${BASH_SOURCE[@]}" script.sh script.sh script.sh >&2 + echo "BASH_LINENO: ${BASH_LINENO[@]}" 52 55 0 >&2 + trap - ERR TERM INT EXIT + # builtin exit "${code}" + on_exit $code true } function set_alternative { @@ -73,7 +109,7 @@ function set_alternative { } function configure_default { - # CAPS LOCK means ESC() + # CAPS LOCK means ESC gsettings set org.gnome.desktop.input-sources xkb-options "['caps:escape']" set_alternative editor nvim @@ -103,24 +139,23 @@ function install_neovim { local shellrc alias_expr shellrc="$HOME/.bashrc" if ! grep -q nvim-vanilla "$shellrc"; then - alias_expr="alias nvim-vanilla='NVIM_APPNAME=nvim-vanilla nvim'" - echo "$alias_expr" >>"$shellrc" - eval "$alias_expr" + echo "alias nvim-vanilla='NVIM_APPNAME=nvim-vanilla nvim'" >>"$shellrc" echo 'nvim-vanilla created!' + RELOAD_SHELL=true else echo 'nvim-vanilla ready!' fi + exit 3 } + ## MAIN -set -Eue + +set -TEue +trap 'on_exit $?' ERR TERM INT EXIT assert_debian13 assert_gnome_desktop - -echo "MIAOU-DESKTOP installation..." - install_ghostty -# install_homebrew -install_neovim +install_homebrew +# install_neovim configure_default -echo SUCCESS