Package: menu
Version: 2.1.37
Severity: wishlist
Tags: patch

It does not seem to be possible to call a command with arguments, using
su-to-root, e.g. "su-to-root -c apt-get install foo" does not work
(error: command "apt-get install foo" not found).

I therefore propose a new option -a for su-to-root, where you can then
pass arguments for the command, e.g.
su-to-root -c apt-get -a "install foo"

Another option might be to pass everything at the end as argument(s).

I'm attaching a patch, which adds the -a option, but I've not really
tested it and it may fail for some of the used programs. Please consider
it only as an implemention of the "-a" idea.

Thank you.
--- ../o/menu-2.1.37/scripts/su-to-root 2008-01-19 20:53:04.000000000 +0100
+++ /usr/sbin/su-to-root        2008-02-10 22:39:27.000000000 +0100
@@ -30,6 +30,7 @@
 usage () {
   transl 'usage: %s [-X] [-p <user>] -c <command>
   -c command: command to execute as a string (mandatory)
+  -a arguments: arguments for command
   -p <user>: user to switch to (default: root)
   -X: command is a X11 program\n' "$0" >&2
   exit 1
@@ -43,6 +44,8 @@
        COMMAND="$i";;
      -X) 
        NEEDS="X11";;
+     -a)
+       ARGS="$i"
    esac
    prev="$i"
 done
@@ -54,20 +57,20 @@
 euid=$(id -u)
 privid=$(id -u $PRIV)
 if test "$euid" = "$privid"; then
-  $COMMAND
+  $COMMAND $ARGS
 else
   case $NEEDS in
   text)
     if test "$euid" != 0; then
-      transl 'About to execute %s.\n' "$COMMAND"
+      transl 'About to execute %s.\n' "$COMMAND $ARGS"
       transl 'This command needs %s privileges to be executed.\n' "$PRIV"
     fi
     
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/bin/X11:/usr/local/sbin:/usr/local/bin
     SHELL=`eshell $PRIV`
     case $SU_TO_ROOT_SU in
-      sux)  suname=sux; pwuser="$PRIV"; cmd='sux  -p "$PRIV"    "$COMMAND"';;
-      sudo) suname=sudo;pwuser="$USER"; cmd='sudo -u "$PRIV"    "$COMMAND"';;
-      *)    suname=su;  pwuser="$PRIV"; cmd='su   -p "$PRIV" -c "$COMMAND"';;
+      sux)  suname=sux; pwuser="$PRIV"; cmd='sux  -p "$PRIV"    "$COMMAND" 
$ARGS';;
+      sudo) suname=sudo;pwuser="$USER"; cmd='sudo -u "$PRIV"    "$COMMAND" 
$ARGS';;
+      *)    suname=su;  pwuser="$PRIV"; cmd='su   -p "$PRIV" -c "$COMMAND" 
$ARGS';;
     esac
     transl 'Using %s...\n' "$suname"
     transl 'Enter %s passwd at prompt.\n' "$pwuser"
@@ -101,14 +104,14 @@
       fi
     fi
     case $SU_TO_ROOT_X in
-      gksu) gksu -u "$PRIV" "$COMMAND";;
-      kdesu) kdesu -u "$PRIV" "$COMMAND";;
-      kde4su) /usr/lib/kde4/libexec/kdesu -u "$PRIV" "$COMMAND";;
+      gksu) gksu -u "$PRIV" "$COMMAND" $ARGS;;
+      kdesu) kdesu -u "$PRIV" "$COMMAND" $ARGS;;
+      kde4su) /usr/lib/kde4/libexec/kdesu -u "$PRIV" "$COMMAND" $ARGS;;
       sux) env SU_TO_ROOT_SU=sux \
-        x-terminal-emulator -e su-to-root -p "$PRIV" -c "$COMMAND";;
+        x-terminal-emulator -e su-to-root -p "$PRIV" -c "$COMMAND" -a "$ARGS";;
   # As a last resort, open a new x-terminal-emulator and prompt for the 
password
   # Do not use -X here!
-      *) x-terminal-emulator -e su-to-root -p "$PRIV" -c "$COMMAND";;
+      *) x-terminal-emulator -e su-to-root -p "$PRIV" -c "$COMMAND" -a 
"$ARGS";;
     esac;;
   esac
 fi

Reply via email to