#!/bin/sh
config() {
  NEW="$1"
  OLD="`dirname $NEW`/`basename $NEW .new`"
  # If there's no config file by that name, mv it over:
  if [ ! -r $OLD ]; then
     mv $NEW $OLD
  elif [ "`cat $OLD | md5sum`" = "`cat $NEW | md5sum`" ]; then # toss the redundant copy
     rm $NEW
  fi
# Otherwise, we leave the .new copy for the admin to consider...
}

#Check if the .kodi/userdata directory exist in the user HOME
if [ ! -d /root/.kodi ] ; then
   mkdir /root/.kodi
fi

if [ ! -d /root/.kodi/userdata ] ; then
   mkdir /root/.kodi/userdata
fi

#Remove files that might exist in /tmp matching our filenames!
if [ -f /tmp/advancedsettings.xml.new ] ; then
   rm -f /tmp/advancedsettings.xml.new
fi

config root/.kodi/userdata/advancedsettings.xml.new
