|
|
|
#!/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
|
|
|
|
#Fix Dark and Light mode CSS on dashboard
|
|
|
|
local argon_mode=$(uci get argon.@global[0].mode 2>/dev/null)
|
|
|
|
local css_path="/www/luci-static/resources/view/dashboard/css/custom.css"
|
|
|
|
|
|
|
|
if [[ "$argon_mode" == "dark" ]]; then
|
|
|
|
echo "Applying dark mode..."
|
|
|
|
rm -f "$css_path"
|
|
|
|
cp -f /etc/dark.css "$css_path"
|
|
|
|
elif [[ "$argon_mode" == "light" ]]; then
|
|
|
|
echo "Applying light mode..."
|
|
|
|
rm -f "$css_path"
|
|
|
|
cp -f /etc/light.css "$css_path"
|
|
|
|
else
|
|
|
|
echo "The Argon theme mode is set to normal or is undefined. No changes made."
|
|
|
|
fi
|
|
|
|
|
|
|
|
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 \
|
|
|
|
"https://source.unsplash.com/1920x1080/daily?wallpapers" |
|
|
|
|
sed -E 's#^.*href="([^?]+)\?.*$#\1?fm=jpg\&fit=crop\&w=1920\&h=1080#'
|
|
|
|
;;
|
|
|
|
unsplash_*)
|
|
|
|
local collection_id=${WEB_PIC_SRC#unsplash_}
|
|
|
|
curl -fks --max-time 3 \
|
|
|
|
"https://source.unsplash.com/collection/${collection_id}/1920x1080" |
|
|
|
|
sed -E 's#^.*href="([^?]+)\?.*$#\1?fm=jpg\&fit=crop\&w=1920\&h=1080#'
|
|
|
|
;;
|
|
|
|
wallhaven)
|
|
|
|
curl -fks --max-time 3 \
|
|
|
|
"https://wallhaven.cc/api/v1/search?resolutions=1920x1080&sorting=random" |
|
|
|
|
jsonfilter -qe '@.data[0].path'
|
|
|
|
;;
|
|
|
|
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
|