RaphaelRochet / arch-update

Update indicator for ArchLinux and Gnome-Shell
https://extensions.gnome.org/extension/1010/archlinux-updates-indicator/
GNU General Public License v3.0
229 stars 69 forks source link

Only show major updates #198

Closed auipga closed 5 months ago

auipga commented 1 year ago

Is there a way to only show major updates and hide the minor ones? I found nothing about this topic.

RaphaelRochet commented 1 year ago

One can easily make a little script to filter out whatever is shown and use it as "check command" instead of default checkupdates script. From the extension, there is no filter option.

auipga commented 1 year ago

Ok, thanks. This is a first working example of checkupgrade-filter Usage:

  1. checkupgrade-filter like checkupgrade, unaltered
  2. checkupgrade-filter --major only major updates (X.x.x-x)
  3. checkupgrade-filter --minor only major updates (x.X.x-x)
  4. checkupgrade-filter --patch only major updates (x.x.X-x)
  5. checkupgrade-filter --release only major updates (x.x.x-X)
  6. combine previous arguments as you wish: checkupgrade-filter --major --release
  7. checkupgrade-filter --minor-up short for --major --minor
  8. checkupgrade-filter --patch-up short for --major --minor --patch In cases 6-8 the packages are grouped in this order: major, minor, patch, release.
#!/usr/bin/env bash

if [ -z $1 ]; then
    checkupdates
    exit $!
fi

major=""
minor=""
patch=""
release=""

while read line; do
    words=(${line// / }) # array ("cryptsetup", "2.5.0-3", "->", "2.5.0-4")
    pkg_name=${words[0]} # "cryptsetup"
    pkg_vold=${words[1]} # "2.5.0-3"
    pkg_vnew=${words[3]} # "2.5.0-4"

    vold_=( ${pkg_vold//./ } ) # array ("2", "5", "0-3")
    vnew_=( ${pkg_vnew//./ } ) # array ("2", "5", "0-4")

    if [[ ${vold_[0]} != ${vnew_[0]} ]]; then # "2"!="2"
        major+="${line}\n"
    elif [[ ${vold_[1]} != ${vnew_[1]} ]]; then # "5"!="5"
        minor+="${line}\n"
    elif [[ ${vold_[2]} != ${vnew_[2]} ]]; then # "0-3"!="0-4"
        if [[ ${pkg_vold##*-} == ${pkg_vnew##*-} ]]; then # "3"=="4"
            patch+="${line}\n"
        else
            release+="${line}\n" # example goes here
        fi
    fi
done < <(checkupdates)

if [ $1 == --patch-up ]; then
    echo -en ${major}
    echo -en ${minor}
    echo -en ${patch}
elif [ $1 == --minor-up ]; then
    echo -en ${major}
    echo -en ${minor}
else
    [[ "$*" =~ "--major" ]]    && echo -en ${major}
    [[ "$*" =~ "--minor" ]]    && echo -en ${minor}
    [[ "$*" =~ "--patch" ]]    && echo -en ${patch}
    [[ "$*" =~ "--release" ]]  && echo -en ${release}
fi
RaphaelRochet commented 1 year ago

You could add this to the wiki section, for others to find it ;)