Skip to content

Commit

Permalink
[eos-bash-shared] eos-update: removed option --nvidia-auto, speedup f…
Browse files Browse the repository at this point in the history
…or the Nvidia check
  • Loading branch information
manuel-192 committed Apr 24, 2024
1 parent 147262d commit e48ec85
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 98 deletions.
114 changes: 45 additions & 69 deletions eos-kernel-nvidia-update-check
Original file line number Diff line number Diff line change
@@ -1,93 +1,69 @@
#!/bin/bash

# On Nvidia GPU machines, kernel and nvidia driver must update together:
# - if linux-lts is updated, nvidia-lts should be updated too
# - if linux is updated, nvidia should be updated too
# Note that if an nvidia*dkms driver is installed, we have nothing to check.
# On Nvidia GPU machines, the non-dkms Nvidia drivers need to be updated
# *in sync* with the corresponding kernel:
# - if linux-lts is updated and nvidia-lts is installed, nvidia-lts should be updated too
# - if linux is updated and nvidia is installed, nvidia should be updated too
#
# This app checks the above and informs the calling app with exit code:
# 0=success
# 1=failure
# On failure also error messages to stderr will be displayed.
# 0 = success, no issue detected
# 1 = failure, update is missing
# 2 = usage error
# On failure also the appopriate error messages will be displayed to stderr.

DIE() {
echo "$progname: error: $1" >&2
exit 1
}
DIE() { echo "==> $progname: error: $1" >&2; exit 2; }

Exit() {
case "$1" in
0) [ $verbose = yes ] && echo "==> no Nvidia driver update issue detected. " >&2 ;;
esac
exit "$1"
}
ExitOK() { [ $verbose = yes ] && echo "==> no Nvidia driver update issue detected. " >&2; exit 0; }
ExitFail() { exit 1; }

Main() {
local -r progname=${0##*/}
local verbose=no
local color=yes
UpdatesInclude() { echo "$updates" | grep "^$1$" >/dev/null ; }
IsInstalled() { expac -Q %n "$1" >/dev/null ; }
DriverCheck() {
if UpdatesInclude "$1" && IsInstalled "$2" && ! UpdatesInclude "$2" ; then
msgs+=("updates include $1 but not $2")
fi
}

while [ "$1" ] ; do
Parameters() {
while true ; do
case "$1" in
-v | --verbose) verbose=yes ;;
--no-color) color=no ;;
-*) DIE "unsupported option '$1'." ;;
*) break ;;
--no-color) RED=""; RESET="" ;;
-*) DIE "unsupported option '$1'" ;;
*) if [ "$1" ] ; then
updates="$(printf "%s\n" "$@")" # from parameters
else
updates="$(checkupdates | awk '{print $1}')" # from a command
fi
return
;;
esac
shift
done
}

