isp-tools

git clone http://git.code.weiherhei.de/isp-tools.git
Log | Files | Refs | README

update_mta (1892B)


      1 #!/bin/bash
      2 
      3 CONFIG=/etc/default/ispconfig
      4 
      5 if [ ! -f $CONFIG  ]; then
      6     echo "File $CONFIG not found"
      7     exit 4;
      8 fi
      9 
     10 source $CONFIG
     11 
     12 
     13 # Datenbank
     14 function sql {
     15     sql=$1
     16     mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -se "$sql" $MYSQL_DATABASE
     17 }
     18 
     19 
     20 
     21 function create_map {
     22     mapfile=$MTA_CONFIG_DIR/$1
     23     sql=$2
     24     echo "# AUTO-GENERATED BY $0 - DO NOT CHANGE!" > $mapfile
     25     sql "$sql"|while read key value; do
     26 	echo $key $value >> $mapfile
     27     done
     28     echo "" >> $mapfile
     29     
     30     # Adding to SCM
     31     hg -R $MTA_CONFIG_DIR add $mapfile
     32     
     33     # Compile Postfix map
     34     /usr/sbin/postmap $mapfile
     35 }
     36 
     37 
     38 last_mail_modified=`sql "select unix_timestamp(max(modified)) FROM (select modified from mailbox union all select modified FROM alias) as modified"`
     39 last_file_modified=`stat --format %Y $MTA_CONFIG_DIR/transport`
     40 
     41 if [ ! "$last_mail_modified" -gt "$last_file_modified" ]; then
     42     exit 0; # all up to date, nothing to do.
     43 fi
     44 
     45 
     46 
     47 create_map transport        "select distinct domain,'virtual:' from alias where active=1"
     48 create_map aliases          "select address,goto from alias where active=1"
     49 create_map sender           "select concat(local_part,'@',domain),concat(local_part,'@',domain) from mailbox where active=1"
     50 create_map virtualforward   "select '# n/a','' from mailbox where active=1"
     51 create_map accounts         "select concat(local_part,'@',domain) , concat(maildir,'/') from mailbox where active=1"
     52 create_map accountsmap      "select concat(local_part,'@',domain) , concat(local_part,'@',domain) from mailbox where active=1"
     53 
     54 # Ablehnen: Deaktivierte Mailboxen und deaktivierte Aliases
     55 create_map recipient_reject "select concat(local_part,'@',domain), 'REJECT' from mailbox where active=0 union select address,'REJECT' from alias where active=0"
     56 
     57 hg -R $MTA_CONFIG_DIR diff
     58 hg -R $MTA_CONFIG_DIR commit -u `whoami` -m "Updating Postfix configuration"
     59 
     60 postfix reload