Merge pull request #285 from rivanfebrian123/master

Revamp error handling
This commit is contained in:
Vince 2021-06-05 21:09:00 +08:00 committed by GitHub
commit 1fd2348098
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 163 additions and 123 deletions

View file

@ -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!"

View file

@ -1,7 +1,7 @@
#! /usr/bin/env bash
# WARNING: Please make this shell not working-directory dependant, for example
# instead of using 'cd blabla', use 'cd "${REPO_DIR}/blabla"'
# instead of using 'ls blabla', use 'ls "${REPO_DIR}/blabla"'
#
# WARNING: Please don't use sudo directly here since it steals our EXIT trap
#
@ -34,6 +34,7 @@ usage() {
helpify "-i, --icon" "[$(IFS='|'; echo "${ICON_VARIANTS[*]}")]" "Set 'Activities' icon" "Default is 'standard'"
# Not sure if "background" is even needed here
helpify "-b, --background" "[default|blank|IMAGE_PATH]" "Set gnome-shell background image" "Default is BigSur-like wallpaper"
helpify "-N, --nautilus-style" "[$(IFS='|'; echo "${NAUTILUS_STYLE_VARIANTS[*]}")]" "Set Nautilus style" "Default is BigSur-like style"
helpify "-HD, --highdefinition" "" "Set to High Definition size" "Default is laptop size"
helpify "--normal, --normalshowapps" "" "Set gnome-shell show apps button style to normal" "Default is bigsur"
helpify "--round, --roundedmaxwindow" "" "Set maximized window to rounded" "Default is square"
@ -121,7 +122,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 +153,5 @@ else
fi
echo; prompt -w "${final_msg}"; echo
[[ -x /usr/bin/notify-send ]] && notify-send "'${name}' theme has been installed. Enjoy!" "${notif_msg}" -i "dialog-information-symbolic"
fi

View file

@ -1,15 +1,21 @@
# WARNING: Please make this shell not working-directory dependant, for example
# instead of using 'cd blabla', use 'cd "${REPO_DIR}/blabla"'
# instead of using 'ls blabla', use 'ls "${REPO_DIR}/blabla"'
#
# WARNING: Don't use "cd" in this shell, use it in a subshell instead,
# for example ( cd blabla && do_blabla ) or $( cd .. && do_blabla )
#
# WARNING: Please don't use sudo directly here since it steals our EXIT trap
#
# WARNING: Please set REPO_DIR variable before using this lib
set -Eeo pipefail
if [[ ! "${REPO_DIR}" ]]; then
echo "Please define 'REPODIR' variable"; exit 1
elif [[ "${WHITESUR_SOURCE[@]}" =~ "lib-core.sh" ]]; then
echo "'lib-core.sh' is already imported"; exit 1
fi
WHITESUR_SOURCE=("lib-core.sh")
###############################################################################
# VARIABLES #
###############################################################################
@ -118,9 +124,8 @@ showapps_normal="false"
msg=""
final_msg="Run '${0} --help' to explore more customization features!"
notif_msg=""
error_msg=""
process_ids=()
errors=()
error_snippet=""
export ANIM_PID="0"
has_any_error="false"
@ -142,7 +147,7 @@ anim=(
)
###############################################################################
# UTILITIES #
# CORE UTILITIES #
###############################################################################
start_animation() {
@ -184,6 +189,110 @@ prompt() {
esac
}
###############################################################################
# SELF SAFETY #
###############################################################################
##### This is the core of error handling, make sure there's no error here #####
### TODO: return "lockWhiteSur()" back for non functional syntax error handling
### and lock dir removal after immediate terminal window closing
if [[ -d "${WHITESUR_TMP_DIR}" ]]; then
start_animation; sleep 2; stop_animation; echo
if [[ -d "${WHITESUR_TMP_DIR}" ]]; then
prompt -e "ERROR: Whitesur installer or tweaks is already running. Probably it's run by '$(ls -ld "${WHITESUR_TMP_DIR}" | awk '{print $3}')'"
exit 1
fi
fi
rm -rf "${WHITESUR_TMP_DIR}"
mkdir -p "${WHITESUR_TMP_DIR}"; exec 2> "${WHITESUR_TMP_DIR}/error_log.txt"
signal_exit() {
rm -rf "${WHITESUR_TMP_DIR}"
stop_animation
}
operation_aborted() {
IFS=$'\n'
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" 2> /dev/null)"; then
if ! repo_ver="$(date -r "${REPO_DIR}" +"%FT%T%z")"; then
repo_ver="unknown"
fi
fi
clear
prompt -e "\n\n Oops! Operation has been aborted or failed...\n"
prompt -e "=========== ERROR LOG ==========="
if ! awk '{printf "\033[1;31m >>> %s\n", $0}' "${WHITESUR_TMP_DIR}/error_log.txt"; then
prompt -e ">>>>>>> No error log found <<<<<<"
fi
prompt -e "\n =========== ERROR INFO =========="
prompt -e "FOUND :"
for i in "${sources[@]}"; do
lines=($(grep -Fn "${error_snippet:-${BASH_COMMAND}}" "${REPO_DIR}/${i}" | cut -d : -f 1 || echo ""))
prompt -e " >>> ${i}$(IFS=';'; [[ "${lines[*]}" ]] && echo " at ${lines[*]}")"
done
prompt -e "SNIPPET:\n >>> ${error_snippet:-${BASH_COMMAND}}"
prompt -e "TRACE :"
for i in "${FUNCNAME[@]}"; do
prompt -e " >>> ${i}"
done
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 "HINT: You can google or report to us the infos above\n"
prompt -i "https://github.com/vinceliuice/WhiteSur-gtk-theme/issues\n\n"
rm -rf "${WHITESUR_TMP_DIR}"; exit 1
}
rootify() {
trap true SIGINT
prompt -w "Executing '$(echo "${@}" | cut -c -35 )...' as root"
if ! sudo "${@}"; then
error_snippet="${*}"
operation_aborted
fi
trap signal_exit SIGINT
}
userify() {
trap true SIGINT
if ! sudo -u "${MY_USERNAME}" "${@}"; then
error_snippet="${*}"
operation_aborted
fi
trap signal_exit SIGINT
}
trap 'operation_aborted' ERR
trap 'signal_exit' INT EXIT TERM
###############################################################################
# USER UTILITIES #
###############################################################################
helpify_title() {
printf "${c_cyan}%s${c_blue}%s ${c_green}%s\n\n" "Usage: " "$0" "[OPTIONS...]"
printf "${c_cyan}%s\n" "OPTIONS:"
@ -475,21 +584,9 @@ remind_relative_path() {
}
###############################################################################
# SYSTEMS #
# MISC #
###############################################################################
rootify() {
trap true SIGINT
prompt -w "Executing '$(echo "${@}" | cut -c -35 )...' as root"
if ! sudo "${@}"; then
errors+=("${*}")
operation_aborted
fi
trap signal_exit SIGINT
}
full_rootify() {
if [[ ! -w "/" ]]; then
prompt -e "ERROR: '${1}' needs a root priviledge. Please run this '${0}' as root"
@ -497,71 +594,6 @@ full_rootify() {
fi
}
userify() {
trap true SIGINT
if ! sudo -u "${MY_USERNAME}" "${@}"; then
errors+=("${*}")
operation_aborted
fi
trap signal_exit SIGINT
}
signal_exit() {
rm -rf "${WHITESUR_TMP_DIR}"
stop_animation
}
operation_aborted() {
IFS=$'\n'
local sources=($(basename -a "${BASH_SOURCE[@]}" | sort -u))
local dist_ids=($(cat '/etc/os-release' | awk -F '=' '/ID/{print $2}'))
clear
if [[ -f "${WHITESUR_TMP_DIR}/error_log.txt" ]]; then
error_msg="$(cat "${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:"
for i in "${sources[@]}"; do
errors+=("$(sed "${BASH_LINENO}q;d" "${REPO_DIR}/${i}")")
errors+=("$(sed "${LINENO}q;d" "${REPO_DIR}/${i}")")
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 :"
for i in "${FUNCNAME[@]}"; do
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 -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"
rm -rf "${WHITESUR_TMP_DIR}"; exit 1
}
usage() {
prompt -e "Usage function is not implemented"; exit 1
}
@ -572,22 +604,7 @@ finalize_argument_parsing() {
[[ "${has_any_error}" == "true" ]] && exit 1 || exit 0
elif [[ "${has_any_error}" == "true" ]]; then
echo; prompt -i "Try '$0 --help' for more information."; exit 1
else
[[ "${need_dialog[@]}" =~ "true" ]] && echo
if [[ -d "${WHITESUR_TMP_DIR}" ]]; then
start_animation; sleep 2; stop_animation; echo
if [[ -d "${WHITESUR_TMP_DIR}" ]]; then
prompt -e "ERROR: Whitesur installer or tweaks is already running. Probably it's run by '$(ls -ld "${WHITESUR_TMP_DIR}" | awk '{print $3}')'"
exit 1
fi
fi
rm -rf "${WHITESUR_TMP_DIR}"; mkdir -p "${WHITESUR_TMP_DIR}"
rm -rf "${THEME_SRC_DIR}/sass/_theme-options-temp.scss"
exec 2> "${WHITESUR_TMP_DIR}/error_log.txt"
trap 'operation_aborted' ERR
trap 'signal_exit' INT EXIT TERM
elif [[ "${need_dialog[@]}" =~ "true" ]]; then
echo
fi
}

View file

@ -1,18 +1,17 @@
# WARNING: Please make this shell not working-directory dependant, for example
# instead of using 'cd blabla', use 'cd "${REPO_DIR}/blabla"'
# instead of using 'ls blabla', use 'ls "${REPO_DIR}/blabla"'
#
# WARNING: Don't use "cd" in this shell, use it in a subshell instead,
# for example ( cd blabla && do_blabla ) or $( cd .. && do_blabla )
#
# WARNING: Please don't use sudo directly here since it steals our EXIT trap
#
# WARNING: Please set REPO_DIR variable before using this lib
###############################################################################
# VARIABLES #
###############################################################################
source "${REPO_DIR}/lib-core.sh"
WHITESUR_SOURCE+=("lib-install.sh")
###############################################################################
# DEPENDENCIES #
@ -23,6 +22,9 @@ install_theme_deps() {
! has_command xmllint || [[ ! -r "/usr/share/gtk-engines/murrine.xml" ]]; then
echo; prompt -w "'glib2.0', 'sassc', 'xmllint', and 'libmurrine' are required for theme installation."
# Be careful of some distro mechanism, some of them use rolling-release
# based installation, e.g., Arch Linux
if has_command zypper; then
rootify zypper in -y sassc glib2-devel gtk2-engine-murrine libxml2-tools
elif has_command apt; then
@ -32,7 +34,14 @@ install_theme_deps() {
elif has_command yum; then
rootify yum install -y sassc glib2-devel gtk-murrine-engine libxml2
elif has_command pacman; then
rootify pacman -S --noconfirm --needed sassc glib2 gtk-engine-murrine libxml2
# Explanation A:
# Arch-based distro doesnt have a seprate repo for each different build.
# This can cause a system call error since an app require the compatible
# version of dependencies. In other words, if you install an new app (which
# you definitely reinstall/upgrade the dependency for that app), but your
# other dependencies are old/expired, you'll end up with broken system.
# That's why we need a full system upgrade here
rootify pacman -Syu --noconfirm --needed sassc glib2 gtk-engine-murrine libxml2
else
prompt -w "WARNING: We're sorry, your distro isn't officially supported yet."
prompt -w "INSTRUCTION: Please make sure you have installed all of the required dependencies. We'll continue the installation in 15 seconds"
@ -45,8 +54,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
@ -58,7 +66,8 @@ install_gdm_deps() {
elif has_command yum; then
rootify yum install -y glib2-devel libxml2 sassc
elif has_command pacman; then
rootify pacman -S --noconfirm --needed glib2 libxml2 sassc
# See Explanation A
rootify pacman -Syu --noconfirm --needed glib2 libxml2 sassc
else
prompt -w "WARNING: We're sorry, your distro isn't officially supported yet."
prompt -w "INSTRUCTION: Please make sure you have installed all of the required dependencies. We'll continue the installation in 15 seconds"
@ -81,7 +90,8 @@ install_beggy_deps() {
elif has_command yum; then
rootify yum install -y ImageMagick
elif has_command pacman; then
rootify pacman -S --noconfirm --needed imagemagick
# See Explanation A
rootify pacman -Syu --noconfirm --needed imagemagick
else
prompt -w "WARNING: We're sorry, your distro isn't officially supported yet."
prompt -w "INSTRUCTION: Please make sure you have installed all of the required dependencies. We'll continue the installation in 15 seconds"
@ -104,7 +114,8 @@ install_dialog_deps() {
elif has_command yum; then
rootify yum install -y dialog
elif has_command pacman; then
rootify pacman -S --noconfirm --needed dialog
# See Explanation A
rootify pacman -Syu --noconfirm --needed dialog
else
prompt -w "WARNING: We're sorry, your distro isn't officially supported yet."
prompt -w "INSTRUCTION: Please make sure you have installed all of the required dependencies. We'll continue the installation in 15 seconds"
@ -186,7 +197,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"

View file

@ -10,9 +10,9 @@ LineWidth=0
#The color (RGBA) of the outer stroke.
OuterStrokeColor=0;;0;;0;;95
#The starting color (RGBA) of the fill gradient.
FillStartColor=235;;235;;235;;50
FillStartColor=209;;209;;209;;110
#The ending color (RGBA) of the fill gradient.
FillEndColor=235;;235;;235;;75
FillEndColor=209;;209;;209;;115
#The color (RGBA) of the inner stroke.
InnerStrokeColor=255;;255;;255;;245
@ -28,7 +28,7 @@ ItemPadding=4
#The size of item indicators, in tenths of a percent of IconSize.
IndicatorSize=5
#The size of the icon-shadow behind every item, in tenths of a percent of IconSize.
IconShadowSize=2
IconShadowSize=0
#The height (in percent of IconSize) to bounce an icon when the application sets urgent.
UrgentBounceHeight=1
#The height (in percent of IconSize) to bounce an icon when launching an application.

View file

@ -163,7 +163,7 @@ $panel_fg: if($trans == 'true', white, $text_color);
@if $trans == 'true' { $panel_bg: if($variant == 'light', rgba(white, $panel_opacity/2 + 0.08), rgba(black, $panel_opacity)); }
@if $black == 'true' { $panel_fg: $text_color; }
$dash_bg: if($variant == 'light', rgba(#f1f1f1, $panel_opacity + 0.2), rgba(#222222, $panel_opacity/2 + 0.6));
$dash_bg: if($variant == 'light', rgba(#d1d1d1, $panel_opacity + 0.33), rgba(#222222, $panel_opacity/2 + 0.6));
$dash_fg: if($variant == 'light', black, white);
// Entry colors

View file

@ -1,7 +1,7 @@
#! /usr/bin/env bash
# WARNING: Please make this shell not working-directory dependant, for example
# instead of using 'cd blabla', use 'cd "${REPO_DIR}/blabla"'
# instead of using 'ls blabla', use 'ls "${REPO_DIR}/blabla"'
#
# WARNING: Please don't use sudo directly here since it steals our EXIT trap
#
@ -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)
@ -216,8 +216,9 @@ else
fi
if [[ "${firefox}" == "false" && "${edit_firefox}" == "false" && "${flatpak}" == "false" && "${snap}" == "false" && "${gdm}" == "false" && "${dash_to_dock}" == "false" ]]; then
echo; prompt -e "Oops... there's nothing to tweaks..."
echo; prompt -i "Run ./tweaks.sh -h for help!..."
echo; prompt -e "Oops... there's nothing to tweak..."
echo; prompt -i "HINT: Don't forget to define which component to tweak, e.g. '--gdm'"
echo; prompt -i "HINT: Run ./tweaks.sh -h for help!..."
fi
echo