Merge branch 'master' of https://github.com/adefaria/clearscm
[clearscm.git] / bin / setup_ssmtp
1 #!/bin/bash
2 ################################################################################
3 #
4 # File:         $RCSfile; $
5 # Revision:     $Revision: 1.2 $
6 # Description:  This script sets up ssmtp mail configuration
7 # Author:       Andrew@DeFaria.com
8 # Created:      Wed Jan  9 12:57:13  2002
9 # Modified:     $Date: 2010/06/08 15:03:27 $
10 # Language:     Bash
11 #
12 # (c) Copyright 2002, ClearSCM, Inc., all rights reserved
13 #
14 ################################################################################
15 # Setup /etc/ssmtp config directory
16 ssmtp_dir=/etc/ssmtp
17 domain=$1
18 mail_server=$2
19 me=$(basename $0)
20
21 function usage {
22   msg="$1"
23
24   echo "$me: <mail_server> <domain>"
25
26   if [ ! -z "$msg" ]; then
27     echo $msg
28   fi
29
30   exit 1
31 } # usage
32
33 if [ -z "$mail_server" ]; then
34   usage "Mail_server not specified"
35 fi
36
37 if [ -z "$domain" ]; then
38   usage "Domain not specified"
39 fi
40
41 mkdir -p $ssmtp_dir
42 chmod 700 $ssmtp_dir
43
44 # Make some simple aliases. Alias $USER to the proper email address and then
45 # alias root, Administrator and postmaster to the user's address thus making
46 # the user "god" of smtp on this machine only.
47 cat > $ssmtp_dir/revaliases <<EOF
48 # sSMTP aliases
49
50 # Format:       local_account:outgoing_address:mailhub
51 #
52 # Example: root:your_login@your.domain:mailhub.your.domain:[port]
53 # where [port] is an optional port number that defaults to 25.
54 $USER:$USER@$domain:$mail_server:25
55 root:$USER@$domain:$mail_server:25
56 Administrator:$USER@$domain:$mail_server:25
57 postmaster:$USER@$domain:$mail_server:25
58 EOF
59
60 # Get a downshifted hostname
61 hostname=$(hostname | tr '[:upper:]' '[:lower:]')
62
63 # Make ssmtp.conf
64 cat > $ssmtp_dir/ssmtp.conf <<EOF
65 # ssmtp.conf: Config file for Cygwin's sstmp sendmail
66 #
67 # The person who gets all mail for userids < 10
68 root=postmaster
69 # The place where the mail goes. The actual machine name is required
70 # no MX records are consulted. Commonly mailhosts are named mail.domain.com
71 # The example will fit if you are in domain.com and you mailhub is so named.
72 mailhub=$mail_server
73 # Where will the mail seem to come from?
74 #rewriteDomain=$USER.$domain
75 # The full hostname
76 hostname=$hostname.$domain
77 # Set this to never rewrite the "From:" line (unless not given) and to
78 # use that address in the "from line" of the envelope.
79 #FromLineOverride=YES
80 EOF