Skip to contentSkip to conversation

ndctl: Generalized make-git-snapshot.sh

PATCH Superseded [email protected] 3 participants 8 messages Feb 15, 2019 libnvdimm: non-volatile memory device

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ndctl: Generalized make-git-snapshot.sh

From: Ira Weiny <[email protected]>

make-git-snapshot.sh made an assumption of the git tree location.

Furthermore, it assumed the user has an rpmbuild environment directory structure set up.

Enhance the script to figure out where in what location it has been cloned and create the rpmbuild directory if the user does not already have it.

---
 make-git-snapshot.sh | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
make-git-snapshot.sh +10 -2
index 142419d623fe..26e29bd7953d 100755
@@ -2,10 +2,18 @@
 set -e
 
 NAME=ndctl
-REFDIR="$HOME/git/ndctl"  # for faster cloning, if available
+
+pushd `dirname $0`
+REFDIR=`pwd`
+popd
+
 UPSTREAM=$REFDIR #TODO update once we have a public upstream
 OUTDIR=$HOME/rpmbuild/SOURCES
 
+if [ ! -d $OUTDIR ]; then
+	mkdir -p $OUTDIR
+fi
+
 [ -n "$1" ] && HEAD="$1" || HEAD="HEAD"
 
 WORKDIR="$(mktemp -d --tmpdir "$NAME.XXXXXXXXXX")"
@@ -14,7 +22,7 @@ trap 'rm -rf $WORKDIR' exit
 [ -d "$REFDIR" ] && REFERENCE="--reference $REFDIR"
 git clone $REFERENCE "$UPSTREAM" "$WORKDIR"
 
-VERSION=$(./git-version)
+VERSION=$($REFDIR/git-version)
 DIRNAME="ndctl-${VERSION}"
 git archive --remote="$WORKDIR" --format=tar --prefix="$DIRNAME/" HEAD | gzip > $OUTDIR/"ndctl-${VERSION}.tar.gz"
 
Signature · 6 lines
2.20.1

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
#1 lore raw
Quoted 26 lines · On Fri, Feb 15, 2019 at 11:21 AM <[email protected]> wrote:

From: Ira Weiny <[email protected]>

make-git-snapshot.sh made an assumption of the git tree location.

Furthermore, it assumed the user has an rpmbuild environment directory structure set up.

Enhance the script to figure out where in what location it has been cloned and create the rpmbuild directory if the user does not already have it.

---
 make-git-snapshot.sh | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
make-git-snapshot.sh +0 -1
index 142419d623fe..26e29bd7953d 100755
@@ -2,10 +2,18 @@
 set -e
 
 NAME=ndctl
-REFDIR="$HOME/git/ndctl"  # for faster cloning, if available

make-git-snapshot.sh line 14

Quoted 10 lines
make-git-snapshot.sh +7 -0
+
+pushd `dirname $0`
+REFDIR=`pwd`
+popd
+
 UPSTREAM=$REFDIR #TODO update once we have a public upstream
 OUTDIR=$HOME/rpmbuild/SOURCES
 
+if [ ! -d $OUTDIR ]; then
+       mkdir -p $OUTDIR

Shouldn't this be rpmdev-setuptree?
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

author
#2 lore raw
Quoted 35 lines · Dan Williams
Quoted 34 lines · On Fri, Feb 15, 2019 at 11:21 AM <[email protected]> wrote:

From: Ira Weiny <[email protected]>

make-git-snapshot.sh made an assumption of the git tree location.

Furthermore, it assumed the user has an rpmbuild environment directory structure set up.

Enhance the script to figure out where in what location it has been cloned and create the rpmbuild directory if the user does not already have it.

---
 make-git-snapshot.sh | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
make-git-snapshot.sh +5 -1
index 142419d623fe..26e29bd7953d 100755
@@ -2,10 +2,18 @@
 set -e
 
 NAME=ndctl
-REFDIR="$HOME/git/ndctl"  # for faster cloning, if available
+
+pushd `dirname $0`
+REFDIR=`pwd`
+popd
+
 UPSTREAM=$REFDIR #TODO update once we have a public upstream
 OUTDIR=$HOME/rpmbuild/SOURCES
 
Quoted 4 lines

make-git-snapshot.sh line 14

