From 5f681a372ac7d2961e3e13bb859ce35b08f22d4a Mon Sep 17 00:00:00 2001 From: remittor Date: Mon, 28 Apr 2025 20:06:02 +0300 Subject: [PATCH] install: Patch luci header.ut for force update browser-cache Aux info: https://github.com/openwrt/luci/pull/7725 --- zapret/comfunc.sh | 32 ++++++++++++++++++++++++++++++++ zapret/init.d.sh | 2 ++ 2 files changed, 34 insertions(+) diff --git a/zapret/comfunc.sh b/zapret/comfunc.sh index c3651f9..1baa6d6 100755 --- a/zapret/comfunc.sh +++ b/zapret/comfunc.sh @@ -156,3 +156,35 @@ function init_before_start remove_cron_task_logs fi } + +function patch_luci_header_ut +{ + # INFO: https://github.com/openwrt/luci/pull/7725 + local header_ut=/usr/share/ucode/luci/template/header.ut + local runtime_uc=/usr/share/ucode/luci/runtime.uc + local newenv + [ ! -f $header_ut ] && return 0 + [ ! -f $runtime_uc ] && return 0 + if grep -q "pkgs_update_time" $runtime_uc; then + return 0 + fi + if grep -q "pkgs_update_time" $header_ut; then + return 0 + fi + sed -i "/^import { access/i import { stat } from 'fs';" $runtime_uc + if ! grep -q "{ stat }" $runtime_uc; then + return 1 + fi + newenv="self.env.pkgs_update_time = stat('/lib/apk/db/installed')?.mtime ?? stat('/usr/lib/opkg/status')?.mtime ?? 0;" + newenv=`adapt_for_sed "$newenv"` + sed -i "/self.env.include =/i $newenv" $runtime_uc + if ! grep -q "pkgs_update_time" $runtime_uc; then + return 1 + fi + sed -i 's/luci.js?v=\(.*\)"><\/script>/luci.js?v=\1-{{ pkgs_update_time }}"><\/script>/g' $header_ut + if ! grep -q "pkgs_update_time" $header_ut; then + return 1 + fi + logger -p notice -t ZAPRET "patch_luci_header_ut: OK" + return 0 +} diff --git a/zapret/init.d.sh b/zapret/init.d.sh index 9dd1146..ef43cf4 100755 --- a/zapret/init.d.sh +++ b/zapret/init.d.sh @@ -25,6 +25,7 @@ is_run_on_boot && IS_RUN_ON_BOOT=1 || IS_RUN_ON_BOOT=0 function enable { local run_on_boot="" + patch_luci_header_ut if [ "$IS_RUN_ON_BOOT" = "1" ]; then if [ -n "$ZAPRET_CFG_SEC_NAME" ]; then run_on_boot=$( get_run_on_boot_option ) @@ -59,6 +60,7 @@ function enabled function boot { local run_on_boot="" + patch_luci_header_ut if [ "$IS_RUN_ON_BOOT" = "1" ]; then if [ -n "$ZAPRET_CFG_SEC_NAME" ]; then run_on_boot=$( get_run_on_boot_option )