add timestamps ()

Reviewed-on: 
Co-authored-by: Michael Grote <michael.grote@posteo.de>
Co-committed-by: Michael Grote <michael.grote@posteo.de>
This commit is contained in:
Michael Grote 2025-02-05 16:29:50 +01:00 committed by Michael Grote
parent 576fc38f9f
commit d9c4e54c1c
2 changed files with 25 additions and 24 deletions

View file

@ -12,6 +12,7 @@ RUN apk add --no-cache \
coreutils \
gawk \
iputils-ping \
moreutils \
&& mkdir /data \
&& touch /data/filter.txt

View file

@ -33,74 +33,74 @@ function check_dependencies {
# pruefe ob jq installiert ist
# https://stackoverflow.com/questions/592620/how-can-i-check-if-a-program-exists-from-a-bash-script
if [[ $MF_DEBUG -eq 1 ]]; then
echo "[DEBUG] check dependencies"
echo "[DEBUG] check dependencies" | ts %Y-%m-%d_%H-%M-%S
fi
if ! command -v jq &> /dev/null
then
echo "[ERROR] jq could not be found!"
echo "[ERROR] jq could not be found!" | ts %Y-%m-%d_%H-%M-%S
exit 5
fi
if ! command -v curl &> /dev/null
then
echo "[ERROR] curl could not be found!"
echo "[ERROR] curl could not be found!" | ts %Y-%m-%d_%H-%M-%S
exit 6
fi
if ! command -v xargs &> /dev/null
then
echo "[ERROR] xargs could not be found!"
echo "[ERROR] xargs could not be found!" | ts %Y-%m-%d_%H-%M-%S
exit 8
fi
if ! command -v sed &> /dev/null
then
echo "[ERROR] sed could not be found!"
echo "[ERROR] sed could not be found!" | ts %Y-%m-%d_%H-%M-%S
exit 9
fi
if ! command -v sort &> /dev/null
then
echo "[ERROR] sort could not be found!"
echo "[ERROR] sort could not be found!" | ts %Y-%m-%d_%H-%M-%S
exit 10
fi
if ! command -v awk &> /dev/null
then
echo "[ERROR] awk could not be found!"
echo "[ERROR] awk could not be found!" | ts %Y-%m-%d_%H-%M-%S
exit 11
fi
}
function check_vars {
if [[ $MF_DEBUG -eq 1 ]]; then
echo "[DEBUG] check if vars are (correctly) set"
echo "[DEBUG] check if vars are (correctly) set" | ts %Y-%m-%d_%H-%M-%S
fi
# pruefe ob alle vars gesetzt sind
# -z = ob laenge gleich null ist
if [[ -z "${MF_AUTH_TOKEN}" ]]; then
# shellcheck disable=SC2016
# shellcheck disable=SC2102
echo [ERROR] '"$MF_AUTH_TOKEN"' not set.
echo [ERROR] '"$MF_AUTH_TOKEN"' not set. | ts %Y-%m-%d_%H-%M-%S
exit 2
fi
if [[ -z "${MF_API_URL}" ]]; then
# shellcheck disable=SC2016
# shellcheck disable=SC2102
echo [ERROR] '"$MF_API_URL"' not set.
echo [ERROR] '"$MF_API_URL"' not set. | ts %Y-%m-%d_%H-%M-%S
exit 3
fi
# prüfe ob filter-datei ein ordner ist
# kann bei einem falschen bind-mount passieren
if [[ -d "$MF_FILTERLIST_FILE" ]]; then
# shellcheck disable=SC2102
echo [ERROR] "$MF_FILTERLIST_FILE" is a directory!
echo [ERROR] "$MF_FILTERLIST_FILE" is a directory! | ts %Y-%m-%d_%H-%M-%S
exit 4
fi
# pruefe ob filter-datei NICHT existiert
if [[ ! -e "$MF_FILTERLIST_FILE" ]]; then
# shellcheck disable=SC2102
echo [ERROR] "$MF_FILTERLIST_FILE" not readable!
echo [ERROR] "$MF_FILTERLIST_FILE" not readable! | ts %Y-%m-%d_%H-%M-%S
exit 1
fi
}
function check_ping_connectivity {
if [[ $MF_DEBUG -eq 1 ]]; then
echo "[DEBUG] check if miniflux can be reached with ping"
echo "[DEBUG] check if miniflux can be reached with ping" | ts %Y-%m-%d_%H-%M-%S
fi
# pruefe ob miniflux erreichbar ist, wenn ja setze abbruchbedingung, sonst warte
mf_ping_connectivity=0
@ -112,16 +112,16 @@ function check_ping_connectivity {
else
mf_ping_connectivity=0
sleep 10
echo "[INFO] wait for miniflux (ping)..."
echo "[INFO] wait for miniflux (ping)..." | ts %Y-%m-%d_%H-%M-%S
if [[ $MF_DEBUG -eq 1 ]]; then
echo "[DEBUG] miniflux could not be pinged, wait 10s"
echo "[DEBUG] miniflux could not be pinged, wait 10s" | ts %Y-%m-%d_%H-%M-%S
fi
fi
done
}
function check_api_connectivity {
if [[ $MF_DEBUG -eq 1 ]]; then
echo "[DEBUG] check if miniflux-api can be reached with curl"
echo "[DEBUG] check if miniflux-api can be reached with curl" | ts %Y-%m-%d_%H-%M-%S
fi
# pruefe ob miniflux erreichbar ist, wenn ja setze abbruchbedingung, sonst warte
mf_api_connectivity=0
@ -132,9 +132,9 @@ function check_api_connectivity {
else
mf_api_connectivity=0
sleep 10
echo "[INFO] wait for miniflux (api)..."
echo "[INFO] wait for miniflux (api)..." | ts %Y-%m-%d_%H-%M-%S
if [[ $MF_DEBUG -eq 1 ]]; then
echo "[DEBUG] api could not be reached, wait 10s"
echo "[DEBUG] api could not be reached, wait 10s" | ts %Y-%m-%d_%H-%M-%S
fi
fi
done
@ -153,22 +153,22 @@ function debug_output {
function get_unread_entries {
# hole alle ungelesenen entries und speichere sie in der variable unread_entries
if [[ $MF_DEBUG -eq 1 ]]; then
echo "[DEBUG] get unread entries from miniflux"
echo "[DEBUG] get unread entries from miniflux" | ts %Y-%m-%d_%H-%M-%S
fi
unread_entries="$(curl --silent --header "X-Auth-Token: $MF_AUTH_TOKEN" "$MF_API_URL/entries?status=unread&limit=0")"
if [[ $MF_DEBUG -eq 1 ]]; then
echo "[DEBUG] show unread entries from miniflux"
echo "[DEBUG] show unread entries from miniflux" | ts %Y-%m-%d_%H-%M-%S
echo -----------------------------------------------------
echo "$unread_entries"
echo -----------------------------------------------------
fi
}
function filter_entries {
echo "[INFO] Filtering entries..."
echo "[INFO] Filtering entries..." | ts %Y-%m-%d_%H-%M-%S
# fuer jede Zeile in $MF_FILTERLIST_FILE
while read -r line; do
if [[ $MF_DEBUG -eq 1 ]]; then
echo "[DEBUG] set search values"
echo "[DEBUG] set search values" | ts %Y-%m-%d_%H-%M-%S
fi
# setze $url auf den Wert vor dem Trennzeichen/Delimiter, ersetze alle Grossschreibungen durch Kleinschreibung
url=$(echo "$line" | tr '[:upper:]' '[:lower:]' | awk --field-separator="::" '{print $1}')
@ -202,8 +202,8 @@ function mark_as_read {
# sende in put request mit curl
# der wert muss escaped werden, aber NICHT die variable die uebergeben wird
if [[ $MF_DEBUG -eq 1 ]]; then
echo "[DEBUG] mark entries as read"
echo "[DEBUG] marked entry ids:"
echo "[DEBUG] mark entries as read" | ts %Y-%m-%d_%H-%M-%S
echo "[DEBUG] marked entry ids:" | ts %Y-%m-%d_%H-%M-%S
# https://unix.stackexchange.com/questions/353321/remove-all-duplicate-word-from-string-using-shell-script
# entfernt doppelte eintraege innerhalb einer zeile
echo "$marked_entries" | xargs -n1 | sort -u | xargs | sed -r 's/\s/\, /g'