config() {
  NEW="$1"
  OLD="$(dirname $NEW)/$(basename $NEW .new)"
  if [ ! -r $OLD ]; then
    mv $NEW $OLD
  elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then
    rm $NEW
  fi
}

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
}

preserve_perms etc/rc.d/rc.lxc.new
config etc/lxc/default.conf.new
config etc/default/lxc.new

( cd etc/bash_completion.d ; rm -rf lxc-attach )
( cd etc/bash_completion.d ; ln -sf lxc lxc-attach )
( cd etc/bash_completion.d ; rm -rf lxc-autostart )
( cd etc/bash_completion.d ; ln -sf lxc lxc-autostart )
( cd etc/bash_completion.d ; rm -rf lxc-cgroup )
( cd etc/bash_completion.d ; ln -sf lxc lxc-cgroup )
( cd etc/bash_completion.d ; rm -rf lxc-checkpoint )
( cd etc/bash_completion.d ; ln -sf lxc lxc-checkpoint )
( cd etc/bash_completion.d ; rm -rf lxc-config )
( cd etc/bash_completion.d ; ln -sf lxc lxc-config )
( cd etc/bash_completion.d ; rm -rf lxc-console )
( cd etc/bash_completion.d ; ln -sf lxc lxc-console )
( cd etc/bash_completion.d ; rm -rf lxc-copy )
( cd etc/bash_completion.d ; ln -sf lxc lxc-copy )
( cd etc/bash_completion.d ; rm -rf lxc-create )
( cd etc/bash_completion.d ; ln -sf lxc lxc-create )
( cd etc/bash_completion.d ; rm -rf lxc-destroy )
( cd etc/bash_completion.d ; ln -sf lxc lxc-destroy )
( cd etc/bash_completion.d ; rm -rf lxc-device )
( cd etc/bash_completion.d ; ln -sf lxc lxc-device )
( cd etc/bash_completion.d ; rm -rf lxc-execute )
( cd etc/bash_completion.d ; ln -sf lxc lxc-execute )
( cd etc/bash_completion.d ; rm -rf lxc-freeze )
( cd etc/bash_completion.d ; ln -sf lxc lxc-freeze )
( cd etc/bash_completion.d ; rm -rf lxc-info )
( cd etc/bash_completion.d ; ln -sf lxc lxc-info )
( cd etc/bash_completion.d ; rm -rf lxc-ls )
( cd etc/bash_completion.d ; ln -sf lxc lxc-ls )
( cd etc/bash_completion.d ; rm -rf lxc-monitor )
( cd etc/bash_completion.d ; ln -sf lxc lxc-monitor )
( cd etc/bash_completion.d ; rm -rf lxc-snapshot )
( cd etc/bash_completion.d ; ln -sf lxc lxc-snapshot )
( cd etc/bash_completion.d ; rm -rf lxc-start )
( cd etc/bash_completion.d ; ln -sf lxc lxc-start )
( cd etc/bash_completion.d ; rm -rf lxc-stop )
( cd etc/bash_completion.d ; ln -sf lxc lxc-stop )
( cd etc/bash_completion.d ; rm -rf lxc-top )
( cd etc/bash_completion.d ; ln -sf lxc lxc-top )
( cd etc/bash_completion.d ; rm -rf lxc-unfreeze )
( cd etc/bash_completion.d ; ln -sf lxc lxc-unfreeze )
( cd etc/bash_completion.d ; rm -rf lxc-unshare )
( cd etc/bash_completion.d ; ln -sf lxc lxc-unshare )
( cd etc/bash_completion.d ; rm -rf lxc-usernsexec )
( cd etc/bash_completion.d ; ln -sf lxc lxc-usernsexec )
( cd etc/bash_completion.d ; rm -rf lxc-wait )
( cd etc/bash_completion.d ; ln -sf lxc lxc-wait )
( cd usr/lib64 ; rm -rf liblxc.so )
( cd usr/lib64 ; ln -sf liblxc.so.1 liblxc.so )
( cd usr/lib64 ; rm -rf liblxc.so.1 )
( cd usr/lib64 ; ln -sf liblxc.so.1.7.0 liblxc.so.1 )
