From b12b54d9529aba23f31c55f9d67a4ce8bfdca80f Mon Sep 17 00:00:00 2001 From: Dimitry Ishenko Date: Fri, 13 Dec 2024 15:28:31 -0500 Subject: [PATCH] interface_package: refactor & sort --- tools/modules/functions/interface_package.sh | 31 ++++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/tools/modules/functions/interface_package.sh b/tools/modules/functions/interface_package.sh index 06d5fc79..38fc0399 100644 --- a/tools/modules/functions/interface_package.sh +++ b/tools/modules/functions/interface_package.sh @@ -1,5 +1,8 @@ # interface_package.sh +# internal function +__pkg_have_stdin() { [[ -t 0 ]] } + declare -A module_options module_options+=( ["package,author"]="@dimitry-ishenko" @@ -11,36 +14,32 @@ module_options+=( pkg_install() { - local apt=(apt-get -y) - [[ -t 0 ]] && apt=(debconf-apt-progress -- ${apt[@]}) - ${apt[@]} install "$@" + __pkg_have_stdin && debconf-apt-progress -- apt-get -y install "$@" || apt-get -y install "$@" } module_options+=( ["package,author"]="@dimitry-ishenko" - ["package,desc"]="Remove package" - ["package,example"]="pkg_remove nmap" - ["package,feature"]="pkg_remove" + ["package,desc"]="Check if package is installed" + ["package,example"]="pkg_installed mc" + ["package,feature"]="pkg_installed" ["package,status"]="Interface" ) -pkg_remove() +pkg_installed() { - local apt=(apt-get -y) - [[ -t 0 ]] && apt=(debconf-apt-progress -- ${apt[@]}) - ${apt[@]} autopurge "$@" + local status=$(dpkg -s "$1" 2>/dev/null | sed -n "s/Status: //p") + ! [[ -z "$status" || "$status" = *deinstall* || "$status" = *not-installed* ]] } module_options+=( ["package,author"]="@dimitry-ishenko" - ["package,desc"]="Check if package is installed" - ["package,example"]="pkg_installed mc" - ["package,feature"]="pkg_installed" + ["package,desc"]="Remove package" + ["package,example"]="pkg_remove nmap" + ["package,feature"]="pkg_remove" ["package,status"]="Interface" ) -pkg_installed() +pkg_remove() { - local status=$(dpkg -s "$1" 2>/dev/null | sed -n "s/Status: //p") - ! [[ -z "$status" || "$status" = *deinstall* || "$status" = *not-installed* ]] + __pkg_have_stdin && debconf-apt-progress -- apt-get -y autopurge "$@" || apt-get -y autopurge "$@" }