( cd usr/bin ; rm -rf avahi-publish-service )
( cd usr/bin ; ln -sf avahi-publish avahi-publish-service )
( cd usr/bin ; rm -rf bvnc )
( cd usr/bin ; ln -sf bssh bvnc )
( cd usr/bin ; rm -rf bshell )
( cd usr/bin ; ln -sf bssh bshell )
( cd usr/bin ; rm -rf avahi-browse-domains )
( cd usr/bin ; ln -sf avahi-browse avahi-browse-domains )
( cd usr/bin ; rm -rf avahi-resolve-address )
( cd usr/bin ; ln -sf avahi-resolve avahi-resolve-address )
( cd usr/bin ; rm -rf avahi-publish-address )
( cd usr/bin ; ln -sf avahi-publish avahi-publish-address )
( cd usr/bin ; rm -rf avahi-resolve-host-name )
( cd usr/bin ; ln -sf avahi-resolve avahi-resolve-host-name )
( cd usr/lib64 ; rm -rf libavahi-glib.so )
( cd usr/lib64 ; ln -sf libavahi-glib.so.1.0.1 libavahi-glib.so )
( cd usr/lib64 ; rm -rf libavahi-core.so )
( cd usr/lib64 ; ln -sf libavahi-core.so.6.0.1 libavahi-core.so )
( cd usr/lib64 ; rm -rf libavahi-gobject.so )
( cd usr/lib64 ; ln -sf libavahi-gobject.so.0.0.1 libavahi-gobject.so )
( cd usr/lib64 ; rm -rf libavahi-core.so.6 )
( cd usr/lib64 ; ln -sf libavahi-core.so.6.0.1 libavahi-core.so.6 )
( cd usr/lib64 ; rm -rf libavahi-ui.so.0 )
( cd usr/lib64 ; ln -sf libavahi-ui.so.0.1.1 libavahi-ui.so.0 )
( cd usr/lib64 ; rm -rf libavahi-common.so.3 )
( cd usr/lib64 ; ln -sf libavahi-common.so.3.5.1 libavahi-common.so.3 )
( cd usr/lib64 ; rm -rf libavahi-client.so.3 )
( cd usr/lib64 ; ln -sf libavahi-client.so.3.2.5 libavahi-client.so.3 )
( cd usr/lib64 ; rm -rf libavahi-client.so )
( cd usr/lib64 ; ln -sf libavahi-client.so.3.2.5 libavahi-client.so )
( cd usr/lib64 ; rm -rf libavahi-common.so )
( cd usr/lib64 ; ln -sf libavahi-common.so.3.5.1 libavahi-common.so )
( cd usr/lib64 ; rm -rf libavahi-glib.so.1 )
( cd usr/lib64 ; ln -sf libavahi-glib.so.1.0.1 libavahi-glib.so.1 )
( cd usr/lib64 ; rm -rf libavahi-ui.so )
( cd usr/lib64 ; ln -sf libavahi-ui.so.0.1.1 libavahi-ui.so )
( cd usr/lib64 ; rm -rf libavahi-gobject.so.0 )
( cd usr/lib64 ; ln -sf libavahi-gobject.so.0.0.1 libavahi-gobject.so.0 )
( 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 )
( 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 bvnc.1.gz )
( cd usr/man/man1 ; ln -sf bssh.1.gz bvnc.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-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 )

# Version: 1.0 - Do not remove this line!

# Update new libraries
ldconfig -r .

# Preserve new configuration files
function install_file() {
  # $1 = File to process
  FILE="$(dirname "$1")/$(basename "$1" .new)"
  if [ ! -e "$FILE" ]
  then
    mv "$FILE.new" "$FILE"
  elif [ "$(cat "$FILE" | md5sum)" != "$(cat "$FILE.new" | md5sum)" ]
  then
    #     |--------|--------------------------------------------------|
    echo "WARNING: $FILE has been customised."
    echo "         Examine the $FILE.new file"
    echo "         and integrate any changes into the custom file."
    echo
  else
    rm -f "$FILE.new"
  fi
}

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

# Warn is dbus is not installed
if [ ! -e usr/bin/dbus-daemon ]; then
  #     |--------|--------------------------------------------------|
  echo "WARNING: The dbus messaging system is not installed."
  echo "         You MUST have the Slackware dbus package installed"
  echo "         for GSB to work correctly."
  echo
  # Note: Do not disable avahi here (as was here in a previous version) as
  #       the user has been warned on the problems.  We can't be responsible
  #       for users not being able to install Slackware correctly :)
fi

# Warn is dbus is not started at boot
if [ ! -x etc/rc.d/rc.messagebus ]; then
  #     |--------|--------------------------------------------------|
  echo "WARNING: The dbus messaging system is not enabled."
  echo "         You MUST have dbus enabled for GSB to work correctly."
  echo "         To enable dbus, chmod rc.messagebus 755."
  echo
  # Note: Do not adjust permissions here (as was done in a previous version) as
  #       the user has been warned on the problems.  We can't be responsible
  #       for users not being able to install Slackware correctly :)
fi

# Reload messagebus service
if [ -x etc/rc.d/rc.messagebus ]; then
  chroot . /etc/rc.d/rc.messagebus reload
fi
