🐶 Sync 2025-11-02 14:26:26
This commit is contained in:
12
luci-theme-argon/root/etc/uci-defaults/30_luci-theme-argon
Normal file
12
luci-theme-argon/root/etc/uci-defaults/30_luci-theme-argon
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ "$PKG_UPGRADE" != 1 ]; then
|
||||
uci get luci.themes.Argon >/dev/null 2>&1 || \
|
||||
uci batch <<-EOF
|
||||
set luci.themes.Argon=/luci-static/argon
|
||||
set luci.main.mediaurlbase=/luci-static/argon
|
||||
commit luci
|
||||
EOF
|
||||
fi
|
||||
|
||||
exit 0
|
||||
72
luci-theme-argon/root/usr/libexec/argon/online_wallpaper
Executable file
72
luci-theme-argon/root/usr/libexec/argon/online_wallpaper
Executable file
@@ -0,0 +1,72 @@
|
||||
#!/bin/sh
|
||||
# author jjm2473
|
||||
|
||||
# the script will be excuted when `argon.@global[0].bing_background == '1'`
|
||||
# defaults to 'bing' to be compatible with old config
|
||||
WEB_PIC_SRC=$(uci -q get argon.@global[0].online_wallpaper || echo 'bing')
|
||||
CACHE=/var/run/argon_${WEB_PIC_SRC}.url
|
||||
WRLOCK=/var/lock/argon_${WEB_PIC_SRC}.lock
|
||||
|
||||
fetch_pic_url() {
|
||||
case $WEB_PIC_SRC in
|
||||
bing)
|
||||
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 "//www.bing.com${picpath}"
|
||||
;;
|
||||
unsplash)
|
||||
curl -fks --max-time 3 \
|
||||
--header "Authorization: Client-ID kmFIroj2ELqXJPtC0XUoyww-Tr_lDU8Ho8uxjptIrCo" \
|
||||
"https://api.unsplash.com/photos/random?count=1&orientation=landscape" |
|
||||
jsonfilter -e "@[0]['urls']['regular']"
|
||||
;;
|
||||
unsplash_*)
|
||||
local collection_id=${WEB_PIC_SRC#unsplash_}
|
||||
curl -fks --max-time 3 \
|
||||
--header "Authorization: Client-ID kmFIroj2ELqXJPtC0XUoyww-Tr_lDU8Ho8uxjptIrCo" \
|
||||
"https://api.unsplash.com/photos/random?count=1&orientation=landscape" |
|
||||
jsonfilter -e "@[0]['urls']['regular']"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
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