Commit cc591b04 authored by Vitaly Lipatov's avatar Vitaly Lipatov

esu: move esu code to esu() function

parent 3955f227
...@@ -488,6 +488,62 @@ assure_root() ...@@ -488,6 +488,62 @@ assure_root()
is_root || fatal "run me only under root" is_root || fatal "run me only under root"
} }
esu()
{
if is_root ; then
if [ -n "$*" ] ; then
[ -n "$quiet" ] || showcmd "$*"
exec "$@"
else
# just shell
showcmd "su -"
exec su -
fi
fi
set_pm_type
escape_args()
{
local output=''
while [ -n "$1" ] ; do
if has_space "$1" ; then
[ -n "$output" ] && output="$output '$1'" || output="'$1'"
else
[ -n "$output" ] && output="$output $1" || output="$1"
fi
shift
done
echo "$output"
}
escaped="$(escape_args "$@")"
# sudo is not accessible, will ask root password
if ! set_sudo ; then
#info "Enter root password:"
if [ -n "$*" ] ; then
[ -n "$quiet" ] || showcmd "su - -c $escaped"
exec su - -c "$escaped"
else
# just shell
showcmd "su -"
exec su -
fi
fi
#info "You can be asked about your password:"
if [ -n "$*" ] ; then
[ -n "$quiet" ] || showcmd "$SUDO su - -c $escaped"
$SUDO su - -c "$escaped"
else
showcmd "$SUDO su -"
$SUDO su -
fi
}
regexp_subst() regexp_subst()
{ {
local expression="$1" local expression="$1"
......
...@@ -61,55 +61,10 @@ if [ "$1" = "-c" ] ; then ...@@ -61,55 +61,10 @@ if [ "$1" = "-c" ] ; then
shift shift
fi fi
if is_root ; then # just an optimization
if [ -n "$*" ] ; then if ! is_root ; then
[ -n "$quiet" ] || showcmd "$*" # need only under user
exec "$@" set_pm_type
else
# just shell
showcmd "su -"
exec su -
fi
fi fi
set_pm_type esu "$@"
escape_args()
{
local output=''
while [ -n "$1" ] ; do
if has_space "$1" ; then
[ -n "$output" ] && output="$output '$1'" || output="'$1'"
else
[ -n "$output" ] && output="$output $1" || output="$1"
fi
shift
done
echo "$output"
}
escaped="$(escape_args "$@")"
# sudo is not accessible, will ask root password
if ! set_sudo ; then
#info "Enter root password:"
if [ -n "$*" ] ; then
[ -n "$quiet" ] || showcmd "su - -c $escaped"
exec su - -c "$escaped"
else
# just shell
showcmd "su -"
exec su -
fi
fi
#info "You can be asked about your password:"
if [ -n "$*" ] ; then
[ -n "$quiet" ] || showcmd "$SUDO su - -c $escaped"
$SUDO su - -c "$escaped"
else
showcmd "$SUDO su -"
$SUDO su -
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment