Provide git-describe based version information when running from within git
[grml2usb.git] / grml2usb
index 1e502e7..b4bbf3c 100755 (executable)
--- a/grml2usb
+++ b/grml2usb
@@ -32,7 +32,22 @@ import uuid
 import shutil
 
 # The line following this line is patched by debian/rules and tarball.sh.
-PROG_VERSION = '***UNRELEASED***'
+PROG_VERSION = '***UNKNOWN***'
+
+# when running from inside git, try to report version information via git-describe
+try:
+    git_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+    with open(os.devnull, 'w') as devnull:
+        PROG_VERSION = subprocess.check_output(["git",
+                                                "-C",
+                                                git_dir,
+                                                "describe",
+                                                "--always",
+                                                "--dirty"],
+                                                stderr=devnull).strip().decode('utf-8', errors='replace') + \
+                                                " (git)"
+except Exception:
+    pass
 
 # global variables
 MOUNTED = set()   # register mountpoints
@@ -41,7 +56,7 @@ DATESTAMP = time.mktime(datetime.datetime.now().timetuple())  # unique identifie
 GRML_FLAVOURS = set()  # which flavours are being installed?
 GRML_DEFAULT = None
 UUID = None
-SYSLINUX_LIBS = "/usr/lib/syslinux/"
+SYSLINUX_LIBS = "/usr/lib/syslinux/modules/bios/"
 GPT_HEADER = b"\x55\xaa\x45\x46\x49\x20\x50\x41\x52\x54"  # original GPT header
 GRUB_INSTALL = None
 
@@ -389,7 +404,7 @@ def check_boot_flag(device):
     except ImportError as e:
         logging.debug("could not import parted, falling back to old bootflag detection")
 
-    with open(boot_dev, 'r') as image:
+    with open(boot_dev, 'rb') as image:
         data = image.read(520)
         bootcode = data[440:]
         gpt_data = bootcode[70:80]
@@ -790,7 +805,7 @@ def check_for_fat(partition):
 
     try:
         udev_info = subprocess.Popen(["/sbin/blkid", "-s", "TYPE", "-o", "value", partition],
-                                     stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+                                     stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
         filesystem = udev_info.communicate()[0].rstrip()
 
         if filesystem != "vfat":
@@ -1855,14 +1870,14 @@ def check_programs():
 
 
 def load_loop():
-    """Runs modprobe loop and throws away it's output"""
+    """Runs modprobe loop and throws away its output"""
     if not which("modprobe"):
         logging.critical("Fatal: modprobe not available, can not continue - sorry.")
         logging.critical("Hint: is /sbin missing in PATH?")
         sys.exit(1)
 
     proc = subprocess.Popen(["modprobe", "loop"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-    proc.wait()
+    proc.communicate()
 
 
 def main():