File 0102-nvme-cli-Add-script-to-determine-host-NQN.patch of Package nvme-cli.22026

From b38de666b0ae385bb35c00280c48a20f4d4d6aae Mon Sep 17 00:00:00 2001
From: Simon Schricker <sschricker@suse.de>
Date: Fri, 17 May 2019 15:36:37 +0200
Subject: [PATCH] nvme-cli: Add script to determine host NQN

* Based on the system-UUID, via dmidecode
* verifies UUID format
---
 scripts/det-hostnqn.sh |   24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 scripts/det-hostnqn.sh

--- /dev/null
+++ b/scripts/det-hostnqn.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+LC_ALL=C
+
+UUID=$(dmidecode -s system-uuid | tr -d '[:space:]')
+
+if [ -z "$UUID" ] ; then
+	>&2 echo "No UUID found, can't determine hostnqn."
+	exit 1
+fi
+
+# convert UUID to lower-case only:
+UUID=$(echo $UUID | tr '[:upper:]' '[:lower:]')
+
+# check UUID format, e.g.: 4c4c4544-0156-4a10-8134-b7d04f383232, so: 8-4-4-4-12
+if ! [[ $UUID =~ ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$ ]] ; then
+	>&2 echo "UUID has invalid format."
+	>&2 echo "Invalid UUID: ${UUID}"
+	exit 2
+fi
+
+HOSTNQN="nqn.2014-08.org.nvmexpress:uuid:${UUID}"
+
+echo $HOSTNQN
openSUSE Build Service is sponsored by