From 97807a4718545574ac48cc9f70ada28e263cf112 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..5aa427c9 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 "$@" }