Quoted 2 lines
make-git-snapshot.sh +2 -0
+if [ ! -d $OUTDIR ]; then
+       mkdir -p $OUTDIR

Shouldn't this be rpmdev-setuptree?

Sure looks like it...

I never knew about that command...

Ira

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#3 lore raw

PATCH v2 1/1 ndctl: Generalized make-git-snapshot.sh

In reply to [email protected]

From: Ira Weiny <[email protected]>

make-git-snapshot.sh made an assumption of the git tree location.

Furthermore, it assumed the user has an rpmbuild environment directory structure set up.

Enhance the script to figure out where in what location it has been cloned and setup the rpmbuild tree if the user does not already have it.

---
Changes since V1
use rpmdev-setuptree

 make-git-snapshot.sh | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
make-git-snapshot.sh +10 -2
index 142419d623fe..513086b1f93d 100755
@@ -2,10 +2,18 @@
 set -e
 
 NAME=ndctl
-REFDIR="$HOME/git/ndctl"  # for faster cloning, if available
+
+pushd `dirname $0`
+REFDIR=`pwd`
+popd
+
 UPSTREAM=$REFDIR #TODO update once we have a public upstream
 OUTDIR=$HOME/rpmbuild/SOURCES
 
+if [ ! -d $OUTDIR ]; then
+	rpmdev-setuptree
+fi
+
 [ -n "$1" ] && HEAD="$1" || HEAD="HEAD"
 
 WORKDIR="$(mktemp -d --tmpdir "$NAME.XXXXXXXXXX")"
@@ -14,7 +22,7 @@ trap 'rm -rf $WORKDIR' exit
 [ -d "$REFDIR" ] && REFERENCE="--reference $REFDIR"
 git clone $REFERENCE "$UPSTREAM" "$WORKDIR"
 
-VERSION=$(./git-version)
+VERSION=$($REFDIR/git-version)
 DIRNAME="ndctl-${VERSION}"
 git archive --remote="$WORKDIR" --format=tar --prefix="$DIRNAME/" HEAD | gzip > $OUTDIR/"ndctl-${VERSION}.tar.gz"
 
Signature · 6 lines
2.20.1

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
maintainer
#4 lore raw
Quoted 25 lines · On Fri, 2019-02-15 at 12:06 -0800, [email protected] wrote:

From: Ira Weiny <[email protected]>

make-git-snapshot.sh made an assumption of the git tree location.

Furthermore, it assumed the user has an rpmbuild environment directory structure set up.

Enhance the script to figure out where in what location it has been cloned and setup the rpmbuild tree if the user does not already have it.

---
Changes since V1
use rpmdev-setuptree

 make-git-snapshot.sh | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
make-git-snapshot.sh +0 -0
index 142419d623fe..513086b1f93d 100755

make-git-snapshot.sh line 7

Quoted 7 lines
make-git-snapshot.sh +3 -1
@@ -2,10 +2,18 @@
 set -e
 
 NAME=ndctl
-REFDIR="$HOME/git/ndctl"  # for faster cloning, if available
+
+pushd `dirname $0`
+REFDIR=`pwd`

We should use the $() syntax for command substitution. Also quote it - pushd "$(dirname "$0")"
And for setting REFDIR, no need to execute the pwd command - just use the $PWD variable from the environment.

Additionally, $0 is not a reliable way to get the location of the script. It is probably best to make an assumption that the script will be run from the top level of an ndctl tree, and test for that instead of trying to deduce where the script is being run from and trying to cd to it.

We only really need the git-version script, and if we can test for its presence, then we can relatively safely assume we're in the right location. If it is not a git tree then we can leave it for git-archive to complain. So something like:

	test -x "./git-version"

should suffice.

make-git-snapshot.sh line 16

Quoted 9 lines
make-git-snapshot.sh +6 -0
+popd
+
 UPSTREAM=$REFDIR #TODO update once we have a public upstream
 OUTDIR=$HOME/rpmbuild/SOURCES
 
+if [ ! -d $OUTDIR ]; then
+	rpmdev-setuptree
+fi
+

There was some discussion around this a while back: [1] and [2]

But we had decided that rpmdev-setuptree was heavy handed in that it can overwrite user configuration and we shouldn't use it. Instead in [2], we added a test for the rpmdev tree to exist, and bail if it doesn't.

