Using checkupdates with a "custom" pacman.conf

Is it possible to make checkupdates “read” from a custom-made pacman.conf? I would like to make a conf file for the testing repo and pass it to checkupdates to see what updates are available in Testing.

I know of --config /path/to/file.conf for pacman. But I am not sure if i use pacman -Syu, would that “mess up” my local database.

I have looked at the code for /usr/bin/checkupdates but it is above my knowledge to make any changes there.

cat /usr/bin/checkupdates

!/usr/bin/bash

checkupdates: Safely print a list of pending updates.

Copyright © 2013 Kyle Keen keenerd@gmail.com

This program is free software; you can redistribute it and/or modify

it under the terms of the GNU General Public License as published by

the Free Software Foundation; either version 2 of the License, or

(at your option) any later version.

This program is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

GNU General Public License for more details.

You should have received a copy of the GNU General Public License

along with this program. If not, see http://www.gnu.org/licenses/.

declare -r myname=‘checkupdates’
declare -r myver=‘1.4.0’

LIBRARY=${LIBRARY:-’/usr/share/makepkg’}

DOWNLOAD_CACHE=0
USE_COLOR=0

Import libmakepkg

source “$LIBRARY”/util/message.sh
source “$LIBRARY”/util/parseopts.sh

usage() {
cat << EOF
${myname} v${myver}

Safely print a list of pending updates

Usage: ${myname} [options]

Options:
-d, --download download pending updates to the pacman cache.
-h, --help display this help message and exit.

Note: Export the “CHECKUPDATES_DB” variable to change the path of the temporary database.

EOF
}

OPT_SHORT=‘dh’
OPT_LONG=(‘download’ ‘help’ ‘nocolor’)

if ! parseopts “$OPT_SHORT” “${OPT_LONG[@]}” – “$@”; then
exit 1
fi
set – “${OPTRET[@]}”
unset OPT_SHORT OPT_LONG OPTRET

while :; do
case $1 in
-d|–download)
DOWNLOAD_CACHE=1 ;;
-h|–help)
usage
exit 0 ;;
–nocolor)
USE_COLOR=‘n’;;
–)
shift
break ;;
esac
shift
done

check if messages are to be printed using color

if [[ -t 2 && $USE_COLOR != “n” ]]; then
colorize
else
unset ALL_OFF BOLD BLUE GREEN RED YELLOW
fi

if ! type -P fakeroot >/dev/null; then
error ‘Cannot find the fakeroot binary.’
exit 1
fi

if [[ -z $CHECKUPDATES_DB ]]; then
CHECKUPDATES_DB="${TMPDIR:-/tmp}/checkup-db-${UID}/"
fi

trap ‘rm -f $CHECKUPDATES_DB/db.lck’ INT TERM EXIT

DBPath="$(pacman-conf DBPath)"
if [[ -z “$DBPath” ]] || [[ ! -d “$DBPath” ]]; then
DBPath="/var/lib/pacman/"
fi

mkdir -p “$CHECKUPDATES_DB”
ln -s “${DBPath}/local” “$CHECKUPDATES_DB” &> /dev/null
if ! fakeroot – pacman -Sy --dbpath “$CHECKUPDATES_DB” --logfile /dev/null &> /dev/null; then
error ‘Cannot fetch updates’
exit 1
fi
mapfile -t updates < <(pacman -Qu --dbpath “$CHECKUPDATES_DB” 2> /dev/null | grep -v ‘[.*]’)

