Page Menu
Home
GitPull.it
Search
Configure Global Search
Log In
Files
F2444381
D163.1729702780.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D163.1729702780.diff
View Options
Index: misctools/become
===================================================================
--- misctools/become
+++ misctools/become
@@ -1,6 +1,8 @@
#!/bin/bash
#
# Copyright © 2013 Marc-André Pelletier <mpelletier@wikimedia.org>
+# 2024 Marc-André Pelletier <mpelletier@wikimedia.org>
+# Valerio Bozzolan <boz@reyboz.it>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@@ -15,25 +17,38 @@
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
-prefix=$(/bin/cat /etc/wmcs-project)
-if [ $# -lt 1 -o "$1" = "--help" ]; then
- echo "usage: $(basename $0) <toolname> [command [args...]]" >&2
- exit 1
+# NOTE: This script relies on the Bash feature "$EUID".
+# So, the shebang cannot use /bin/sh.
+
+# Be strict. In case of an error, die without proceeding.
+set -e
+
+# This contains a short string. Example: "tools".
+prefix=$(< /etc/wmcs-project)
+
+# Require the right number of arguments.
+if [ $# -lt 1 ] || [ "$1" = "--help" ]; then
+ echo "usage: $(basename "$0") <toolname> [command [args...]]" >&2
+ exit 1
fi
+
+# This is the tool name. Example: "croptool".
tool="$1"
+
+# Discard the first argument, that is, the name of this script.
shift
# 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
+ 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 unless the user is root.
-if [ $EUID -ne 0 ] && ! echo " $(groups) " | fgrep -q " $prefix.$tool "; then
+if [ $EUID -ne 0 ] && ! echo " $(groups) " | grep --fixed-strings --quiet " $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
+ if echo ",$(getent group "$prefix.$tool" | cut -d : -f 4)," | grep --fixed-strings --quiet ",$(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 $tool\"." >&2
else
@@ -45,4 +60,4 @@
fi
# Execute sudo.
-exec /usr/bin/sudo -niu "$prefix.$tool" "$@"
+exec /usr/bin/sudo --non-interactive --login --user="$prefix.$tool" "$@"
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Oct 23, 18:59 (9 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
641420
Default Alt Text
D163.1729702780.diff (2 KB)
Attached To
Mode
D163: ASDLOL
Attached
Detach File
Event Timeline
Log In to Comment