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 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 )
( cd usr/share/bash-completion/completions ; rm -rf lxc-attach )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-attach )
( cd usr/share/bash-completion/completions ; rm -rf lxc-autostart )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-autostart )
( cd usr/share/bash-completion/completions ; rm -rf lxc-cgroup )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-cgroup )
( cd usr/share/bash-completion/completions ; rm -rf lxc-checkpoint )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-checkpoint )
( cd usr/share/bash-completion/completions ; rm -rf lxc-config )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-config )
( cd usr/share/bash-completion/completions ; rm -rf lxc-console )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-console )
( cd usr/share/bash-completion/completions ; rm -rf lxc-copy )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-copy )
( cd usr/share/bash-completion/completions ; rm -rf lxc-create )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-create )
( cd usr/share/bash-completion/completions ; rm -rf lxc-destroy )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-destroy )
( cd usr/share/bash-completion/completions ; rm -rf lxc-device )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-device )
( cd usr/share/bash-completion/completions ; rm -rf lxc-execute )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-execute )
( cd usr/share/bash-completion/completions ; rm -rf lxc-freeze )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-freeze )
( cd usr/share/bash-completion/completions ; rm -rf lxc-info )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-info )
( cd usr/share/bash-completion/completions ; rm -rf lxc-ls )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-ls )
( cd usr/share/bash-completion/completions ; rm -rf lxc-monitor )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-monitor )
( cd usr/share/bash-completion/completions ; rm -rf lxc-snapshot )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-snapshot )
( cd usr/share/bash-completion/completions ; rm -rf lxc-start )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-start )
( cd usr/share/bash-completion/completions ; rm -rf lxc-stop )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-stop )
( cd usr/share/bash-completion/completions ; rm -rf lxc-top )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-top )
( cd usr/share/bash-completion/completions ; rm -rf lxc-unfreeze )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-unfreeze )
( cd usr/share/bash-completion/completions ; rm -rf lxc-unshare )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-unshare )
( cd usr/share/bash-completion/completions ; rm -rf lxc-usernsexec )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-usernsexec )
( cd usr/share/bash-completion/completions ; rm -rf lxc-wait )
( cd usr/share/bash-completion/completions ; ln -sf lxc lxc-wait )