Main() {
local -r progname=${0##*/}
local RED=$'\e[0;91m'
local RESET=$'\e[0m'
local verbose=no
local updates="" # will contain all updates, separated by newline; see Parameters()
local msgs=()
local pkgs=()

PATH=/usr/bin:$PATH
expac %n nvidia nvidia-lts >/dev/null || exit 0 # nothing to do
echo ":: Nvidia check..." >&2

# Quick check is Nvidia modules are in use.
lsmod | grep nvidia >/dev/null || Exit 0
Parameters "$@"

# If any of these nvidia dkms versions are installed, we have nothing to do.
expac -Q %n nvidia-dkms nvidia-470xx-dkms nvidia-390xx-dkms >/dev/null && Exit 0
DriverCheck linux nvidia
DriverCheck linux-lts nvidia-lts

# Get list of packages to be updated from parameters or otherwise.
if [ "$1" ] ; then
pkgs=("$@")
if [ ${#msgs[@]} -eq 0 ] ; then
ExitOK
else
readarray -t pkgs <<< $(checkupdates | awk '{print $1}')
fi

# Find and show potential problems with Nvidia related updates.

local NVIDIA=( nvidia nvidia-lts )
local LINUX=( linux linux-lts )
local ix count=${#LINUX[@]}
local ll nn

for ((ix=0; ix < count; ix++)) ; do
ll=${LINUX[$ix]}
nn=${NVIDIA[$ix]}
case "$(printf "%s\n" "${pkgs[@]}" | grep -P "^$ll$|^$nn$")" in
"$ll")
expac %n $nn >/dev/null && msgs+=("warning: $ll would be upgraded, $nn not!")
;;
# "$nn") msgs+=("warning: $nn would be upgraded, $ll not!") ;;
esac
done

if [ ${#msgs[@]} -gt 0 ] ; then
if [ "$color" = "yes" ] ; then
local -r RED=$'\e[0;91m'
local -r RESET=$'\e[0m'
else
local -r RED=""
local -r RESET=""
fi
local msg
for msg in "${msgs[@]}" ; do
echo "${RED}==> $progname: $msg${RESET}" >&2
done
exit 1
echo "${RED}==> $progname: warning: $(printf "%s\n" "${msgs[@]}")${RESET}" >&2
ExitFail
fi
Exit 0
}

Main "$@"
26 changes: 6 additions & 20 deletions eos-update
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ ClearDatabases() {

OptionCheck() {
case "$1" in
--nvidia | --nvidia-auto)
IsSupportedOS || {
WARN "sorry, the nvidia check is implemented only in $OS, option $1 ignored."
return 1
}
;;
--nvidia) IsSupportedOS "$1" || return 1 ;;
esac
return 0
}
Expand All @@ -64,10 +59,6 @@ Options() {
while true ; do
case "$1" in
--nvidia) OptionCheck "$1" && nvidia=yes ;;
--nvidia-auto) if OptionCheck "$1" ; then
lsmod | grep -w nvidia >/dev/null && nvidia=yes
fi
;;
--no-keyring) keyring=no ;;
--no-sync) sync=":" ;;
--keyrings-reset) ResetKeyrings ;;
Expand Down Expand Up @@ -111,13 +102,12 @@ Optional help:
- Can clear package databases in case of contant problems with them.
- Can reset keyrings in case of constant problems with them.
- Updates AUR packages (with option --helper, see Usage below).
- Ad hoc check (only on EndeavourOS) for Nvidia GPU driver vs. kernel updates (non-dkms only).
- Ad hoc check for Nvidia GPU driver vs. kernel updates (non-dkms only).
Usage: $progname [options]
Options:
--help, -h This help.
--nvidia Check also nvidia driver vs. kernel updates. Useful only with the Nvidia GPU.
--nvidia-auto If nvidia module is in use, automatically apply option --nvidia.
--clear-databases Clears package database files.
Use this only if package database issues constantly make system update fail.
--keyrings-reset Resets Arch and EndeavourOS keyrings.
Expand Down Expand Up @@ -153,14 +143,12 @@ EOF
}

IsSupportedOS() {
[ "$isSupportedOS" = "yes" ] && return 0
if [ -r /usr/lib/endeavouros-release ] || [ -n "$(grep -iw endeavouros /etc/*-release)" ] ; then
OS=EndeavourOS
isSupportedOS=yes
if [ -x /usr/bin/eos-kernel-nvidia-update-check ] ; then
return 0
else
WARN "the Nvidia check requires package 'eos-bash-shared' fully installed, option $1 ignored."
return 1
fi
isSupportedOS=no
return 1
}

DiskSpace() {
Expand Down Expand Up @@ -194,8 +182,6 @@ Main() {
local helper2=":"
local lock=/var/lib/pacman/db.lck
local rmopt=f
local isSupportedOS=""
local OS=""

local subopts=()
local afteropts=()
Expand Down
10 changes: 1 addition & 9 deletions eos-update-extras
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@
echo2() { echo "$@" >&2 ; }
WARN() { echo2 "==> $progname: warning: $1" ; }

Nvidia-check() {
Nvidia-check-needed() { expac -Q %n nvidia nvidia-lts > /dev/null ; }

Nvidia-check-needed || return 0
echo2 ":: Nvidia check..."
eos-kernel-nvidia-update-check -v $updates
}

Parameters() {
local arg
local update_first=() # these will be updated before others
Expand All @@ -23,7 +15,7 @@ Parameters() {
arg="$1"
case "$arg" in
--nvidia)
Nvidia-check || WARN "'Nvidia & kernel' check failed."
eos-kernel-nvidia-update-check $updates || WARN "'Nvidia & kernel' check failed."
;;
--keyrings | --keyring)
for arg in archlinux-keyring endeavouros-keyring ; do
Expand Down

0 comments on commit e48ec85

Please sign in to comment.