2014-08-29 22:55:11 +02:00
|
|
|
#!/usr/bin/env python3
|
2015-02-18 15:06:10 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2014-08-29 22:55:11 +02:00
|
|
|
# === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
#
|
|
|
|
# Copyright 2014, Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
|
|
|
|
#
|
|
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import libcalamares
|
2015-01-19 03:06:12 +01:00
|
|
|
from libcalamares.utils import check_chroot_call, chroot_call
|
2014-08-29 22:55:11 +02:00
|
|
|
|
2015-02-18 15:47:24 +01:00
|
|
|
|
2014-08-29 22:55:11 +02:00
|
|
|
class PackageManager:
|
2015-02-21 11:24:53 +01:00
|
|
|
""" Package manager class.
|
2015-02-20 20:54:25 +01:00
|
|
|
|
|
|
|
:param backend:
|
|
|
|
"""
|
2014-08-29 22:55:11 +02:00
|
|
|
def __init__(self, backend):
|
|
|
|
self.backend = backend
|
|
|
|
|
2015-03-02 00:28:14 +01:00
|
|
|
def install(self, pkgs, from_local=False):
|
2015-02-21 10:46:01 +01:00
|
|
|
""" Installs packages.
|
2015-02-20 20:54:25 +01:00
|
|
|
|
|
|
|
:param pkgs:
|
2015-06-14 13:25:37 +02:00
|
|
|
:param from_local:
|
2015-02-20 20:54:25 +01:00
|
|
|
"""
|
2014-08-29 22:55:11 +02:00
|
|
|
if self.backend == "packagekit":
|
|
|
|
for pkg in pkgs:
|
|
|
|
check_chroot_call(["pkcon", "-py", "install", pkg])
|
|
|
|
elif self.backend == "zypp":
|
2015-06-14 13:25:37 +02:00
|
|
|
check_chroot_call(["zypper", "--non-interactive", "--quiet-install", "install",
|
|
|
|
"--auto-agree-with-licenses", "install"] + pkgs)
|
2014-08-29 22:55:11 +02:00
|
|
|
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":
|
2015-06-14 13:25:37 +02:00
|
|
|
check_chroot_call(["urpmi", "--download-all", "--no-suggests", "--no-verify-rpm",
|
|
|
|
"--fastunsafe", "--ignoresize", "--nolock", "--auto"] + pkgs)
|
2014-08-29 22:55:11 +02:00
|
|
|
elif self.backend == "apt":
|
|
|
|
check_chroot_call(["apt-get", "-q", "-y", "install"] + pkgs)
|
|
|
|
elif self.backend == "pacman":
|
2015-06-14 13:25:37 +02:00
|
|
|
if from_local:
|
|
|
|
pacman_flags = "-U"
|
|
|
|
else:
|
|
|
|
pacman_flags = "-Sy"
|
|
|
|
|
2015-03-02 00:28:14 +01:00
|
|
|
check_chroot_call(["pacman", pacman_flags, "--noconfirm"] + pkgs)
|
2015-06-08 18:56:24 +02:00
|
|
|
elif self.backend == "portage":
|
|
|
|
check_chroot_call(["emerge", "-v"] + pkgs)
|
|
|
|
elif self.backend == "entropy":
|
|
|
|
check_chroot_call(["equo", "i"] + pkgs)
|
2014-08-29 22:55:11 +02:00
|
|
|
|
|
|
|
def remove(self, pkgs):
|
2015-02-21 10:46:01 +01:00
|
|
|
""" Removes packages.
|
2015-02-20 20:54:25 +01:00
|
|
|
|
|
|
|
:param pkgs:
|
|
|
|
"""
|
2014-08-29 22:55:11 +02:00
|
|
|
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":
|
2015-01-19 02:57:29 +01:00
|
|
|
check_chroot_call(["yum", "--disablerepo=*", "-C", "-y", "remove"] + pkgs)
|
2014-08-29 22:55:11 +02:00
|
|
|
elif self.backend == "dnf":
|
2015-01-19 03:06:12 +01:00
|
|
|
# ignore the error code for now because dnf thinks removing a nonexistent package is an error
|
|
|
|
chroot_call(["dnf", "--disablerepo=*", "-C", "-y", "remove"] + pkgs)
|
2014-08-29 22:55:11 +02:00
|
|
|
elif self.backend == "urpmi":
|
2015-02-22 13:38:37 +01:00
|
|
|
check_chroot_call(["urpme", "--auto"] + pkgs)
|
2014-08-29 22:55:11 +02:00
|
|
|
elif self.backend == "apt":
|
|
|
|
check_chroot_call(["apt-get", "--purge", "-q", "-y", "remove"] + pkgs)
|
2014-11-27 11:02:42 +01:00
|
|
|
check_chroot_call(["apt-get", "--purge", "-q", "-y", "autoremove"])
|
2014-08-29 22:55:11 +02:00
|
|
|
elif self.backend == "pacman":
|
2014-11-28 20:54:35 +01:00
|
|
|
check_chroot_call(["pacman", "-Rs", "--noconfirm"] + pkgs)
|
2015-06-08 18:56:24 +02:00
|
|
|
elif self.backend == "portage":
|
|
|
|
check_chroot_call(["emerge", "-C"] + pkgs)
|
|
|
|
elif self.backend == "entropy":
|
|
|
|
check_chroot_call(["equo", "rm"] + pkgs)
|
2014-08-29 22:55:11 +02:00
|
|
|
|
2015-02-18 15:47:24 +01:00
|
|
|
|
2014-08-29 22:55:11 +02:00
|
|
|
def run_operations(pkgman, entry):
|
2015-02-21 10:46:01 +01:00
|
|
|
""" Call package manager with given parameters.
|
2015-02-20 20:54:25 +01:00
|
|
|
|
|
|
|
:param pkgman:
|
|
|
|
:param entry:
|
|
|
|
"""
|
2014-08-29 22:55:11 +02:00
|
|
|
for key in entry.keys():
|
|
|
|
if key == "install":
|
|
|
|
pkgman.install(entry[key])
|
|
|
|
elif key == "remove":
|
|
|
|
pkgman.remove(entry[key])
|
2015-03-04 16:19:26 +01:00
|
|
|
elif key == "localInstall":
|
2015-03-02 00:28:14 +01:00
|
|
|
pkgman.install(entry[key], from_local=True)
|
2014-08-29 22:55:11 +02:00
|
|
|
|
2015-02-18 15:47:24 +01:00
|
|
|
|
2014-08-29 22:55:11 +02:00
|
|
|
def run():
|
2015-02-21 10:46:01 +01:00
|
|
|
""" Calls routine with detected package manager to install locale packages
|
|
|
|
or remove drivers not needed on the installed system.
|
2015-02-20 20:54:25 +01:00
|
|
|
|
|
|
|
:return:
|
|
|
|
"""
|
2014-08-29 22:55:11 +02:00
|
|
|
backend = libcalamares.job.configuration.get("backend")
|
2015-06-14 13:25:37 +02:00
|
|
|
|
2015-06-08 18:56:24 +02:00
|
|
|
if backend not in ("packagekit", "zypp", "yum", "dnf", "urpmi", "apt", "pacman", "portage", "entropy"):
|
2015-06-14 13:25:37 +02:00
|
|
|
return "Bad backend", "backend=\"{}\"".format(backend)
|
2014-08-29 22:55:11 +02:00
|
|
|
|
|
|
|
pkgman = PackageManager(backend)
|
|
|
|
operations = libcalamares.job.configuration.get("operations", [])
|
2015-06-14 13:25:37 +02:00
|
|
|
|
2014-08-29 22:55:11 +02:00
|
|
|
for entry in operations:
|
|
|
|
run_operations(pkgman, entry)
|
|
|
|
|
2014-10-27 18:39:11 +01:00
|
|
|
if libcalamares.globalstorage.contains("packageOperations"):
|
2014-10-27 16:58:42 +01:00
|
|
|
operations = libcalamares.globalstorage.value("packageOperations")
|
2015-06-14 13:25:37 +02:00
|
|
|
|
2014-10-27 16:58:42 +01:00
|
|
|
for entry in operations:
|
|
|
|
run_operations(pkgman, entry)
|
2014-08-29 22:55:11 +02:00
|
|
|
|
|
|
|
return None
|