Blame SOURCES/sendmail.etc-mail-make

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