Prepare the new error handling
This commit is contained in:
parent
ab44578b1f
commit
94821276a7
2 changed files with 57 additions and 47 deletions
70
lib-core.sh
70
lib-core.sh
|
@ -8,14 +8,12 @@
|
|||
#
|
||||
# WARNING: Please set REPO_DIR variable before using this lib
|
||||
|
||||
set -Eeo pipefail
|
||||
|
||||
###############################################################################
|
||||
# VARIABLES #
|
||||
###############################################################################
|
||||
|
||||
if [[ "${LIB_CORE_IMPORTED}" == "true" ]]; then
|
||||
echo "ERROR: lib-core.sh is already imported"; exit 1
|
||||
else LIB_CORE_IMPORTED="true"; fi
|
||||
|
||||
export WHITESUR_PID=$$
|
||||
MY_USERNAME="$(logname 2> /dev/null || echo ${SUDO_USER:-${USER}})"
|
||||
|
||||
|
@ -118,7 +116,7 @@ final_msg="Run '${0} --help' to explore more customization features!"
|
|||
notif_msg=""
|
||||
error_msg=""
|
||||
process_ids=()
|
||||
ANIM_PID="0"
|
||||
export ANIM_PID="0"
|
||||
has_any_error="false"
|
||||
|
||||
# Colors and animation
|
||||
|
@ -159,11 +157,11 @@ start_animation() {
|
|||
done
|
||||
) &
|
||||
|
||||
ANIM_PID="${!}"
|
||||
export ANIM_PID="${!}"
|
||||
}
|
||||
|
||||
stop_animation() {
|
||||
kill -13 "${ANIM_PID}" &> /dev/null
|
||||
kill -13 "${ANIM_PID}" &> /dev/null || true
|
||||
setterm -cursor on
|
||||
}
|
||||
|
||||
|
@ -448,6 +446,12 @@ backup_file() {
|
|||
fi
|
||||
}
|
||||
|
||||
userify_file() {
|
||||
if [[ "$(ls -ld "${1}" | awk '{print $3}')" != "${MY_USERNAME}" ]]; then
|
||||
rootify chown "${MY_USERNAME}:" "${1}"
|
||||
fi
|
||||
}
|
||||
|
||||
check_theme_file() {
|
||||
[[ -f "${1}" || -f "${1}.bak" ]]
|
||||
}
|
||||
|
@ -460,16 +464,11 @@ remind_relative_path() {
|
|||
# SYSTEMS #
|
||||
###############################################################################
|
||||
|
||||
lockWhiteSur() {
|
||||
while [[ -e "/proc/${WHITESUR_PID}" ]]; do sleep 0.1; done
|
||||
rm -rf "${WHITESUR_TMP_DIR}"
|
||||
}; export -f lockWhiteSur
|
||||
|
||||
rootify() {
|
||||
trap true SIGINT
|
||||
prompt -w "Executing '$(echo "${@}" | cut -c -35 )...' as root"
|
||||
sudo ${@} 2> "${WHITESUR_TMP_DIR}/error_log.txt" || operation_canceled
|
||||
trap sig_c SIGINT
|
||||
sudo ${@} || operation_aborted
|
||||
trap stop_animation SIGINT
|
||||
}
|
||||
|
||||
full_rootify() {
|
||||
|
@ -481,31 +480,42 @@ full_rootify() {
|
|||
|
||||
userify() {
|
||||
trap true SIGINT
|
||||
sudo -u "${MY_USERNAME}" ${@} 2> "${WHITESUR_TMP_DIR}/error_log.txt" || operation_canceled
|
||||
trap sig_c SIGINT
|
||||
sudo -u "${MY_USERNAME}" ${@} || operation_aborted
|
||||
trap stop_animation SIGINT
|
||||
}
|
||||
|
||||
sig_c() {
|
||||
kill -13 ${process_ids[*]} &> /dev/null
|
||||
stop_animation; wait ${process_ids[*]} &> /dev/null; operation_canceled
|
||||
signal_exit() {
|
||||
rm -rf "${WHITESUR_TMP_DIR}"
|
||||
stop_animation
|
||||
}
|
||||
|
||||
operation_canceled() {
|
||||
operation_aborted() {
|
||||
local sources=($(basename -a "${BASH_SOURCE[@]}" | sort -u))
|
||||
|
||||
clear
|
||||
|
||||
if [[ -f "${WHITESUR_TMP_DIR}/error_log.txt" ]]; then
|
||||
error_msg="$(cat "${WHITESUR_TMP_DIR}/error_log.txt")"
|
||||
fi
|
||||
|
||||
if [[ ${error_msg} != "" ]]; then
|
||||
prompt -e "\n\n Oops! An error is detected...\n"
|
||||
prompt -e "ERROR LOG:\n${error_msg}\n"
|
||||
prompt -i "TIP: you can google or report to us the error log above\n\n"
|
||||
else
|
||||
prompt -e "\n\n Oops! Operation has been canceled or failed...\n\n"
|
||||
fi
|
||||
prompt -e "\n\n Oops! Operation has been aborted or failed...\n"
|
||||
prompt -e "ERROR LOG:\n${error_msg}\n"
|
||||
|
||||
exit 1
|
||||
prompt -e "ERROR INFO:"
|
||||
prompt -e " SOURCES : $(IFS=';'; echo "${sources[*]}")"
|
||||
prompt -e " LINES : ${LINENO};${BASH_LINENO}"
|
||||
prompt -e " SNIPPETS:"
|
||||
|
||||
for i in "${sources[@]}"; do
|
||||
prompt -e ">>> $(sed "${BASH_LINENO}q;d" "${REPO_DIR}/${i}")"
|
||||
prompt -e ">>> $(sed "${LINENO}q;d" "${REPO_DIR}/${i}")"
|
||||
done
|
||||
|
||||
prompt -e ">>> ${BASH_COMMAND}\n"
|
||||
|
||||
prompt -i "TIP: you can google or report to us the infos above\n\n"
|
||||
|
||||
rm -rf "${WHITESUR_TMP_DIR}"; exit 1
|
||||
}
|
||||
|
||||
usage() {
|
||||
|
@ -519,7 +529,6 @@ finalize_argument_parsing() {
|
|||
elif [[ "${has_any_error}" == "true" ]]; then
|
||||
echo; prompt -i "Try '$0 --help' for more information."; exit 1
|
||||
else
|
||||
trap sig_c SIGINT
|
||||
[[ "${need_dialog[@]}" =~ "true" ]] && echo
|
||||
|
||||
if [[ -d "${WHITESUR_TMP_DIR}" ]]; then
|
||||
|
@ -533,6 +542,7 @@ finalize_argument_parsing() {
|
|||
|
||||
rm -rf "${WHITESUR_TMP_DIR}"; mkdir -p "${WHITESUR_TMP_DIR}"
|
||||
rm -rf "${THEME_SRC_DIR}/sass/_theme-options-temp.scss"
|
||||
nohup bash -c lockWhiteSur &> /dev/null 2> /dev/null & disown ${!}
|
||||
exec 2> "${WHITESUR_TMP_DIR}/error_log.txt"
|
||||
trap 'operation_aborted' ERR; trap 'signal_exit' SIGINT; trap 'signal_exit' EXIT
|
||||
fi
|
||||
}
|
||||
|
|
|
@ -12,10 +12,6 @@
|
|||
# VARIABLES #
|
||||
###############################################################################
|
||||
|
||||
if [[ "${LIB_INSTALL_IMPORTED}" == "true" ]]; then
|
||||
echo "ERROR: lib-install.sh is already imported"; exit 1
|
||||
else LIB_INSTALL_IMPORTED="true"; fi
|
||||
|
||||
source "${REPO_DIR}/lib-core.sh"
|
||||
|
||||
###############################################################################
|
||||
|
@ -448,18 +444,19 @@ config_firefox() {
|
|||
for d in "${FIREFOX_DIR_HOME}/"*"default"*; do
|
||||
rm -rf "${d}/chrome"
|
||||
userify ln -sf "${FIREFOX_THEME_DIR}" "${d}/chrome"
|
||||
userify echo "user_pref(\"toolkit.legacyUserProfileCustomizations.stylesheets\", true);" >> "${d}/prefs.js"
|
||||
userify echo "user_pref(\"browser.tabs.drawInTitlebar\", true);" >> "${d}/prefs.js"
|
||||
userify echo "user_pref(\"browser.uidensity\", 0);" >> "${d}/prefs.js"
|
||||
userify echo "user_pref(\"layers.acceleration.force-enabled\", true);" >> "${d}/prefs.js"
|
||||
userify echo "user_pref(\"mozilla.widget.use-argb-visuals\", true);" >> "${d}/prefs.js"
|
||||
userify_file "${d}/prefs.js"
|
||||
echo "user_pref(\"toolkit.legacyUserProfileCustomizations.stylesheets\", true);" >> "${d}/prefs.js"
|
||||
echo "user_pref(\"browser.tabs.drawInTitlebar\", true);" >> "${d}/prefs.js"
|
||||
echo "user_pref(\"browser.uidensity\", 0);" >> "${d}/prefs.js"
|
||||
echo "user_pref(\"layers.acceleration.force-enabled\", true);" >> "${d}/prefs.js"
|
||||
echo "user_pref(\"mozilla.widget.use-argb-visuals\", true);" >> "${d}/prefs.js"
|
||||
done
|
||||
}
|
||||
|
||||
edit_firefox_theme_prefs() {
|
||||
[[ ! -d "${FIREFOX_THEME_DIR}" ]] && install_firefox_theme ; config_firefox
|
||||
${EDITOR:-nano} "${FIREFOX_THEME_DIR}/userChrome.css"
|
||||
${EDITOR:-nano} "${FIREFOX_THEME_DIR}/customChrome.css"
|
||||
userify ${EDITOR:-nano} "${FIREFOX_THEME_DIR}/userChrome.css"
|
||||
userify ${EDITOR:-nano} "${FIREFOX_THEME_DIR}/customChrome.css"
|
||||
}
|
||||
|
||||
remove_firefox_theme() {
|
||||
|
@ -476,6 +473,7 @@ install_dash_to_dock_theme() {
|
|||
|
||||
if [[ -d "${DASH_TO_DOCK_DIR_HOME}" ]]; then
|
||||
backup_file "${DASH_TO_DOCK_DIR_HOME}/stylesheet.css" "userify"
|
||||
userify_file "${DASH_TO_DOCK_DIR_HOME}/stylesheet.css"
|
||||
userify sassc ${SASSC_OPT} "${DASH_TO_DOCK_SRC_DIR}/stylesheet$(destify ${colors[0]}).scss" "${DASH_TO_DOCK_DIR_HOME}/stylesheet.css"
|
||||
elif [[ -d "${DASH_TO_DOCK_DIR_ROOT}" ]]; then
|
||||
backup_file "${DASH_TO_DOCK_DIR_ROOT}/stylesheet.css" "rootify"
|
||||
|
@ -614,7 +612,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_canceled ;;
|
||||
*) operation_aborted ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
|
@ -636,7 +634,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_canceled ;;
|
||||
*) operation_aborted ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
|
@ -656,7 +654,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_canceled ;;
|
||||
*) operation_aborted ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
|
@ -664,7 +662,9 @@ show_nautilus_style_dialog() {
|
|||
}
|
||||
|
||||
show_needed_dialogs() {
|
||||
[[ "${need_dialog["-p"]}" == "true" ]] && install_dialog_deps && show_panel_opacity_dialog
|
||||
[[ "${need_dialog["-s"]}" == "true" ]] && install_dialog_deps && show_sidebar_size_dialog
|
||||
[[ "${need_dialog["-N"]}" == "true" ]] && install_dialog_deps && show_nautilus_style_dialog
|
||||
if [[ "${need_dialog[@]}" =~ "true" ]]; then install_dialog_deps; fi
|
||||
|
||||
if [[ "${need_dialog["-p"]}" == "true" ]]; then show_panel_opacity_dialog; fi
|
||||
if [[ "${need_dialog["-s"]}" == "true" ]]; then show_sidebar_size_dialog; fi
|
||||
if [[ "${need_dialog["-N"]}" == "true" ]]; then show_nautilus_style_dialog; fi
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue