diff --git a/src/modules/packages/main.py b/src/modules/packages/main.py new file mode 100644 index 000000000..2413990b4 --- /dev/null +++ b/src/modules/packages/main.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 +# encoding: utf-8 +# === This file is part of Calamares - === +# +# Copyright 2014, Pier Luigi Fiorini +# +# Calamares is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Calamares is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Calamares. If not, see . + +import libcalamares +from libcalamares.utils import check_chroot_call + +class PackageManager: + def __init__(self, backend): + self.backend = backend + + def install(self, pkgs): + if self.backend == "packagekit": + for pkg in pkgs: + check_chroot_call(["pkcon", "-py", "install", pkg]) + elif self.backend == "zypp": + check_chroot_call(["zypper", "--non-interactive", "--quiet-install", "install", "--auto-agree-with-licenses", "install"] + pkgs) + elif self.backend == "yum": + check_chroot_call(["yum", "install", "-y"] + pkgs) + elif self.backend == "dnf": + check_chroot_call(["dnf", "install", "-y"] + pkgs) + elif self.backend == "urpmi": + check_chroot_call(["urpmi"] + pkgs) + elif self.backend == "apt": + check_chroot_call(["apt-get", "-q", "-y", "install"] + pkgs) + elif self.backend == "pacman": + check_chroot_call(["pacman", "-Sy"] + pkgs) + + def remove(self, pkgs): + if self.backend == "packagekit": + for pkg in pkgs: + check_chroot_call(["pkcon", "-py", "remove", pkg]) + elif self.backend == "zypp": + check_chroot_call(["zypper", "--non-interactive", "remove"] + pkgs) + elif self.backend == "yum": + check_chroot_call(["yum", "-y", "remove"] + pkgs) + elif self.backend == "dnf": + check_chroot_call(["dnf", "-y", "remove"] + pkgs) + elif self.backend == "urpmi": + check_chroot_call(["urpme"] + pkgs) + elif self.backend == "apt": + check_chroot_call(["apt-get", "--purge", "-q", "-y", "remove"] + pkgs) + elif self.backend == "pacman": + check_chroot_call(["pacman", "-R"] + pkgs) + +def run_operations(pkgman, entry): + for key in entry.keys(): + if key == "install": + pkgman.install(entry[key]) + elif key == "remove": + pkgman.remove(entry[key]) + +def run(): + backend = libcalamares.job.configuration.get("backend") + if backend not in ("packagekit", "zypp", "yum", "dnf", "urpmi", "apt", "pacman"): + return ("Bad backend", "backend=\"{}\"".format(backend)) + + pkgman = PackageManager(backend) + + operations = libcalamares.job.configuration.get("operations", []) + for entry in operations: + run_operations(pkgman, entry) + + operations = libcalamares.globalstorage.value("packageOperations") + for entry in operations: + run_operations(pkgman, entry) + + return None diff --git a/src/modules/packages/module.desc b/src/modules/packages/module.desc new file mode 100644 index 000000000..6a0423614 --- /dev/null +++ b/src/modules/packages/module.desc @@ -0,0 +1,5 @@ +--- +type: "job" +name: "packages" +interface: "python" +script: "main.py" diff --git a/src/modules/packages/packages.conf b/src/modules/packages/packages.conf new file mode 100644 index 000000000..6cfe8b7a5 --- /dev/null +++ b/src/modules/packages/packages.conf @@ -0,0 +1,41 @@ +--- +# +# Which package manager to use, options are: +# - packagekit - PackageKit CLI tool +# - zypp - Zypp RPM frontend +# - yum - Yum RPM frontend +# - dnf - DNF, the new RPM frontend +# - urpmi - Mandriva package manager +# - apt - APT frontend for DEB and RPM +# - pacman - Pacman +# +backend: packagekit +# +# List of maps with package operations such as install or remove. +# Distro developers can provide a list of packages to remove +# from the installed system (for instance packages meant only +# for the live system). +# +# A job implementing a distro specific logic to determine other +# packages that need to be installed or removed can run before +# this one. Distro developers may want to install locale packages +# or remove drivers not needed on the installed system. +# This job will populate a list of dictionaries in the global +# storage called "packageOperations" and it is processed +# after the static list in the job configuration. +# +#operations: +# - install: +# - pkg1 +# - pkg2 +# - remove: +# - pkg3 +# - pkg4 +# - install: +# - pkg5 +# - remove: +# - pkg2 +# - pkg1 +# install: +# - pkgs6 +# - pkg7 diff --git a/src/modules/packages/test.yaml b/src/modules/packages/test.yaml new file mode 100644 index 000000000..ba84cddc9 --- /dev/null +++ b/src/modules/packages/test.yaml @@ -0,0 +1,6 @@ +rootMountPoint: /tmp/mount +packageOperations: + - install: + - vi + - remove: + - vi