Tim Landscheidt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/147096

Change subject: become: Make more user-friendly
......................................................................

become: Make more user-friendly

Currently, if you try to become a tool that you are not a member of,
the error message is rather cryptic:

| scfc@tools-login:~$ become coursestats
| sudo: sorry, a password is required to run sudo
| scfc@tools-login:~$

This change makes the error message more meaningful and also addresses
the common issue when a user has been made a member of the group but
his login session predates that change.

Bug: 68156
Change-Id: I801608bf5cf47d339343838987240336cb012998
---
M configure.ac
M debian/changelog
M misctools/become
3 files changed, 36 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/labs/toollabs 
refs/changes/96/147096/1

diff --git a/configure.ac b/configure.ac
index 92d1b80..d2b4f81 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
-AC_INIT([toollabs], [1.0.4dev], [[email protected]])
+AC_INIT([toollabs], [1.0.8dev], [[email protected]])
 AC_CONFIG_AUX_DIR([build-aux])
 AC_CONFIG_TESTDIR([tests])
 
diff --git a/debian/changelog b/debian/changelog
index a3b166b..2a4f89f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+toollabs (1.0.8dev) unstable; urgency=low
+
+  * become: Made more user-friendly.
+
+ -- Tim Landscheidt <[email protected]>  Thu, 17 Jul 2014 12:29:01 +0000
+
 toollabs (1.0.7) unstable; urgency=low
 
   * Marc-André Pelletier: fixes for eqiad
diff --git a/misctools/become b/misctools/become
index 2b6fbbc..9479dc1 100755
--- a/misctools/become
+++ b/misctools/become
@@ -1,11 +1,11 @@
-#! /bin/bash
+#!/bin/bash
 #
 # Copyright © 2013 Marc-André Pelletier <[email protected]>
-# 
+#
 # Permission to use, copy, modify, and/or distribute this software for any
 # purpose with or without fee is hereby granted, provided that the above
 # copyright notice and this permission notice appear in all copies.
-# 
+#
 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
@@ -15,22 +15,35 @@
 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #
 
-prefix=$(/bin/cat /etc/wmflabs-project)
+# Test whether we were given at least a tool name.
+PREFIX=$(/bin/cat /etc/wmflabs-project)
 if [ $# -lt 1 ]; then
   echo "usage: $(basename $0) <toolname> [command [args...]]" >&2
   exit 1
 fi
-if ! id "$prefix.$1" >/dev/null 2>&1
-then
-  echo "$(basename $0): no such tool '$1'" >&2
-  exit 1
-fi
-if ! [ -d "/data/project/$1" ]
-then
-  echo "$(basename $0): no such tool '$1'" >&2
-  exit 1
-fi
-user="$1"
+TOOL="$1"
 shift
-exec /usr/bin/sudo -niu "$prefix.$user" "$@"
 
+# Test whether the given tool exists.
+if ! id "$PREFIX.$TOOL" >/dev/null 2>&1 || ! [ -d "/data/project/$TOOL" ]; then
+  echo "$(basename $0): no such tool '$TOOL'" >&2
+  exit 1
+fi
+
+# Test whether the user is a member of the tool's group in this
+# session.
+if ! echo " $(groups) " | fgrep -q " $PREFIX.$TOOL "; then
+    # Test whether the user is a member of the tool's group at all.
+    if echo ",$(getent group "$PREFIX.$TOOL" | cut -d : -f 4)," | fgrep -q 
",$(id -nu),"; then
+        echo "You were added to the group $PREFIX.$TOOL after you started this 
login session." >&2
+        echo "You need to log out and in again to be able to \"become 
$PREFIX.$TOOL\"." >&2
+    else
+        echo "You are not a member of the group $PREFIX.$TOOL." >&2
+        echo "Any existing member of the tool's group can add you to that." >&2
+    fi
+
+    exit 1
+fi
+
+# Execute sudo.
+exec /usr/bin/sudo -niu "$PREFIX.$TOOL" "$@"

-- 
To view, visit https://gerrit.wikimedia.org/r/147096
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I801608bf5cf47d339343838987240336cb012998
Gerrit-PatchSet: 1
Gerrit-Project: labs/toollabs
Gerrit-Branch: master
Gerrit-Owner: Tim Landscheidt <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to