( cd usr/bin ; rm -rf avahi-resolve-host-name )
( cd usr/bin ; ln -sf avahi-resolve avahi-resolve-host-name )
( cd usr/bin ; rm -rf avahi-publish-address )
( cd usr/bin ; ln -sf avahi-publish avahi-publish-address )
( cd usr/bin ; rm -rf bshell )
( cd usr/bin ; ln -sf bssh bshell )
( cd usr/bin ; rm -rf avahi-resolve-address )
( cd usr/bin ; ln -sf avahi-resolve avahi-resolve-address )
( cd usr/bin ; rm -rf avahi-browse-domains )
( cd usr/bin ; ln -sf avahi-browse avahi-browse-domains )
( cd usr/bin ; rm -rf bvnc )
( cd usr/bin ; ln -sf bssh bvnc )
( cd usr/bin ; rm -rf avahi-publish-service )
( cd usr/bin ; ln -sf avahi-publish avahi-publish-service )
( cd usr/lib64 ; rm -rf libavahi-ui-gtk3.so )
( cd usr/lib64 ; ln -sf libavahi-ui-gtk3.so.0.1.4 libavahi-ui-gtk3.so )
( cd usr/lib64 ; rm -rf libavahi-gobject.so )
( cd usr/lib64 ; ln -sf libavahi-gobject.so.0.0.4 libavahi-gobject.so )
( cd usr/lib64 ; rm -rf libavahi-common.so )
( cd usr/lib64 ; ln -sf libavahi-common.so.3.5.3 libavahi-common.so )
( cd usr/lib64 ; rm -rf libavahi-glib.so )
( cd usr/lib64 ; ln -sf libavahi-glib.so.1.0.2 libavahi-glib.so )
( cd usr/lib64 ; rm -rf libavahi-ui-gtk3.so.0 )
( cd usr/lib64 ; ln -sf libavahi-ui-gtk3.so.0.1.4 libavahi-ui-gtk3.so.0 )
( cd usr/lib64 ; rm -rf libavahi-common.so.3 )
( cd usr/lib64 ; ln -sf libavahi-common.so.3.5.3 libavahi-common.so.3 )
( cd usr/lib64 ; rm -rf libavahi-core.so.7 )
( cd usr/lib64 ; ln -sf libavahi-core.so.7.0.2 libavahi-core.so.7 )
( cd usr/lib64 ; rm -rf libavahi-client.so.3 )
( cd usr/lib64 ; ln -sf libavahi-client.so.3.2.9 libavahi-client.so.3 )
( cd usr/lib64 ; rm -rf libavahi-client.so )
( cd usr/lib64 ; ln -sf libavahi-client.so.3.2.9 libavahi-client.so )
( cd usr/lib64 ; rm -rf libavahi-core.so )
( cd usr/lib64 ; ln -sf libavahi-core.so.7.0.2 libavahi-core.so )
( cd usr/lib64 ; rm -rf libavahi-gobject.so.0 )
( cd usr/lib64 ; ln -sf libavahi-gobject.so.0.0.4 libavahi-gobject.so.0 )
( cd usr/lib64 ; rm -rf libavahi-glib.so.1 )
( cd usr/lib64 ; ln -sf libavahi-glib.so.1.0.2 libavahi-glib.so.1 )
( cd usr/man/man1 ; rm -rf avahi-resolve-address.1.gz )
( cd usr/man/man1 ; ln -sf avahi-resolve.1.gz avahi-resolve-address.1.gz )
( cd usr/man/man1 ; rm -rf avahi-resolve-host-name.1.gz )
( cd usr/man/man1 ; ln -sf avahi-resolve.1.gz avahi-resolve-host-name.1.gz )
( cd usr/man/man1 ; rm -rf avahi-publish-service.1.gz )
( cd usr/man/man1 ; ln -sf avahi-publish.1.gz avahi-publish-service.1.gz )
( cd usr/man/man1 ; rm -rf avahi-browse-domains.1.gz )
( cd usr/man/man1 ; ln -sf avahi-browse.1.gz avahi-browse-domains.1.gz )
( cd usr/man/man1 ; rm -rf avahi-publish-address.1.gz )
( cd usr/man/man1 ; ln -sf avahi-publish.1.gz avahi-publish-address.1.gz )

