refactor: notify-Timeout/Multi-User, bing atomar+Timeouts, Toggle vereinfacht

This commit is contained in:
humocs-man committed 2026-10-10 17:08:52 +02:00
1 parent 00ecfa5778
commit d26c1f90f5
5 files changed
+88 -50

No files matched your search

+21 -5
View File
@@ -15,20 +15,36 @@ mkdir -p "${OUTDIR}"
TODAY="$(date +%F)"
TARGET="${OUTDIR}/bing-${TODAY}.jpg"
TMPFILE="${TARGET}.part"
# Atomarer Download: direkt auf TARGET wuerde bei Abbruch eine korrupte
# Teil-Datei hinterlassen, die `[[ ! -s ]]` danach den ganzen Tag lang
# ueberspringen wuerde. Timeouts, damit kein haengender Call den
# oneshot-Service blockiert (siehe auch TimeoutStartSec in der Unit).
if [[ ! -s "${TARGET}" ]]; then
JSON="$(curl -fsSL --retry 3 --retry-delay 5 "${API}")"
JSON="$(curl -fsSL --retry 3 --retry-delay 5 --connect-timeout 15 --max-time 120 "${API}")"
URLBASE="$(printf '%s' "${JSON}" | jq -r '.images[0].urlbase // empty')"
[[ -n "${URLBASE}" ]] || { echo "Bing-Antwort ohne urlbase"; exit 1; }
curl -fsSL --retry 3 --retry-delay 5 -o "${TARGET}" "https://www.bing.com${URLBASE}_UHD.jpg"
curl -fsSL --retry 3 --retry-delay 5 --connect-timeout 15 --max-time 300 \
-o "${TMPFILE}" "https://www.bing.com${URLBASE}_UHD.jpg" \
&& mv -f "${TMPFILE}" "${TARGET}"
echo "Geladen: ${TARGET}"
else
echo "Bereits vorhanden: ${TARGET}"
fi
rm -f "${TMPFILE}" 2>/dev/null || true
# Alte behalten wir 7 Tage (Rotation via Noctalia-Automation moeglich)
ls -t "${OUTDIR}"/bing-*.jpg 2>/dev/null | tail -n +8 | xargs -r rm -f --
echo "Bereinigt, behalten: $(ls "${OUTDIR}"/bing-*.jpg 2>/dev/null | wc -l)"
# Alte behalten wir 7 Tage (Rotation via Noctalia-Automation moeglich).
# find statt ls-Parsing (Leerzeichen in Pfaden), Anzahl via Array
# (pipefail-sicher, kein wc-Subshell-Abbruch bei 0 Treffern).
mapfile -t KEEP < <(find "${OUTDIR}" -maxdepth 1 -name 'bing-*.jpg' -printf '%T@ %p\n' 2>/dev/null | sort -rn | head -n 7 | cut -d' ' -f2-)
if [[ "${#KEEP[@]}" -gt 0 ]]; then
KEEPLIST="|$(printf '%s|' "${KEEP[@]}")"
while IFS= read -r -d '' f; do
[[ "${KEEPLIST}" == *"|${f}|"* ]] || rm -f -- "${f}"
done < <(find "${OUTDIR}" -maxdepth 1 -name 'bing-*.jpg' -print0 2>/dev/null)
fi
echo "Bereinigt, behalten: ${#KEEP[@]}"
# Direkt setzen. Laeuft die Shell noch nicht (Timer feuert beim Login via
# Persistent oft vor Noctalia), bis zu ~2 Min warten statt aufzugeben.