#!/bin/sh

#if [ "$#"  != "4" ]; then
#    echo "Wrong number of parameters!"
#    exit 1
#fi

wget -O $1 $2

if [ "$?" == "0" ]; then
	if [ -f $1 ]; then
		echo "Download successful, write configuration file..."
		psi -o write -t cfg -f $1 -r no
		if [ -f $1 ]; then
			echo "Write successful. Rebooting..."
		else
			echo "Write failed! Rebooting..."
		fi
	else
		echo "Configuration file does not exist!"
	fi
else
	echo "Couldn't get configuration file, error code $? "
fi

reboot
