diff --git a/tools/modules/functions/package.sh b/tools/modules/functions/package.sh new file mode 100644 index 00000000..55fab74c --- /dev/null +++ b/tools/modules/functions/package.sh @@ -0,0 +1,46 @@ +# 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" +) + +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" +) + +package_is_installed() +{ + 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"]="Wrapper for package removal" + ["package,example"]="package_remove nmap" + ["package,feature"]="package_remove" + ["package,status"]="active" +) + +package_remove() +{ + local apt=(apt-get -y) + [[ -t 0 ]] && apt=(debconf-apt-progress -- ${apt[@]}) + ${apt[@]} autopurge "$@" +}