Skip to content

Commit

Permalink
[eos-update-notifier] changed the options of eos-arch-news, now no op…
Browse files Browse the repository at this point in the history
…tions means 'show news', and option --save means check date first
  • Loading branch information
EndeavourOS committed Aug 12, 2023
1 parent 56dd00b commit 730b109
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
6 changes: 3 additions & 3 deletions eos-update-notifier/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pkgname=eos-update-notifier
pkgdesc="Software update notifier and 'news for you' for EndeavourOS users."
pkgver=23
pkgrel=9
pkgrel=10
arch=('any')
license=('GPL')
depends=(eos-bash-shared pacman-contrib xdg-utils libnotify)
Expand Down Expand Up @@ -34,13 +34,13 @@ source=(
$_url/$pkgname.service
$_url/checkupdatesext
)
sha512sums=('dff3dbefdfbde11297084ca2615f4a40da59206df6a10a83702c16175afd5297e6ff94bc7f8158937affe898781aa1c9b8497b7b615e9c0271318a92a3eb0f17'
sha512sums=('eabffcc15f562ae6a4a1a7956c341815184bb1c49ca7451119268204a60559e0ad810a6a6e401e2f5a7acff5335685b8a5bccf41dc65e1c5f38d8347755d387a'
'566f6cb295d3bc0af6ee85e33dde9df1a0cde9a043f501c99571db13b26394406a6d8017c7564a3e38ff5365f6dfe1e095b7c1f50674e85b2d9c8ef1a5c822b2'
'd046e675f98a52b9c310e970c5a0b0bc92b08b60d55b9d39140516977e8a6ceb4b3f9d9b05d12fce377b5744f4563e5e66a86ceecafb57f5bd486f968dc57234'
'bc90ed908f1ce44a77a621fed0e095bec32109b563e5d6e80ded2757ee092f905a392ad6c314aa55d75e7800abb4188b69d20784e8b5f65c8af19ffb160fd026'
'd5d4d92a9fd0d7a4425bb7000d208d717846ff30c2c31abac94c88840d3e8edc4862a6aacbb576330ff9d7644e63cf90e509caad629d9ed516f378e62b26e168'
'4c0debbea2fdbfbd86725494bdd5433adb1d3c586168e3cb24b9823501ccc25cdc594854963fb248b5c43a7449a2d348b067791adcea395879a47f3d5ff557f5'
'd6ad967f2da2e056526bf6e73a1bd2573ca119dbecc30bac41e0eb215df83f0c3aaff3c8f3712752bda6f9aac5d82c5665f9956bca3e9ec326ff0554b208027e'
'c33d879c3a0dd3309e633b15f6bde41543317131a2ab15b077f97f7532e88e2afb426ebd299e5d3309b6677e4fdea93b2452548c9904f219d5a5d43e87586157'
'a1e17d8f2f1579b000dacdc7a37be698c29528365d9e94d636ceffb3eb8346e16b4ff8ca04ce8ea35d9fff346fe548449d3609f3d448219eb5d89b2c3a5ac571'
'daa4868b0e2a554990b4091cade1e99f92cf1b450afa5bbe49183e622d53a3994f2227d5d8cf852e22a8c5781c7780433fbf529556131a8b48effe51b9e7e7e1'
'566f6cb295d3bc0af6ee85e33dde9df1a0cde9a043f501c99571db13b26394406a6d8017c7564a3e38ff5365f6dfe1e095b7c1f50674e85b2d9c8ef1a5c822b2'
Expand Down
55 changes: 33 additions & 22 deletions eos-update-notifier/eos-arch-news
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/bin/bash
#
# Shows all Arch news in a browser.
# To show only "unseen" news, saves the date of the latest news flash you've seen
# Shows Arch news in a browser.
#
# To avoid showing the news page every time (and to show only "unseen" news),
# saves the date of the latest news flash you've seen
# and shows the news page only if there's more after that.
# This happens with option --save.

DIE() {
echo "$progname: error: $1" >&2
Expand All @@ -14,43 +17,51 @@ Usage() {
Usage: $progname [options]
Options:
-h | --help This help.
-u | --unread "Unread" all Arch news.
-s | --save Show news only if there are newer than you've already seen.
-u | --unread "Unread" all Arch news, i.e. news reading starts fresh.
EOF
}

ShowNews() { setsid "$browser" "$news_url" &> /dev/null ; }

Main() {
local -r progname="${0##*/}"
local -r latestfile="$HOME/.config/EOS-arch-news.conf"
local -r file_for_latest_news_read_date="$HOME/.config/EOS-arch-news.conf" # stores the date of the latest news "seen"
local -r news_url=https://archlinux.org/news
local -r bashlib=/usr/share/endeavouros/scripts/eos-script-lib-yad
source $bashlib || DIE "failed to read file '$bashlib'."
local -r browser=$(eos_select_browser) # find the default browser
local show_always=yes

[ -n "$browser" ] || DIE "browser not found!"

while [ -n "$1" ] ; do
case "$1" in
--help | -h)
Usage; return ;;
--unread | -u)
rm -f "$latestfile"; return ;;
-h | --help) Usage; return ;;
-s | --save) show_always=no ;;
-u | --unread) rm -f "$file_for_latest_news_read_date"; return ;;
esac
shift
done
if [ $show_always = yes ] ; then
ShowNews
return
fi

local -r latest_seen="$(cat "$latestfile" 2>/dev/null)" # get the date of the latest visited news
local -r url=https://archlinux.org/news
local -r data=$(curl -Lsm 20 $url)

[ -n "$data" ] || DIE "sorry, cannot fetch Arch news. Please try again later."
local -r latest_read_date="$(cat "$file_for_latest_news_read_date" 2>/dev/null)" # the date of the latest visited news
local -r news_data=$(curl -Lsm 20 $news_url) # Reads the first page only, currently (Aug-2023)
# less than 30 000 bytes.

local -r bashlib=/usr/share/endeavouros/scripts/eos-script-lib-yad
source $bashlib || DIE "failed to read file '$bashlib'."
[ -n "$news_data" ] || DIE "sorry, cannot fetch Arch news. Please try again later."

local dates=()
readarray -t dates <<< $(echo "$data" | grep '^[ \t]*<td>[0-9-]*</td>$' | sed 's|^[ \t]*<td>\([0-9-]*\)</td>$|\1|')
readarray -t dates <<< $(echo "$news_data" | grep '^[ \t]*<td>[0-9-]*</td>$' | sed 's|^[ \t]*<td>\([0-9-]*\)</td>$|\1|')

local -r latest=${dates[0]}
local -r latest_news_dates=${dates[0]}

if [[ "$latest" > "$latest_seen" ]] ; then
local browser=$(eos_select_browser) # find the default browser
[ -n "$browser" ] || DIE "browser not found!"
echo "$latest" > "$latestfile" # save the date of the latest news
setsid "$browser" $url &> /dev/null
if [[ "$latest_news_dates" > "$latest_read_date" ]] ; then
echo "$latest_news_dates" > "$file_for_latest_news_read_date" # save the date of the latest news
ShowNews
fi
}

Expand Down
2 changes: 1 addition & 1 deletion eos-update-notifier/eos-update-notifier
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ CheckArchNews() {
case "$ArchNewsProg" in
eos-arch-news)
# eos-arch-news does not (yet) use $newsdays ...
tmpdays=""
tmpdays="--save"
;;
arch-news-for-you)
if [ "$newsdays" -gt 0 ] ; then
Expand Down

0 comments on commit 730b109

Please sign in to comment.