From 07d0e57dbaad20ce612f2999a8c0ffb92f7ef15a Mon Sep 17 00:00:00 2001 From: Muhammad Rivan Date: Wed, 21 Apr 2021 19:56:32 +0700 Subject: [PATCH] Use different approach for distro detection and do a code refactoring --- install.sh | 2 +- lib-core.sh | 7 +++++-- lib-install.sh | 13 ++++++++----- src/assets/render-all-assets.sh | 2 +- tweaks.sh | 8 ++++---- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/install.sh b/install.sh index 4988d0e..6dd0e26 100755 --- a/install.sh +++ b/install.sh @@ -126,7 +126,7 @@ else echo; install_themes; echo; prompt -s "Done!" - if [[ "${DISTRO_BASE}" == "arch" && "$(which xfce4-session 2> /dev/null)" ]]; then + if is_my_distro "arch" && has_command xfce4-session; then msg="XFCE: you may need to logout after changing your theme to fix your panel opacity." notif_msg="${msg}\n\n${final_msg}" diff --git a/lib-core.sh b/lib-core.sh index da41589..0ec7e95 100755 --- a/lib-core.sh +++ b/lib-core.sh @@ -18,7 +18,6 @@ else LIB_CORE_IMPORTED="true"; fi export WHITESUR_PID=$$ MY_USERNAME="$(logname 2> /dev/null || echo ${SUDO_USER:-${USER}})" -DISTRO_BASE="$(cat '/etc/os-release' | awk -F '=' '/ID_LIKE/{print $2}')" if command -v gnome-shell &> /dev/null; then if (( $(gnome-shell --version | cut -d ' ' -f 3 | cut -d . -f 1) >= 4 )); then @@ -204,6 +203,10 @@ has_command() { command -v "$1" &> /dev/null } +is_my_distro() { + [[ "$(cat '/etc/os-release' | awk -F '=' '/ID/{print $2}')" =~ "${1}" ]] +} + ############################################################################### # PARAMETERS # ############################################################################### @@ -454,7 +457,7 @@ backup_file() { } check_theme_file() { - [[ -f "${1}" || -f "${1}.bak" ]] && return 0 || return 1 + [[ -f "${1}" || -f "${1}.bak" ]] } remind_relative_path() { diff --git a/lib-install.sh b/lib-install.sh index ba6f8fe..2a0732a 100755 --- a/lib-install.sh +++ b/lib-install.sh @@ -23,8 +23,8 @@ source "${REPO_DIR}/lib-core.sh" ############################################################################### install_theme_deps() { - if [[ ! "$(which glib-compile-resources 2> /dev/null)" || ! "$(which sassc 2> /dev/null)" || \ - ! -r "/usr/share/gtk-engines/murrine.xml" || ! "$(which xmllint 2> /dev/null)" ]]; then + if ! has_command glib-compile-resources || ! has_command sassc || \ + ! has_command xmllint || [[ ! -r "/usr/share/gtk-engines/murrine.xml" ]]; then echo; prompt -w "'glib2.0', 'sassc', 'xmllint', 'libmurrine' are required for theme installation." if has_command zypper; then @@ -47,7 +47,7 @@ install_theme_deps() { } install_beggy_deps() { - if [[ ! "$(which convert 2> /dev/null)" ]]; then + if ! has_command convert; then echo; prompt -w "'imagemagick' are required for this option." if has_command zypper; then @@ -67,7 +67,7 @@ install_beggy_deps() { } install_dialog_deps() { - if [[ ! "$(which dialog 2> /dev/null)" ]]; then + if ! has_command dialog; then echo; prompt -w "'dialog' are required for this option." if has_command zypper; then @@ -297,9 +297,12 @@ install_theemy() { remove_packy() { rm -rf "${dest}/${name}$(destify ${1})$(destify ${2})$(destify ${3})$(destify ${4})" - rm -rf "${dest}/${name}$(destify ${1})-mdpi" + rm -rf "${dest}/${name}$(destify ${1})" rm -rf "${dest}/${name}$(destify ${1})-hdpi" rm -rf "${dest}/${name}$(destify ${1})-xhdpi" + + # Backward compatibility + rm -rf "${dest}/${name}$(destify ${1})-mdpi" } ############################################################################### diff --git a/src/assets/render-all-assets.sh b/src/assets/render-all-assets.sh index bb405dd..b2554dc 100755 --- a/src/assets/render-all-assets.sh +++ b/src/assets/render-all-assets.sh @@ -8,7 +8,7 @@ has_command() { "$1" -v $1 > /dev/null 2>&1 } -if [ ! "$(which inkscape 2> /dev/null)" ]; then +if ! has_command inkscape; then echo inkscape and optipng needs to be installed to generate the assets. if has_command zypper; then sudo zypper in inkscape optipng diff --git a/tweaks.sh b/tweaks.sh index e805e1a..477b1f5 100755 --- a/tweaks.sh +++ b/tweaks.sh @@ -67,7 +67,7 @@ while [[ $# -gt 0 ]]; do edit_firefox="true" ;; esac - if [[ ! "$(which firefox 2> /dev/null)" ]]; then + if ! has_command firefox; then prompt -e "'${1}' ERROR: There's no Firefox installed in your system" has_any_error="true" elif [[ ! -d "${FIREFOX_DIR_HOME}" ]]; then @@ -81,21 +81,21 @@ while [[ $# -gt 0 ]]; do -F|--flatpak) flatpak="true"; - if [[ ! "$(which flatpak 2> /dev/null)" ]]; then + if ! has_command flatpak; then prompt -e "'${1}' ERROR: There's no Flatpak installed in your system" has_any_error="true" fi; shift ;; -s|--snap) snap="true"; - if [[ ! "$(which snap 2> /dev/null)" ]]; then + if ! has_command snap; then prompt -e "'${1}' ERROR: There's no Snap installed in your system" has_any_error="true" fi; shift ;; -g|--gdm) gdm="true"; full_rootify "${1}" - if [[ ! "$(which gdm 2> /dev/null)" && ! "$(which gdm3 2> /dev/null)" ]]; then + if ! has_command gdm && ! has_command gdm3; then prompt -e "'${1}' ERROR: There's no GDM installed in your system" has_any_error="true" fi; shift ;;