summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMürsel Türk2022-10-10 22:04:19 +0200
committerMürsel Türk2022-10-10 22:04:19 +0200
commit6426257fd0b3c5e176e2a3a29bdaa07aee0cbc0d (patch)
tree4966d5cdc7090fc9c4d1aaa06cae9741fc0c9b38 /tools
parentSome improvements (diff)
downloadvm-inspector-6426257fd0b3c5e176e2a3a29bdaa07aee0cbc0d.tar.gz
vm-inspector-6426257fd0b3c5e176e2a3a29bdaa07aee0cbc0d.tar.xz
vm-inspector-6426257fd0b3c5e176e2a3a29bdaa07aee0cbc0d.zip
Improve detection of used package manager
Diffstat (limited to 'tools')
-rw-r--r--tools/inspect_os.py38
1 files changed, 33 insertions, 5 deletions
diff --git a/tools/inspect_os.py b/tools/inspect_os.py
index e374464..ce03ee9 100644
--- a/tools/inspect_os.py
+++ b/tools/inspect_os.py
@@ -31,7 +31,8 @@ def get_linux_os_info(path):
Returns:
Name and version of linux distribution as a dictionary. For example:
- {'name': 'CentOS Linux', 'version': '6.0 (Final)'}
+ {'name': 'CentOS Linux', 'version': '6.0 (Final)',
+ 'package_manager': 'rpm'}
"""
release_files = {}
for root, dirs, _ in os.walk(path):
@@ -54,7 +55,7 @@ def get_linux_os_info(path):
L.debug("release files: %s", release_files)
- name = version = ""
+ name = version = package_manager = ""
if "centos-release" in release_files:
L.debug("parsing %s", release_files["centos-release"])
# CentOS 6.* doesn't have os-release, but centos-release.
@@ -63,6 +64,7 @@ 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()
+ package_manager = "rpm"
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,
@@ -71,6 +73,7 @@ def get_linux_os_info(path):
with open(release_files["gentoo-release"]) as f:
if m := re.match(r"^(Gentoo).*release\s(.*)$", f.read()):
name, version = m.groups()
+ package_manager = "portage"
elif "os-release" in release_files:
L.debug("parsing %s", release_files["os-release"])
with open(release_files["os-release"]) as f:
@@ -86,6 +89,24 @@ def get_linux_os_info(path):
# These are using a rolling release model.
if not version:
version = kv.get("BUILD_ID", "")
+ id_like = kv.get("ID_LIKE", kv.get("ID", ""))
+ id_like = id_like.strip().strip("'\"").split()
+ for i in id_like:
+ if i == "alpine":
+ package_manager = "apk"
+ elif i in ("debian", "ubuntu"):
+ package_manager = "dpkg"
+ elif i == "arch":
+ package_manager = "pacman"
+ elif i in ("centos", "fedora", "rhel"):
+ package_manager = "rpm"
+ elif i in ("opensuse", "suse"):
+ package_manager = "rpm"
+ elif i == "ol": # Oracle Linux 6.10
+ package_manager = "rpm"
+ else:
+ continue
+ break
elif "system-release" in release_files:
# RedHat (RHEL) provides the redhat-release file. However, it does not
# seem to be reliable for determining which operating system it is.
@@ -95,13 +116,19 @@ def get_linux_os_info(path):
with open(release_files["system-release"]) as f:
if m := re.match(r"^(.*)\srelease\s(.*)$", f.read()):
name, version = m.groups()
+ package_manager = "rpm"
if not name or not version:
return {}
name = name.strip().strip("'\"")
version = version.strip().strip("'\"")
- return {"name": name, "version": version}
+
+ return {
+ "name": name,
+ "version": version,
+ "package_manager": package_manager
+ }
@log
@@ -113,7 +140,8 @@ def get_windows_os_info(path):
Returns:
Name and version of windows distribution as a dictionary. For example:
- {'name': 'Microsoft Windows XP', 'version': '5.1'}
+ {'name': 'Microsoft Windows XP', 'version': '5.1',
+ 'package_manager': 'win'}
"""
software = None
@@ -154,4 +182,4 @@ def get_windows_os_info(path):
if not name or not version:
return {}
- return {"name": name, "version": version}
+ return {"name": name, "version": version, "package_manager": "win"}