From b8bd9c2e3897cf75296f2945cd1e14290196b9aa Mon Sep 17 00:00:00 2001 From: Muhammad Rivan Date: Wed, 2 Jun 2021 23:04:59 +0700 Subject: [PATCH] Revamp debugging --- clean-git.sh | 7 +++++ install.sh | 8 ++++-- lib-core.sh | 76 +++++++++++++++++++++++++++----------------------- lib-install.sh | 8 ++++-- tweaks.sh | 4 +-- 5 files changed, 61 insertions(+), 42 deletions(-) diff --git a/clean-git.sh b/clean-git.sh index 7c3a88a..52dd452 100755 --- a/clean-git.sh +++ b/clean-git.sh @@ -7,3 +7,10 @@ git clean -d -f -X git add . + +! command -v beautysh && sudo pip install beautysh +beautysh -i 2 -s paronly *.sh + +git add . + +echo "DONE!" diff --git a/install.sh b/install.sh index b14f792..0bb70a4 100755 --- a/install.sh +++ b/install.sh @@ -121,7 +121,9 @@ else if [[ "${interactive}" == 'true' ]]; then show_panel_opacity_dialog; show_sidebar_size_dialog; show_nautilus_style_dialog prompt -w "DIALOG: '--size' and '--panel' parameters are ignored if exist."; echo - else show_needed_dialogs; fi + else + show_needed_dialogs + fi prompt -w "Removing the old '${name}' themes..." @@ -150,6 +152,8 @@ else fi echo; prompt -w "${final_msg}"; echo - + rootify ls /mama; ls /mama; ls /mama + ls /mama + ls /mama [[ -x /usr/bin/notify-send ]] && notify-send "'${name}' theme has been installed. Enjoy!" "${notif_msg}" -i "dialog-information-symbolic" fi diff --git a/lib-core.sh b/lib-core.sh index d521e66..4f485d2 100755 --- a/lib-core.sh +++ b/lib-core.sh @@ -9,6 +9,8 @@ # WARNING: Please set REPO_DIR variable before using this lib set -Eeo pipefail +WHITESUR_SOURCE=() +WHITESUR_SOURCE+=("lib-core.sh") ############################################################################### # VARIABLES # @@ -118,9 +120,9 @@ showapps_normal="false" msg="" final_msg="Run '${0} --help' to explore more customization features!" notif_msg="" -error_msg="" process_ids=() -errors=() +whitesur_error="" +whitesur_lines=() export ANIM_PID="0" has_any_error="false" @@ -481,12 +483,13 @@ remind_relative_path() { rootify() { trap true SIGINT prompt -w "Executing '$(echo "${@}" | cut -c -35 )...' as root" - + if ! sudo "${@}"; then - errors+=("${*}") + whitesur_lines+=("${BASH_LINENO}") + whitesur_error="${*}" operation_aborted fi - + trap signal_exit SIGINT } @@ -499,12 +502,13 @@ full_rootify() { userify() { trap true SIGINT - + if ! sudo -u "${MY_USERNAME}" "${@}"; then - errors+=("${*}") + whitesur_lines+=("${BASH_LINENO}") + whitesur_error="${*}" operation_aborted fi - + trap signal_exit SIGINT } @@ -515,46 +519,48 @@ signal_exit() { operation_aborted() { IFS=$'\n' - local sources=($(basename -a "${BASH_SOURCE[@]}" | sort -u)) - local dist_ids=($(cat '/etc/os-release' | awk -F '=' '/ID/{print $2}')) + local sources=($(basename -a "${WHITESUR_SOURCE[@]}" "${BASH_SOURCE[@]}" | sort -u)) + local dist_ids=($(awk -F '=' '/ID/{print $2}' "/etc/os-release")) + local repo_ver="" + local lines=() + + if ! repo_ver="$(cd "${REPO_DIR}"; git log -1 --date=format-local:"%FT%T%z" --format="%ad")"; then + if ! repo_ver="$(date -r "${REPO_DIR}" +"%FT%T%z")"; then + repo_ver="unknown" + fi + fi + + #whitesur_lines=($(printf "%s\n" "${whitesur_lines[@]}" | sort -u)) clear + prompt -e "\n\n Oops! Operation has been aborted or failed...\n" + prompt -e "=========== ERROR LOG ===========" + if [[ -f "${WHITESUR_TMP_DIR}/error_log.txt" ]]; then - error_msg="$(cat "${WHITESUR_TMP_DIR}/error_log.txt")" + awk '{printf "\033[1;31m >>> %s\n", $0}' "${WHITESUR_TMP_DIR}/error_log.txt" fi - prompt -e "\n\n Oops! Operation has been aborted or failed...\n" - prompt -e "ERROR LOG:\n${error_msg}\n" - - prompt -e "ERROR INFO:" - prompt -e " SOURCES : $(IFS=';'; echo "${sources[*]}")" - prompt -e " LINES : ${LINENO};${BASH_LINENO}" - prompt -e " SNIPPETS:" + prompt -e "\n =========== ERROR INFO ==========" + prompt -e "FOUND :" for i in "${sources[@]}"; do - errors+=("$(sed "${BASH_LINENO}q;d" "${REPO_DIR}/${i}")") - errors+=("$(sed "${LINENO}q;d" "${REPO_DIR}/${i}")") + lines=($(grep -Fn "${whitesur_error:-${BASH_COMMAND}}" "${REPO_DIR}/${i}" | cut -d : -f 1 || echo "")) + prompt -e " >>> ${i} $(IFS=';'; [[ "${lines[*]}" ]] && echo "at ${lines[*]}")" done - errors+=("${BASH_COMMAND}") - errors=($(printf "%s\n" "${errors[@]}" | sort -u)) - - for i in "${errors[@]}"; do - [[ ! "${i}" =~ "errors+=" && ! "${i}" =~ "operation_aborted" ]] && prompt -e ">>> ${i}" - done - - prompt -e " TRACE :" + prompt -e "SNIPPET:\n >>> ${whitesur_error:-${BASH_COMMAND}}" + prompt -e "TRACE :" for i in "${FUNCNAME[@]}"; do - prompt -e ">>> ${i}" + prompt -e " >>> ${i}" done - - echo - prompt -e "SYSTEM INFO:" - prompt -e " DISTRO : $(IFS=';'; echo "${dist_ids[*]}")" - prompt -e " SUDO : $([[ -w "/" ]] && echo "yes" || echo "no")" - prompt -e " GNOME : ${GNOME_VERSION}\n" + + prompt -e "\n =========== SYSTEM INFO =========" + prompt -e "DISTRO : $(IFS=';'; echo "${dist_ids[*]}")" + prompt -e "SUDO : $([[ -w "/" ]] && echo "yes" || echo "no")" + prompt -e "GNOME : ${GNOME_VERSION}" + prompt -e "REPO : ${repo_ver}\n" prompt -i "TIP: you can google or report to us the infos above\n" prompt -i "https://github.com/vinceliuice/WhiteSur-gtk-theme/issues\n\n" diff --git a/lib-install.sh b/lib-install.sh index 8032564..6eddbcf 100755 --- a/lib-install.sh +++ b/lib-install.sh @@ -13,6 +13,7 @@ ############################################################################### source "${REPO_DIR}/lib-core.sh" +WHITESUR_SOURCE+=("lib-install.sh") ############################################################################### # DEPENDENCIES # @@ -45,8 +46,7 @@ install_theme_deps() { install_gdm_deps() { #TODO: @vince, do we also need "sassc" here? - if ! has_command glib-compile-resources || ! has_command xmllint || \ - ! has_command sassc; then + if ! has_command glib-compile-resources || ! has_command xmllint || ! has_command sassc; then echo; prompt -w "'glib2.0', 'xmllint', and 'sassc' are required for theme installation." if has_command zypper; then @@ -186,7 +186,9 @@ install_shelly() { if [[ -z "${6}" ]]; then TARGET_DIR="${dest}/${name}${color}${opacity}${alt}${theme}/gnome-shell" - else TARGET_DIR="${6}"; fi + else + TARGET_DIR="${6}" + fi mkdir -p "${TARGET_DIR}" mkdir -p "${TARGET_DIR}/assets" diff --git a/tweaks.sh b/tweaks.sh index 17b014b..4608f5b 100755 --- a/tweaks.sh +++ b/tweaks.sh @@ -54,7 +54,7 @@ while [[ $# -gt 0 ]]; do # at once case "${1}" in - # Parameters that don't require value + # Parameters that don't require value -r|--remove|--revert) uninstall='true'; shift ;; -h|--help) @@ -113,7 +113,7 @@ while [[ $# -gt 0 ]]; do no_darken="true"; shift ;; -n|--no-blur) no_blur="true"; shift ;; - # Parameters that require value, single use + # Parameters that require value, single use -b|--background) check_param "${1}" "${1}" "${2}" "must" "must" "must" "false" && shift 2 || shift ;; -i|--icon)