Files
init.sh/lib/pkgman.sh

244 lines
6.0 KiB
Bash

#!/bin/bash
# ------------------------------------------------------------------------------
# Package manager integration
# This file is part of the init.sh project
# Copyright (c) 2019-2024 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
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Upgrade package database
pkgupdt()
{
prnt I "Updating package list..."
$PKG_MAN $COM_UPDATE
}
export -f pkgupdt
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Installation
pkginst()
{
prnt I "Installing packages..."
if [[ $# -lt 1 ]]; then
prnt E "pkginst(): some required parameters are missing."
exit 11
fi
if [[ ! $INSTALL_MODE == dev ]]; then
exec_preinst $@
$PKG_MAN $COM_INSTALL $@
exec_postinst
else
local pkg=
for pkg in $@; do
exec_preinst $pkg
$PKG_MAN $COM_INSTALL $pkg
exec_postinst
done
unset pkg
fi
}
export -f pkginst
# ------------------------------------------------------------------------------
# Upgrade
pkgupgd()
{
prnt I "Applying system upgrade..."
exec_preupgd
$PKG_MAN $COM_UPGRADE
exec_postupgd
}
export -f pkgupgd
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Uninstallation
pkgrm()
{
prnt I "Uninstalling packages..."
if [[ $# -lt 1 ]]; then
prnt E "pkgrem(): some required parameters are missing."
exit 11
fi
if [[ ! $INSTALL_MODE == dev ]]; then
exec_prerm $@
$PKG_MAN $COM_REMOVE $@
exec_postrm
else
local pkg=
for pkg in $@; do
exec_prerm $pkg
$PKG_MAN $COM_REMOVE $pkg
exec_postrm
done
uset pkg
fi
}
export -f pkgrm
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Cleanup
pkgautorm()
{
prnt I "Uninstalling unneeded packages..."
exec_preautorm
$PKG_MAN $COM_AUTOREM
exec_postautorm
}
export -f pkgautorm
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Execute preinstallation code
exec_preinst()
{
local pkglist=$(get_install_list $@)
for pkg in $pkglist; do
if [[ $(function_exists preinst_$pkg) ]]; then
prnt I "Running $pkg preinstallation script..."
preinst_$pkg
fi
done
export POSTINSTLIST=$pkglist
unset pkglist
}
export -f exec_preinst
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Execute postinstallation code
exec_postinst()
{
if [[ -z $POSTINSTLIST ]]; then
return 0
fi
for pkg in $POSTINSTLIST; do
if [[ $(function_exists postinst_$pkg) ]]; then
prnt I "Running $pkg postinstallation script..."
postinst_$pkg
fi
done
unset POSTINSTLIST
}
export -f exec_postinst
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Execute preremove code
exec_prerm()
{
local pkglist=$(get_remove_list $@)
unset $cmd
for pkg in $pkglist; do
if [[ $(function_exists prerm_$pkg) ]]; then
prnt I "Running $pkg preremove script..."
prerm_$pkg
fi
done
export POSTRMLIST=$pkglist
unset pkglist
}
export -f exec_prerm
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Execute postremove code
exec_postrm()
{
if [[ -z $POSTRMLIST ]]; then
return 0
fi
for pkg in $POSTRMLIST; do
if [[ $(function_exists postrm_$pkg) ]]; then
prnt I "Running $pkg postremove script..."
postrm_$pkg
fi
done
unset POSTRMLIST
}
export -f exec_postrm
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Execute preupgrade code
exec_preupgd()
{
local pkglist=$(get_upgrade_list)
for pkg in $pkglist; do
if [[ $(function_exists preupgd_$pkg) ]]; then
prnt I "Running $pkg preupgrade script..."
preupgd_$pkg
fi
done
export POSTUPGDLIST=$pkglist
unset pkglist
}
export -f exec_preupgd
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Execute postupgrade code
exec_postupgd()
{
if [[ -z $POSTUPGDLIST ]]; then
return 0
fi
for pkg in $POSTUPGDLIST; do
if [[ $(function_exists postupgd_$pkg) ]]; then
prnt I "Running $pkg postupgrade script..."
postupgd_$pkg
fi
done
unset POSTUPGDLIST
}
export -f exec_postupgd
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Execute prerm code in autoremove context
exec_preautorm()
{
local pkglist=$(get_autorem_list)
for pkg in $pkglist; do
if [[ $(function_exists prerm_$pkg) ]]; then
prnt I "Running $pkg preremove script..."
prerm_$pkg
fi
done
export POSTRMLIST=$pkglist
unset pkglist
}
export -f exec_preautorm
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Execute postrm code in autoremove context
exec_postautorm()
{
exec_postrm
}
export -f exec_postautorm
# ------------------------------------------------------------------------------
# EOF