#!/bin/sh

# Copyright (C) 2013-2018 Algo Communication Products Ltd.
# restore settings from uploaded file

if [ "$#" != "1" ]; then
	cat <<EOF
Usage: $0 <saved-settings.conf>
EOF
	exit 1
fi

CONF_FILE=/tmp/web/mp/user.conf
mv /tmp/web/mp/"$1" $CONF_FILE

fromdos $CONF_FILE
# append newline to the end of file if it does not exist
if [ "$(tail -c 1 $CONF_FILE)" != "" ]; then
	echo "" >> $CONF_FILE
fi
if ! diff $CONF_FILE /opt/algo/config/user.conf > /dev/null; then
	cp $CONF_FILE /opt/algo/config/user.conf
	sync
fi
rm -f /tmp/web/mp/*
