Files
init.sh/modules/install_pkg.sh

76 lines
2.3 KiB
Bash

# ------------------------------------------------------------------------------
# Install or remove packages
# This file is part of the init.sh project
# Copyright (c) 2019-2021 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# ------------------------------------------------------------------------------
# This file is distributed under 3-clause BSD license.
# The complete license agreement can be obtained at:
# https://opensource.org/licenses/BSD-3-Clause
# ------------------------------------------------------------------------------
# Variable:
# * PKGS_RMLIST: packages to remove
# * PKGS_BLACKLIST: package to mark as forbidden (will be removed if not)
# * PKGSEL: List of package to install
# ------------------------------------------------------------------------------
export VER_install_pkg="0.1.4"
export DEP_install_pkg="upgrade_dist"
install_pkg()
{
# Remove unnecessary packages
if [[ -n $PKGS_RMLIST ]]; then
prnt I "Removing some undesired packages..."
pkgrm $PKGS_RMLIST
fi
# Blacklist some anoying packages (and remove them if needed)
if [[ -n PKGS_BLACKLIST ]]; then
for pkg in $PKGS_BLACKLIST; do
prnt I "Placing $pkg into the blacklist..."
local dest=/etc/apt/preferences.d/blacklist_$pkg
installfile pkgman/blacklist.conf $dest &&
sed -i -e "s/@pkg@/pkg/" $dest
tagfile $dest
# If blacklisted we suppose uninstall as well (if neeeded)
pkgrm $pkg
done
fi
# Install all the configured packages
if [[ -n $PKGSEL ]]; then
prnt I "Installing the package selection..."
pkginst $PKGSEL
fi
# Cleaning
prnt I "Removing not needed anymore package..."
pkgautorm
}
precheck_install_pkg()
{
if [[ -z PKGS_RMLIST ]]; then
prnt I "No package to remove."
else
prnt I "$(echo $PKGS_RMLIST | wc -w) package to remove."
fi
if [[ -z PKGS_BLACKLIST ]]; then
prnt W "The packages $pkg will be placed into the blacklist !"
fi
if [[ -z $PKGSEL ]]; then
prnt W "No additionnal package to install !"
else
prnt I "$(echo $PKGSEL | wc -w) additionnal package have to be installed."
fi
file_exists pkgman/blacklist.conf
}
export -f install_pkg
export -f precheck_install_pkg
# EOF