Repository: cobbler/cobbler

Issue:
Windows import cannot be performed when using package "file" version lower than 5.37
### Describe the bug

Windows import fails due to lack of support for MIME application/x-ms-wim in package `file` version earlier than 5.37.

<!--- HINT: You can paste gist.github.com links for long logs or larger files -->

### Steps to reproduce

1. mount -o loop,ro Win10_22H2_English_x64v1.iso /mnt
2. cobbler import --path=/mnt --name=win10

### Expected behavior

The Windows import should be successful.

### Cobbler version

<!--- Paste output from `cobbler version` -->
````paste below
Cobbler 3.4.0
````

### Operating system

Rocky Linux 8

### Cobbler log

<!--- Paste (partial) output from `/var/log/cobbler/cobbler.log` -->
````paste below
````

### Screenshots

<!--- If applicable, add screenshots to help explain your problem. -->

### Additional information

<!--- Add any other context about the problem here. -->



Discussion:

Resolving patch:
diff --git a/cobbler/modules/managers/import_signatures.py b/cobbler/modules/managers/import_signatures.py
--- a/cobbler/modules/managers/import_signatures.py
+++ b/cobbler/modules/managers/import_signatures.py
@@ -15,7 +15,17 @@
 import re
 import shutil
 import stat
-from typing import TYPE_CHECKING, Any, Callable, Dict, Iterable, List, Optional, Union
+from typing import (
+    TYPE_CHECKING,
+    Any,
+    Callable,
+    Dict,
+    Iterable,
+    List,
+    Optional,
+    Tuple,
+    Union,
+)
 
 import magic  # type: ignore
 
@@ -119,7 +129,11 @@ def get_file_lines(self, filename: str) -> Union[List[str], List[bytes]]:
                     return file_fd.readlines()
             except Exception:
                 pass
-        if ftype.mime_type == "application/x-ms-wim":  # type: ignore
+        if (
+            ftype.mime_type == "application/x-ms-wim"  # type: ignore
+            or self.file_version < (5, 37)
+            and filename.lower().endswith(".wim")
+        ):
             cmd = "/usr/bin/wiminfo"
             if os.path.exists(cmd):
                 cmd = f"{cmd} {filename}"
@@ -137,6 +151,30 @@ def get_file_lines(self, filename: str) -> Union[List[str], List[bytes]]:
             )
         return []
 
+    def get_file_version(self) -> Tuple[int, int]:
+        """
+        This calls file and asks for the version number.
+
+        :return: The major file version number.
+        """
+        cmd = "/usr/bin/file"
+        if os.path.exists(cmd):
+            cmd = f"{cmd} -v"
+            version_list = utils.subprocess_get(cmd).splitlines()
+            if len(version_list) < 1:
+                return (0, 0)
+            version_list = version_list[0].split("-")
+            if len(version_list) != 2 or version_list[0] != "file":
+                return (0, 0)
+            version_list = version_list[1].split(".")
+            if len(version_list) < 2:
+                return (0, 0)
+            version: List[int] = []
+            for v in version_list:
+                version.append(int(v))
+            return (version[0], version[1])
+        return (0, 0)
+
     def run(
         self,
         path: str,
@@ -165,6 +203,7 @@ def run(
         self.arch = arch
         self.breed = breed
         self.os_version = os_version
+        self.file_version: Tuple[int, int] = self.get_file_version()
 
         self.path = path
         self.rootdir = path
diff --git a/cobbler/tftpgen.py b/cobbler/tftpgen.py
--- a/cobbler/tftpgen.py
+++ b/cobbler/tftpgen.py
@@ -1692,7 +1692,11 @@ def generate_ipxe(self, what: str, name: str) -> str:
         result = self.write_pxe_file(
             None, system, profile, distro, arch, image, bootloader_format="ipxe"
         )
-        return "" if not result else result
+        if not result:
+            return ""
+        result_split = result.splitlines(True)
+        result_split[0] = "#!ipxe\n"
+        return "".join(result_split)
 
     def generate_bootcfg(self, what: str, name: str) -> str:
         """


Test patch:
diff --git a/system-tests/tests/svc-ipxe-profile b/system-tests/tests/svc-ipxe-profile
--- a/system-tests/tests/svc-ipxe-profile
+++ b/system-tests/tests/svc-ipxe-profile
@@ -13,7 +13,7 @@ cobbler profile add --name fake --distro fake
 cobbler system add --name testbed --profile fake --image fakeimage
 # Prepare expected result
 cat >${tmp}/a <<-EOF
-:fake
+#!ipxe
 kernel /images/fake/vmlinuz  
 initrd /images/fake/initramfs
 boot