Skip to content

Instantly share code, notes, and snippets.

@thingsiplay
Last active March 17, 2024 18:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thingsiplay/c67d200dffc0bdb5c143fade10727c9a to your computer and use it in GitHub Desktop.
Save thingsiplay/c67d200dffc0bdb5c143fade10727c9a to your computer and use it in GitHub Desktop.
Check Updates List for Archlinux using checkupdates
#!/bin/env bash
# Check Updates List
# Report and notify only when specific packages needs an update on Archlinux.
#
# Usage:
# checkupdateslist [package]...
#
# Example:
# $ checkupdateslist
# $ checkupdateslist yt-dlp retroarch
# $ checkupdateslist "*pipewire*"
#
# Required programs:
# checkupdates notify-send grep awk wc tr
#
# On Arch:
# - checkupdates from package extra/pacman-contrib
# - notify-send from package extra/libnotify
# An optional configuration file in form of `key=value` format.
# Note that value should NOT be enclosed by quotes, as the config
# file is not a script. Supported options are basically the below
# variables.
#
# Example:
# packages = linux firefox
# expire_ms = 15000
#
config_file="${HOME}/.config/checkupdateslist.cfg"
# Default list of packages to check. The package names should match exactly.
# Multiple packages are separated by space. Any given arguments to the script
# will overwrite the default.
packages='linux linux-lts linux-zen'
# Time in millesconds until notify message disappears.
# "" = (empty) do not display notification
# 0 = does not disappear automatically
# 15000 = 15 seconds
# expire_ms=""
expire_ms="0"
# Parse and load configuration file from key=value pairs.
# Whitespace surrounding key name and its value are removed.
if [ -f "${config_file}" ]; then
while IFS='=' read -r key value; do
key="$(echo "${key}" | awk '{$1=$1};1')"
case "${key}" in
"packages" | "expire_ms")
value="$(echo "${value}" | awk '{$1=$1};1')"
declare "${key}=${value}"
;;
*) ;;
esac
done <"${config_file}"
fi
if [[ "${#}" -gt 0 ]]; then
packages="${*}"
fi
if [[ "${packages}" =~ [^a-zA-Z0-9*\ \-] ]]; then
echo 'Only a-z, A-Z, 0-9, space, dash and star as a wildcard characters' \
'allowed for list of package names.'
exit 3
fi
if [[ "${expire_ms}" =~ [^0-9] ]]; then
echo 'Only digits are allowed for expiration time.'
exit 3
fi
# Prepare list as an extended regex for grep.
packages="${packages// /|}"
packages="${packages//\*/.*}"
# To test output, replace below `checkupdates` with `yay -Q` temporarily.
updateslist="$(checkupdates |
awk '{print $1}' |
grep -E "^(${packages})$")"
count="$(echo -n "${updateslist}" | wc -w)"
if [[ "${count}" -gt 0 ]]; then
if [ "${expire_ms}" != "" ]; then
title="${0##*/}"
notify-send -a "${title}" \
-t "${expire_ms}" \
"${count} important update(s) available:" "${updateslist}" || exit 5
fi
echo "${updateslist}"
fi
exit 0
packages = linux firefox
expire_ms = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment