#!/bin/sh

# Warning, problems can occur if the device restarts in the middle of this uci-default script

if [ -x /bin/sysrepoctl ]; then
	match=$(sysrepoctl -l | grep "ietf-ssh-server\ ")
	if [ ! "$match" ]; then
		sysrepoctl --install --yang=/etc/sysrepo/yang/ietf-ssh-server.yang -p 600
	fi

	match=$(sysrepoctl -l | grep "ietf-tls-server\ ")
	if [ ! "$match" ]; then
		sysrepoctl --install --yang=/etc/sysrepo/yang/ietf-tls-server.yang -p 600
	fi

	match=$(sysrepoctl -l | grep "iana-crypt-hash\ ")
	if [ ! "$match" ]; then
		sysrepoctl --install --yang=/etc/sysrepo/yang/iana-crypt-hash.yang -p 600
	fi

	match=$(sysrepoctl -l | grep "ietf-x509-cert-to-name\ ")
	if [ ! "$match" ]; then
		sysrepoctl --install --yang=/etc/sysrepo/yang/ietf-x509-cert-to-name.yang -p 600
	fi

	match=$(sysrepoctl -l | grep "ietf-netconf-server\ ")
	if [ ! "$match" ]; then
		sysrepoctl --install --yang=/etc/sysrepo/yang/ietf-netconf-server.yang -o root:root -p 600
		sysrepoctl -m ietf-netconf-server -e listen
		sysrepoctl -m ietf-netconf-server -e ssh-listen
		sysrepoctl -m ietf-netconf-server -e tls-listen
		sysrepoctl -m ietf-netconf-server -e call-home
		sysrepoctl -m ietf-netconf-server -e ssh-call-home
		sysrepoctl -m ietf-netconf-server -e tls-call-home
		if [ -x /bin/sysrepocfg ]; then
			sysrepocfg -d startup -i /usr/share/netopeer2-server/stock_config.xml ietf-netconf-server
			rm /usr/share/netopeer2-server/stock_config.xml
		fi
	fi

	match=$(sysrepoctl -l | grep "ietf-system\ ")
	if [ ! "$match" ]; then
		sysrepoctl --install --yang=/etc/sysrepo/yang/ietf-system.yang -o root:root -p 600
		sysrepoctl -m ietf-system -e authentication
		sysrepoctl -m ietf-system -e local-users
	fi
fi

exit 0
