Skip to content

Commit

Permalink
Add wrapper for package manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitry-ishenko committed Dec 13, 2024
1 parent 3740e7d commit f71a78a
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tools/modules/functions/interface_package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# interface_package.sh

declare -A module_options
module_options+=(
["package,author"]="@dimitry-ishenko"
["package,desc"]="Install package"
["package,example"]="pkg_install neovim"
["package,feature"]="pkg_install"
["package,status"]="Interface"
)

pkg_install()
{
local apt=(apt-get -y)
[[ -t 0 ]] && apt=(debconf-apt-progress -- ${apt[@]})
${apt[@]} install "$@"
}

module_options+=(
["package,author"]="@dimitry-ishenko"
["package,desc"]="Remove package"
["package,example"]="pkg_remove nmap"
["package,feature"]="pkg_remove"
["package,status"]="Interface"
)

pkg_remove()
{
local apt=(apt-get -y)
[[ -t 0 ]] && apt=(debconf-apt-progress -- ${apt[@]})
${apt[@]} autopurge "$@"
}

module_options+=(
["package,author"]="@dimitry-ishenko"
["package,desc"]="Check if package is installed"
["package,example"]="pkg_installed mc"
["package,feature"]="pkg_installed"
["package,status"]="Interface"
)

pkg_installed()
{
local status=$(dpkg -s "$1" 2>/dev/null | sed -n "s/Status: //p")
! [[ -z "$status" || "$status" = *deinstall* || "$status" = *not-installed* ]]
}

0 comments on commit f71a78a

Please sign in to comment.