summaryrefslogtreecommitdiffstats
path: root/core/includes
diff options
context:
space:
mode:
authorSimon Rettberg2021-07-07 17:28:24 +0200
committerSimon Rettberg2021-07-07 17:28:24 +0200
commite5d9d9262ba5d9434891945de63f1eae66badabe (patch)
tree724a92ae86de55414c2284f3c55a453d16a9a67b /core/includes
parentAdd sub-target feature: Targets can contain other targets (diff)
downloadmltk-e5d9d9262ba5d9434891945de63f1eae66badabe.tar.gz
mltk-e5d9d9262ba5d9434891945de63f1eae66badabe.tar.xz
mltk-e5d9d9262ba5d9434891945de63f1eae66badabe.zip
setup_target: Install all required packages at once at the start
If we can't satisfy the requirements of all modules, bail out early instead of some time halfway through the module list. This is also faster than invoking apt for every single package.
Diffstat (limited to 'core/includes')
-rw-r--r--core/includes/packagemanager.inc112
1 files changed, 11 insertions, 101 deletions
diff --git a/core/includes/packagemanager.inc b/core/includes/packagemanager.inc
index 5b798c22..1e5b236d 100644
--- a/core/includes/packagemanager.inc
+++ b/core/includes/packagemanager.inc
@@ -22,7 +22,7 @@ list_content_packages() {
done
}
-list_content_package(){
+list_content_package() {
#[ -z "$EXTRA_PACKAGES" ] || pinfo "Listing additional packages: $EXTRA_PACKAGES"
[ $# -gt 2 ] && perror "'list_content_package' accepts max 2 args. $# given."
local OP="-e"
@@ -83,110 +83,20 @@ list_packet_files() {
}
#
-# Convenience function
-#
-# install all dependencies of a module
-# goes through all package as given in the variable REQUIRED_INSTALLED_PACKAGES
-install_dependencies() {
- [ -z "${REQUIRED_INSTALLED_PACKAGES}${REQUIRED_CONTENT_PACKAGES}" ] && return
- # add all REQUIRED_CONTENT_PACKAGES that are not tagged as optional
- local TO_INSTALL="$REQUIRED_INSTALLED_PACKAGES"
- for pkg in $REQUIRED_CONTENT_PACKAGES ; do
- if [ "${pkg:0:1}" != "@" ]; then
- TO_INSTALL="$TO_INSTALL $pkg"
- fi
- done
- install_packages "$TO_INSTALL"
-}
-
-#
-# install given packet through system's packet manager
-# uses PACKET_HANDLER as determined in helper/system.inc
-#
-install_packages() {
- [ $# -eq 0 ] && perror "Sanity check failed: no argument given to install_package"
- local PACKAGE_LIST="$@"
- local INSTALLED_PACKAGES=""
- local LRET=""
-
- for PKG in ${PACKAGE_LIST}; do
- # check if installed:
- # this is done mainly for performance reasons, even though
- # reinstalling all packages is a valid possibility too...
- if [ "x$PACKET_HANDLER" == "xdpkg" ]; then
- dpkg -l ${PKG} > /dev/null 2>&1
- LRET=$?
- elif [ "x$PACKET_HANDLER" == "xrpm" ]; then
- rpm -ql "${PKG}" > /dev/null 2>&1
- LRET=$?
- else
- perror "No packet manager / handler determined, this should not happen!"
- fi
-
- if [ "x$LRET" == "x0" ]; then
- # check if it is completly installed, not just leftover configuration files
- if [ "x$PACKET_HANDLER" == "xdpkg" ]; then
- local INSTALL_STATUS=$(dpkg -l "${PKG}" | grep "${PKG}" | cut -c1-2)
- if [[ $INSTALL_STATUS != "ii" ]]; then
- pinfo "$PKG is either missing or a meta-package! Installing it to be sure..."
- install_package "${PKG}"
- else
- # package installed
- pdebug "${PKG} installed!"
- fi
- elif [ "x$PACKET_HANDLER" == "xrpm" ]; then
- # TODO: blindly install again for now
- rpm -q "${PKG}" >/dev/null 2>&1 || install_package "${PKG}"
- fi
- else
- # package not installed
- pdebug "$PKG not installed!"
- install_package $PKG
- fi
- done
- [ ! -z "$INSTALLED_PACKAGES" ] && pinfo "New packages installed: ${INSTALLED_PACKAGES}"
-}
-
-#
# install individual package depending on package manager
#
-install_package() {
- if [ "$#" -ne 1 ]; then
- perror "Only call install_package with one argument!"
- fi
-
- if [ "x$PACKET_MANAGER" == "xapt" ]; then
- apt-get install -y ${PKG}
- local IRET=$?
- if [ "x$IRET" == "x0" ]; then
- # $PGK was installed successfully
- INSTALLED_PACKAGES+="$PKG "
- else
- # PKG was not installed
- # TODO error handling
- perror "install_packages: apt-get failed with '$IRET' for package '$PKG'"
+install_packages() {
+ if [ "$PACKET_MANAGER" == "apt" ]; then
+ if ! apt-get install --no-install-recommends -y "$@"; then
+ perror "install_packages: apt-get failed, see log"
fi
- elif [ "x$PACKET_MANAGER" == "xzypper" ]; then
- zypper --no-refresh --non-interactive install --force-resolution ${PKG}
- local IRET=$?
- if [ "x$IRET" == "x0" ]; then
- # $PGK was installed successfully
- INSTALLED_PACKAGES+="$PKG "
- else
- # PKG was not installed
- # TODO error handling
- perror "install_packages: zypper failed with '$IRET' for package '$PKG'"
+ elif [ "$PACKET_MANAGER" == "zypper" ]; then
+ if ! zypper --no-refresh --non-interactive install --force-resolution "$@"; then
+ perror "install_packages: zypper failed, see log"
fi
- elif [ "x$PACKET_MANAGER" == "xyum" ]; then
- yum --assumeyes install ${PKG}
- local IRET=$?
- if [ "x$IRET" == "x0" ]; then
- # $PGK was installed successfully
- INSTALLED_PACKAGES+="$PKG "
- else
- # PKG was not installed
- # TODO error handling
- perror "install_packages: yum failed with '$IRET' for package '$PKG'"
+ elif [ "$PACKET_MANAGER" == "yum" ]; then
+ if ! yum --assumeyes install "$@"; then
+ perror "install_packages: yum failed, see log"
fi
else
perror "No packet manager determined, this should not happen!"