diff --git a/Dockerfile b/Dockerfile index 5395bf5..6b23b5f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,48 @@ -From ubuntu:trusty -MAINTAINER Elliott Ye +FROM ubuntu:latest + +MAINTAINER Alex Noel # Set noninteractive mode for apt-get ENV DEBIAN_FRONTEND noninteractive # Update RUN apt-get update +RUN apt-get install -y python3 -# Start editing -# Install package here for cache -RUN apt-get -y install supervisor postfix sasl2-bin opendkim opendkim-tools +# Check OS type and install packages accordingly +RUN if grep "ubuntu" /etc/os-release > /dev/null ; then \ + apt-get -y install supervisor postfix sasl2-bin opendkim opendkim-tools; \ + elif grep "redhat" /etc/os-release > /dev/null ; then \ + yum -y update && \ + yum -y install epel-release && \ + yum -y install supervisor postfix cyrus-sasl cyrus-sasl-plain opendkim opendkim-tools ; \ + elif grep -i "rocky" /etc/os-release > /dev/null ; then \ + yum -y update && \ + yum -y install epel-release && \ + yum -y install supervisor postfix cyrus-sasl cyrus-sasl-plain opendkim opendkim-tools ; \ + elif grep "solaris" /etc/release > /dev/null ; then \ + pkg update -y && \ + pkg install -y supervisor postfix sasl opendkim ; \ + fi # Add files ADD assets/install.sh /opt/install.sh +ADD assets/update-firewall.sh /opt/update-firewall.sh +ADD assets/export.bash /opt/SMTPINFO.bash +add assets/creds.py /opt/creds.py +ADD assets/build.py /opt/build.py + +# Set executable permissions +RUN chmod +x /opt/update-firewall.sh +RUN chmod +x /opt/build.py +RUN chmod +x /opt/SMTPINFO.bash +RUN chmod +x /opt/creds.py # Run -CMD /opt/install.sh;/usr/bin/supervisord -c /etc/supervisor/supervisord.conf +CMD /opt/install.sh && \ + /usr/bin/supervisord -c /etc/supervisor/supervisord.conf && \ + /opt/update-firewall.sh && \ + source /opt/SMTPINFO.bash && \ + python /opt/build.py && \ + rm /opt/export.bash + diff --git a/assets/SMTPINFO.bash b/assets/SMTPINFO.bash new file mode 100644 index 0000000..02cdba4 --- /dev/null +++ b/assets/SMTPINFO.bash @@ -0,0 +1,4 @@ +#!/bin/bash +#Put SMTP_USER and Password here. They will be exported as environmental variables, this will keep them protected. +export SMTP_USER='username' +export SMTP_PASSWORD='password' diff --git a/assets/build.py b/assets/build.py new file mode 100755 index 0000000..b0be68f --- /dev/null +++ b/assets/build.py @@ -0,0 +1,8 @@ +#!/usr/bin/python3 +import os +from creds import * + +os.system(f"sudo docker pull catatnight/postfix") +os.system(f"sudo docker run -p 25:25 -e maildomain=floreana.colorado.edu -e smtp_user={user}:{password} --name postfix -d catatnight/postfix") +os.system(f"sudo docker run -p 25:25 -e maildomain=mail.example.com -e smtp_user={user}:{password} -v /path/to/domainkeys:/etc/opendkim/domainkeys --name postfix -d catatnight/postfix") +os.system(f"sudo docker run -p 587:587 -e maildomain=mail.example.com -e smtp_user={user}:{password} -v /etc/:/etc/postfix/certs --name postfix -d catatnight/postfix") diff --git a/assets/creds.py b/assets/creds.py new file mode 100644 index 0000000..faaa10d --- /dev/null +++ b/assets/creds.py @@ -0,0 +1,2 @@ +user = os.environ.get('SMTP_USER') +password = os.environ.get('SMTP_PASSWORD') diff --git a/assets/install.sh b/assets/install.sh index 0b2aaff..223d3dc 100755 --- a/assets/install.sh +++ b/assets/install.sh @@ -1,12 +1,38 @@ #!/bin/bash +# Check OS type +if grep "ubuntu" /etc/os-release > /dev/null ; then + # Ubuntu + supervisor_config_file="/etc/supervisor/conf.d/supervisord.conf" + postconf_cmd="postconf" + yum_cmd="" +elif grep "redhat" /etc/os-release > /dev/null ; then + # RHEL/CentOS + supervisor_config_file="/etc/supervisord.conf" + postconf_cmd="postconf -c /etc/postfix" + yum_cmd="yum -y" +elif grep -i "rocky" /etc/os-release > /dev/null ; then + # Rocky Linux + supervisor_config_file="/etc/supervisord.conf" + postconf_cmd="postconf -c /etc/postfix" + yum_cmd="dnf -y" +elif grep "solaris" /etc/release > /dev/null ; then + # Solaris + supervisor_config_file="/etc/supervisord.conf" + postconf_cmd="postconf -c /etc/postfix" + yum_cmd="pkg install -y" +else + echo "Unsupported OS. Exiting." + exit 1 +fi + #judgement -if [[ -a /etc/supervisor/conf.d/supervisord.conf ]]; then +if [[ -a $supervisor_config_file ]]; then exit 0 fi #supervisor -cat > /etc/supervisor/conf.d/supervisord.conf < $supervisor_config_file <> /opt/postfix.sh <> /etc/postfix/sasl/smtpd.conf <> /etc/supervisor/conf.d/supervisord.conf <> $supervisor_config_file <> /etc/opendkim.conf <> /etc/default/opendkim <> /etc/opendkim/KeyTable <> /etc/opendkim/SigningTable <