From 4d1b8213e3098b0837c71ac1ac921bc751e9ab6f Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 19 Jul 2022 13:27:23 -0500 Subject: Improve logging --- runsfeed | 74 +++++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 27 deletions(-) (limited to 'runsfeed') diff --git a/runsfeed b/runsfeed index 3fc6ee6..0db2bac 100755 --- a/runsfeed +++ b/runsfeed @@ -21,35 +21,41 @@ main() { export sfeedpath="$SFEED_DATA/feeds" test -d "$(dirname "$sfeedrc")" || mkdir -p "$(dirname "$sfeedrc")" test -d "$sfeedpath" || mkdir -p "$sfeedpath" + touch /tmp/runsfeed.ok if ! $NOFETCH; then - log Finding Invidious host... - get_invidious_url "https://api.invidious.io/instances.json?sort_by=health" + logok "Finding Invidious host" \ + get_invidious_url "https://api.invidious.io/instances.json?sort_by=health" fi - log Removing unsubscribed feeds... - remove_unsubs "$sfeedrc" - log Updating feeds... - update "$sfeedrc" - log Updating urls... - update_urls "$sfeedrc" - log Generating HTML... - html "$sfeedpath"/* >/tmp/sfeed-index.html && - mv /tmp/sfeed-index.html "$SFEED_OUTPUT/index.html" - log - LIMIT=0 html "$sfeedpath"/* >/tmp/sfeed-feeds.html && - mv /tmp/sfeed-feeds.html "$SFEED_OUTPUT/feeds.html" - log - log Generating RSS... - atom "$sfeedpath" >/tmp/feeds.xml && - mv /tmp/feeds.xml "$SFEED_OUTPUT/feeds.xml" - atom "$sfeedpath" 7 >/tmp/feeds-short.xml && - mv /tmp/feeds-short.xml "$SFEED_OUTPUT/feeds-short.xml" - log Generating OPML... - opml "$sfeedrc" >/tmp/feeds.opml && - mv /tmp/feeds.opml "$SFEED_OUTPUT/feeds.opml" - # log Archiving old feeds... + logok "Removing unsubscribed feeds" \ + remove_unsubs "$sfeedrc" + logok -n "Updating feeds" \ + update "$sfeedrc" + logok "Updating urls" \ + update_urls "$sfeedrc" + logok "Generating HTML" '{ + html "$sfeedpath"/* >/tmp/sfeed-index.html && + mv /tmp/sfeed-index.html "$SFEED_OUTPUT/index.html"; + LIMIT=0 html "$sfeedpath"/* >/tmp/sfeed-feeds.html && + mv /tmp/sfeed-feeds.html "$SFEED_OUTPUT/feeds.html"; + }' + logok "Generating RSS" '{ + atom "$sfeedpath" >/tmp/feeds.xml && + mv /tmp/feeds.xml "$SFEED_OUTPUT/feeds.xml"; + atom "$sfeedpath" 7 >/tmp/feeds-short.xml && + mv /tmp/feeds-short.xml "$SFEED_OUTPUT/feeds-short.xml"; + }' + logok "Generating OPML" '{ + opml "$sfeedrc" >/tmp/feeds.opml && + mv /tmp/feeds.opml "$SFEED_OUTPUT/feeds.opml"; + }' + # logok "Archiving old feeds" \ # archive "$sfeedpath"/* - log Done. + if [ -f /tmp/runsfeed.ok ]; then + echo >&2 'Done.' + else + echo >&2 'Done (some errors).' + fi } runcmd() { @@ -74,8 +80,22 @@ get_invidious_url() { head -n1 | tee /tmp/invidious.host } -log() { - printf '%s\n' "$*" >&2 +logok() { + newline='' + if [ "x$1" = x-n ]; then + newline='\n' + shift + fi + printf "%s...$newline" "$1" >&2 + shift + if output="$(eval "$@" | tee /dev/stderr)"; then + printf '%s\n' "${output:-ok}" + return 0 + else + rm /tmp/runsfeed.ok + printf 'ERROR\n' + return 1 + fi } update() { -- cgit 1.4.1-21-gabe81