Blame SOURCES/sendmail.etc-mail-make

784b94
#!/bin/sh
784b94
# Generate db and cf files if necessary. This used to be handled by
784b94
# /etc/mail/Makefile.
784b94
784b94
teste() {
784b94
  if ! test -e "$1"; then
784b94
    echo "$1 doesn't exist"
784b94
    exit 2
784b94
  fi
784b94
}
784b94
784b94
makedb() {
784b94
  teste "${1%.db}"
784b94
784b94
  if [ -z "$SM_FORCE_DBREBUILD" ]; then
784b94
    test "${1%.db}" -nt "$1" || return 0
784b94
  fi
784b94
784b94
  if [ "$1" = userdb.db ]; then
784b94
    makemap btree "$1" < "${1%.db}"
784b94
  else
784b94
    makemap hash "$1" < "${1%.db}"
784b94
  fi
784b94
}
784b94
784b94
makealiasesdb() {
784b94
  uptodate=1
784b94
784b94
  if [ -z "$SM_FORCE_DBREBUILD" ]; then
784b94
    files=$(grep '^O AliasFile=' sendmail.cf |
784b94
      while read a; do echo ${a#*=}; done)
784b94
784b94
    for a in $files; do
784b94
      if [ "$a" = /etc/aliases ]; then
784b94
        # /etc/aliases.db may be used by other MTA, make sure nothing
784b94
        # has touched it since our last newaliases call
784b94
        test "$a" -nt "${a}.db" ||
784b94
          test aliasesdb-stamp -nt "${a}.db" ||
784b94
          test aliasesdb-stamp -ot "${a}.db" || continue
784b94
      else
784b94
        test "$a" -nt "${a}.db" || continue
784b94
      fi
784b94
784b94
      uptodate=0
784b94
      break
784b94
    done
784b94
  else
784b94
    uptodate=0
784b94
  fi
784b94
784b94
  [ $uptodate = 1 ] && return 0
784b94
784b94
  # check if alternatives is configured to sendmail
784b94
  if [ "$(readlink -e /usr/bin/newaliases)" = /usr/sbin/sendmail.sendmail ]
784b94
  then
784b94
    /usr/bin/newaliases > /dev/null
784b94
    touch -r /etc/aliases.db aliasesdb-stamp 2> /dev/null
784b94
  else
784b94
    rm -f aliasesdb-stamp
784b94
  fi
784b94
}
784b94
784b94
makecf() {
784b94
  mc=${1%.cf}.mc
784b94
784b94
  teste "$mc"
784b94
784b94
  if [ -z "$SM_FORCE_CFREBUILD" ]; then
784b94
    test "$mc" -nt "$1" || return 0
784b94
  fi
784b94
784b94
  if test -f /usr/share/sendmail-cf/m4/cf.m4; then
784b94
    umask 022
784b94
    [ -e "$1" ] && mv -f "$1" "$1".bak
784b94
    m4 "$mc" > "$1"
784b94
  else
784b94
    echo "WARNING: '$mc' is modified. Please install package sendmail-cf to update your configuration."
784b94
    exit 15
784b94
  fi
784b94
}
784b94
784b94
makeall() {
784b94
  # These could be used by sendmail, but are not part of the default install.
784b94
  # To use them you will have to generate your own sendmail.cf with
784b94
  # FEATURE('whatever')
784b94
  test -f bitdomain && makedb bitdomain.db
784b94
  test -f uudomain && makedb uudomain.db
784b94
  test -f genericstable && makedb genericstable.db
784b94
  test -f userdb && makedb userdb.db
784b94
  test -f authinfo && makedb authinfo.db
784b94
784b94
  makedb virtusertable.db
784b94
  makedb access.db
784b94
  makedb domaintable.db
784b94
  makedb mailertable.db
784b94
784b94
  makecf sendmail.cf
784b94
  makecf submit.cf
784b94
}
784b94
784b94
cd /etc/mail || exit 1
784b94
784b94
[ $# -eq 0 ] && makeall
784b94
784b94
for target; do
784b94
  case "$target" in
784b94
    *.db)
784b94
      makedb "$target"
784b94
      ;;
784b94
    *.cf)
784b94
      makecf "$target"
784b94
      ;;
784b94
    all)
784b94
      makeall
784b94
      ;;
784b94
    aliases)
784b94
      makealiasesdb
784b94
      ;;
784b94
    clean)
784b94
      rm -f *.db *~ aliasesdb-stamp
784b94
      ;;
784b94
    start|stop|restart)
784b94
      service sendmail "$target"
784b94
      ;;
784b94
    *)
784b94
      echo "Don't know how to make $target"
784b94
      exit 2
784b94
  esac
784b94
done