The one improvement I can see to this is:

if [ ! -d $OUTDIR ]; then
mkdir -p $OUTDIR
fi

That way if components of OUTDIR are missing, we can make those directories only, which is harmless.

[1]: https://lists.01.org/pipermail/linux-nvdimm/2017-November/013378.html
[2]: https://lists.01.org/pipermail/linux-nvdimm/2017-November/013408.html

make-git-snapshot.sh trap 'rm -rf $WORKDIR' exit · line 28

Quoted 12 lines
make-git-snapshot.sh +1 -1
 [ -n "$1" ] && HEAD="$1" || HEAD="HEAD"
 
 WORKDIR="$(mktemp -d --tmpdir "$NAME.XXXXXXXXXX")"
@@ -14,7 +22,7 @@ trap 'rm -rf $WORKDIR' exit
 [ -d "$REFDIR" ] && REFERENCE="--reference $REFDIR"
 git clone $REFERENCE "$UPSTREAM" "$WORKDIR"
 
-VERSION=$(./git-version)
+VERSION=$($REFDIR/git-version)
 DIRNAME="ndctl-${VERSION}"
 git archive --remote="$WORKDIR" --format=tar --prefix="$DIRNAME/" HEAD | gzip > $OUTDIR/"ndctl-${VERSION}.tar.gz"
 

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

author
#5 lore raw
Quoted 29 lines · Vishal Verma
Quoted 27 lines · On Fri, 2019-02-15 at 12:06 -0800, [email protected] wrote:

From: Ira Weiny <[email protected]>

make-git-snapshot.sh made an assumption of the git tree location.

Furthermore, it assumed the user has an rpmbuild environment directory structure set up.

Enhance the script to figure out where in what location it has been cloned and setup the rpmbuild tree if the user does not already have it.

---
Changes since V1
use rpmdev-setuptree

 make-git-snapshot.sh | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
make-git-snapshot.sh +0 -0
index 142419d623fe..513086b1f93d 100755
@@ -2,10 +2,18 @@
 set -e
 
Quoted 10 lines

make-git-snapshot.sh line 7

Quoted 5 lines
make-git-snapshot.sh +3 -1
 NAME=ndctl
-REFDIR="$HOME/git/ndctl"  # for faster cloning, if available
+
+pushd `dirname $0`
+REFDIR=`pwd`

We should use the $() syntax for command substitution. Also quote it - pushd "$(dirname "$0")"
And for setting REFDIR, no need to execute the pwd command - just use the $PWD variable from the environment.

Probably irrelevant with your comments below.

Quoted 6 lines

Additionally, $0 is not a reliable way to get the location of the script. It is probably best to make an assumption that the script will be run from the top level of an ndctl tree, and test for that instead of trying to deduce where the script is being run from and trying to cd to it.

When can $0 not be the name of the script?

Quoted 7 lines

We only really need the git-version script, and if we can test for its presence, then we can relatively safely assume we're in the right location. If it is not a git tree then we can leave it for git-archive to complain. So something like:

	test -x "./git-version"

Ah ok... Then the stuff above is irrelevant.

And I would prefer something more explicit than just returning.

But the real question is if this is really supposed to be run by a user or not. If not then your way is better.

make-git-snapshot.sh +6 -3
index 513086b1f93d..fccf1da0d61b 100755
@@ -3,9 +3,12 @@ set -e
 
 NAME=ndctl
 
-pushd `dirname $0`
-REFDIR=`pwd`
-popd
+if [ ! -x ./git-version ]; then
+       echo "$0 : ERROR: Must run from top level of git tree"
+       exit 1
+fi
+
+REFDIR=$PWD
 
 UPSTREAM=$REFDIR #TODO update once we have a public upstream
 OUTDIR=$HOME/rpmbuild/SOURCES
Quoted 19 lines

should suffice.

make-git-snapshot.sh line 16

Quoted 9 lines
make-git-snapshot.sh +6 -0
+popd
+
 UPSTREAM=$REFDIR #TODO update once we have a public upstream
 OUTDIR=$HOME/rpmbuild/SOURCES
 
+if [ ! -d $OUTDIR ]; then
+	rpmdev-setuptree
+fi
+

There was some discussion around this a while back: [1] and [2]

