#!/bin/sh
set -e
export LC_ALL=C

install_from_default() {
  if [ ! -f $2 ]; then
    cp -p $1 $2
  fi
}

update_to_current_default() {
  if [ -f $2 ]; then
    md5=`md5sum $2 | cut -f 1 -d " "`
    case "$md5" in
      # base-files 3.0.0 to 3.1.15
      109e33e2c91d1853b5bc56078a96aa18)
        ;;
      # base-files 3.1.8 and 3.1.9
      3114ea9cf2f3bd8d120b4da96e3832d5)
        ;;
      # base-files 3.1.16 to 7.2 and libc-bin 2.19-18 to 2.22-11
      295c15c4bdac80e50b37689ef08f359c)
        ;;
      # base-files 6.6
      30b82cb1ce20d480703da2208a4607b4)
        ;;
      # base-files 7.3 and libc-bin 2.22-12
      f8e97bf611374634c7cb3a6085503ab5)
        ;;
      # modified file
      *)
        return
        ;;
    esac
    if ! cmp -s $1 $2; then
      echo "Updating $2 to current default."
      cp -p $1 $2
    fi
  fi
}

if [ "$1" = "configure" ] && [ "$2" = "" ] ; then
  install_from_default /usr/share/libc-bin/nsswitch.conf /etc/nsswitch.conf
fi

if [ "$1" = "configure" ] && [ "$2" != "" ]; then
  update_to_current_default /usr/share/libc-bin/nsswitch.conf /etc/nsswitch.conf
fi

if [ "$1" = "triggered" ] || [ "$1" = "configure" ]; then
  LDCONFIG_NOTRIGGER=y
  export LDCONFIG_NOTRIGGER
  ldconfig || ldconfig --verbose
  exit 0
fi



exit 0

