Wait for user input if run_elevated fails

* This is a workaround for su/sudo timeouts
* Should help with issue #17
This commit is contained in:
2Shirt 2018-02-28 13:32:45 -07:00
parent d82ad55113
commit 51f9f91195

View file

@ -32,7 +32,7 @@ fi
function ask() { function ask() {
while :; do while :; do
read -p "$1 " -r answer read -p "$1 [Y/N] " -r answer
if echo "$answer" | egrep -iq '^(y|yes|sure)$'; then if echo "$answer" | egrep -iq '^(y|yes|sure)$'; then
return 0 return 0
elif echo "$answer" | egrep -iq '^(n|no|nope)$'; then elif echo "$answer" | egrep -iq '^(n|no|nope)$'; then
@ -122,10 +122,20 @@ function run_elevated() {
prog="$1" prog="$1"
shift shift
if which sudo >/dev/null 2>&1; then if which sudo >/dev/null 2>&1; then
sudo "$prog" $* if ! sudo "$prog" $*; then
echo "ERROR: Failed to run '$prog'"
if ask "Retry?"; then
sudo "$prog" $*
fi
fi
else else
echo -n "Root " echo -n "Root "
su -c "export REAL_USER=$USER && '$prog' $*" if ! su -c "export REAL_USER=$USER && '$prog' $*"; then
echo "ERROR: Failed to run '$prog'"
if ask "Retry?"; then
su -c "export REAL_USER=$USER && '$prog' $*"
fi
fi
fi fi
} }