#!/bin/sh
# Миграция /etc/config/mavp2p со старой схемы (config proxy ..., upstream luci-app-mavp2p)
# на схему форка (config mavp2p 'global' + config endpoint). Старый файл сохраняется.
cfg=/etc/config/mavp2p
def=/usr/share/mavp2p/mavp2p.default
[ -f "$def" ] || exit 0
if [ ! -f "$cfg" ] || grep -q "^config proxy" "$cfg" || ! grep -q "^config mavp2p 'global'" "$cfg"; then
	[ -f "$cfg" ] && cp "$cfg" "$cfg.pre-migrate-$(date +%Y%m%d%H%M%S)"
	cp "$def" "$cfg"
	logger -t mavp2p "config migrated to endpoint schema (old copy kept next to it)"
fi
exit 0
