martin f. krafft: Enhance bugscript to optionally run as root

Martin F. Krafft madduck at alioth.debian.org
Tue May 5 09:52:55 UTC 2009


Module: mdadm
Branch: build
Commit: 0bcce4d3bb7c9c2b68f937411d55aa22736f90f5
URL:    http://git.debian.org/?p=pkg-mdadm/mdadm.git;a=commit;h=0bcce4d3bb7c9c2b68f937411d55aa22736f90f5

Author: martin f. krafft <madduck at debian.org>
Date:   Tue May  5 10:51:37 2009 +0200

Enhance bugscript to optionally run as root

Signed-off-by: martin f. krafft <madduck at debian.org>

---

 debian/bugscript |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 debian/changelog |    2 ++
 debian/presubj   |   17 +++++++++++++++++
 debian/rules     |    1 +
 4 files changed, 67 insertions(+), 0 deletions(-)

diff --git a/debian/bugscript b/debian/bugscript
index 4fb920c..7ecd2cc 100755
--- a/debian/bugscript
+++ b/debian/bugscript
@@ -28,6 +28,53 @@ if ! command -v yesno >/dev/null; then
   exec 3>&1
 fi
 
+if [ $(id -u) != 0 ]; then
+  if [ -x "$(command -v sudo)" ]; then
+    yesno "Gather system information as root using sudo? (Y/n) " yep
+    if [ "$REPLY" = yep ]; then
+      echo running sudo "$0" "$@"...
+      sudo "$0" "$@" && exit 0
+      echo "sudo invocation failed, trying /bin/su..."
+    fi
+  fi
+
+  yesno "Gather system information as root using su? (Y/n) " yep
+  if [ "$REPLY" = yep ]; then
+    ARGS=
+    for i in "$@"; do ARGS="${ARGS:+$ARGS }'$1'"; shift; done
+    echo "running su root -s '/bin/sh -c $0 $ARGS'..."
+    su root -s /bin/sh -c "$0 $ARGS" && exit 0
+    unset ARGS
+    echo "su invocation failed."
+  fi
+
+  # arrive here only if neither sudo nor su worked:
+  yesno "Will you provide system information in the bug report yourself? (N/y) " nop
+  if [ "$REPLY" = yep ]; then
+    cat <<_eof >&3
+
+IMPORTANT:
+  please do not forget to include all relevant system information with this
+  bug report. You could run
+    /usr/share/bug/mdadm/script 3>&1
+  as root and attach or include the output.
+
+_eof
+    exit 0
+  fi
+
+  # try our best
+  cat <<_eof >&3
+
+WARNING:
+  the following output was not generated by the root user. If you can, please
+  replace the following up until "-- System Information:" with the output of
+    /usr/share/bug/mdadm/script 3>&1
+  run as root. Thanks!
+
+_eof
+fi
+
 if [ ! -r /proc/mdstat ]; then
   echo "The local system does not have MD (RAID) support: no drivers loaded."
   echo "Without MD support, I cannot collect as much information as I'd like."
diff --git a/debian/changelog b/debian/changelog
index 09d6da6..504f000 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -4,6 +4,8 @@ mdadm (2.6.9-3) unstable; urgency=low
     the prerequisites (closes: #526793).
   * Change my previous recommendation for postfix over to the new virtual
     package default-mta (see #522300 and #508644).
+  * Enhance bugscript, which now asks to run as root (sudo/su) if invoked by
+    a normal user.
 
  -- martin f. krafft <madduck at debian.org>  Sun, 03 May 2009 17:29:47 +0200
 
diff --git a/debian/presubj b/debian/presubj
new file mode 100644
index 0000000..9eb304f
--- /dev/null
+++ b/debian/presubj
@@ -0,0 +1,17 @@
+Gathering information relevant to mdadm as root
+===============================================
+
+If you are not reporting bugs as root (which you should not), you will be
+prompted to give permission to run a script to collect relevant information
+from your system as the root user. Only the root user has access to some
+information that might be relevant to the bug report you are about to file.
+
+
+** Please give permission to run the script as root when asked momentarily.
+
+
+If you would rather obtain the same information manually, you can run
+  /usr/share/bug/mdadm/script 3>&1
+as root and include or attach the output.
+
+ -- martin f. krafft <madduck at debian.org>  Tue, 05 May 2009 11:26:32 +0200
diff --git a/debian/rules b/debian/rules
index 67aacda..81ed63e 100755
--- a/debian/rules
+++ b/debian/rules
@@ -74,6 +74,7 @@ install: build
 	install -m0755 debian/mkconf $(DESTDIR)/usr/share/mdadm
 	install -m0755 debian/checkarray $(DESTDIR)/usr/share/mdadm
 	install -m0755 debian/bugscript $(DESTDIR)/usr/share/bug/mdadm/script
+	install -m0544 debian/presubj $(DESTDIR)/usr/share/bug/mdadm
 
 	install -m0755 debian/mdadm-startall $(DESTDIR)/sbin
 




More information about the pkg-mdadm-commits mailing list