All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] script fixes
@ 2019-07-02  4:12 Paul Eggleton
  2019-07-02  4:12 ` [PATCH 1/4] scripts/contrib/ddimage: fix typo Paul Eggleton
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Paul Eggleton @ 2019-07-02  4:12 UTC (permalink / raw)
  To: openembedded-core

A few minor fixes for the ddimage script and one for list-packageconfig-flags.

The following changes since commit 1f8a73261c7a134821c40845da27d8edbb0763b6:

  Revert "pigz: Add debug for autobuilder errors" (2019-06-30 23:33:12 +0100)

are available in the Git repository at:

  git://git.openembedded.org/openembedded-core-contrib paule/ddimage-fixes2
  http://cgit.openembedded.org/openembedded-core-contrib/log/?h=paule/ddimage-fixes2

Paul Eggleton (4):
  scripts/contrib/ddimage: fix typo
  scripts/contrib/ddimage: replace blacklist with mount check
  scripts/contrib/ddimage: be explicit whether device doesn't exist or
    isn't writeable
  list-packageconfig-flags: print PN instead of P

 scripts/contrib/ddimage                     | 89 +++++++++++++++++----
 scripts/contrib/list-packageconfig-flags.py |  2 +-
 2 files changed, 75 insertions(+), 16 deletions(-)

-- 
2.20.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] scripts/contrib/ddimage: fix typo
  2019-07-02  4:12 [PATCH 0/4] script fixes Paul Eggleton
@ 2019-07-02  4:12 ` Paul Eggleton
  2019-07-02  4:12 ` [PATCH 2/4] scripts/contrib/ddimage: replace blacklist with mount check Paul Eggleton
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Paul Eggleton @ 2019-07-02  4:12 UTC (permalink / raw)
  To: openembedded-core

UNKOWN -> UNKNOWN

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
---
 scripts/contrib/ddimage | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/contrib/ddimage b/scripts/contrib/ddimage
index b577d1ca2ab..01ff4318514 100755
--- a/scripts/contrib/ddimage
+++ b/scripts/contrib/ddimage
@@ -49,7 +49,7 @@ device_details() {
 	if [ -f "/sys/class/block/$DEV/device/vendor" ]; then
 		echo "  vendor: $(cat /sys/class/block/$DEV/device/vendor)"
 	else
-		echo "  vendor: UNKOWN"
+		echo "  vendor: UNKNOWN"
 	fi
 	if [ -f "/sys/class/block/$DEV/device/model" ]; then
 		echo "   model: $(cat /sys/class/block/$DEV/device/model)"
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] scripts/contrib/ddimage: replace blacklist with mount check
  2019-07-02  4:12 [PATCH 0/4] script fixes Paul Eggleton
  2019-07-02  4:12 ` [PATCH 1/4] scripts/contrib/ddimage: fix typo Paul Eggleton
