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
}
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
IFS=$'\n'
@ -240,7 +246,7 @@ operation_aborted() {
# to be cut. Sleeping for awhile may help
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 ==========="
echo -e "${log}"
@ -277,44 +283,34 @@ operation_aborted() {
}
rootify() {
local result=0
local result="0"
trap true SIGINT
prompt -w "Executing '$(echo "${@}" | cut -c -35 )...' as root"
if [[ -p /dev/stdin ]]; then
! sudo "${@}" < /dev/stdin && result=1
error_snippet="${*}"
! sudo "${@}" < /dev/stdin && result="1"; error_snippet="${*}"
else
! sudo "${@}" && result=1
error_snippet="${*}"
! sudo "${@}" && result="1"; error_snippet="${*}"
fi
trap signal_exit SIGINT
return "${result}"
}
userify() {
local result=0
trap true SIGINT
local result="0"
if [[ -p /dev/stdin ]]; then
! sudo -u "${MY_USERNAME}" "${@}" < /dev/stdin && result=1
error_snippet="${*}"
! sudo -u "${MY_USERNAME}" "${@}" < /dev/stdin && result="1"; error_snippet="${*}"
else
! sudo -u "${MY_USERNAME}" "${@}" && result=1
error_snippet="${*}"
! sudo -u "${MY_USERNAME}" "${@}" && result="1"; error_snippet="${*}"
fi
trap signal_exit SIGINT
return "${result}"
}
trap 'operation_aborted' ERR
trap 'signal_exit' INT EXIT TERM
trap 'signal_exit' EXIT
trap 'signal_error' ERR
trap 'signal_abort' INT TERM TSTP
###############################################################################
# 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
# '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() {
prompt -w "WARNING: We're sorry, your distro isn't officially supported yet."
@ -63,7 +66,7 @@ prepare_swupd() {
dist="NAME=\"Clear Linux OS\"\nVERSION=1\nID=clear-linux-os\nID_LIKE=clear-linux-os\n"
dist+="VERSION_ID=${ver}\nANSI_COLOR=\"1;35\"\nSUPPORT_URL=\"https://clearlinux.org\"\nBUILD_ID=${ver}"
prompt -w "\nCLEAR LINUX: Your 'swupd' is broken"
prompt -w "\n CLEAR LINUX: Your 'swupd' is broken"
prompt -i "CLEAR LINUX: Patching 'swupd' distro version detection and try again...\n"
rootify rm -rf "/etc/os-release"; echo -e "${dist}" | rootify tee "/usr/lib/os-release" > /dev/null
rootify ln -s "/usr/lib/os-release" "/etc/os-release"
@ -720,7 +723,7 @@ show_panel_opacity_dialog() {
2) panel_opacity="${PANEL_OPACITY_VARIANTS[2]}" ;;
3) panel_opacity="${PANEL_OPACITY_VARIANTS[3]}" ;;
4) panel_opacity="${PANEL_OPACITY_VARIANTS[4]}" ;;
*) operation_aborted ;;
*) signal_abort ;;
esac
fi
@ -742,7 +745,7 @@ show_sidebar_size_dialog() {
2) sidebar_size="${SIDEBAR_SIZE_VARIANTS[2]}" ;;
3) sidebar_size="${SIDEBAR_SIZE_VARIANTS[3]}" ;;
4) sidebar_size="${SIDEBAR_SIZE_VARIANTS[4]}" ;;
*) operation_aborted ;;
*) signal_abort ;;
esac
fi
@ -762,7 +765,7 @@ show_nautilus_style_dialog() {
1) nautilus_style="${NAUTILUS_STYLE_VARIANTS[1]}" ;;
2) nautilus_style="${NAUTILUS_STYLE_VARIANTS[2]}" ;;
3) nautilus_style="${NAUTILUS_STYLE_VARIANTS[3]}" ;;
*) operation_aborted ;;
*) signal_abort ;;
esac
fi