Skip to content

Commit

Permalink
Initial support for archlinux updates through pacman_cli
Browse files Browse the repository at this point in the history
  • Loading branch information
k4z4n0v4 committed Jan 5, 2024
1 parent e0b0922 commit 5a1cf73
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 3 deletions.
6 changes: 5 additions & 1 deletion vmupdate/agent/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ def get_package_manager(os_data, log, log_handler, log_level, no_progress):

if no_progress:
from source.dnf.dnf_cli import DNFCLI as PackageManager
elif os_data["os_family"] == "ArchLinux":
from source.pacman.pacman_cli import PACMANCLI as PackageManager
else:
print(os_data["os_family"])
raise NotImplementedError(
"Only Debian and RedHat based OS is supported.")

Expand All @@ -86,5 +89,6 @@ def get_package_manager(os_data, log, log_handler, log_level, no_progress):
if __name__ == '__main__':
try:
sys.exit(main())
except RuntimeError:
except RuntimeError as ex:
print(ex)
sys.exit(1)
2 changes: 1 addition & 1 deletion vmupdate/agent/source/common/package_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def upgrade_internal(self, remove_obsolete: bool) -> ProcessResult:
Just run upgrade via CLI.
"""
cmd = [self.package_manager,
"-y",
"--noconfirm" if self.package_manager == "pacman" else "-y",
*self.get_action(remove_obsolete)]

return self.run_cmd(cmd)
20 changes: 20 additions & 0 deletions vmupdate/agent/source/pacman/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# coding=utf-8
#
# The Qubes OS Project, http://www.qubes-os.org
#
# Copyright (C) 2022 Piotr Bartman <[email protected]>
#
# This program 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 2
# of the License, or (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
68 changes: 68 additions & 0 deletions vmupdate/agent/source/pacman/pacman_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# coding=utf-8
#
# The Qubes OS Project, http://www.qubes-os.org
#
# Copyright (C) 2022 Piotr Bartman <[email protected]>
#
# This program 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 2
# of the License, or (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.

import shutil
from typing import List

from source.common.package_manager import PackageManager
from source.common.process_result import ProcessResult


class PACMANCLI(PackageManager):
def __init__(self, log_handler, log_level):
super().__init__(log_handler, log_level)
self.package_manager: str = "pacman"

def refresh(self, hard_fail: bool) -> ProcessResult:
"""
Use package manager to refresh available packages.
:param hard_fail: raise error if some repo is unavailable
:return: (exit_code, stdout, stderr)
"""
cmd = [ self.package_manager,
"-Sy" ]
return self.run_cmd(cmd)

def get_packages(self):
"""
Use pacman to return the installed packages and their versions.
"""

cmd = [ self.package_manager,
"-Q" ]
# EXAMPLE OUTPUT:
# qubes-vm-core 4.2.25-1
result = self.run_cmd(cmd)

packages = {}
for line in result.out.splitlines():
cols = line.split()
package, version = cols
packages.setdefault(package, []).append(version)

return packages

def get_action(self, remove_obsolete) -> List[str]:
"""
Pacman will handle obsoletions itself
"""
return ["-Syu"]
5 changes: 4 additions & 1 deletion vmupdate/agent/source/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_os_data(logger: Optional = None) -> Dict[str, Any]:
name: "Linux" or a string identifying the operating system,
codename (optional): an operating system release code name,
release (optional): packaging.version.Version,
os_family: "Unknown", "RedHat", "Debian".
os_family: "Unknown", "RedHat", "Debian", "ArchLinux".
"""
data = {}

Expand Down Expand Up @@ -64,6 +64,9 @@ def get_os_data(logger: Optional = None) -> Dict[str, Any]:
if 'rhel' in family or 'fedora' in family:
data["os_family"] = 'RedHat'

if 'arch' in family:
data["os_family"] = 'ArchLinux'

return data


Expand Down

0 comments on commit 5a1cf73

Please sign in to comment.