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

preserve_perms() {
  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
}

config etc/jabberd2/c2s.xml.new
config etc/jabberd2/jabberd-c2s.conf.new
config etc/jabberd2/jabberd-router.conf.new
config etc/jabberd2/jabberd-s2s.conf.new
config etc/jabberd2/jabberd-sm.conf.new
config etc/jabberd2/jabberd.cfg.new
config etc/jabberd2/router-filter.xml.new
config etc/jabberd2/router-users.xml.new
config etc/jabberd2/router.xml.new
config etc/jabberd2/s2s.xml.new
config etc/jabberd2/sm.xml.new
config etc/jabberd2/templates/roster.xml.new

preserve_perms etc/rc.d/rc.jabberd2.new
( cd usr/lib64/jabberd ; rm -rf mod_active.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_active.so.0.0.0 mod_active.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_offline.so )
( cd usr/lib64/jabberd ; ln -sf mod_offline.so.0.0.0 mod_offline.so )
( cd usr/lib64/jabberd ; rm -rf mod_template-roster.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_template-roster.so.0.0.0 mod_template-roster.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_iq-last.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_iq-last.so.0.0.0 mod_iq-last.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_help.so )
( cd usr/lib64/jabberd ; ln -sf mod_help.so.0.0.0 mod_help.so )
( cd usr/lib64/jabberd ; rm -rf mod_status.so )
( cd usr/lib64/jabberd ; ln -sf mod_status.so.0.0.0 mod_status.so )
( cd usr/lib64/jabberd ; rm -rf mod_privacy.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_privacy.so.0.0.0 mod_privacy.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_roster.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_roster.so.0.0.0 mod_roster.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_iq-time.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_iq-time.so.0.0.0 mod_iq-time.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_roster.so )
( cd usr/lib64/jabberd ; ln -sf mod_roster.so.0.0.0 mod_roster.so )
( cd usr/lib64/jabberd ; rm -rf mod_iq-last.so )
( cd usr/lib64/jabberd ; ln -sf mod_iq-last.so.0.0.0 mod_iq-last.so )
( cd usr/lib64/jabberd ; rm -rf mod_iq-vcard.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_iq-vcard.so.0.0.0 mod_iq-vcard.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_deliver.so )
( cd usr/lib64/jabberd ; ln -sf mod_deliver.so.0.0.0 mod_deliver.so )
( cd usr/lib64/jabberd ; rm -rf mod_iq-version.so )
( cd usr/lib64/jabberd ; ln -sf mod_iq-version.so.0.0.0 mod_iq-version.so )
( cd usr/lib64/jabberd ; rm -rf mod_session.so )
( cd usr/lib64/jabberd ; ln -sf mod_session.so.0.0.0 mod_session.so )
( cd usr/lib64/jabberd ; rm -rf mod_echo.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_echo.so.0.0.0 mod_echo.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_pep.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_pep.so.0.0.0 mod_pep.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_roster-publish.so )
( cd usr/lib64/jabberd ; ln -sf mod_roster-publish.so.0.0.0 mod_roster-publish.so )
( cd usr/lib64/jabberd ; rm -rf mod_disco.so )
( cd usr/lib64/jabberd ; ln -sf mod_disco.so.0.0.0 mod_disco.so )
( cd usr/lib64/jabberd ; rm -rf mod_template-roster.so )
( cd usr/lib64/jabberd ; ln -sf mod_template-roster.so.0.0.0 mod_template-roster.so )
( cd usr/lib64/jabberd ; rm -rf mod_announce.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_announce.so.0.0.0 mod_announce.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_iq-vcard.so )
( cd usr/lib64/jabberd ; ln -sf mod_iq-vcard.so.0.0.0 mod_iq-vcard.so )
( cd usr/lib64/jabberd ; rm -rf mod_roster-publish.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_roster-publish.so.0.0.0 mod_roster-publish.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_iq-ping.so )
( cd usr/lib64/jabberd ; ln -sf mod_iq-ping.so.0.0.0 mod_iq-ping.so )
( cd usr/lib64/jabberd ; rm -rf mod_iq-private.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_iq-private.so.0.0.0 mod_iq-private.so.0 )
( cd usr/lib64/jabberd ; rm -rf libstorage.so.0 )
( cd usr/lib64/jabberd ; ln -sf libstorage.so.0.0.0 libstorage.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_help.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_help.so.0.0.0 mod_help.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_offline.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_offline.so.0.0.0 mod_offline.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_validate.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_validate.so.0.0.0 mod_validate.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_iq-version.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_iq-version.so.0.0.0 mod_iq-version.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_iq-private.so )
( cd usr/lib64/jabberd ; ln -sf mod_iq-private.so.0.0.0 mod_iq-private.so )
( cd usr/lib64/jabberd ; rm -rf mod_iq-ping.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_iq-ping.so.0.0.0 mod_iq-ping.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_disco.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_disco.so.0.0.0 mod_disco.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_presence.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_presence.so.0.0.0 mod_presence.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_status.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_status.so.0.0.0 mod_status.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_active.so )
( cd usr/lib64/jabberd ; ln -sf mod_active.so.0.0.0 mod_active.so )
( cd usr/lib64/jabberd ; rm -rf mod_amp.so )
( cd usr/lib64/jabberd ; ln -sf mod_amp.so.0.0.0 mod_amp.so )
( cd usr/lib64/jabberd ; rm -rf mod_vacation.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_vacation.so.0.0.0 mod_vacation.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_iq-time.so )
( cd usr/lib64/jabberd ; ln -sf mod_iq-time.so.0.0.0 mod_iq-time.so )
( cd usr/lib64/jabberd ; rm -rf mod_echo.so )
( cd usr/lib64/jabberd ; ln -sf mod_echo.so.0.0.0 mod_echo.so )
( cd usr/lib64/jabberd ; rm -rf mod_deliver.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_deliver.so.0.0.0 mod_deliver.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_pep.so )
( cd usr/lib64/jabberd ; ln -sf mod_pep.so.0.0.0 mod_pep.so )
( cd usr/lib64/jabberd ; rm -rf mod_vacation.so )
( cd usr/lib64/jabberd ; ln -sf mod_vacation.so.0.0.0 mod_vacation.so )
( cd usr/lib64/jabberd ; rm -rf mod_session.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_session.so.0.0.0 mod_session.so.0 )
( cd usr/lib64/jabberd ; rm -rf mod_announce.so )
( cd usr/lib64/jabberd ; ln -sf mod_announce.so.0.0.0 mod_announce.so )
( cd usr/lib64/jabberd ; rm -rf libstorage.so )
( cd usr/lib64/jabberd ; ln -sf libstorage.so.0.0.0 libstorage.so )
( cd usr/lib64/jabberd ; rm -rf mod_presence.so )
( cd usr/lib64/jabberd ; ln -sf mod_presence.so.0.0.0 mod_presence.so )
( cd usr/lib64/jabberd ; rm -rf mod_validate.so )
( cd usr/lib64/jabberd ; ln -sf mod_validate.so.0.0.0 mod_validate.so )
( cd usr/lib64/jabberd ; rm -rf mod_privacy.so )
( cd usr/lib64/jabberd ; ln -sf mod_privacy.so.0.0.0 mod_privacy.so )
( cd usr/lib64/jabberd ; rm -rf mod_amp.so.0 )
( cd usr/lib64/jabberd ; ln -sf mod_amp.so.0.0.0 mod_amp.so.0 )
