Skip to content

Commit

Permalink
interface_package: refactor & sort
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitry-ishenko committed Dec 13, 2024
1 parent 01737c2 commit b12b54d
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions tools/modules/functions/interface_package.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# interface_package.sh

# internal function
__pkg_have_stdin() { [[ -t 0 ]] }

declare -A module_options
module_options+=(
["package,author"]="@dimitry-ishenko"
Expand All @@ -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 "$@"
}

0 comments on commit b12b54d

Please sign in to comment.