@ 2019-07-02  4:12 ` Paul Eggleton
  2019-07-02  4:12 ` [PATCH 3/4] scripts/contrib/ddimage: be explicit whether device doesn't exist or isn't writeable Paul Eggleton
  2019-07-02  4:12 ` [PATCH 4/4] list-packageconfig-flags: print PN instead of P Paul Eggleton
  3 siblings, 0 replies; 5+ messages in thread
From: Paul Eggleton @ 2019-07-02  4:12 UTC (permalink / raw)
  To: openembedded-core

The blacklist, whilst previously useful for safety, is now becoming
obsolete - on my current system, the main storage is at /dev/nvme* and
if I plug in a USB stick it shows up as /dev/sdb which was previously
blacklisted. To make this more flexible, remove the blacklist and
instead check if the specified device is mounted, has a partition
that is mounted, or is otherwise in use according to the kernel, and
show an appropriate error and quit if so.

To make this robust, also ensure we handle where the specified device is
a symlink to another device.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
---
 scripts/contrib/ddimage | 80 ++++++++++++++++++++++++++++++++++-------
 1 file changed, 67 insertions(+), 13 deletions(-)

diff --git a/scripts/contrib/ddimage b/scripts/contrib/ddimage
index 01ff4318514..a7dc5f7487b 100755
--- a/scripts/contrib/ddimage
+++ b/scripts/contrib/ddimage
@@ -3,10 +3,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 #
 
-# Default to avoiding the first two disks on typical Linux and Mac OS installs
-# Better safe than sorry :-)
-BLACKLIST_DEVICES="/dev/sda /dev/sdb /dev/disk1 /dev/disk2"
-
 # 1MB blocksize
 BLOCKSIZE=1048576
 
@@ -32,7 +28,6 @@ image_details() {
 }
 
 device_details() {
-	DEV=$1
 	BLOCK_SIZE=512
 
 	echo "Device details"
@@ -45,7 +40,13 @@ device_details() {
 	fi
 
 	# Default / Linux information collection
-	echo "  device: $DEVICE"
+	ACTUAL_DEVICE=`readlink -f $DEVICE`
+	DEV=`basename $ACTUAL_DEVICE`
+	if [ "$ACTUAL_DEVICE" != "$DEVICE" ] ; then
+		echo "  device: $DEVICE -> $ACTUAL_DEVICE"
+	else
+		echo "  device: $DEVICE"
+	fi
 	if [ -f "/sys/class/block/$DEV/device/vendor" ]; then
 		echo "  vendor: $(cat /sys/class/block/$DEV/device/vendor)"
 	else
@@ -64,6 +65,49 @@ device_details() {
 	echo ""
 }
 
+check_mount_device() {
+	if cat /proc/self/mounts | awk '{ print $1 }' | grep /dev/ | grep -q -E "^$1$" ; then
+		return 0
+	fi
+	return 1
+}
+
+is_mounted() {
+	if [ "$(uname)" = "Darwin" ]; then
+		if df | awk '{ print $1 }' | grep /dev/ | grep -q -E "^$1(s[0-9]+)?$" ; then
+			return 0
+		fi
+	else
+		if check_mount_device $1 ; then
+			return 0
+		fi
+		DEV=`basename $1`
+		if [ -d /sys/class/block/$DEV/ ] ; then
+			PARENT_BLKDEV=`basename $(readlink -f "/sys/class/block/$DEV/..")`
+			if [ "$PARENT_BLKDEV" != "block" ] ; then
+				if check_mount_device $PARENT_BLKDEV ; then
+					return 0
+				fi
+			fi
+			for CHILD_BLKDEV in `find /sys/class/block/$DEV/ -mindepth  1 -maxdepth 1 -name "$DEV*" -type d`
+			do
+				if check_mount_device /dev/`basename $CHILD_BLKDEV` ; then
+					return 0
+				fi
+			done
+		fi
+	fi
+	return 1
+}
+
+is_inuse() {
+	HOLDERS_DIR="/sys/class/block/`basename $1`/holders"
+	if [ -d $HOLDERS_DIR ] && [ `ls -A $HOLDERS_DIR` ] ; then
+		return 0
+	fi
+	return 1
+}
+
 if [ $# -ne 2 ]; then
 	usage
 	exit 1
@@ -78,13 +122,23 @@ if [ ! -e "$IMAGE" ]; then
 	exit 1
 fi
 
+if [ "$(uname)" = "Darwin" ]; then
+	# readlink doesn't support -f on MacOS, just assume it isn't a symlink
+	ACTUAL_DEVICE=$DEVICE
+else
+	ACTUAL_DEVICE=`readlink -f $DEVICE`
+fi
+if is_mounted $ACTUAL_DEVICE ; then
+	echo "ERROR: Device $DEVICE is currently mounted - check if this is the right device, and unmount it first if so"
+	device_details
+	exit 1
+fi
+if is_inuse $ACTUAL_DEVICE ; then
+	echo "ERROR: Device $DEVICE is currently in use (possibly part of LVM) - check if this is the right device!"
+	device_details
+	exit 1
+fi
 
-for i in ${BLACKLIST_DEVICES}; do
-	if [ "$i" = "$DEVICE" ]; then
-		echo "ERROR: Device $DEVICE is blacklisted"
-		exit 1
-	fi
-done
 
 if [ ! -w "$DEVICE" ]; then
 	echo "ERROR: Device $DEVICE does not exist or is not writable"
@@ -93,7 +147,7 @@ if [ ! -w "$DEVICE" ]; then
 fi
 
 image_details $IMAGE
-device_details $(basename $DEVICE)
+device_details
 
 printf "Write $IMAGE to $DEVICE [y/N]? "
 read RESPONSE
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] scripts/contrib/ddimage: be explicit whether device doesn't exist or isn't writeable
  2019-07-02  4:12 [PATCH 0/4] script fixes Paul Eggleton
  2019-07-02  4:12 ` [PATCH 1/4] scripts/contrib/ddimage: fix typo Paul Eggleton
  2019-07-02  4:12 ` [PATCH 2/4] scripts/contrib/ddimage: replace blacklist with mount check Paul Eggleton
@ 2019-07-02  4:12 ` Paul Eggleton
  2019-07-02  4:12 ` [PATCH 4/4] list-packageconfig-flags: print PN instead of P Paul Eggleton
  3 siblings, 0 replies; 5+ messages in thread
From: Paul Eggleton @ 2019-07-02  4:12 UTC (permalink / raw)
  To: openembedded-core

Make the error messages a little more friendly.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
---
 scripts/contrib/ddimage | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/scripts/contrib/ddimage b/scripts/contrib/ddimage
index a7dc5f7487b..7f2ad112a62 100755
--- a/scripts/contrib/ddimage
+++ b/scripts/contrib/ddimage
@@ -122,6 +122,12 @@ if [ ! -e "$IMAGE" ]; then
 	exit 1
 fi
 
+if [ ! -e "$DEVICE" ]; then
+	echo "ERROR: Device $DEVICE does not exist"
+	usage
+	exit 1
+fi
+
 if [ "$(uname)" = "Darwin" ]; then
 	# readlink doesn't support -f on MacOS, just assume it isn't a symlink
 	ACTUAL_DEVICE=$DEVICE
@@ -139,9 +145,8 @@ if is_inuse $ACTUAL_DEVICE ; then
 	exit 1
 fi
 
-
 if [ ! -w "$DEVICE" ]; then
-	echo "ERROR: Device $DEVICE does not exist or is not writable"
+	echo "ERROR: Device $DEVICE is not writable - possibly use sudo?"
 	usage
 	exit 1
 fi
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] list-packageconfig-flags: print PN instead of P
  2019-07-02  4:12 [PATCH 0/4] script fixes Paul Eggleton
                   ` (2 preceding siblings ...)
  2019-07-02  4:12 ` [PATCH 3/4] scripts/contrib/ddimage: be explicit whether device doesn't exist or isn't writeable Paul Eggleton
@ 2019-07-02  4:12 ` Paul Eggleton
  3 siblings, 0 replies; 5+ messages in thread
