Blame SOURCES/sendmail.etc-mail-make

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