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 12, 2024
1 parent 3740e7d commit 46b5412
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions tools/modules/functions/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# package.sh

declare -A module_options
module_options+=(
["package,author"]="@dimitry-ishenko"
["package,desc"]="Wrapper for package installation"
["package,example"]="package_install neovim"
["package,feature"]="package_install"
["package,status"]="active"
)

function package_install()
{
local apt=(apt-get -y)
[[ -t 0 ]] && apt=(debconf-apt-progress -- ${apt[@]})

${apt[@]} install "$@"
}

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

function package()
{
local apt=(apt-get -y)
[[ -t 0 ]] && apt=(debconf-apt-progress -- ${apt[@]})

case "$1" in
install) ${apt[@]} install "${@:2}";;

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

remove) ${apt[@]} autopurge "${@:2}";;
esac
}

module_options+=(
["package,author"]="@dimitry-ishenko"
["package,desc"]="Wrapper for package manipulation"
["package,example"]="install is-installed remove"
["package,feature"]="package"
["package,status"]="active"
)

function package()
{
local apt=(apt-get -y)
[[ -t 0 ]] && apt=(debconf-apt-progress -- ${apt[@]})

case "$1" in
install) ${apt[@]} install "${@:2}";;

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

remove) ${apt[@]} autopurge "${@:2}";;
esac
}

0 comments on commit 46b5412

Please sign in to comment.