Blame SOURCES/sendmail.etc-mail-make

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