Improve stability

This commit is contained in:
Muhammad Rivan 2021-06-12 10:07:19 +07:00
parent 3912767cd0
commit 9dd112f1b0
No known key found for this signature in database
GPG key ID: C56A200FD936FAAA
2 changed files with 40 additions and 38 deletions

View file

@ -21,7 +21,7 @@ WHITESUR_SOURCE=("lib-core.sh")
#--------------System--------------# #--------------System--------------#
export WHITESUR_PID=$$ export WHITESUR_PID=$$
MY_USERNAME="$(logname 2> /dev/null || echo ${SUDO_USER:-${USER}})" MY_USERNAME="$(logname || echo ${SUDO_USER:-${USER}})"
if command -v gnome-shell &> /dev/null; then if command -v gnome-shell &> /dev/null; then
if (( $(gnome-shell --version | cut -d ' ' -f 3 | cut -d . -f 1) >= 4 )); then if (( $(gnome-shell --version | cut -d ' ' -f 3 | cut -d . -f 1) >= 4 )); then
@ -137,7 +137,6 @@ swupd_packages=""
swupd_url="https://cdn.download.clearlinux.org/current/x86_64/os/Packages/" swupd_url="https://cdn.download.clearlinux.org/current/x86_64/os/Packages/"
swupd_ver_url="https://cdn.download.clearlinux.org/latest" swupd_ver_url="https://cdn.download.clearlinux.org/latest"
swupd_prepared="false" swupd_prepared="false"
apt_prepared="false"
xbps_prepared="false" xbps_prepared="false"
#------------Decoration-----------# #------------Decoration-----------#
@ -241,7 +240,7 @@ signal_error() {
local lines=() local lines=()
local log="$(awk '{printf "\033[1;31m >>> %s\n", $0}' "${WHITESUR_TMP_DIR}/error_log.txt" || echo "")" local log="$(awk '{printf "\033[1;31m >>> %s\n", $0}' "${WHITESUR_TMP_DIR}/error_log.txt" || echo "")"
if ! repo_ver="$(cd "${REPO_DIR}"; git log -1 --date=format-local:"%FT%T%z" --format="%ad" 2> /dev/null)"; then 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 if ! repo_ver="$(date -r "${REPO_DIR}" +"%FT%T%z")"; then
repo_ver="unknown" repo_ver="unknown"
fi fi
@ -296,9 +295,9 @@ trap 'signal_abort' INT TERM TSTP
############################################################################### ###############################################################################
ask() { ask() {
echo -e "${c_magenta}\r" echo -ne "${c_magenta}"
read -p " ${2}: " ${1} 2>&1 read -p " ${2}: " ${1} 2>&1
echo -e "${c_default}" echo -ne "${c_default}"
} }
confirm() { confirm() {
@ -343,7 +342,7 @@ has_command() {
} }
has_flatpak_app() { has_flatpak_app() {
flatpak list --columns=application 2> /dev/null | grep "${1}" &> /dev/null || return 1 flatpak list --columns=application | grep "${1}" &> /dev/null || return 1
} }
has_snap_app() { has_snap_app() {
@ -492,8 +491,6 @@ check_param() {
fi fi
done ;; done ;;
-a) -a)
[[ "${alts_set}" == "false" ]] && alts=()
if [[ "${value}" == "all" ]]; then if [[ "${value}" == "all" ]]; then
for i in {0..2}; do for i in {0..2}; do
alts+=("${ALT_VARIANTS[i]}") alts+=("${ALT_VARIANTS[i]}")
@ -623,40 +620,46 @@ remind_relative_path() {
############################################################################### ###############################################################################
sudo() { sudo() {
local result="0" local result="1"
prompt -w "Executing '$(echo "${@}" | cut -c -35 )...' as root" prompt -w "Executing '$(echo "${@}" | cut -c -35 )...' as root"
if ! ${SUDO_BIN} -n true 2> /dev/null; then if ! ${SUDO_BIN} -n true &> /dev/null; then
echo -e "${c_magenta} Authentication is required:${c_default}" echo -e "${c_magenta} Authentication is required:${c_default}"
fi fi
# Don't combine '[[ ... ]]' and '! ... < /dev/stdin' cause it's gonna
# break the logic/workflow
if [[ -p /dev/stdin ]]; then if [[ -p /dev/stdin ]]; then
if ! ${SUDO_BIN} "${@}" < /dev/stdin; then ${SUDO_BIN} "${@}" < /dev/stdin
result="1"; WHITESUR_COMMAND="${*}" else
fi ${SUDO_BIN} "${@}"
elif ! ${SUDO_BIN} "${@}"; then
result="1"; WHITESUR_COMMAND="${*}"
fi fi
result="${?}"
[[ "${result}" != "0" ]] && WHITESUR_COMMAND="${*}"
return "${result}" return "${result}"
} }
udo() { udo() {
local result="0" local result="1"
# Don't combine '[[ ... ]]' and '! ... < /dev/stdin' cause it's gonna # Just in case. We put the prompt here to make it less annoying
# break the logic/workflow if ! ${SUDO_BIN} -u "${MY_USERNAME}" -n true &> /dev/null; then
if [[ -p /dev/stdin ]]; then prompt -w "Executing '$(echo "${@}" | cut -c -35 )...' as user"
if ! ${SUDO_BIN} -u "${MY_USERNAME}" "${@}" < /dev/stdin; then echo -e "${c_magenta} Authentication is required:${c_default}"
result="1"; WHITESUR_COMMAND="${*}"
fi
elif ! ${SUDO_BIN} -u "${MY_USERNAME}" "${@}"; then
result="1"; WHITESUR_COMMAND="${*}"
fi fi
if [[ -p /dev/stdin ]]; then
${SUDO_BIN} -u "${MY_USERNAME}" "${@}" < /dev/stdin
else
${SUDO_BIN} -u "${MY_USERNAME}" "${@}"
fi
result="${?}"
[[ "${result}" != "0" ]] && WHITESUR_COMMAND="${*}"
return "${result}" return "${result}"
} }

View file

@ -63,7 +63,7 @@ prepare_deps() {
if (( remote_time_int > local_time_int )); then if (( remote_time_int > local_time_int )); then
prompt -w "\n DEPS: Your system clock is wrong" prompt -w "\n DEPS: Your system clock is wrong"
prompt -i "DEPS: Updating your system clock...\n" prompt -i "DEPS: Updating your system clock...\n"
sudo date -s "${remote_time}" &> /dev/null; sudo hwclock --systohc sudo date -s "${remote_time}"; sudo hwclock --systohc
fi fi
} }
@ -76,7 +76,7 @@ prepare_swupd() {
local dist="" local dist=""
if has_command dnf; then if has_command dnf; then
prompt -w "CLEAR LINUX: You have 'dnf' installed in your system. It may break your system especially when you remove a package\n" prompt -w "CLEAR LINUX: You have 'dnf' installed in your system. It may break your system especially when you remove a package"
confirm remove "CLEAR LINUX: You wanna remove it?"; echo confirm remove "CLEAR LINUX: You wanna remove it?"; echo
fi fi
@ -111,16 +111,15 @@ install_swupd_packages() {
done done
} }
prepare_apt() { prepare_install_apt_packages() {
[[ "${apt_prepared}" == "true" ]] && return 0 sudo apt update -y; sudo apt install -y "${@}"
if ! sudo apt update; then if [[ "${?}" == "100" ]]; then
prompt -w "\n APT: Your repo lists are broken" prompt -w "\n APT: Your repo lists might be broken"
prompt -i "APT: Full-cleaning your repo lists and try again...\n" prompt -i "APT: Full-cleaning your repo lists and try again...\n"
sudo apt clean; sudo rm -rf /var/lib/apt/lists; sudo apt update sudo apt clean -y; sudo rm -rf /var/lib/apt/lists
sudo apt update -y; sudo apt install -y "${@}"
fi fi
apt_prepared="true"
} }
prepare_xbps() { prepare_xbps() {
@ -150,7 +149,7 @@ install_theme_deps() {
# Rolling release # Rolling release
prepare_swupd && sudo swupd bundle-add libglib libxml2 && install_swupd_packages sassc libsass prepare_swupd && sudo swupd bundle-add libglib libxml2 && install_swupd_packages sassc libsass
elif has_command apt; then elif has_command apt; then
prepare_apt && sudo apt install -y sassc libglib2.0-dev-bin gtk2-engines-murrine libxml2-utils prepare_install_apt_packages sassc libglib2.0-dev-bin gtk2-engines-murrine libxml2-utils
elif has_command dnf; then elif has_command dnf; then
sudo dnf install -y sassc glib2-devel gtk-murrine-engine libxml2 sudo dnf install -y sassc glib2-devel gtk-murrine-engine libxml2
elif has_command yum; then elif has_command yum; then
@ -182,7 +181,7 @@ install_beggy_deps() {
# Rolling release # Rolling release
prepare_swupd && sudo swupd bundle-add ImageMagick prepare_swupd && sudo swupd bundle-add ImageMagick
elif has_command apt; then elif has_command apt; then
prepare_apt && sudo apt install -y imagemagick prepare_install_apt_packages imagemagick
elif has_command dnf; then elif has_command dnf; then
sudo dnf install -y ImageMagick sudo dnf install -y ImageMagick
elif has_command yum; then elif has_command yum; then
@ -210,7 +209,7 @@ install_dialog_deps() {
# Rolling release # Rolling release
prepare_swupd && install_swupd_packages dialog prepare_swupd && install_swupd_packages dialog
elif has_command apt; then elif has_command apt; then
prepare_apt && sudo apt install -y dialog prepare_install_apt_packages dialog
elif has_command dnf; then elif has_command dnf; then
sudo dnf install -y dialog sudo dnf install -y dialog
elif has_command yum; then elif has_command yum; then