From bace810ae2ce4f9e0251d29f5ddca16772d2e0c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Launay?= Date: Wed, 27 Dec 2023 01:34:50 +0100 Subject: [PATCH 01/10] Remove debug echo and redirect git errors to null --- waybar-updates | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/waybar-updates b/waybar-updates index 72add60..2cff345 100755 --- a/waybar-updates +++ b/waybar-updates @@ -73,7 +73,6 @@ function check_devel_updates() { 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") @@ -104,7 +103,7 @@ function build_devel_list() { 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) + lastcommit=$(git ls-remote --heads "$source" 2>/dev/null | awk '{ print $1}' | cut -c1-7) if ! echo "$version" | grep -q "$lastcommit"; then echo "$pkgname $version $source ${lastcommit//$'\n'/ }" >> "$tmp_devel_packages_file" fi From 90fa33a88ef72ee36bdba40b91946d57be7c1da6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Launay?= Date: Wed, 27 Dec 2023 03:30:54 +0100 Subject: [PATCH 02/10] Add check news from archlinux.org --- waybar-updates | 73 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/waybar-updates b/waybar-updates index 2cff345..dfb04d4 100755 --- a/waybar-updates +++ b/waybar-updates @@ -5,7 +5,8 @@ usage() { -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 - -d, --devel Enable devel checks" + -d, --devel Enable check for development packages update + -n, --news Print new news from the Arch Linux homepage. News is considered new if it is newer than the build date of all native packages" exit 2 } @@ -13,8 +14,9 @@ interval=6 cycles_number=600 packages_limit=10 devel=false +news=false -PARSED_ARGUMENTS=$(getopt -o "hi:c:l:d::" --long "help,interval,cycles,packages-limit,devel::" --name "waybar-updates" -- "$@") +PARSED_ARGUMENTS=$(getopt -o "hi:c:l:d::n::" --long "help,interval,cycles,packages-limit,devel::,news::" --name "waybar-updates" -- "$@") eval set -- "$PARSED_ARGUMENTS" while :; do case "$1" in @@ -34,6 +36,10 @@ while :; do devel=true shift 2 ;; + -n | --news) + news=true + shift 2 + ;; -h | --help) usage ;; --) shift @@ -139,6 +145,68 @@ function check_aur_updates() { aur_updates_count=$(echo "$aur_updates" | grep -vc ^$) } +function check_news() { + date_format=+$(locale -k LC_TIME | grep ^d_fmt | cut -d= -f2) + + aur=$(pacman -Qqm) + native=$(pacman -Qneq) + + last_native_app_build_date=$(paclog --grep="upgraded " | grep -Ev "${aur//$'\n'/'|'}" | grep -wE "${native//$'\n'/'|'}" | tail -1 | awk '{print $1}') + last_native_app_build_date="2023-11-01T21:25:21+0100" # DEBUG pour avoir les deux derniers affichés + + last_native_app_build_date=$(date --date "${last_native_app_build_date}" +%s) + + feed=$(curl -s https://archlinux.org/feeds/news/) + + read_feed() { + local IFS='>' + read -rd '<' TAG VALUE + } + + rem_html() { + echo "$1" | sed -e 's/<//g' \ + -e 's/<[^>]*>//g' \ + -e 's/&gt;/>/g;/&lt;/g' \ + -e 's/>/>/g;s/</ Date: Wed, 27 Dec 2023 03:35:32 +0100 Subject: [PATCH 03/10] Add initial start for check_news --- waybar-updates | 1 + 1 file changed, 1 insertion(+) diff --git a/waybar-updates b/waybar-updates index dfb04d4..64dd549 100755 --- a/waybar-updates +++ b/waybar-updates @@ -242,6 +242,7 @@ function cleanup() { # sync at the first start check_updates online +if [ $news == true ];then check_news; fi pacman_updates_checksum="" aur_updates_checksum="" devel_updates_checksum="" From 99f451273e3fd77639b9f940d814e16cb427f60c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Launay?= Date: Wed, 27 Dec 2023 03:45:22 +0100 Subject: [PATCH 04/10] Change notification icon and comment testing date --- waybar-updates | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/waybar-updates b/waybar-updates index 64dd549..f44d6a1 100755 --- a/waybar-updates +++ b/waybar-updates @@ -152,7 +152,7 @@ function check_news() { native=$(pacman -Qneq) last_native_app_build_date=$(paclog --grep="upgraded " | grep -Ev "${aur//$'\n'/'|'}" | grep -wE "${native//$'\n'/'|'}" | tail -1 | awk '{print $1}') - last_native_app_build_date="2023-11-01T21:25:21+0100" # DEBUG pour avoir les deux derniers affichés + # last_native_app_build_date="2023-11-01T21:25:21+0100" # Uncomment to try last_native_app_build_date=$(date --date "${last_native_app_build_date}" +%s) @@ -194,7 +194,7 @@ function check_news() { ;; '/item') if [ "$pubDate_s" -ge "$last_native_app_build_date" ]; then - command=$(notify-send -a waybar-updates -u normal -i software-update-available-symbolic \ + command=$(notify-send -a waybar-updates -u normal -i notification-new-symbolic \ --action "readmore=Read online" \ "$(printf '%s: %s' "${pubDate:1:-1}" "$title")" \ "$description") From 5a81d6c234dfb8af01c80a72dd2d456f413f4d13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Launay?= Date: Wed, 27 Dec 2023 17:57:02 +0100 Subject: [PATCH 05/10] Remove brackets for date convert --- waybar-updates | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/waybar-updates b/waybar-updates index f44d6a1..b5ced54 100755 --- a/waybar-updates +++ b/waybar-updates @@ -154,7 +154,7 @@ function check_news() { last_native_app_build_date=$(paclog --grep="upgraded " | grep -Ev "${aur//$'\n'/'|'}" | grep -wE "${native//$'\n'/'|'}" | tail -1 | awk '{print $1}') # last_native_app_build_date="2023-11-01T21:25:21+0100" # Uncomment to try - last_native_app_build_date=$(date --date "${last_native_app_build_date}" +%s) + last_native_app_build_date=$(date --date "${last_native_app_build_date:1:-1}" +%s) feed=$(curl -s https://archlinux.org/feeds/news/) From be1f07ca80d55455ce8f5b091485348a3422c1da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Launay?= Date: Fri, 29 Dec 2023 20:42:06 +0100 Subject: [PATCH 06/10] Update README with -n news option --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ca38449..a3907bf 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,8 @@ Tiny Waybar module to check Arch Linux updates from official repositories and AU - 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)) +- Can check for development packages upstream changes (see -d [option](#command-line-options)) +- Can print new news from the Arch Linux homepage (see -n [option](#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. @@ -81,7 +82,11 @@ 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) +- `-d, --devel`: Also check for development packages upstream changes (default: disabled) +- `-n, --news` [(opt) all] (default: disabled) + - Print new news from the Arch Linux homepage. + - News is considered new if it is newer than the build date of all native packages. + - Run with --news all to print all news regardless of the publication date. ## Localization From ad4cef3438954f061efc0567ab685720d1e08293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Launay?= Date: Fri, 29 Dec 2023 20:43:15 +0100 Subject: [PATCH 07/10] Update usage() --- waybar-updates | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/waybar-updates b/waybar-updates index b5ced54..144bf2e 100755 --- a/waybar-updates +++ b/waybar-updates @@ -2,11 +2,13 @@ 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 - -d, --devel Enable check for development packages update - -n, --news Print new news from the Arch Linux homepage. News is considered new if it is newer than the build date of all native packages" + -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 + -d, --devel Enable check for development packages update + -n, --news [(opt) all] Print new news from the Arch Linux homepage. + News is considered new if it is newer than the build date of all native packages. + Run with --news all to print all news regardless of the publication date." exit 2 } From 629dd3e8d78709f68983ced1142389dec3c12810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Launay?= Date: Fri, 29 Dec 2023 20:43:46 +0100 Subject: [PATCH 08/10] Add --news all to print older news --- waybar-updates | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/waybar-updates b/waybar-updates index 144bf2e..fc55eb6 100755 --- a/waybar-updates +++ b/waybar-updates @@ -17,6 +17,7 @@ cycles_number=600 packages_limit=10 devel=false news=false +allnews=false PARSED_ARGUMENTS=$(getopt -o "hi:c:l:d::n::" --long "help,interval,cycles,packages-limit,devel::,news::" --name "waybar-updates" -- "$@") eval set -- "$PARSED_ARGUMENTS" @@ -41,6 +42,9 @@ while :; do -n | --news) news=true shift 2 + if [ "$2" == "all" ]; then + allnews=true + fi ;; -h | --help) usage ;; --) @@ -195,7 +199,7 @@ function check_news() { description=$(rem_html "$VALUE") ;; '/item') - if [ "$pubDate_s" -ge "$last_native_app_build_date" ]; then + if { [ "$pubDate_s" -ge "$last_native_app_build_date" ] || [ $allnews == true ] ;}; then command=$(notify-send -a waybar-updates -u normal -i notification-new-symbolic \ --action "readmore=Read online" \ "$(printf '%s: %s' "${pubDate:1:-1}" "$title")" \ From 15eafd693ac544c08cbf99690ab631c9d804adda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Launay?= Date: Sun, 7 Jan 2024 14:19:35 +0100 Subject: [PATCH 09/10] Download the PKGBUILD once only --- waybar-updates | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/waybar-updates b/waybar-updates index fc55eb6..3419eff 100755 --- a/waybar-updates +++ b/waybar-updates @@ -106,9 +106,9 @@ function build_devel_list() { 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=\(.*?\)' | \ + PKGBUILD=$(curl -s "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=$pkgname") + eval "$(grep "$custom_pkgbuild_vars" <<< "$PKGBUILD")" + eval source="$(grep -zPo '(?s)source=\(.*?\)' <<< "$PKGBUILD" | \ awk '/git/{print "source="$1}' | \ sed 's/source=//g' | sed '/http/p' | \ sed 's/(//;s/)//g' | tr -d '\0' | head -1)" @@ -134,7 +134,7 @@ function check_aur_updates() { rm -f "$tmp_aur_packages_file" tmp_aur_packages_file=$(mktemp --suffix -waybar-updates) # shellcheck disable=SC2046 - new_aur_packages=$(curl -s "https://aur.archlinux.org/rpc?v=5&type=info$(printf '&arg[]=%s' $(echo "$old_aur_packages" | cut -f1 -d' '))" | + new_aur_packages=$(curl -s "https://aur.archlinux.org/rpc?v=5&type=info$(printf '&arg[]=%s' $(echo "$old_aur_packages" 2>/dev/null | cut -f1 -d' '))" | jq -r '.results[] | .Name + " " + .Version' | tee "$tmp_aur_packages_file") elif [ "$1" == "offline" ]; then new_aur_packages=$(cat "$tmp_aur_packages_file") @@ -162,7 +162,7 @@ function check_news() { last_native_app_build_date=$(date --date "${last_native_app_build_date:1:-1}" +%s) - feed=$(curl -s https://archlinux.org/feeds/news/) + feed=$(curl -s https://archlinux.org/feeds/news/ 2>/dev/null) read_feed() { local IFS='>' From 927b47feb12e1728b16b6f3e8a7599df18582c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Launay?= Date: Wed, 17 Jan 2024 13:25:57 +0100 Subject: [PATCH 10/10] redirect error to /dev/null --- waybar-updates | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/waybar-updates b/waybar-updates index 3419eff..60542e2 100755 --- a/waybar-updates +++ b/waybar-updates @@ -107,11 +107,11 @@ function build_devel_list() { (( i++ )) if [ -z "$source" ]; then PKGBUILD=$(curl -s "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=$pkgname") - eval "$(grep "$custom_pkgbuild_vars" <<< "$PKGBUILD")" + eval "$(grep "$custom_pkgbuild_vars" <<< "$PKGBUILD")" 2>/dev/null eval source="$(grep -zPo '(?s)source=\(.*?\)' <<< "$PKGBUILD" | \ awk '/git/{print "source="$1}' | \ sed 's/source=//g' | sed '/http/p' | \ - sed 's/(//;s/)//g' | tr -d '\0' | head -1)" + sed 's/(//;s/)//g' | tr -d '\0' | head -1) 2>/dev/null" source=$(sed 's/^\(.*\)\(http.*$\)/\2/;s/\"//;s/'\''//' <<< "$source") source=$(cut -f1 -d"#" <<< "$source") fi