linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: sagi@grimberg.me (Sagi Grimberg)
Subject: [PATCH nvme-cli v2 2/2] nvme.spec/debian: Auto generate host nqn as part of install
Date: Thu, 17 Nov 2016 14:54:48 +0200	[thread overview]
Message-ID: <1479387288-13367-3-git-send-email-sagi@grimberg.me> (raw)
In-Reply-To: <1479387288-13367-1-git-send-email-sagi@grimberg.me>

The installation will generate a hostnqn and store it in
/etc/nvme/hostnqn file (in case it doesn't exist).
This file will be removed upon uninstallation (purge on for debian).

Signed-off-by: Sagi Grimberg <sagi at grimberg.me>
---
 debian/postinst | 20 ++++++++++++++++++++
 debian/postrm   | 10 ++++++++++
 nvme.spec.in    | 17 +++++++++++++++++
 3 files changed, 47 insertions(+)
 create mode 100644 debian/postinst
 create mode 100644 debian/postrm

diff --git a/debian/postinst b/debian/postinst
new file mode 100644
index 000000000000..b258cf569c3e
--- /dev/null
+++ b/debian/postinst
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+set -e
+
+case "$1" in
+    configure|install)
+	if [ ! -f /etc/nvme/hostnqn ]; then
+		install -D /dev/null /etc/nvme/hostnqn
+		echo $(nvme gen-hostnqn) > /etc/nvme/hostnqn
+        fi
+        ;;
+
+    upgrade|abort-upgrade)
+        ;;
+    *)
+        echo "postinst called with unknown argument \`$1'" >&2
+        exit 0
+        ;;
+esac
+exit 0
diff --git a/debian/postrm b/debian/postrm
new file mode 100644
index 000000000000..a7a724352327
--- /dev/null
+++ b/debian/postrm
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+if [ "$1" = "purge" ]; then
+	if [ -d /etc/nvme ]; then
+		rm -f /etc/nvme/hostnqn
+		if [ ! -n "$(ls -A /etc/nvme)" ]; then
+			rm -rf /etc/nvme
+		fi
+	fi
+fi
diff --git a/nvme.spec.in b/nvme.spec.in
index a4718773a962..6efb28847005 100644
--- a/nvme.spec.in
+++ b/nvme.spec.in
@@ -33,6 +33,23 @@ make install DESTDIR=%{buildroot} PREFIX=/usr
 %clean
 rm -rf $RPM_BUILD_ROOT
 
+%post
+if [ $1 = 1 ]; then # 1 : This package is being installed for the first time
+	if [ ! -f /etc/nvme/hostnqn ]; then
+		install -D /dev/null /etc/nvme/hostnqn
+		echo $(nvme gen-hostnqn) > /etc/nvme/hostnqn
+        fi
+fi
+
+%preun
+if [ "$1" = "remove" ]; then
+	if [ -d /etc/nvme ]; then
+		rm -f /etc/nvme/hostnqn
+		if [ ! -n "$(ls -A /etc/nvme)" ]; then
+			rm -rf /etc/nvme
+		fi
+	fi
+fi
 %changelog
 * Thu Oct 15 2015 Keith Busch <keith.busch at intel.com>
 - Initial RPM spec
-- 
2.7.4

  parent reply	other threads:[~2016-11-17 12:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-17 12:54 [PATCH nvme-cli v2 0/2] auto generate hostnqn file on installation Sagi Grimberg
2016-11-17 12:54 ` [PATCH nvme-cli v2 1/2] nvme-cli: Add nvme hostnqn generation option Sagi Grimberg
2016-11-17 13:34   ` Christoph Hellwig
2016-11-17 17:53     ` J Freyensee
2016-11-17 12:54 ` Sagi Grimberg [this message]
2016-11-17 13:36   ` [PATCH nvme-cli v2 2/2] nvme.spec/debian: Auto generate host nqn as part of install Christoph Hellwig
2016-11-17 17:51     ` J Freyensee
2016-11-17 17:58       ` J Freyensee
2016-11-17 14:36 ` [PATCH nvme-cli v2 0/2] auto generate hostnqn file on installation Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1479387288-13367-3-git-send-email-sagi@grimberg.me \
    --to=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).