You are not logged in.

#1 2026-05-21 15:39:25

LinuxLover471
Member
From: Asia, India
Registered: 2025-02-23
Posts: 178

A Script to: Check for package updates with pkgctl and bump version

Hi! I hope that you are doing well.

I maintain some packages myself and all of us maintainers know how tedious it is to check for the updates of each and every package by ourselves, so we just use pkgctl version check and pkgctl version upgrade.

Though I noticed that it's also TOO tedious to run the above listed separately on each package, and then handle the edge cases like somebody else ( example: a co-maintainer ) already having bumped the package.

So I decided to make a script that does the job for you.

#!/bin/bash

pkgpath=$HOME/repos/aur

auto_pull=false
auto_bump=false

for arg in "$@"; do
    case "$arg" in
    --pull)
        auto_pull=true
        ;;
    --bump)
        auto_bump=true
        ;;
    --yes)
        auto_pull=true
        auto_bump=true
        ;;
    *)
        echo "Unknown option: $arg"
        exit 1
        ;;
    esac
done

if ! pacman -Q devtools git nvchecker >/dev/null 2>&1; then
    sudo pacman -S --needed devtools git nvchecker
fi

all_pkgs=() # Hold all packages into this array.

for pkgdir in "$pkgpath"/*/; do
    # VCS packages don't require version checking.
    pkgname=$(basename "$pkgdir")
    [[ "$pkgname" == *-git ]] && continue

    all_pkgs+=("$pkgname")
done

tmp=$(mktemp) # Temporary file to hold pkgctl output.

cd "$pkgpath"
script -qe -c "pkgctl version check ${all_pkgs[*]}" "$tmp"

if [[ "$?" != 2 ]]; then
    echo
    echo "==> No packages require updating, exiting..."
    exit 0
fi

out_pkgs=() # Hold out-of-date packages.

for pkg in "${all_pkgs[@]}"; do
    # Use this weird command to grep the outdated packages from the pkgctl output.
    grep -Pq "\Q$pkg\E(?=\x1b.*: upgrade from version)" "$tmp" && out_pkgs+=("$pkg")
done

rm -f "$tmp" # Reclaim memory (Almost forgot this!)

for pkg in "${out_pkgs[@]}"; do
    echo
    echo "===>  $pkg  <==="

    if $auto_pull; then
        pull_choice="y"
    else
        echo "==> Do you want to check if the package has already been bumped?"
        read -rp "==> Choose yes if somebody else can also bump the package. [Y/n]:" pull_choice
        pull_choice="${pull_choice,,}"
    fi

    cd "${pkgpath}/${pkg}"

    if [[ -z $pull_choice || $pull_choice == "y" ]]; then
        echo "-> Running git pull <="
        git pull

        pkgctl version check
        case $? in
        # Go to the next iteration if package is upto date,
        # or .nvchecker.toml is missing.
        0 | 3) continue ;;
        esac
    fi

    if $auto_bump; then
        upg_choice="y"
    else
        read -rp "==> Do you want to upgrade (bump) the package? [Y/n]:" upg_choice
        upg_choice="${upg_choice,,}"
    fi

    if [[ -z $upg_choice || $upg_choice == "y" ]]; then
        pkgctl version upgrade
        makepkg --printsrcinfo >.SRCINFO
        echo "==> NOTE: Please manually remove the downloaded sources and push the update!"
        continue
    fi
    echo "==> Skipping updating the package."
done

It doesn't have a specific name, it's simply saved as 'check_package_updates.sh' on my system, and aliased via .bashrc to 'check_package_updates' so that I can run it from any directory.

Even though I have tried to make this fast and correct to the extent of my knowledge, If you feel that anything can be improved, please don't hesitate to reach me!

NOTE: Please do NOT bump the package before confirming there are no breaking changes or anything to be fixed in your PKGBUILD, thank you.

I hope that you find this little script of mine useful!
Have fun!

Last edited by LinuxLover471 (2026-06-22 09:50:42)


--- asyync1024

Offline

#2 2026-05-21 17:45:41

gromit
Administrator
From: Germany
Registered: 2024-02-10
Posts: 1,540
Website

Re: A Script to: Check for package updates with pkgctl and bump version

Did you already see pkgctl version check, pkgctl version upgrade and pkgctl version setup?

Offline

#3 2026-05-22 07:23:28

LinuxLover471
Member
From: Asia, India
Registered: 2025-02-23
Posts: 178

Re: A Script to: Check for package updates with pkgctl and bump version

@gromit
I didn't know that such tool existed! Holy cow. I have improved my original script which will now be using pkgctl version AND will have the ability to bump packages, and push via git, which isn't done by default.

EDIT: Removed pushing via git as it encourages not testing the package, and also we need to manually remove the sources downloaded while updating checksums.

EDIT 2: Added VCS package skipping, this allows for cleaner output, and also prevents unnecessary processing, improving script speed even more.

EDIT 3: Revamped the entire script, now it batches together the pkgctl invocations, and uses grep to extract the package names from the output, then asks for git pull etc on those in out_pkgs.

EDIT 4: Fixed memory leak (tmp file) and added arguments, --pull and --bump, which set pull and bump to yes by default, without human interaction, and --yes to enable both.

Thanks for the insight!

Last edited by LinuxLover471 (2026-06-21 16:47:17)


--- asyync1024

Offline

Board footer

Powered by FluxBB