Files
init.sh/modules/install_pkg.sh
2021-09-08 15:47:39 +02:00

66 lines
2.2 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.1"
install_pkg()
{
# Remove unnecessary packages
[[ -n $PKGS_RMLIST ]] &&
prnt I "Suppression de paquets supperflus..." &&
pkgrem $PKGS_RMLIST
# Blacklist some anoying packages (and remove them if needed)
if [[ -n PKGS_BLACKLIST ]]; then
for pkg in $PKGS_BLACKLIST; do
prnt I "Mise du paquet $pkg en liste noire..."
local dest=/usr/apt/preferences.d/blacklist_$pkg.conf
installfile blacklist.conf $dest &&
sed -i -e "s/@pkg@/pkg/" $dest
# If blacklisted we suppose uninstall as well (if neeeded)
pkgrem $pkg
done
fi
# Install all the configured packages
[[ -n $PKGSEL ]] &&
prnt I "Installation de la sélection de paquets..." &&
pkginst $PKGSEL
# Cleaning
prnt I "Suppression des paquets résiduels le cas échéant..."
pkgautorem
}
precheck_install_pkg()
{
if [[ -z PKGS_RMLIST ]]; then
prnt I "Aucun paquet à désinstaller"
else
prnt I "$(echo $PKGS_RMLIST | wc -w) paquets à supprimer."
fi
[[ -z PKGS_BLACKLIST ]] &&
prnt W "Les paquets $pkg seront placés en liste noire !"
if [[ -z $PKGSEL ]]; then
prnt W "Pas de paquet additionel à installer !"
else
prnt I "$(echo $PKGSEL | wc -w) paquets additionels seront installés."
fi
}
export -f install_pkg
export -f precheck_install_pkg