Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
savely-krasovsky committed Apr 21, 2024
2 parents 15ea9e4 + b12e7df commit 99c71ad
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 11 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
on:
push:
branches:
- master
pull_request:
branches:
- master

name: "ShellCheck"
permissions: {}

jobs:
shellcheck:
name: ShellCheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@2.0.0
with:
additional_files: 'waybar-updates'
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# waybar-updates

[![ShellCheck](https://github.com/L11R/waybar-updates/actions/workflows/shellcheck.yml/badge.svg)](https://github.com/L11R/waybar-updates/actions/workflows/shellcheck.yml)

Tiny Waybar module to check Arch Linux updates from official repositories and AUR.

## Features
- Sends notifications about updates.
- Supports GNU gettext localization (contribute new po-files!)
- Checks updates from AUR using Aurweb RPC, so works independently.
- Can check for development packages upstream changes (see -d [options](#command-line-options))
- Shows updates in the tooltip.
- Supports two states: `pending-updates` and `updated` to use different icons or hide module.
- Uses infinite loop to supply Waybar JSON updates.
Expand All @@ -23,6 +26,7 @@ Tiny Waybar module to check Arch Linux updates from official repositories and AU
- curl
- jq
- libnotify
- git (if using --devel [option](#command-line-options))

## Usage

Expand Down Expand Up @@ -77,6 +81,7 @@ The following options are available:
- `-i, --interval`: Interval between checks (default: 6 seconds)
- `-c, --cycles`: Cycles between online checks (e.g. 6s * 600 cycles = 3600s = 1h between online checks) (default: 600 cycles)
- `-l, --packages-limit`: Maximum number of packages to be shown in notifications and tooltip (default: 10)
- `-d, --devel`: Also check for development packages upstream changes (default:disabled)


## Localization
Expand Down
5 changes: 5 additions & 0 deletions po/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Generator: Poedit 3.2.2\n"

msgid "%d devel-update available from AUR"
msgid_plural "%d devel-updates available from AUR"
msgstr[0] "%d mise à jour devel disponible via AUR"
msgstr[1] "%d mises à jour devel disponibles via AUR"

msgid "%d update available from AUR"
msgid_plural "%d updates available from AUR"
msgstr[0] "%d mise à jour disponible via AUR"
Expand Down
6 changes: 6 additions & 0 deletions po/ru.po
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ msgstr ""
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<12 || n%100>14) ? 1 : 2);\n"
"X-Generator: Poedit 3.2.2\n"

msgid "%d devel-update available from AUR"
msgid_plural "%d devel-updates available from AUR"
msgstr[0] "%d devel-обновление доступно из AUR"
msgstr[1] "%d devel-обновления доступно из AUR"
msgstr[2] "%d devel-обновлений доступно из AUR"

msgid "%d update available from AUR"
msgid_plural "%d updates available from AUR"
msgstr[0] "%d обновление доступно из AUR"
Expand Down
5 changes: 5 additions & 0 deletions po/tr_TR.po
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 3.3.1\n"

msgid "%d devel-update available from AUR"
msgid_plural "%d devel-updates available from AUR"
msgstr[0] "AUR'dan %d devel-güncellemesi mevcut"
msgstr[1] "AUR'dan %d devel-güncellemesi mevcut"

# In Turkish, the plural suffix is not used if the number of the mentioned entity is specified. That's why singular and plural translations are the same.
msgid "%d update available from AUR"
msgid_plural "%d updates available from AUR"
Expand Down
114 changes: 103 additions & 11 deletions waybar-updates
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ usage() {
echo "Usage: waybar-updates [options]
-i, --interval Interval between checks
-c, --cycles Cycles between online checks (e.g. 6s * 600 cycles = 3600s = 1h between online checks)
-l, --packages-limit Maximum number of packages to be shown in notifications and tooltip"
-l, --packages-limit Maximum number of packages to be shown in notifications and tooltip
-d, --devel Enable devel checks"
exit 2
}

interval=6
cycles_number=600
packages_limit=10
devel=false

PARSED_ARGUMENTS=$(getopt -o "hi:c:l:" --long "help,interval,cycles,packages-limit" --name "waybar-updates" -- "$@")
PARSED_ARGUMENTS=$(getopt -o "hi:c:l:d::" --long "help,interval,cycles,packages-limit,devel::" --name "waybar-updates" -- "$@")
eval set -- "$PARSED_ARGUMENTS"
while :; do
case "$1" in
Expand All @@ -28,6 +30,10 @@ while :; do
packages_limit="$2"
shift 2
;;
-d | --devel)
devel=true
shift 2
;;
-h | --help) usage ;;
--)
shift
Expand All @@ -51,6 +57,60 @@ function check_pacman_updates() {
pacman_updates_count=$(echo "$pacman_updates" | grep -vc ^$)
}

function check_devel_updates() {
ignored_packages=$(pacman-conf IgnorePkg)
if [ "$1" == "online" ]; then
develsuffixes="git"
develpackages=$(pacman -Qm | grep -Ee "$develsuffixes")
if [ -n "$ignored_packages" ]; then
develpackages=$(grep -vF "$ignored_packages" <<< "$develpackages")
fi
rm -f "$tmp_devel_packages_file"
tmp_devel_packages_file=$(mktemp --suffix -waybar-updates)
build_devel_list "$develpackages" "online"
elif [ "$1" == "offline" ]; then
new_devel_packages=$(pacman -Qm | grep -Ee "$develsuffixes")
old_devel_packages=$(awk '{printf ("%s %s\n", $1, $3)}' "$tmp_devel_packages_file")

develpackages=$(LC_ALL=C join <(echo "$old_devel_packages") <(echo "$new_devel_packages"))
echo "d:$develpackages"

if [[ $(echo "$develpackages" | grep -vc ^$) -ne 0 ]]; then
develpackages=$(awk '{printf ("%s %s %s\n", $1, $3, $2)}' <<< "$develpackages")
build_devel_list "$develpackages" "offline"
fi
fi
devel_updates=$(awk '{printf ("%s %s\n", $1, $2)}' "$tmp_devel_packages_file")
devel_updates_checksum=$(echo "$devel_updates" | sha256sum)
devel_updates_count=$(echo "$devel_updates" | grep -vc ^$)
}

function build_devel_list() {
custom_pkgbuild_vars="_gitname=\|_githubuser=\|_githubrepo=\|_gitcommit=\|url=\|_pkgname=\|_gitdir=\|_repo_name=\|_gitpkgname=\|source_dir=\|_name="

truncate -s 0 "$tmp_devel_packages_file"

i=0
while read -r pkgname version source
do
(( i++ ))
if [ -z "$source" ]; then
eval "$(curl -s "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=$pkgname" | grep "$custom_pkgbuild_vars")"
eval source="$(curl -s "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=$pkgname" | \
grep -zPo '(?s)source=\(.*?\)' | \
awk '/git/{print "source="$1}' | \
sed 's/source=//g' | sed '/http/p' | \
sed 's/(//;s/)//g' | tr -d '\0' | head -1)"
source=$(sed 's/^\(.*\)\(http.*$\)/\2/;s/\"//;s/'\''//' <<< "$source")
source=$(cut -f1 -d"#" <<< "$source")
fi
lastcommit=$(git ls-remote --heads "$source" | awk '{ print $1}' | cut -c1-7)
if ! echo "$version" | grep -q "$lastcommit"; then
echo "$pkgname $version $source ${lastcommit//$'\n'/ }" >> "$tmp_devel_packages_file"
fi
done <<< "$1"
}

function check_aur_updates() {
ignored_packages=$(pacman-conf IgnorePkg)
if [ -n "$ignored_packages" ]; then
Expand All @@ -69,8 +129,8 @@ function check_aur_updates() {
new_aur_packages=$(cat "$tmp_aur_packages_file")
fi

aur_updates=$(join <(echo "$old_aur_packages") <(echo "$new_aur_packages") |
while read -r pkg a b; do
aur_updates=$(LC_ALL=C join <(echo "$old_aur_packages") <(echo "$new_aur_packages") |
while LC_ALL=C read -r pkg a b; do
case "$(vercmp "$a" "$b")" in
-1) printf "%s %s -> %s\n" "$pkg" "$a" "$b" ;;
esac
Expand All @@ -84,12 +144,17 @@ function check_updates() {
if [ "$1" == "online" ]; then
check_pacman_updates online
check_aur_updates online
if [ $devel == true ];then check_devel_updates online; fi
elif [ "$1" == "offline" ]; then
check_pacman_updates offline
check_aur_updates offline
if [ $devel == true ];then check_devel_updates offline; fi
fi
if [ $devel == true ];then
total_updates_count=$((pacman_updates_count + aur_updates_count + devel_updates_count))
else
total_updates_count=$((pacman_updates_count + aur_updates_count))
fi
total_updates_count=$((pacman_updates_count + aur_updates_count))
}
function json() {
Expand All @@ -104,13 +169,15 @@ function json() {
function cleanup() {
echo "Cleaning up..."
rm -f "$tmp_aur_packages_file"
rm -f "$tmp_devel_packages_file"
exit 0
}
# sync at the first start
check_updates online
pacman_updates_checksum=""
aur_updates_checksum=""
devel_updates_checksum=""
# count cycles to check updates using network sometime
cycle=0
Expand All @@ -120,6 +187,7 @@ trap cleanup SIGINT SIGTERM
while true; do
previous_pacman_updates_checksum=$pacman_updates_checksum
previous_aur_updates_checksum=$aur_updates_checksum
if [ $devel == true ];then previous_devel_updates_checksum=$devel_updates_checksum; fi
if [ "$cycle" -ge "$cycles_number" ]; then
check_updates online
Expand All @@ -128,9 +196,19 @@ while true; do
check_updates offline
cycle=$((cycle + 1))
fi
if [ "$previous_pacman_updates_checksum" == "$pacman_updates_checksum" ] &&
[ "$previous_aur_updates_checksum" == "$aur_updates_checksum" ]; then
if [ $devel == true ];then
condition (){
{ [ "$previous_pacman_updates_checksum" == "$pacman_updates_checksum" ] &&
[ "$previous_aur_updates_checksum" == "$aur_updates_checksum" ] &&
[ "$previous_devel_updates_checksum" == "$devel_updates_checksum" ] ;}
}
else
condition (){
{ [ "$previous_pacman_updates_checksum" == "$pacman_updates_checksum" ] &&
[ "$previous_aur_updates_checksum" == "$aur_updates_checksum" ] ;}
}
fi
if condition; then
sleep "$interval"
continue
fi
Expand All @@ -141,7 +219,7 @@ while true; do
if [ "$pacman_updates_count" -gt 0 ]; then
template=$(ngettext "waybar-updates" "%d update available from pacman" "%d updates available from pacman" "$pacman_updates_count")
# shellcheck disable=SC2059
notify-send -u normal -i software-update-available-symbolic \
notify-send -a waybar-updates -u normal -i software-update-available-symbolic \
"$(printf "$template" "$pacman_updates_count")" \
"$(echo "$pacman_updates" | head -n "$packages_limit")"
Expand All @@ -150,7 +228,7 @@ while true; do
if [ "$aur_updates_count" -gt 0 ]; then
template=$(ngettext "waybar-updates" "%d update available from AUR" "%d updates available from AUR" "$aur_updates_count")
# shellcheck disable=SC2059
notify-send -u normal -i software-update-available-symbolic \
notify-send -a waybar-updates -u normal -i software-update-available-symbolic \
"$(printf "$template" "$aur_updates_count")" \
"$(echo "$aur_updates" | head -n "$packages_limit")"
Expand All @@ -160,7 +238,21 @@ while true; do
tooltip+="\n$aur_updates"
fi
fi
if [ $devel == true ];then
if [ "$devel_updates_count" -gt 0 ]; then
template=$(ngettext "waybar-updates" "%d devel-update available from AUR" "%d devel-updates available from AUR" "$devel_updates_count")
# shellcheck disable=SC2059
notify-send -a waybar-updates -u normal -i software-update-available-symbolic \
"$(printf "$template" "$devel_updates_count")" \
"$(echo "$devel_updates" | head -n "$packages_limit")"
if [ -z "$tooltip" ]; then
tooltip+="$devel_updates"
else
tooltip+="\n$devel_updates"
fi
fi
fi
if [ "$total_updates_count" -gt 0 ]; then
json $total_updates_count "pending-updates" "$(echo -e "$tooltip" | head -n "$packages_limit" | sed -e 's/\x1b\[[0-9;]*m//g')" "pending-updates"
else
Expand Down

0 comments on commit 99c71ad

Please sign in to comment.