if (( ${#updates[@]} )); then
printf ‘%s\n’ “${updates[@]}”
if (( DOWNLOAD_CACHE )); then
sudo pacman -Sw --noconfirm “${updates[@]%% *}” --dbpath “$CHECKUPDATES_DB” --logfile /dev/null
fi
else
exit 2
fi

vim: set noet:

[pebcak@eos-cinnamon ~]$ cat /usr/bin/checkupdates | grep pacman.conf
DBPath="$(pacman-conf DBPath)"

It doesn’t look like it from what you included there.

You could do something like this in a script:

sudo cp /etc/pacman.conf /etc/pacman-save.conf
sudo cp /etc/pacman-testing.conf /etc/pacman.conf
checkupdates
sudo mv /etc/pacman-save.conf /etc/pacman.conf
3 Likes

Made the script check-testing in ~/.local/share/bin with your suggested command lines. Made it executable and ran it in a terminal. Worked perfectly!

Thank you so much!

3 Likes

Another approach would be to copy the script (which you’ve done), then change one line:

diff --git a/checkupdates b/checkupdates
index a454b5e..10741e7 100755
--- a/checkupdates
+++ b/checkupdates
@@ -99,7 +99,7 @@ fi
 
 mkdir -p "$CHECKUPDATES_DB"
 ln -s "${DBPath}/local" "$CHECKUPDATES_DB" &> /dev/null
-if ! fakeroot -- pacman -Sy --dbpath "$CHECKUPDATES_DB" --logfile /dev/null &> /dev/null; then
+if ! fakeroot -- pacman -Sy --dbpath "$CHECKUPDATES_DB" --logfile /dev/null --config /path/to/pacman.conf &> /dev/null; then
        error 'Cannot fetch updates'
        exit 1
 fi

No sudo required. :wink:

2 Likes

Thanks @jonathon!

I’ll see if I can make it work. I’ll get back to you with the report or (more questions) a bit later on.

@jonathon
Something weird is going on or I have missed something or both :slightly_smiling_face:

I copied /usr/bin/checkupdates to a file called check-test-repos in ~/.local/share/bin and changed that one line according to your suggestion and pointed the pacman -Sy to /etc/pacman-testing.conf (the same conf file used before making check-testing according to dalto’s suggestion).

Now when I run check-test-repos I get no packages to be upgradable from Testing while with the previous script, I get (the system is fully updated in sync with the stable):

automake 1.16.2-3 -> 1.16.3-1
chromium 87.0.4280.88-1 -> 87.0.4280.88-2
firefox 83.0-2 -> 84.0-1
geeqie 1.6-1 -> 1.6-2
gnupg 2.2.24-1 -> 2.2.25-1
groff 1.22.4-3 -> 1.22.4-4
iwd 1.9-1 -> 1.10-1
libcap 2.45-2 -> 2.46-1
libnm 1.26.4-1 -> 1.28.0-2
libusb 1.0.23-3 -> 1.0.24-1
libx11 1.7.0-1 -> 1.7.0-2
networkmanager 1.26.4-1 -> 1.28.0-2
pcre2 10.35-1 -> 10.36-1
python 3.9.0-1 -> 3.9.1-1
python-packaging 20.7-1 -> 20.8-1
python-setuptools 1:50.3.2-4 -> 1:51.0.0-1
qt5-webengine 5.15.2-1 -> 5.15.2-2
re2 1:20201001-1 -> 1:20201101-1
systemd 247.1-3 -> 247.1-4
systemd-libs 247.1-3 -> 247.1-4
systemd-sysvcompat 247.1-3 -> 247.1-4
xorg-server 1.20.10-2 -> 1.20.10-3
xorg-server-common 1.20.10-2 -> 1.20.10-3
here is check-test-repos based on cheupdates

#!/usr/bin/bash

checkupdates: Safely print a list of pending updates.

Copyright © 2013 Kyle Keen keenerd@gmail.com

This program is free software; you can redistribute it and/or modify

it under the terms of the GNU General Public License as published by

the Free Software Foundation; either version 2 of the License, or

(at your option) any later version.

This program is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

GNU General Public License for more details.

You should have received a copy of the GNU General Public License

along with this program. If not, see http://www.gnu.org/licenses/.

declare -r myname=‘checkupdates’
declare -r myver=‘1.4.0’

LIBRARY=${LIBRARY:-’/usr/share/makepkg’}

DOWNLOAD_CACHE=0
USE_COLOR=0

Import libmakepkg

source “$LIBRARY”/util/message.sh
source “$LIBRARY”/util/parseopts.sh

usage() {
cat << EOF
${myname} v${myver}

Safely print a list of pending updates

Usage: ${myname} [options]

Options:
-d, --download download pending updates to the pacman cache.
-h, --help display this help message and exit.

Note: Export the “CHECKUPDATES_DB” variable to change the path of the temporary database.

EOF
}

OPT_SHORT=‘dh’
OPT_LONG=(‘download’ ‘help’ ‘nocolor’)

if ! parseopts “$OPT_SHORT” “${OPT_LONG[@]}” – “$@”; then
exit 1
fi
set – “${OPTRET[@]}”
unset OPT_SHORT OPT_LONG OPTRET

while :; do
case $1 in
-d|–download)
DOWNLOAD_CACHE=1 ;;
-h|–help)
usage
exit 0 ;;
–nocolor)
USE_COLOR=‘n’;;
–)
shift
break ;;
esac
shift
done

check if messages are to be printed using color

if [[ -t 2 && $USE_COLOR != “n” ]]; then
colorize
else
unset ALL_OFF BOLD BLUE GREEN RED YELLOW
fi

if ! type -P fakeroot >/dev/null; then
error ‘Cannot find the fakeroot binary.’
exit 1
fi

if [[ -z $CHECKUPDATES_DB ]]; then
CHECKUPDATES_DB="${TMPDIR:-/tmp}/checkup-db-${UID}/"
fi

trap ‘rm -f $CHECKUPDATES_DB/db.lck’ INT TERM EXIT

DBPath="$(pacman-conf DBPath)"
if [[ -z “$DBPath” ]] || [[ ! -d “$DBPath” ]]; then
DBPath="/var/lib/pacman/"
fi

mkdir -p “$CHECKUPDATES_DB”
ln -s “${DBPath}/local” “$CHECKUPDATES_DB” &> /dev/null
#if ! fakeroot – pacman -Sy --dbpath “$CHECKUPDATES_DB” --logfile /dev/null &> /dev/null; then
if ! fakeroot – pacman -Sy --dbpath “$CHECKUPDATES_DB” --logfile /dev/null --config /etc/pacman-testing.conf &> /dev/null; then
error ‘Cannot fetch updates’
exit 1

fi
mapfile -t updates < <(pacman -Qu --dbpath “$CHECKUPDATES_DB” 2> /dev/null | grep -v ‘[.*]’)

if (( ${#updates[@]} )); then
printf ‘%s\n’ “${updates[@]}”
if (( DOWNLOAD_CACHE )); then
sudo pacman -Sw --noconfirm “${updates[@]%% *}” --dbpath “$CHECKUPDATES_DB” --logfile /dev/null
fi
else
exit 2
fi

vim: set noet:

Not sure but it seems it ignores the --config /etc/pacman-testing.conf part.

It is possible you also need to change this line if it is reading the config:

mapfile -t updates < <(pacman -Qu --dbpath “$CHECKUPDATES_DB” 2> /dev/null | grep -v ‘[.*]’)
2 Likes

The solution to this topic goes to @dalto and @jonathon for their joint efforts. Thank you guys!
:purple_heart:

Great! Changed the line to

mapfile -t updates < <(pacman -Qu --config /etc/pacman-testing.conf --dbpath “$CHECKUPDATES_DB” 2> /dev/null | grep -v ‘[.*]’)

and it’s working! Awesome!

Thank you so much!

2 Likes