Skip to content

Instantly share code, notes, and snippets.

@kafene
Created June 16, 2018 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kafene/5e3d3a28cd7a5eac050dbdd1b22df9e3 to your computer and use it in GitHub Desktop.
Save kafene/5e3d3a28cd7a5eac050dbdd1b22df9e3 to your computer and use it in GitHub Desktop.
Install Mailhog
#!/usr/bin/env bash
set -euo pipefail
if [[ -f /usr/local/bin/mailhog ]]; then
echo 'It seems mailhog is already installed.' >&2
echo 'Remove </usr/local/bin/mailhog> to force reinstallation.' >&2
exit 1
fi
if [[ "$EUID" -ne 0 ]]; then
echo 'This script must be run with root privileges (hint: use sudo)' >&2
exit 1
fi
echo 'Installing Mailhog...'
# These can be overridden using environment variables if needed
# e.g. `DOWNLOAD_URL=http://example.com/mailhog_v2.0 /path/to/mailhog-install.sh`
download_url="${DOWNLOAD_URL:-https://github.com/mailhog/MailHog/releases/download/v1.0.0/MailHog_linux_amd64}"
install_path="${INSTALL_PATH:-/usr/local/bin/mailhog}"
curl -LSso "$install_path" "$download_url"
chmod +x /usr/local/bin/mailhog
cat > /etc/systemd/system/mailhog.service <<EOF
[Unit]
Description=Mailhog
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/env /usr/local/bin/mailhog > /dev/null 2>&1 &
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable mailhog
systemctl start mailhog
systemctl status mailhog
# Something like this might be necessary to allow outside access.
# It will depend on what firewall you're using but this is just
# an example with ufw, to allow access to the web interface:
# ufw allow out 8025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment