mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-01 08:13:56 +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 @@
|
||||
config global
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
uci batch <<EOF
|
||||
set luci.themes.Fluent=/luci-static/fluent
|
||||
commit luci
|
||||
EOF
|
||||
|
||||
if ! uci -q get fluent.@global[0] >/dev/null 2>&1; then
|
||||
uci set fluent.global=global
|
||||
uci commit fluent
|
||||
fi
|
||||
|
||||
mkdir -p /www/luci-static/fluent/background
|
||||
chmod 0755 /www/luci-static/fluent/background
|
||||
exit 0
|
||||
@@ -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
|
||||
+274
@@ -0,0 +1,274 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
if command -v apk >/dev/null 2>&1; then
|
||||
PKG_EXT=".apk"
|
||||
else
|
||||
PKG_EXT=".ipk"
|
||||
fi
|
||||
|
||||
readonly bg_path="/www/luci-static/fluent/background"
|
||||
readonly tmp_path="/tmp/fluent_background.tmp"
|
||||
readonly update_pkg="/tmp/fluent-update${PKG_EXT}"
|
||||
readonly i18n_pkg="/tmp/fluent-i18n-update${PKG_EXT}"
|
||||
|
||||
case "$1" in
|
||||
"list")
|
||||
json_init
|
||||
json_add_object "avail"
|
||||
json_close_object
|
||||
json_add_object "remove"
|
||||
json_add_string "filename" "filename"
|
||||
json_close_object
|
||||
json_add_object "rename"
|
||||
json_add_string "newname" "filename"
|
||||
json_close_object
|
||||
json_add_object "set_mode"
|
||||
json_add_string "mode" "mode"
|
||||
json_close_object
|
||||
json_add_object "get_version"
|
||||
json_close_object
|
||||
json_add_object "start_download"
|
||||
json_add_string "url" "url"
|
||||
json_add_string "i18n_url" "i18n_url"
|
||||
json_add_string "i18n_urls" "i18n_urls"
|
||||
json_close_object
|
||||
json_add_object "check_download"
|
||||
json_close_object
|
||||
json_add_object "do_install"
|
||||
json_add_string "hash" "hash"
|
||||
json_add_string "i18n_hash" "i18n_hash"
|
||||
json_add_string "i18n_hashes" "i18n_hashes"
|
||||
json_close_object
|
||||
json_add_object "get_install_log"
|
||||
json_close_object
|
||||
json_dump
|
||||
json_cleanup
|
||||
;;
|
||||
"call")
|
||||
case "$2" in
|
||||
"avail")
|
||||
json_init
|
||||
json_add_int "avail" "$(df | grep -E '/$' | awk '{print $4}')"
|
||||
json_dump
|
||||
json_cleanup
|
||||
;;
|
||||
"remove")
|
||||
read -r input
|
||||
json_load "$input"
|
||||
json_get_var filename "filename"
|
||||
json_cleanup
|
||||
if dirname "$filename" | grep -q ".."; then
|
||||
echo '{ "result": 255 }'
|
||||
exit 255
|
||||
fi
|
||||
rm -f "$bg_path/$filename"
|
||||
echo '{ "result": 0 }'
|
||||
;;
|
||||
"rename")
|
||||
read -r input
|
||||
json_load "$input"
|
||||
json_get_var newname "newname"
|
||||
json_cleanup
|
||||
if dirname "$newname" | grep -q ".."; then
|
||||
echo '{ "result": 255 }'
|
||||
exit 255
|
||||
fi
|
||||
mkdir -p "$bg_path"
|
||||
if mv "$tmp_path" "$bg_path/$newname" 2>"/dev/null"; then
|
||||
chmod 0644 "$bg_path/$newname"
|
||||
echo '{ "result": 0 }'
|
||||
else
|
||||
echo '{ "result": 1 }'
|
||||
fi
|
||||
;;
|
||||
"set_mode")
|
||||
read -r input
|
||||
json_load "$input"
|
||||
json_get_var mode "mode"
|
||||
json_cleanup
|
||||
case "$mode" in
|
||||
light|dark|auto) ;;
|
||||
*)
|
||||
echo '{ "result": 255 }'
|
||||
exit 255
|
||||
;;
|
||||
esac
|
||||
if uci -q set fluent.@global[0].mode="$mode" && uci -q commit fluent; then
|
||||
echo '{ "result": 0 }'
|
||||
else
|
||||
echo '{ "result": 1 }'
|
||||
fi
|
||||
;;
|
||||
"get_version")
|
||||
version=""
|
||||
pkg_type="ipk"
|
||||
i18n_installed=0
|
||||
installed_i18n=""
|
||||
if command -v apk >/dev/null 2>&1; then
|
||||
pkg_type="apk"
|
||||
version=$(apk list -I luci-theme-fluent 2>/dev/null | awk '{print $1}' | sed 's/^luci-theme-fluent-//' | head -1)
|
||||
installed_i18n=$(apk list -I 2>/dev/null | grep -E '^luci-i18n-fluent-' | awk '{print $1}' | sed 's/^luci-i18n-fluent-//')
|
||||
else
|
||||
version=$(opkg status luci-theme-fluent 2>/dev/null | grep -m1 'Version:' | awk '{print $2}')
|
||||
installed_i18n=$(opkg list-installed 2>/dev/null | grep -E '^luci-i18n-fluent-' | awk '{print $1}' | sed 's/^luci-i18n-fluent-//')
|
||||
fi
|
||||
if echo "$installed_i18n" | grep -q "^zh-cn$"; then
|
||||
i18n_installed=1
|
||||
fi
|
||||
if [ -z "$version" ]; then
|
||||
version="1.0.1-dev"
|
||||
fi
|
||||
json_init
|
||||
json_add_string "version" "$version"
|
||||
json_add_string "pkg_type" "$pkg_type"
|
||||
json_add_boolean "i18n_zh_cn_installed" "$i18n_installed"
|
||||
json_add_array "installed_i18n"
|
||||
for lang in $installed_i18n; do
|
||||
json_add_string "" "$lang"
|
||||
done
|
||||
json_close_array
|
||||
json_dump
|
||||
json_cleanup
|
||||
;;
|
||||
"start_download")
|
||||
read -r input
|
||||
json_load "$input"
|
||||
json_get_var url "url"
|
||||
json_get_var i18n_url "i18n_url"
|
||||
json_get_var i18n_urls "i18n_urls"
|
||||
json_cleanup
|
||||
|
||||
rm -f "$update_pkg"
|
||||
rm -f /tmp/fluent-i18n-*
|
||||
rm -f /tmp/fluent-update.log
|
||||
|
||||
if [ -n "$url" ]; then
|
||||
download_cmd=""
|
||||
if command -v uclient-fetch >/dev/null 2>&1; then
|
||||
download_cmd="uclient-fetch -O $update_pkg \"$url\""
|
||||
urls_to_dl="${i18n_urls:-$i18n_url}"
|
||||
idx=1
|
||||
for u in $urls_to_dl; do
|
||||
download_cmd="$download_cmd && uclient-fetch -O /tmp/fluent-i18n-${idx}${PKG_EXT} \"$u\""
|
||||
idx=$((idx + 1))
|
||||
done
|
||||
else
|
||||
download_cmd="wget -O $update_pkg \"$url\""
|
||||
urls_to_dl="${i18n_urls:-$i18n_url}"
|
||||
idx=1
|
||||
for u in $urls_to_dl; do
|
||||
download_cmd="$download_cmd && wget -O /tmp/fluent-i18n-${idx}${PKG_EXT} \"$u\""
|
||||
idx=$((idx + 1))
|
||||
done
|
||||
fi
|
||||
nohup sh -c "$download_cmd >/tmp/fluent-update.log 2>&1" >/dev/null 2>&1 &
|
||||
echo '{ "result": 0 }'
|
||||
else
|
||||
echo '{ "result": 255, "message": "Missing URL" }'
|
||||
fi
|
||||
;;
|
||||
"check_download")
|
||||
json_init
|
||||
size1=$(ls -l $update_pkg 2>/dev/null | awk '{print $5}')
|
||||
size2=$(ls -l /tmp/fluent-i18n-* 2>/dev/null | awk '{sum+=$5} END {print sum}')
|
||||
size=$(( ${size1:-0} + ${size2:-0} ))
|
||||
json_add_int "size" "$size"
|
||||
|
||||
if pgrep -f "fluent-update" >/dev/null; then
|
||||
json_add_boolean "running" 1
|
||||
else
|
||||
json_add_boolean "running" 0
|
||||
if [ "$size" -eq 0 ]; then
|
||||
# If process exited and size is 0, download failed
|
||||
json_add_int "code" 255
|
||||
else
|
||||
json_add_int "code" 0
|
||||
fi
|
||||
fi
|
||||
json_dump
|
||||
json_cleanup
|
||||
;;
|
||||
"do_install")
|
||||
read -r input
|
||||
json_load "$input"
|
||||
json_get_var hash "hash"
|
||||
json_get_var i18n_hash "i18n_hash"
|
||||
json_get_var i18n_hashes "i18n_hashes"
|
||||
json_cleanup
|
||||
|
||||
if [ -z "$hash" ]; then
|
||||
echo '{ "result": 255, "message": "Missing hash parameter" }'
|
||||
exit 255
|
||||
fi
|
||||
|
||||
if [ ! -f "$update_pkg" ]; then
|
||||
echo '{ "result": 255, "message": "Package file not found" }'
|
||||
exit 255
|
||||
fi
|
||||
|
||||
if [ "$hash" != "skip" ]; then
|
||||
if ! echo "$hash" | grep -qE '^[0-9a-fA-F]{64}$'; then
|
||||
echo '{ "result": 255, "message": "Invalid hash parameter" }'
|
||||
exit 255
|
||||
fi
|
||||
actual_hash=$(sha256sum "$update_pkg" | awk '{print $1}')
|
||||
if [ "$actual_hash" != "$hash" ]; then
|
||||
echo '{ "result": 255, "message": "Hash verification failed" }'
|
||||
exit 255
|
||||
fi
|
||||
fi
|
||||
|
||||
hashes_to_check="${i18n_hashes:-$i18n_hash}"
|
||||
if [ -n "$hashes_to_check" ]; then
|
||||
idx=1
|
||||
for h in $hashes_to_check; do
|
||||
target_i18n_pkg="/tmp/fluent-i18n-${idx}${PKG_EXT}"
|
||||
if [ -f "$target_i18n_pkg" ] && [ "$h" != "skip" ]; then
|
||||
if ! echo "$h" | grep -qE '^[0-9a-fA-F]{64}$'; then
|
||||
echo '{ "result": 255, "message": "Invalid i18n hash parameter" }'
|
||||
exit 255
|
||||
fi
|
||||
actual_i18n_hash=$(sha256sum "$target_i18n_pkg" | awk '{print $1}')
|
||||
if [ "$actual_i18n_hash" != "$h" ]; then
|
||||
echo '{ "result": 255, "message": "i18n Hash verification failed" }'
|
||||
exit 255
|
||||
fi
|
||||
fi
|
||||
idx=$((idx + 1))
|
||||
done
|
||||
fi
|
||||
|
||||
install_cmd=""
|
||||
pkgs="$update_pkg"
|
||||
i18n_files=$(ls /tmp/fluent-i18n-* 2>/dev/null)
|
||||
if [ -n "$i18n_files" ]; then
|
||||
pkgs="$pkgs $i18n_files"
|
||||
fi
|
||||
|
||||
if command -v apk >/dev/null 2>&1; then
|
||||
install_cmd="apk add --allow-untrusted $pkgs"
|
||||
else
|
||||
install_cmd="opkg install $pkgs"
|
||||
fi
|
||||
|
||||
nohup sh -c "sleep 1 && $install_cmd > /tmp/fluent-install.log 2>&1 ; rm -f $pkgs ; /etc/init.d/rpcd restart" >/dev/null 2>&1 &
|
||||
|
||||
echo '{ "result": 0 }'
|
||||
;;
|
||||
"get_install_log")
|
||||
json_init
|
||||
if [ -f "/tmp/fluent-install.log" ]; then
|
||||
json_add_string "log" "$(cat /tmp/fluent-install.log)"
|
||||
else
|
||||
json_add_string "log" ""
|
||||
fi
|
||||
json_dump
|
||||
json_cleanup
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"admin/system/fluent-config": {
|
||||
"title": "Fluent Theme",
|
||||
"order": 90,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "fluent-config"
|
||||
},
|
||||
"depends": {
|
||||
"acl": [ "luci-theme-fluent" ],
|
||||
"uci": { "fluent": true }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"luci-theme-fluent": {
|
||||
"description": "Grant UCI and file access for luci-theme-fluent config view",
|
||||
"read": {
|
||||
"file": {
|
||||
"/www/luci-static/fluent/background/*": [ "list" ]
|
||||
},
|
||||
"ubus": {
|
||||
"luci.fluent": [ "avail", "remove", "rename", "set_mode", "get_version", "check_download", "get_install_log" ]
|
||||
},
|
||||
"uci": [ "fluent" ]
|
||||
},
|
||||
"write": {
|
||||
"file": {
|
||||
"/tmp/fluent_background.tmp": [ "write" ],
|
||||
"/tmp/fluent-update.ipk": [ "write" ],
|
||||
"/tmp/fluent-update.apk": [ "write" ]
|
||||
},
|
||||
"ubus": {
|
||||
"luci.fluent": [ "set_mode", "do_install", "start_download" ]
|
||||
},
|
||||
"uci": [ "fluent" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user