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/pulse/client.conf.new
config etc/pulse/daemon.conf.new
config etc/pulse/default.pa.new
config etc/pulse/system.pa.new
preserve_perms etc/rc.d/rc.pulseaudio.new

# Make sure the pulse user is in the audio group:
chroot . /usr/sbin/usermod -a -G audio pulse 1> /dev/null 2> /dev/null

# Make sure the root user is in the audio group:
chroot . /usr/sbin/usermod -a -G audio root 1> /dev/null 2> /dev/null

( cd usr/bin ; rm -rf pamon )
( cd usr/bin ; ln -sf pacat pamon )
( cd usr/bin ; rm -rf paplay )
( cd usr/bin ; ln -sf pacat paplay )
( cd usr/bin ; rm -rf parecord )
( cd usr/bin ; ln -sf pacat parecord )
( cd usr/bin ; rm -rf parec )
( cd usr/bin ; ln -sf pacat parec )
( cd usr/man/man1 ; rm -rf parecord.1.gz )
( cd usr/man/man1 ; ln -sf pacat.1.gz parecord.1.gz )
( cd usr/man/man1 ; rm -rf paplay.1.gz )
( cd usr/man/man1 ; ln -sf pacat.1.gz paplay.1.gz )
( cd usr/man/man1 ; rm -rf pamon.1.gz )
( cd usr/man/man1 ; ln -sf pacat.1.gz pamon.1.gz )
( cd usr/man/man1 ; rm -rf parec.1.gz )
( cd usr/man/man1 ; ln -sf pacat.1.gz parec.1.gz )
( cd usr/share/bash-completion/completions ; rm -rf pacat )
( cd usr/share/bash-completion/completions ; ln -sf pulseaudio pacat )
( cd usr/share/bash-completion/completions ; rm -rf padsp )
( cd usr/share/bash-completion/completions ; ln -sf pulseaudio padsp )
( cd usr/share/bash-completion/completions ; rm -rf pacmd )
( cd usr/share/bash-completion/completions ; ln -sf pulseaudio pacmd )
( cd usr/share/bash-completion/completions ; rm -rf paplay )
( cd usr/share/bash-completion/completions ; ln -sf pulseaudio paplay )
( cd usr/share/bash-completion/completions ; rm -rf parecord )
( cd usr/share/bash-completion/completions ; ln -sf pulseaudio parecord )
( cd usr/share/bash-completion/completions ; rm -rf parec )
( cd usr/share/bash-completion/completions ; ln -sf pulseaudio parec )
( cd usr/share/bash-completion/completions ; rm -rf pactl )
( cd usr/share/bash-completion/completions ; ln -sf pulseaudio pactl )
( cd usr/share/bash-completion/completions ; rm -rf pasuspender )
( cd usr/share/bash-completion/completions ; ln -sf pulseaudio pasuspender )
( cd usr/lib64 ; rm -rf libpulse-mainloop-glib.so )
( cd usr/lib64 ; ln -sf libpulse-mainloop-glib.so.0.0.5 libpulse-mainloop-glib.so )
( cd usr/lib64 ; rm -rf libpulse-simple.so.0 )
( cd usr/lib64 ; ln -sf libpulse-simple.so.0.1.0 libpulse-simple.so.0 )
( cd usr/lib64 ; rm -rf libpulse-mainloop-glib.so.0 )
( cd usr/lib64 ; ln -sf libpulse-mainloop-glib.so.0.0.5 libpulse-mainloop-glib.so.0 )
( cd usr/lib64 ; rm -rf libpulse-simple.so )
( cd usr/lib64 ; ln -sf libpulse-simple.so.0.1.0 libpulse-simple.so )
( cd usr/lib64 ; rm -rf libpulse.so )
( cd usr/lib64 ; ln -sf libpulse.so.0.20.0 libpulse.so )
( cd usr/lib64 ; rm -rf libpulse.so.0 )
( cd usr/lib64 ; ln -sf libpulse.so.0.20.0 libpulse.so.0 )
