Add update-vendor.sh symlink support, unify install.sh vendor flow

- update-vendor.sh now creates webui/vendor symlinks (htm.js)
- install.sh calls update-vendor.sh after package install
- Add vendor/.empty and webui/vendor/.empty as directory placeholders in git
This commit is contained in:
2026-07-01 00:44:08 +00:00
parent 575cf06a4b
commit 8c13ad55ce
32 changed files with 1371 additions and 445 deletions
+14 -20
View File
@@ -1,6 +1,5 @@
"""Dnsmasq daemon handler."""
import hashlib
import logging
from copy import deepcopy
from datetime import UTC, datetime
@@ -26,7 +25,15 @@ from daemon.iface import (
POST_DNSMASQ_UPSTREAMS,
)
from daemon.server import NotFoundError, refresh_state, registry
from lib.common import deep_merge, ensure_dirs, load_json, run, save_json
from lib.common import (
_APPLY_HASH_KEY,
config_hash,
deep_merge,
ensure_dirs,
load_json,
run,
save_json,
)
from lib.sync import SyncEvent, bus
logger = logging.getLogger(__name__)
@@ -51,20 +58,6 @@ DEFAULT_CFG: dict[str, Any] = {
"dns": {"upstreams": ["8.8.8.8", "1.1.1.1"], "domain": None, "custom_records": []},
}
# Internal field for tracking applied config version
_APPLY_HASH_KEY = "_last_applied_hash"
def _config_hash(cfg: dict[str, Any]) -> str:
"""Compute a hash of the config, excluding the _last_applied_hash field.
Used to detect whether the JSON config has changed since the last apply.
"""
import json
clean = {k: v for k, v in cfg.items() if k != _APPLY_HASH_KEY}
return hashlib.sha256(json.dumps(clean, sort_keys=True).encode()).hexdigest()
def _get_state() -> dict[str, Any] | None:
"""Retrieve cached dnsmasq state from the state store."""
@@ -144,7 +137,8 @@ def get_config(_request: Any, _body: Any) -> dict[str, Any]:
dm = _get_dnsmasq_state()
if dm:
return dm.get("config", {})
return _get_config()
cfg = _get_config()
return {k: v for k, v in cfg.items() if k != _APPLY_HASH_KEY}
@registry.register(POST_DNSMASQ_CONFIG)
@@ -199,11 +193,11 @@ def apply_config(_request: Any, _body: Any) -> dict[str, Any]:
f.write(conf_text)
run(["cp", str(tmp), DNSMASQ_CONF], sudo=True)
tmp.unlink(missing_ok=True)
run(["systemctl", "reload", "dnsmasq"], sudo=True)
logger.info("dnsmasq config written and reloaded")
run(["systemctl", "restart", "dnsmasq"], sudo=True)
logger.info("dnsmasq config written and restarted")
# Store the config hash so state collector can detect pending changes
cfg_after = _get_config()
cfg_after[_APPLY_HASH_KEY] = _config_hash(cfg_after)
cfg_after[_APPLY_HASH_KEY] = config_hash(cfg_after)
_save_config(cfg_after)
sync_result = bus.emit(
SyncEvent("dnsmasq", "config_saved", {"action": "config_applied"})