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...
}

perms() {
  # Keep same perms on file
  NEW="$1"
  OLD="$(dirname $NEW)/$(basename $NEW .new)"
  if [ -e $OLD ]; then
	  cp -a $OLD $NEW.incoming
	  cat $NEW > $NEW.incoming
	  mv $NEW.incoming $NEW
  fi
  config $NEW
}

perms etc/rc.d/rc.ntopng.new
perms etc/ntopng/ntopng.conf.new

( cd usr/doc/ntopng-6.6/nedge/src/api/rest ; rm -rf rest-api-v2-nedge-ext.json )
( cd usr/doc/ntopng-6.6/nedge/src/api/rest ; ln -sf ../../../../../httpdocs/misc/rest-api-v2-nedge-ext.json rest-api-v2-nedge-ext.json )
( cd usr/doc/ntopng-6.6/src/api/rest ; rm -rf rest-api-v2.json )
( cd usr/doc/ntopng-6.6/src/api/rest ; ln -sf ../../../../httpdocs/misc/rest-api-v2.json rest-api-v2.json )
( cd usr/share/ntopng/httpdocs/geoip ; rm -rf README.geolocation.md )
( cd usr/share/ntopng/httpdocs/geoip ; ln -sf ../../doc/README.geolocation.md README.geolocation.md )