But we had decided that rpmdev-setuptree was heavy handed in that it can overwrite user configuration and we shouldn't use it. Instead in [2], we added a test for the rpmdev tree to exist, and bail if it doesn't.

Quoted 5 lines

The one improvement I can see to this is:

if [ ! -d $OUTDIR ]; then
mkdir -p $OUTDIR
fi

Dan?

Ira

Quoted 14 lines

That way if components of OUTDIR are missing, we can make those directories only, which is harmless.

[1]: https://lists.01.org/pipermail/linux-nvdimm/2017-November/013378.html
[2]: https://lists.01.org/pipermail/linux-nvdimm/2017-November/013408.html

Quoted 7 lines
make-git-snapshot.sh +0 -0
 [ -n "$1" ] && HEAD="$1" || HEAD="HEAD"
 
 WORKDIR="$(mktemp -d --tmpdir "$NAME.XXXXXXXXXX")"
@@ -14,7 +22,7 @@ trap 'rm -rf $WORKDIR' exit
 [ -d "$REFDIR" ] && REFERENCE="--reference $REFDIR"
 git clone $REFERENCE "$UPSTREAM" "$WORKDIR"
 
Quoted 6 lines

make-git-snapshot.sh trap 'rm -rf $WORKDIR' exit · line 28

Quoted 5 lines
make-git-snapshot.sh +1 -1
-VERSION=$(./git-version)
+VERSION=$($REFDIR/git-version)
 DIRNAME="ndctl-${VERSION}"
 git archive --remote="$WORKDIR" --format=tar --prefix="$DIRNAME/" HEAD | gzip > $OUTDIR/"ndctl-${VERSION}.tar.gz"
 

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

maintainer
#6 lore raw
Quoted 42 lines · Ira Weiny
Quoted 28 lines · Vishal Verma
Quoted 27 lines · On Fri, 2019-02-15 at 12:06 -0800, [email protected] wrote:

From: Ira Weiny <[email protected]>

make-git-snapshot.sh made an assumption of the git tree location.

Furthermore, it assumed the user has an rpmbuild environment directory structure set up.

Enhance the script to figure out where in what location it has been cloned and setup the rpmbuild tree if the user does not already have it.

---
Changes since V1
use rpmdev-setuptree

 make-git-snapshot.sh | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
make-git-snapshot.sh +0 -0
index 142419d623fe..513086b1f93d 100755
@@ -2,10 +2,18 @@
 set -e
 
Quoted 10 lines

make-git-snapshot.sh line 7

Quoted 5 lines
make-git-snapshot.sh +3 -1
 NAME=ndctl
-REFDIR="$HOME/git/ndctl"  # for faster cloning, if available
+
+pushd `dirname $0`
+REFDIR=`pwd`

We should use the $() syntax for command substitution. Also quote it - pushd "$(dirname "$0")"
And for setting REFDIR, no need to execute the pwd command - just use the $PWD variable from the environment.

Probably irrelevant with your comments below.

Quoted 7 lines
Quoted 5 lines

Additionally, $0 is not a reliable way to get the location of the script. It is probably best to make an assumption that the script will be run from the top level of an ndctl tree, and test for that instead of trying to deduce where the script is being run from and trying to cd to it.

When can $0 not be the name of the script?

For the common case of calling ./script, it is probably fine. But consider for example:

	$ bash < /tmp/test
	script was called as bash

Or say if someone decided to symlink it somewhere for convenience:

	$ readlink -f /usr/bin/test-symlink && test-symlink 
	/tmp/test
	script was called as /usr/bin/test-symlink

Agreed that in this case those are unlikely, but the point is using $0 for 'locating yourself' is just fragile and should be avoided.

See this for more commentary:
http://mywiki.wooledge.org/BashFAQ/028

Quoted 22 lines
Quoted 7 lines

We only really need the git-version script, and if we can test for its presence, then we can relatively safely assume we're in the right location. If it is not a git tree then we can leave it for git-archive to complain. So something like:

	test -x "./git-version"

Ah ok... Then the stuff above is irrelevant.

And I would prefer something more explicit than just returning.

But the real question is if this is really supposed to be run by a user or not. If not then your way is better.

make-git-snapshot.sh +0 -0
index 513086b1f93d..fccf1da0d61b 100755
@@ -3,9 +3,12 @@ set -e
 
 NAME=ndctl

