#!/bin/sh
	# K5：升级后必须清掉 LuCI 的索引与模块缓存，否则新版的路由与页面要等缓存自己
	# 过期才生效 —— 用户点完「更新」看到的还是旧界面，会以为没装上。
	# 与上游 LuCI 包的 postinst-pkg 做法一致（luci-compat 等都这么写）。
	# IPKG_INSTROOT 非空表示是在构建镜像、不是在真机上装，此时什么都不做。
	[ -n "${IPKG_INSTROOT}" ] || {
		rm -f /tmp/luci-indexcache.* 2>/dev/null
		rm -rf /tmp/luci-modulecache/ 2>/dev/null
		/etc/init.d/rpcd reload 2>/dev/null
		# N-KMIRROR：装完就在后台从官方镜像取内核，用户打开页面去登录时多半已经就绪。
		# 已有可用内核（升级场景）时它什么也不做；交给 procd，不占着包管理器。
		[ -x /usr/share/openclash-kejibear/kjx.sh ] && /usr/share/openclash-kejibear/kjx.sh core_install_bg >/dev/null 2>&1
		# 从旧包名 luci-app-kejibear 升上来：卸旧包、接管登录凭据（没有旧包痕迹时什么也不做）
		[ -x /usr/share/openclash-kejibear/kjx.sh ] && /usr/share/openclash-kejibear/kjx.sh legacy_takeover_bg >/dev/null 2>&1
	}
	exit 0
