Subversion Repositories configs

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 - 1
#!/bin/sh
2
# Generate db and cf files if necessary. This used to be handled by
3
# /etc/mail/Makefile.
4
 
5
teste() {
6
  if ! test -e "$1"; then
7
    echo "$1 doesn't exist"
8
    exit 2
9
  fi
10
}
11
 
12
makedb() {
13
  teste "${1%.db}"
14
 
15
  if [ -z "$SM_FORCE_DBREBUILD" ]; then
16
    test "${1%.db}" -nt "$1" || return 0
17
  fi
18
 
19
  if [ "$1" = userdb.db ]; then
20
    makemap btree "$1" < "${1%.db}"
21
  else
22
    makemap hash "$1" < "${1%.db}"
23
  fi
24
}
25
 
26
makealiasesdb() {
27
  uptodate=1
28
 
29
  if [ -z "$SM_FORCE_DBREBUILD" ]; then
30
    files=$(grep '^O AliasFile=' sendmail.cf |
31
      while read a; do echo ${a#*=}; done)
32
 
33
    for a in $files; do
34
      if [ "$a" = /etc/aliases ]; then
35
        # /etc/aliases.db may be used by other MTA, make sure nothing
36
        # has touched it since our last newaliases call
37
        test "$a" -nt "${a}.db" ||
38
          test aliasesdb-stamp -nt "${a}.db" ||
39
          test aliasesdb-stamp -ot "${a}.db" || continue
40
      else
41
        test "$a" -nt "${a}.db" || continue
42
      fi
43
 
44
      uptodate=0
45
      break
46
    done
47
  else
48
    uptodate=0
49
  fi
50
 
51
  [ $uptodate = 1 ] && return 0
52
 
53
  # check if alternatives is configured to sendmail
54
  if [ "$(readlink -e /usr/bin/newaliases)" = /usr/sbin/sendmail.sendmail ]
55
  then
56
    /usr/bin/newaliases > /dev/null
57
    touch -r /etc/aliases.db aliasesdb-stamp 2> /dev/null
58
  else
59
    rm -f aliasesdb-stamp
60
  fi
61
}
62
 
63
makecf() {
64
  mc=${1%.cf}.mc
65
 
66
  teste "$mc"
67
 
68
  if [ -z "$SM_FORCE_CFREBUILD" ]; then
69
    test "$mc" -nt "$1" || return 0
70
  fi
71
 
72
  if test -f /usr/share/sendmail-cf/m4/cf.m4; then
73
    umask 022
74
    [ -e "$1" ] && mv -f "$1" "$1".bak
75
    m4 "$mc" > "$1"
76
  else
77
    echo "WARNING: '$mc' is modified. Please install package sendmail-cf to update your configuration."
78
    exit 15
79
  fi
80
}
81
 
82
makeall() {
83
  # These could be used by sendmail, but are not part of the default install.
84
  # To use them you will have to generate your own sendmail.cf with
85
  # FEATURE('whatever')
86
  test -f bitdomain && makedb bitdomain.db
87
  test -f uudomain && makedb uudomain.db
88
  test -f genericstable && makedb genericstable.db
89
  test -f userdb && makedb userdb.db
90
  test -f authinfo && makedb authinfo.db
91
 
92
  makedb virtusertable.db
93
  makedb access.db
94
  makedb domaintable.db
95
  makedb mailertable.db
96
 
97
  makecf sendmail.cf
98
  makecf submit.cf
99
}
100
 
101
cd /etc/mail || exit 1
102
 
103
[ $# -eq 0 ] && makeall
104
 
105
for target; do
106
  case "$target" in
107
    *.db)
108
      makedb "$target"
109
      ;;
110
    *.cf)
111
      makecf "$target"
112
      ;;
113
    all)
114
      makeall
115
      ;;
116
    aliases)
117
      makealiasesdb
118
      ;;
119
    clean)
120
      rm -f *.db *~ aliasesdb-stamp
121
      ;;
122
    start|stop|restart)
123
      service sendmail "$target"
124
      ;;
125
    *)
126
      echo "Don't know how to make $target"
127
      exit 2
128
  esac
129
done