summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMürsel Türk2022-09-19 20:31:40 +0200
committerMürsel Türk2022-09-19 20:31:40 +0200
commit9f2789dc20ed97a6282f30a1e37973cfb43c65b5 (patch)
tree55bd3f522a6d38b1d5c364bf3973d04f0fe584e7 /tools
parentAdd support for alpine linux (diff)
downloadvm-inspector-9f2789dc20ed97a6282f30a1e37973cfb43c65b5.tar.gz
vm-inspector-9f2789dc20ed97a6282f30a1e37973cfb43c65b5.tar.xz
vm-inspector-9f2789dc20ed97a6282f30a1e37973cfb43c65b5.zip
Add support for gentoo linux
Diffstat (limited to 'tools')
-rw-r--r--tools/inspect_apps.py58
-rw-r--r--tools/inspect_os.py8
2 files changed, 66 insertions, 0 deletions
diff --git a/tools/inspect_apps.py b/tools/inspect_apps.py
index 613649b..a1a1157 100644
--- a/tools/inspect_apps.py
+++ b/tools/inspect_apps.py
@@ -9,6 +9,7 @@ __all__ = [
"list_applications_apk",
"list_applications_dpkg",
"list_applications_pacman",
+ "list_applications_portage",
"list_applications_rpm",
"list_applications_windows"
]
@@ -222,6 +223,63 @@ def list_applications_pacman(path):
@log
+def list_applications_portage(path):
+ """Find all packages installed on the linux distribution Gentoo Linux.
+
+ See also:
+ https://wiki.gentoo.org/wiki/Portage
+
+ Args:
+ path (str): Path to the mounted filesystem.
+
+ Returns:
+ List of packages. For example:
+ [{'name': 'sys-devel/bison', 'version': '3.8.2'}, ...]
+ """
+ portage_db = None
+
+ locations = [
+ "var/db/pkg",
+ "db/pkg" # separated /var partition
+ ]
+
+ for location in locations:
+ db = os.path.join(path, location)
+ if os.path.exists(db):
+ portage_db = db
+ break
+
+ # btrfs?
+ if portage_db is None:
+ for dir in subdirs(path):
+ new_path = os.path.join(path, dir)
+ for location in locations:
+ db = os.path.join(new_path, location)
+ if os.path.exists(db):
+ portage_db = db
+ break
+ if portage_db is not None:
+ break
+
+ if portage_db is None:
+ L.debug("portage database not found")
+ return []
+
+ pkgs = []
+ for cat in subdirs(portage_db):
+ for pkg in subdirs(os.path.join(portage_db, cat)):
+ # https://projects.gentoo.org/pms/8/pms.html#x1-150003
+ if m := re.match(r"^(.+)-(\d.*)$", pkg):
+ name, version = m.groups()
+ pkgs.append({
+ "name": "/".join([cat, name]),
+ "version": version
+ })
+
+ return pkgs
+
+
+@log
def list_applications_rpm(path):
"""Find all packages installed on a rpm-based linux distribution.
diff --git a/tools/inspect_os.py b/tools/inspect_os.py
index 9848c2e..892ca8a 100644
--- a/tools/inspect_os.py
+++ b/tools/inspect_os.py
@@ -61,6 +61,14 @@ def get_linux_os_info(path):
# AlmaLinux 8.* and Rocky Linux 8.* also have centos-release.
if m := re.match(r"^(.*)\srelease\s(.*)$", f.read()):
name, version = m.groups()
+ elif "gentoo-release" in release_files:
+ # Gentoo now has a VERSION_ID tag in os-release, which did not exist
+ # before. See also https://bugs.gentoo.org/788190. For consistency,
+ # gentoo-release is parsed before os-release at this point.
+ L.debug("parsing %s", release_files["gentoo-release"])
+ with open(release_files["gentoo-release"]) as f:
+ if m := re.match(r"^(Gentoo).*release\s(.*)$", f.read()):
+ name, version = m.groups()
elif "os-release" in release_files:
L.debug("parsing %s", release_files["os-release"])
with open(release_files["os-release"]) as f: