mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-10-30 11:45:13 +08:00
💋 Sync 2026-10-04 04:16:09
This commit is contained in:
1 parent
f6b2df73ec
commit
f62992fd80
745 files changed
+212416
-1173
No files matched your search
@@ -0,0 +1,58 @@
|
||||
#!/bin/sh
|
||||
# author jjm2473, customized for fluent
|
||||
|
||||
WEB_PIC_SRC=$(uci -q get fluent.@global[0].login_bg || echo 'bing')
|
||||
|
||||
if [ "$WEB_PIC_SRC" != "bing" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
CACHE=/var/run/fluent_${WEB_PIC_SRC}.url
|
||||
WRLOCK=/var/lock/fluent_${WEB_PIC_SRC}.lock
|
||||
|
||||
fetch_pic_url() {
|
||||
local picpath=$(curl -fks --max-time 3 \
|
||||
"https://www.bing.com/HPImageArchive.aspx?format=js&n=1" |
|
||||
jsonfilter -qe '@.images[0].url')
|
||||
[ -n "${picpath}" ] && echo "https://www.bing.com${picpath}"
|
||||
}
|
||||
|
||||
try_update() {
|
||||
local lock="$WRLOCK"
|
||||
exec 200>$lock
|
||||
|
||||
if flock -n 200 >/dev/null 2>&1; then
|
||||
local picurl=$(fetch_pic_url)
|
||||
if [ -n "$picurl" ]; then
|
||||
echo "${picurl}" | tee "$CACHE"
|
||||
else
|
||||
if [ -s "$CACHE" ]; then
|
||||
cat "$CACHE"
|
||||
else
|
||||
touch "$CACHE"
|
||||
fi
|
||||
fi
|
||||
flock -u 200 >/dev/null 2>&1
|
||||
elif [ -s "$CACHE" ]; then
|
||||
cat "$CACHE"
|
||||
fi
|
||||
}
|
||||
|
||||
get_url() {
|
||||
if [ -f "$CACHE" ]; then
|
||||
local idle_t=$(($(date '+%s') - $(date -r "$CACHE" '+%s' 2>/dev/null || echo '0')))
|
||||
if [ -s "$CACHE" ]; then
|
||||
if [ $idle_t -le 43200 ]; then
|
||||
cat "$CACHE"
|
||||
return
|
||||
fi
|
||||
else
|
||||
if [ $idle_t -le 120 ]; then
|
||||
return
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
try_update
|
||||
}
|
||||
|
||||
get_url
|
||||
Reference in new issue
Block a user