A weird thing happen... I have send you a messages but gotten nothing back and my send message is /dev/null (???) so I send it again... :-/ with a better version.
Please note, that gettext strings which includes VARS must be evaluated.
See
eval_gettext()
{
eval 'echo $1'
}
I was playing arround and now it works like expected...
To test, change the line
if [ -n "$(which gettext.sh)"] ; then
to
if [ -z "$(which gettext.sh)"] ; then
^
and you can see, that it is working properly now. The script is tested.
The su-to-root script produce 6 gettext strings:
----8<-----------------------------------------------------------------
msgid "usage: \\$0 [-X] [-p <user>] -c <command>\n -c command: command to
execute\n -p <user>: user to switch to (default: root)\n -X: command is a X11
program\n"
msgid "About to execute \\$COMMAND.\nThis command needs \\$PRIV privileges to
be executed.\n"
msgid "Using \\$suname...\nEnter \\$PRIV passwd:\n"
msgid "Y"
msgid "y"
msgid "Incorrect password or command failed. Try again? (y/n)"
----8<-----------------------------------------------------------------
And then Bill, are you sure, this works only with /bin/bash and not
with other shells? Maybe you should use /bin/sh.
Thanks, Greetings and nice Day
Michelle Konzack
Systemadministrator
Tamay Dogan Network
Debian GNU/Linux Consultant
--
Linux-User #280138 with the Linux Counter, http://counter.li.org/
##################### Debian GNU/Linux Consultant #####################
Michelle Konzack Apt. 917 ICQ #328449886
50, rue de Soultz MSN LinuxMichi
0033/6/61925193 67100 Strasbourg/France IRC #Debian (irc.icq.com)
#!/bin/bash
if test -r ~/.su-to-rootrc; then
. ~/.su-to-rootrc
fi
PRIV=root
COMMAND=
NEEDS=text
if [ -n "$(which gettext.sh)" ] ; then
. gettext.sh
export TEXTDOMAIN=su-to-root
export TEXTDOMAINDIR=/usr/share/locale
else
gettext()
{
#---------------------------------------------
# Normal text can be outputed as it is
echo "$1"
}
eval_gettext()
{
#---------------------------------------------
# "echo $1" must be evaluated since a string
# of 'value ${val}' aould not work
eval 'echo $1'
}
fi
#-------------------------------------------------
# We do not need this
#transf() {
# txt="$1";
# shift;
# if [ -n "$gettext" ]; then
# txt="$(gettext su-to-root "$txt")";
# fi
# printf "$txt" "$@"
#}
eshell() {
getent passwd $1 | cut -f7 -d:
}
usage() {
# transf 'usage: %s [-X] [-p <user>] -c <command>
# -c command: command to execute
# -p <user>: user to switch to (default: root)
# -X: command is a X11 program\n' $0 >&2
GT_text=`eval_gettext "usage: $0 [-X] [-p <user>] -c <command>\n -c
command: command to execute\n -p <user>: user to switch to (default: root)\n
-X: command is a X11 program\n"`
echo -e "${GT_text}"
exit 1
}
for i in "$@"; do
case "$prev" in
-p)
PRIV="$i";;
-c)
COMMAND="$i";;
-X)
NEEDS="X11";;
esac
prev="$i"
done
if [ -z "$COMMAND" ] ; then
usage;
fi
euid=$(id -u)
privid=$(id -u $PRIV)
if test "$euid" = "$privid"; then
$COMMAND
else
case $NEEDS in
text)
if test "$euid" != 0; then
# transf "About to execute %s.\n" $COMMAND
# transf "This command needs %s$PRIV privileges to be executed.\n" $PRIV
GT_text=$(eval_gettext "About to execute $COMMAND.\nThis command needs
$PRIV privileges to be executed.\n")
echo -e "${GT_text}"
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; cmd='sux -p "$PRIV" "$COMMAND"';;
sudo) suname=sudo;cmd='sudo -u "$PRIV" "$COMMAND"';;
*) suname=su; cmd='su -p "$PRIV" -c "$COMMAND"';;
esac
# transf 'Using %s...\n' $suname
# transf 'Enter %s passwd:\n' $PRIV
GT_text=$(eval_gettext "Using $suname...\nEnter $PRIV passwd:\n")
echo -e "${GT_text}"
#---------------------------------------------
# Translate the input string
GT_YES=$(gettext 'Y')
GT_yes=$(gettext 'y')
while ! eval $cmd; do
# transf 'Incorrect password or command failed. Try again? (y/n)'
GT_text=`gettext "Incorrect password or command failed. Try again? (y/n)"`
echo "${GT_text}"
read ans
if test "$ans" != "${GT_YES}" -a "$ans" != "${GT_yes}"; then
exit 1
fi
done;;
X11)
if test -z "$SU_TO_ROOT_X"; then
if which gksu >/dev/null 2>&1 ; then
if test "X$KDE_FULL_SESSION" = "Xtrue" \
&& which kdesu >/dev/null 2>&1 ; then
SU_TO_ROOT_X=kdesu
else
SU_TO_ROOT_X=gksu
fi;
elif which kdesu >/dev/null 2>&1 ; then
SU_TO_ROOT_X=kdesu
elif which sux >/dev/null 2>&1 ; then
SU_TO_ROOT_X=sux
else
SU_TO_ROOT_X=su-to-root
fi
fi
case $SU_TO_ROOT_X in
gksu) gksu -u "$PRIV" "$COMMAND";;
kdesu) kdesu -u "$PRIV" "$COMMAND";;
sux) env SU_TO_ROOT_SU=sux \
x-terminal-emulator -e su-to-root -p "$PRIV" -c "$COMMAND";;
# 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";;
esac;;
esac
fi
signature.pgp
Description: Digital signature