From: Paul Eggleton @ 2019-07-02  4:12 UTC (permalink / raw)
  To: openembedded-core

P (which is ${PN}-${PV}) isn't terribly useful in this context - we
don't really care what the version is, but we do want to know what the
recipe is so we can find it or set PACKAGECONFIG_pn-<PN> in our
configuration, so display ${PN} instead.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
---
 scripts/contrib/list-packageconfig-flags.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/contrib/list-packageconfig-flags.py b/scripts/contrib/list-packageconfig-flags.py
index b1d6c852d86..d6de4dc84d2 100755
--- a/scripts/contrib/list-packageconfig-flags.py
+++ b/scripts/contrib/list-packageconfig-flags.py
@@ -65,7 +65,7 @@ def collect_pkgs(data_dict):
     for fn in data_dict:
         pkgconfigflags = data_dict[fn].getVarFlags("PACKAGECONFIG")
         pkgconfigflags.pop('doc', None)
-        pkgname = data_dict[fn].getVar("P")
+        pkgname = data_dict[fn].getVar("PN")
         pkg_dict[pkgname] = sorted(pkgconfigflags.keys())
 
     return pkg_dict
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-07-02  4:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-02  4:12 [PATCH 0/4] script fixes Paul Eggleton
2019-07-02  4:12 ` [PATCH 1/4] scripts/contrib/ddimage: fix typo Paul Eggleton
2019-07-02  4:12 ` [PATCH 2/4] scripts/contrib/ddimage: replace blacklist with mount check Paul Eggleton
2019-07-02  4:12 ` [PATCH 3/4] scripts/contrib/ddimage: be explicit whether device doesn't exist or isn't writeable Paul Eggleton
2019-07-02  4:12 ` [PATCH 4/4] list-packageconfig-flags: print PN instead of P Paul Eggleton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.