Suggest to rerun from root when needed

keleg@ noted that otherwise it may download and process dnf metadata and only then dnf will say that it is unable to install packages
This commit is contained in:
Mikhail Novosyolov 2022-10-27 23:39:18 +03:00
parent 0531e53749
commit 53f9579aa4
3 changed files with 32 additions and 1 deletions

View file

@ -3,7 +3,7 @@ Name: auto-krokodil
Group: System/Kernel and hardware
License: GPLv3
Url: https://abf.io/import/auto-krokodil
Version: 0.24
Version: 0.25
Release: 1
BuildArch: noarch
%ifarch %{ix86} %{x86_64}

View file

@ -12,6 +12,7 @@ readonly EXIT_GENERICERROR=1
readonly EXIT_ENODRIVER=10
readonly EXIT_ENOGPU=20
readonly EXIT_ENOCOMMONDRIVER=30
readonly EXIT_ENOPERM=40
# use fake output of lspci for development on hardware without Nvidia
KROKO_FAKE_LSPCI="${KROKO_FAKE_LSPCI:-0}"
@ -363,6 +364,28 @@ _cli_autoinstall(){
dnf $KROKO_DNF_OPTS -y --allowerasing shell "$dnfcmd"
}
_check_root(){
# TODO: convert to gettext (*.po) when there are more translatable messages
# For now there is only this message
local text_en="Unable to install packages. Rerun this command from root"
local text_ru="Невозможно установить пакеты. Перезапустите эту команду от root"
local text
if [[ "${LANG:-}" =~ ru(|_.*)".UTF-8" ]]
then text="$text_ru"
else text="$text_en"
fi
if [ "$EUID" != 0 ]; then
_echo_err "$text":
local s
if command -v sudo >/dev/null 2>&1
then s=sudo
else s='#'
fi
_echo_err "$s $0 $*"
return $EXIT_ENOPERM
fi
}
_main(){
case "${1:-}" in
"get-gpus" )
@ -372,6 +395,7 @@ _main(){
_cli_best_driver
;;
"autoinstall" )
_check_root "$@"
_cli_autoinstall
;;
"help" | "--help" | "-h" )

View file

@ -8,10 +8,17 @@ line_from_lspci;0000;NVIDIA 3;nvidia470-core,nvidia510-core,nvidia515-core;nvidi
test "$(echo 'line_from_lspci;0000;NVIDIA 1;nvidia390-core;nvidia390-core' | _select_best_driver)" = nvidia390-core
set +e
echo 'line_from_lspci;0000;NVIDIA 1;nvidia510-core,nvidia515-core;nvidia515-core
line_from_lspci;0000;NVIDIA 2;nvidia390-core,nvidia470-core;nvidia470-core,
line_from_lspci;0000;NVIDIA 3;nvidia340-core;nvidia340-core' | _select_best_driver 2>/dev/null
test $? = $EXIT_ENOCOMMONDRIVER || exit 1
_check_root 2>/dev/null
rc=$?
[ "$EUID" = 0 ] && [ "$rc" = 0 ]
[ "$EUID" != 0 ] && [ "$rc" = $EXIT_ENOPERM ]
set -e
echo FINISHED OK