-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure-msmtp.sh
executable file
·65 lines (60 loc) · 1.7 KB
/
configure-msmtp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
# configure-msmtp.sh
# This script is part of dora -- Docker container for Rails
# https://github.com/bovender/dora
source /etc/container_environment.sh
echo "# dora configuring msmtp"
MSMTPRC=/etc/msmtprc
if [[ $(id -u) != 0 ]]; then
echo "Script was invoked by user '$(id -u -n)'; re-invoking with sudo..."
echo
set -x
exec sudo "$0" "$@"
fi
function show_help() {
echo "Usage: $(basename $0) [options]"
echo "Options:"
echo " -f, --force: Force configuration even if $MSMTPRC exists"
echo " -h, --help: Show this help"
echo "This script creates $MSMTPRC with the content of the following variables:"
echo " \$RAILS_SMTP_HOST=$RAILS_SMTP_HOST"
echo " \$RAILS_SMTP_PORT=$RAILS_SMTP_PORT"
echo " \$RAILS_SMTP_USER=$RAILS_SMTP_USER"
echo " \$RAILS_SMTP_PASS=$RAILS_SMTP_PASS"
echo " \$RAILS_SMTP_FROM=$RAILS_SMTP_FROM"
}
while [[ $1 != "" ]]; do
case $1 in
-h | --help )
show_help
exit
;;
-f | --force )
FORCE=1
;;
esac
shift
done
if [[ $RAILS_SMTP_HOST == "" ]]; then
echo "FATAL: environment variable \$RAILS_SMTP_HOST is empty!"
exit 1
elif [[ -a $MSMTPRC && $FORCE != "1" ]]; then
echo "FATAL: $MSMTPRC exists; use -f or --force to overwrite"
exit 1
else
[[ -a $MSMTPRC ]] && echo "WARNING: $MSMTPRC exists; forcing overwrite!"
# Note that the heredoc lines must be preceded by true tabs
cat <<-EOF | tee $MSMTPRC
# msmtp configuration written by dora ($(basename $0)) on $(date -Is)
account default
host $RAILS_SMTP_HOST
port $RAILS_SMTP_PORT
user $RAILS_SMTP_USER
from $RAILS_SMTP_FROM
password $RAILS_SMTP_PASS
tls on
tls_starttls off
EOF
chown root:root $MSMTPRC
chmod 0600 $MSMTPRC
fi