Skip to content

Instantly share code, notes, and snippets.

@goeroeku
Last active September 21, 2021 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goeroeku/d6f51672e65310e1ff6b20413c441839 to your computer and use it in GitHub Desktop.
Save goeroeku/d6f51672e65310e1ff6b20413c441839 to your computer and use it in GitHub Desktop.
IDCH One Install Mailcoach
#!/bin/bash
#
# Mailcoach activation script
#
# This script will configure Apache with the domain
# provided by the user and offer the option to set up
# LetsEncrypt as well.
# Enable Mailcoach on firstlogin
echo "This script will copy the Mailcoach installation into"
echo "your web root and move the existing one to /var/www/mailcoach"
echo "--------------------------------------------------"
echo "This setup requires a domain name."
echo "If you do not have one yet, you may cancel this setup, press Ctrl+C."
echo "This script will run again on your next login"
echo "--------------------------------------------------"
echo "Enter the domain name for your new Mailcoach site."
echo "(ex. example.org or test.example.org) do not include www or http/s"
echo "--------------------------------------------------"
a=0
while [ $a -eq 0 ]
do
read -p "Domain/Subdomain name: " dom
if [ -z "$dom" ]
then
a=0
echo "Please provide a valid domain or subdomain name to continue or press Ctrl+C to cancel"
else
a=1
fi
done
# Set some default zero values
license=""
validLicense=""
email="0"
username="0"
pass="0"
rm -f /etc/nginx/sites-available/mailcoach
rm -f /etc/nginx/sites-enabled/mailcoach
cp -f /etc/nginx/sites-available/master /etc/nginx/sites-available/mailcoach
sed -i "s/mail.idch.com/$dom/g" /etc/nginx/sites-available/mailcoach
ln -sf /etc/nginx/sites-available/mailcoach /etc/nginx/sites-enabled
echo -en "\n"
echo "Next, you have the option of configuring LetsEncrypt to secure your new site."
echo "Before doing this, be sure that you have pointed your domain or subdomain to this server's IP address."
echo "You can also run LetsEncrypt certbot later with the command 'certbot --nginx'"
echo "--------------------------------------------------"
certbot --nginx --agree-tos --redirect --register-unsafely-without-email -n -d $dom; echo "Mailcoach has been enabled at https://$dom.";
echo -en "Please provide the credentials for your admin user of Mailcoach."
while [ $email == "0" ]
do
echo -en "\n"
read -p "Email Address: " email
done
while [ $username == "0" ]
do
echo -en "\n"
read -p "Name: " username
done
while [ $pass == "0" ]
do
echo -en "\n"
read -s -p "Password: " pass
done
echo -en "\n\n"
echo "Finalizing installation..."
cd /var/www/mailcoach
cp -f .env-master .env
sed -i "s/mail.idch.com/$dom/g" .env
sed -i "s/mail.idch.com/$dom/g" config-mailcoach-app/app.json
php artisan key:generate --force --quiet
chown -Rf www-data:www-data /var/www/mailcoach
#echo -en "Refresh database..."
#echo -en "\n\n"
php artisan migrate:fresh --force --quiet
echo -en "Creating user..."
echo -en "\n\n"
php artisan mailcoach:make-user --username="$username" --email="$email" --password="$pass"
service nginx restart
echo "Installation complete. Access your new Mailcoach site in a browser to continue. Database credentials can be found in /var/www/mailcoach/.env"
#!/bin/bash
#
# Mailcoach activation script
## add common utilities
sudo apt install software-properties-common zip unzip
## add php repo
sudo add-apt-repository ppa:ondrej/php
## update system
sudo apt update -y && sudo apt upgrade -y
## install php devendencies, need php 8.0
sudo apt install php8.0-fpm php8.0-zip php8.0-mbstring php8.0-xml
## install composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
## install nginx
sudo apt install nginx
## set mailcoach license
### https://spatie.be/docs/laravel-mailcoach/v4/installation/in-an-existing-laravel-app
## create project mailcoach
composer create-project spatie/Mailcoach mailcoach
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment