Commit bf2b397c authored by Vitaly Lipatov's avatar Vitaly Lipatov

esu: add messages if sudo or su is missed or not accessible

parent 51ee433c
...@@ -504,6 +504,43 @@ assure_root() ...@@ -504,6 +504,43 @@ assure_root()
is_root || fatal "run me only under root" is_root || fatal "run me only under root"
} }
check_su_access()
{
is_command su && return
[ ! -f /bin/su ] && warning "/bin/su is missed. Try install su package (http://altlinux.org/su)." && return 1
local group="$(stat -c '%G' /bin/su)" || fatal
warning "Check if you are in $group group to have access to su command."
return 1
}
check_sudo_access()
{
is_command sudo && return
local cmd=''
local i
for i in /bin/sudo /usr/bin/sudo ; do
[ -f $i ] && cmd="$i"
done
[ ! -f $cmd ] && warning "sudo command is missed. Try install sudo package (http://altlinux.org/sudo)." && return 1
local group="$(stat -c '%G' $cmd)" || fatal
warning "Check if you are in $group group to have access to sudo command."
return 1
}
check_sudo_access_only()
{
is_command sudo && return
local cmd=''
local i
for i in /bin/sudo /usr/bin/sudo ; do
[ -f $i ] && cmd="$i"
done
[ ! -f $cmd ] && return 1
local group="$(stat -c '%G' $cmd)" || fatal
warning "sudo command is presence, but is not accessible for you. Check if you are in $group group to have access to sudo command."
return 1
}
esu() esu()
{ {
if is_root ; then if is_root ; then
...@@ -543,9 +580,10 @@ esu() ...@@ -543,9 +580,10 @@ esu()
escaped="$(escape_args "$@")" escaped="$(escape_args "$@")"
check_sudo_access_only
# sudo is not accessible, will ask root password # sudo is not accessible, will ask root password
if ! set_sudo ; then if ! set_sudo ; then
check_su_access
#info "Enter root password:" #info "Enter root password:"
if [ -n "$*" ] ; then if [ -n "$*" ] ; then
[ -n "$quiet" ] || showcmd "su - -c $escaped" [ -n "$quiet" ] || showcmd "su - -c $escaped"
...@@ -557,6 +595,8 @@ esu() ...@@ -557,6 +595,8 @@ esu()
fi fi
fi fi
check_sudo_access
#info "You can be asked about your password:" #info "You can be asked about your password:"
if [ -n "$*" ] ; then if [ -n "$*" ] ; then
[ -n "$quiet" ] || showcmd "$SUDO su - -c $escaped" [ -n "$quiet" ] || showcmd "$SUDO su - -c $escaped"
......
...@@ -67,10 +67,9 @@ if [ "$1" = "-c" ] ; then ...@@ -67,10 +67,9 @@ if [ "$1" = "-c" ] ; then
shift shift
fi fi
# just an optimization # just ignore
if ! is_root ; then if [ "$1" = "-" ] ; then
# need only under user shift
set_pm_type
fi fi
esu "$@" esu "$@"
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