#!/bin/bash
#
# kate: tab-indents off; tab-width 4; indent-width 4;
#
# This file is responsible for installing override files
# which can not be packaged directly due to rpm file
# conflicts

# We need to disable update-motd.service to prevent it from clobbering our /etc/motd override
if systemctl -q is-active update-motd.service; then
  systemctl --no-block mask --now update-motd.service
fi

# Install custom config overrides from %{_sysconfdir}/%{name}/overrides
SRCDIR=/usr/share/ng-encis/overrides/
for i in `find $SRCDIR -type f -printf '%P\n'`; do
  SRC="$SRCDIR/$i"
  DST="/$i"

  # Make a backup of the existing file if we haven't already
  [ -e "$DST" ] && [ ! -e "$DST.ngbak" ] && cp "$DST" "$DST.ngbak"

  # Replace the contents of the existing file with the contents of
  # the override file, this should ensure that security contexts etc
  # of the original target file are maintained
  cat $SRC >$DST
done