# Preserve new configuration files
install_file() {
  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...
}

install_file etc/avahi/avahi-daemon.conf.new
install_file etc/rc.d/rc.avahidaemon.new
install_file etc/rc.d/rc.avahidnsconfd.new
install_file etc/dbus-1/system.d/avahi-dbus.conf.new
#install_file etc/dbus-1/system-local.conf.new

# If the netdev and avahi groups don't exist, add them
if ! grep "^avahi:" etc/group >/dev/null 2>&1; then
  echo "avahi:x:85:" >>etc/group
fi
if ! grep "^avahi:" etc/gshadow >/dev/null 2>&1; then
  echo "avahi:*::" >>etc/gshadow
fi
if ! grep "^avahi-autoipd:" etc/group >/dev/null 2>&1; then
  echo "avahi-autoipd:x:88:" >>etc/group
fi
if ! grep "^avahi-autoipd:" etc/gshadow >/dev/null 2>&1; then
  echo "avahi-autoipd:*::" >>etc/gshadow
fi

# If the avahi-autoipd user doesn't exist, add it
if ! grep "^avahi-autoipd:" etc/passwd >/dev/null 2>&1; then
  echo "avahi-autoipd:x:88:88:avahi-autoipd:/etc/avahi:/bin/false" >>etc/passwd
fi
if ! grep "^avahi-autoipd:" etc/shadow >/dev/null 2>&1; then
  echo "avahi-autoipd:*:9797:0:::::" >>etc/shadow
fi

# If the avahi user doesn't exist, add it
if ! grep "^avahi:" etc/passwd >/dev/null 2>&1; then
  echo "avahi:x:85:85:avahi:/etc/avahi:/bin/false" >>etc/passwd
fi
if ! grep "^avahi:" etc/shadow >/dev/null 2>&1; then
  echo "avahi:*:9797:0:::::" >>etc/shadow
fi

# If rc.local doesn't exist, create it
if [ ! -e etc/rc.d/rc.local ]; then
  echo "#!/bin/sh" >etc/rc.d/rc.local
  chmod 755 etc/rc.d/rc.local
fi

# If rc.local_shutdown doesn't exist, create it
if [ ! -e etc/rc.d/rc.local_shutdown ]; then
  echo "#!/bin/sh" >etc/rc.d/rc.local_shutdown
  chmod 755 etc/rc.d/rc.local_shutdown
fi

# Add service start to rc.local
if ! grep "/etc/rc.d/rc.avahidaemon" etc/rc.d/rc.local >/dev/null 2>&1; then
  cat <<EOF >>etc/rc.d/rc.local

# To disable avahi, chmod rc.avahidaemon and rc.avahidnsconfd to 644
if [ -x /etc/rc.d/rc.avahidaemon -a -x /etc/rc.d/rc.avahidnsconfd ]; then
  /etc/rc.d/rc.avahidaemon start
  /etc/rc.d/rc.avahidnsconfd start
fi
EOF
fi

# Add service shutdown to rc.local_shutdown
if ! grep "/etc/rc.d/rc.avahidaemon" etc/rc.d/rc.local_shutdown >/dev/null 2>&1; then
  cat << EOF >>etc/rc.d/rc.local_shutdown

if [ -x /etc/rc.d/rc.avahidaemon -a -x /etc/rc.d/rc.avahidnsconfd ]; then
  /etc/rc.d/rc.avahidaemon stop
  /etc/rc.d/rc.avahidnsconfd stop
fi
EOF
fi

# Update desktop database
if [ -x usr/bin/update-desktop-database ]; then
  usr/bin/update-desktop-database >/dev/null 2>&1
fi
