#!/bin/sh

REDIRECTOR=$(cat /etc/ucentral/profile.json | jsonfilter -e '@.redirector')
if [ -n "$REDIRECTOR" ]; then
	uci -c /etc/config-shadow/ set ucentral.config.server="$REDIRECTOR"
	uci -c /etc/config-shadow/ commit ucentral                            
	/etc/init.d/firstcontact disable
	/etc/init.d/ucentral enable     
else                                    
	rm /etc/ucentral/redirector.json
	/etc/init.d/firstcontact enable 
	/etc/init.d/ucentral disable    
fi

exit 0
