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.9.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 )
