From 46b5412fa4015cdeea867177ee24972101760b90 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/package.sh | 69 ++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tools/modules/functions/package.sh diff --git a/tools/modules/functions/package.sh b/tools/modules/functions/package.sh new file mode 100644 index 00000000..ac9d9565 --- /dev/null +++ b/tools/modules/functions/package.sh @@ -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 +} +