#!/bin/sh
# Post-install setup for luci-app-cloudreve

chmod +x /etc/init.d/cloudreve >/dev/null 2>&1

uci -q batch <<-EOF >/dev/null
	delete ucitrack.@cloudreve[-1]
	add ucitrack cloudreve
	set ucitrack.@cloudreve[-1].init=cloudreve
	commit ucitrack
EOF

# 清理旧版本遗留的配置键（第五轮评审：storage_path → root_path，删 listen_address）
uci -q delete cloudreve.@cloudreve[0].storage_path
uci -q delete cloudreve.@cloudreve[0].listen_address
uci -q delete cloudreve.@cloudreve[0].database_path
uci commit cloudreve

# 旧版本可能遗留空的 /etc/cloudreve 目录，清理掉（配置已移回用户数据目录）
[ -d /etc/cloudreve ] && [ -z "$(ls -A /etc/cloudreve 2>/dev/null)" ] && rmdir /etc/cloudreve 2>/dev/null

rm -f /tmp/luci-indexcache
rm -f /tmp/luci-modulecache/*

exit 0
