Commit bbf488e9 authored by Sam B's avatar Sam B
Browse files

checkupdates: Provide --nosync option



Adds an option to not attempt to sync the CHECKUPDATES_DB. This provides
a way to very quickly get a list of outdated packages provided there is
a different mechanism to update CHECKUPDATES_DB already in place such as
a crontab entry or systemd.timer.

Signed-off-by: Sam B's avatarSamir Benmendil <me@rmz.io>
parent 871ffc94
......@@ -26,6 +26,10 @@ Options
*-d, \--download*::
Download any pending updates to the pacman cache.
*-n, \--nosync*::
Do not sync the temporary database, works best when the temporary database is
update regularly through some other means such as a cronjob or systemd timer.
*-h, \--help*::
Display syntax and command line options.
......
......@@ -58,6 +58,7 @@ Usage: ${myname} [options]
Options:
-d, --download download pending updates to the pacman cache.
-n, --nosync do not sync the temporary database.
-h, --help display this help message and exit.
Note: Export the "CHECKUPDATES_DB" variable to change the path of the temporary database.
......@@ -65,8 +66,8 @@ Note: Export the "CHECKUPDATES_DB" variable to change the path of the temporary
__EOF__
}
OPT_SHORT='dh'
OPT_LONG=('download' 'help' 'nocolor')
OPT_SHORT='dnh'
OPT_LONG=('download' 'help' 'nocolor' 'norefresh')
if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
exit 1
......@@ -74,10 +75,13 @@ fi
set -- "${OPTRET[@]}"
unset OPT_SHORT OPT_LONG OPTRET
SYNC=1
while :; do
case $1 in
-d|--download)
DOWNLOAD_CACHE=1 ;;
-n|--nosync)
SYNC=0 ;;
-h|--help)
usage
exit 0 ;;
......@@ -112,10 +116,12 @@ if [[ -z "$DBPath" ]] || [[ ! -d "$DBPath" ]]; then
DBPath="@localstatedir@/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
die 'Cannot fetch updates'
if (( ${SYNC} )); then
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
die 'Cannot fetch updates'
fi
fi
mapfile -t updates < <(pacman -Qu --dbpath "$CHECKUPDATES_DB" 2> /dev/null | grep -v '\[.*\]')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment