From f71a78a6a8269630d57ff74a5659e6bb28fbe091 Mon Sep 17 00:00:00 2001 From: Dimitry Ishenko Date: Wed, 11 Dec 2024 21:45:01 -0500 Subject: [PATCH] Add wrapper for package manipulation --- tools/modules/functions/interface_package.sh | 46 ++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tools/modules/functions/interface_package.sh diff --git a/tools/modules/functions/interface_package.sh b/tools/modules/functions/interface_package.sh new file mode 100644 index 00000000..06d5fc79 --- /dev/null +++ b/tools/modules/functions/interface_package.sh @@ -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* ]] +}