MXBackup

by plumata
6 deployments · 1 still active · last rev. 6 years ago

StackScript for a MX Backup configuration.

Compatible with: No distros currently supported
						#!/bin/bash
#
# mxbackup
#
# Summary: Installs Postix on Debian platforms as an MX backup. Tested on Ubuntu 9.10 i686 (32bit).
#
# Copyright (c) 2010, Charles Hooper <chooper@plumata.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, 
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# * Neither the name of Plumata LLC nor the names of its contributors may be
# used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

# <udf name="mailname" label="Choose a mailname, often times this is the hostname">
# <udf name="postmaster" label="Postmaster email address (not local.)" example="your.email@gmail.com">

# Write out preseed file
cat > /tmp/postfix-preseed.cfg << EOF
postfix postfix/root_address    string
postfix postfix/rfc1035_violation       boolean false
postfix postfix/retry_upgrade_warning   boolean
postfix postfix/kernel_version_warning  boolean
postfix postfix/mydomain_warning        boolean
postfix postfix/mynetworks      string  127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
postfix postfix/not_configured  error
postfix postfix/mailbox_limit   string  0
postfix postfix/relayhost       string
postfix postfix/procmail        boolean
postfix postfix/bad_recipient_delimiter error
postfix postfix/protocols       select
postfix postfix/mailname        string  /etc/mailname
postfix postfix/tlsmgr_upgrade_warning  boolean
postfix postfix/recipient_delim string  +
postfix postfix/main_mailer_type        select  No configuration
postfix postfix/destinations    string
postfix postfix/chattr  boolean false
EOF

# New sources.list
cat > /etc/apt/sources.list << EOF
## main & restricted repositories
deb http://us.archive.ubuntu.com/ubuntu/ karmic main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ karmic main restricted

deb http://security.ubuntu.com/ubuntu karmic-security main restricted
deb-src http://security.ubuntu.com/ubuntu karmic-security main restricted

## universe repositories
deb http://us.archive.ubuntu.com/ubuntu/ karmic universe
deb-src http://us.archive.ubuntu.com/ubuntu/ karmic universe
deb http://us.archive.ubuntu.com/ubuntu/ karmic-updates universe
deb-src http://us.archive.ubuntu.com/ubuntu/ karmic-updates universe

deb http://security.ubuntu.com/ubuntu karmic-security universe
deb-src http://security.ubuntu.com/ubuntu karmic-security universe
EOF

# Update
apt-get -y update && apt-get -y upgrade

# Install debconf-utils so we can _use_ our preseed file
apt-get -y install debconf-utils

# Load preseed file
debconf-set-selections /tmp/postfix-preseed.cfg

# Install postfix et. al
apt-get -y install postfix postfix-doc pflogsumm

# Open up submission port
sed -i -e "s/#submission/submission/" /etc/postfix/master.cf

# Create/write out config files
cat > /etc/postfix/main.cf << EOF
# See /usr/share/postfix/main.cf.dist for a commented, more complete version

# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
myorigin = /etc/mailname

smtpd_banner = \$myhostname ESMTP \$mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

####
# Disable local delivery
mydestination =
local_recipient_maps =
local_transport = error:local mail delivery is disabled
virtual_alias_maps = hash:/etc/postfix/virtual

mynetworks = 127.0.0.0/8

parent_domain_matches_subdomains =
    debug_peer_list,
    smtpd_access_maps

smtpd_recipient_restrictions =
    permit_mynetworks,
    reject_unauth_destination

# Relay and specify smarthost
transport_maps = hash:/etc/postfix/transport
relay_domains = hash:/etc/postfix/transport

show_user_unknown_table_name = no

# Misc config
message_size_limit = 30720000
EOF

cat > /etc/postfix/virtual << EOF
postmaster      ${POSTMASTER}
abuse           ${POSTMASTER}
root            ${POSTMASTER}
security        ${POSTMASTER}
admin           ${POSTMASTER}
support         ${POSTMASTER}
EOF

# transport will have to be filled in after install
echo -n "" > /etc/postfix/transport

echo -n "${MAILNAME}" > /etc/mailname

# Write reload script
cat > /etc/postfix/reload << EOF
#!/bin/bash
# Build hashes and reload postfix
postmap /etc/postfix/virtual
postmap /etc/postfix/transport
postfix reload
EOF
chmod +x /etc/postfix/reload

/etc/postfix/reload