make-git-snapshot.sh set -e · line 11

Quoted 10 lines
make-git-snapshot.sh +6 -3
 
-pushd `dirname $0`
-REFDIR=`pwd`
-popd
+if [ ! -x ./git-version ]; then
+       echo "$0 : ERROR: Must run from top level of git tree"
+       exit 1
+fi
+
+REFDIR=$PWD

Yes this looks fine to me.

Quoted 46 lines
make-git-snapshot.sh +0 -0
 UPSTREAM=$REFDIR #TODO update once we have a public upstream
 OUTDIR=$HOME/rpmbuild/SOURCES
 
Quoted 19 lines

should suffice.

make-git-snapshot.sh line 16

Quoted 9 lines
make-git-snapshot.sh +6 -0
+popd
+
 UPSTREAM=$REFDIR #TODO update once we have a public upstream
 OUTDIR=$HOME/rpmbuild/SOURCES
 
+if [ ! -d $OUTDIR ]; then
+	rpmdev-setuptree
+fi
+

There was some discussion around this a while back: [1] and [2]

But we had decided that rpmdev-setuptree was heavy handed in that it can overwrite user configuration and we shouldn't use it. Instead in [2], we added a test for the rpmdev tree to exist, and bail if it doesn't.

Quoted 5 lines

The one improvement I can see to this is:

if [ ! -d $OUTDIR ]; then
mkdir -p $OUTDIR
fi

Dan?

Ira

Quoted 13 lines

That way if components of OUTDIR are missing, we can make those directories only, which is harmless.

[1]: https://lists.01.org/pipermail/linux-nvdimm/2017-November/013378.html
[2]: https://lists.01.org/pipermail/linux-nvdimm/2017-November/013408.html

Quoted 7 lines
make-git-snapshot.sh +0 -0
 [ -n "$1" ] && HEAD="$1" || HEAD="HEAD"
 
 WORKDIR="$(mktemp -d --tmpdir "$NAME.XXXXXXXXXX")"
@@ -14,7 +22,7 @@ trap 'rm -rf $WORKDIR' exit
 [ -d "$REFDIR" ] && REFERENCE="--reference $REFDIR"
 git clone $REFERENCE "$UPSTREAM" "$WORKDIR"
 
Quoted 5 lines
Quoted 5 lines

make-git-snapshot.sh trap 'rm -rf $WORKDIR' exit · line 28

Quoted 5 lines
make-git-snapshot.sh +1 -1
-VERSION=$(./git-version)
+VERSION=$($REFDIR/git-version)
 DIRNAME="ndctl-${VERSION}"
 git archive --remote="$WORKDIR" --format=tar --prefix="$DIRNAME/" HEAD | gzip > $OUTDIR/"ndctl-${VERSION}.tar.gz"
 

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#7 lore raw

PATCH v3 1/1 ndctl: Generalized make-git-snapshot.sh

In reply to [email protected]

From: Ira Weiny <[email protected]>

make-git-snapshot.sh made an assumption of the git tree location.

Furthermore, it assumed the user has an rpmbuild environment directory structure set up.

Enhance the script to error out if not run in the root of the git tree and create the output directory if the user does not already have it.

---
Changes since V2
Don't use $0 to determine git tree location Instead expect user to run within root of git tree
Error out if not

Changes since V1
use rpmdev-setuptree

 make-git-snapshot.sh | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
make-git-snapshot.sh +12 -1
index 142419d623fe..0b5de17a6d5c 100755
@@ -2,10 +2,21 @@
 set -e
 
 NAME=ndctl
-REFDIR="$HOME/git/ndctl"  # for faster cloning, if available
+
+if [ ! -x ./git-version ]; then
+	echo "$0 : ERROR: Must run from top level of git tree"
+	exit 1
+fi
+
+REFDIR=$PWD
+
 UPSTREAM=$REFDIR #TODO update once we have a public upstream
 OUTDIR=$HOME/rpmbuild/SOURCES
 
+if [ ! -d $OUTDIR ]; then
+	mkdir -p $OUTDIR
+fi
+
 [ -n "$1" ] && HEAD="$1" || HEAD="HEAD"
 
 WORKDIR="$(mktemp -d --tmpdir "$NAME.XXXXXXXXXX")"
Signature · 6 lines
2.20.1

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm