Differenciate between error and abort signal

This commit is contained in:
Muhammad Rivan 2021-06-10 08:51:40 +07:00
parent 024815263d
commit 8886bea5c6
No known key found for this signature in database
GPG key ID: C56A200FD936FAAA
2 changed files with 25 additions and 26 deletions

View file

@ -220,7 +220,13 @@ signal_exit() {
stop_animation stop_animation
} }
operation_aborted() { signal_abort() {
signal_exit
prompt -e "\n\n Oops! Operation has been aborted...\n\n"
exit 1
}
signal_error() {
# TODO: make this more accurate # TODO: make this more accurate
IFS=$'\n' IFS=$'\n'
@ -240,7 +246,7 @@ operation_aborted() {
# to be cut. Sleeping for awhile may help # to be cut. Sleeping for awhile may help
sleep 0.75; clear sleep 0.75; clear
prompt -e "\n\n Oops! Operation has been aborted or failed...\n" prompt -e "\n\n Oops! Operation failed...\n"
prompt -e "=========== ERROR LOG ===========" prompt -e "=========== ERROR LOG ==========="
echo -e "${log}" echo -e "${log}"
@ -277,44 +283,34 @@ operation_aborted() {
} }
rootify() { rootify() {
local result=0 local result="0"
trap true SIGINT
prompt -w "Executing '$(echo "${@}" | cut -c -35 )...' as root" prompt -w "Executing '$(echo "${@}" | cut -c -35 )...' as root"
if [[ -p /dev/stdin ]]; then if [[ -p /dev/stdin ]]; then
! sudo "${@}" < /dev/stdin && result=1 ! sudo "${@}" < /dev/stdin && result="1"; error_snippet="${*}"
error_snippet="${*}"
else else
! sudo "${@}" && result=1 ! sudo "${@}" && result="1"; error_snippet="${*}"
error_snippet="${*}"
fi fi
trap signal_exit SIGINT
return "${result}" return "${result}"
} }
userify() { userify() {
local result=0 local result="0"
trap true SIGINT
if [[ -p /dev/stdin ]]; then if [[ -p /dev/stdin ]]; then
! sudo -u "${MY_USERNAME}" "${@}" < /dev/stdin && result=1 ! sudo -u "${MY_USERNAME}" "${@}" < /dev/stdin && result="1"; error_snippet="${*}"
error_snippet="${*}"
else else
! sudo -u "${MY_USERNAME}" "${@}" && result=1 ! sudo -u "${MY_USERNAME}" "${@}" && result="1"; error_snippet="${*}"
error_snippet="${*}"
fi fi
trap signal_exit SIGINT
return "${result}" return "${result}"
} }
trap 'operation_aborted' ERR trap 'signal_exit' EXIT
trap 'signal_exit' INT EXIT TERM trap 'signal_error' ERR
trap 'signal_abort' INT TERM TSTP
############################################################################### ###############################################################################
# USER UTILITIES # # USER UTILITIES #

View file

@ -33,7 +33,10 @@ WHITESUR_SOURCE+=("lib-install.sh")
# for installing a util, e.g. 'sassc' (from 'desktop-dev' bundle, or # for installing a util, e.g. 'sassc' (from 'desktop-dev' bundle, or
# 'os-utils-gui-dev' bundle, or any other 'sassc' provider bundle) # 'os-utils-gui-dev' bundle, or any other 'sassc' provider bundle)
# Manual package installation is needed for that, but please don't use 'dnf' # Manual package installation is needed for that, but please don't use 'dnf'.
# The known worst impact of using 'dnf' is you install 'sassc' and then you
# remove it, and you run 'sudo dnf upgrade', and boom! Your 'sudo' and other
# system utilities have gone!
installation_sorry() { installation_sorry() {
prompt -w "WARNING: We're sorry, your distro isn't officially supported yet." prompt -w "WARNING: We're sorry, your distro isn't officially supported yet."
@ -720,7 +723,7 @@ show_panel_opacity_dialog() {
2) panel_opacity="${PANEL_OPACITY_VARIANTS[2]}" ;; 2) panel_opacity="${PANEL_OPACITY_VARIANTS[2]}" ;;
3) panel_opacity="${PANEL_OPACITY_VARIANTS[3]}" ;; 3) panel_opacity="${PANEL_OPACITY_VARIANTS[3]}" ;;
4) panel_opacity="${PANEL_OPACITY_VARIANTS[4]}" ;; 4) panel_opacity="${PANEL_OPACITY_VARIANTS[4]}" ;;
*) operation_aborted ;; *) signal_abort ;;
esac esac
fi fi
@ -742,7 +745,7 @@ show_sidebar_size_dialog() {
2) sidebar_size="${SIDEBAR_SIZE_VARIANTS[2]}" ;; 2) sidebar_size="${SIDEBAR_SIZE_VARIANTS[2]}" ;;
3) sidebar_size="${SIDEBAR_SIZE_VARIANTS[3]}" ;; 3) sidebar_size="${SIDEBAR_SIZE_VARIANTS[3]}" ;;
4) sidebar_size="${SIDEBAR_SIZE_VARIANTS[4]}" ;; 4) sidebar_size="${SIDEBAR_SIZE_VARIANTS[4]}" ;;
*) operation_aborted ;; *) signal_abort ;;
esac esac
fi fi
@ -762,7 +765,7 @@ show_nautilus_style_dialog() {
1) nautilus_style="${NAUTILUS_STYLE_VARIANTS[1]}" ;; 1) nautilus_style="${NAUTILUS_STYLE_VARIANTS[1]}" ;;
2) nautilus_style="${NAUTILUS_STYLE_VARIANTS[2]}" ;; 2) nautilus_style="${NAUTILUS_STYLE_VARIANTS[2]}" ;;
3) nautilus_style="${NAUTILUS_STYLE_VARIANTS[3]}" ;; 3) nautilus_style="${NAUTILUS_STYLE_VARIANTS[3]}" ;;
*) operation_aborted ;; *) signal_abort ;;
esac esac
fi fi