Last active
April 8, 2019 01:48
-
-
Save cminovici/400babb285ac7d2e779cb65e35b1bbfb to your computer and use it in GitHub Desktop.
Mailhog install & configure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
PHP_INI_PATH="/etc/php.ini"; | |
PHP_INI_CLI_PATH="/etc/php-cli.ini"; | |
FOLDER_PATH="$HOME/mailhog"; | |
PORT_NUMBER=8025; | |
MAILHOG_FILE="$FOLDER_PATH/MailHog_linux_amd64"; | |
MHSEND_FILE="$FOLDER_PATH/mhsendmail_linux_amd64"; | |
MAILHOG_URL="https://github.com/mailhog/MailHog/releases/download/v1.0.0/MailHog_linux_amd64"; | |
MHSEND_URL="https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64"; | |
if [[ ! -e ${FOLDER_PATH} ]]; then | |
mkdir -p ${FOLDER_PATH} | |
fi | |
# https://github.com/mailhog/MailHog | |
echo "Download and install Mailhog..."; | |
if [[ ! -f ${MAILHOG_FILE} ]]; then | |
wget -O ${MAILHOG_FILE} ${MAILHOG_URL} | |
if [[ $? -ne 0 ]]; then | |
echo "wget failed" | |
exit 1; | |
fi | |
chmod +x ${MAILHOG_FILE}; | |
else | |
echo "Mailhog already exists! Skipping ..."; | |
fi | |
# https://github.com/mailhog/mhsendmail | |
echo "Download and install mhsendmail..."; | |
if [[ ! -f ${MHSEND_FILE} ]]; then | |
wget -O ${MHSEND_FILE} ${MHSEND_URL} | |
if [[ $? -ne 0 ]]; then | |
echo "wget failed" | |
exit 1; | |
fi | |
chmod +x ${MHSEND_FILE}; | |
else | |
echo "mhsendmail already exists! Skipping ..."; | |
fi | |
echo "Setting it up ..."; | |
for file in ${PHP_INI_PATH} ${PHP_INI_CLI_PATH} | |
do | |
grep -q 'sendmail_path' ${file} && sudo sed -i "s#^\(sendmail_path\).*#\1=${MHSEND_FILE}#" ${file} || echo "sendmail_path=${MHSEND_FILE}" | sudo tee -a ${file} | |
done | |
if [[ $? -ne 0 ]]; then | |
echo "Changing mailhog path in ${PHP_INI_PATH} failed" | |
exit 1; | |
fi | |
echo "Restarting web server" | |
sudo systemctl restart nginx.service && sudo systemctl restart php-fpm.service | |
echo "Starting Mailhog..." | |
sudo pkill -f MailHog | |
#lsof -i tcp:${PORT_NUMBER} | awk 'NR!=1 {print $2}' | xargs sudo kill | |
sudo nohup ${MAILHOG_FILE} -hostname=${HOSTNAME}:${PORT_NUMBER} > ${FOLDER_PATH}/log 2>&1 & | |
if [[ $? -ne 0 ]]; then | |
echo "Starting failed" | |
exit 1; | |
else | |
echo "Mailhog daemon started (${FOLDER_PATH}/log for debugging)" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment