2016-11-06 15:03:51 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# .---. . .
|
|
|
|
# | | |
|
|
|
|
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
|
|
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
|
|
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
|
|
#
|
|
|
|
# Freedom in the Cloud
|
|
|
|
#
|
|
|
|
# mailpile app
|
|
|
|
#
|
|
|
|
# License
|
|
|
|
# =======
|
|
|
|
#
|
|
|
|
# Copyright (C) 2016 Bob Mottram <bob@freedombone.net>
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-11-09 14:15:48 +01:00
|
|
|
VARIANTS="full full-vim mailbox"
|
2016-11-06 15:03:51 +01:00
|
|
|
|
|
|
|
IN_DEFAULT_INSTALL=0
|
|
|
|
SHOW_ON_ABOUT=1
|
|
|
|
|
|
|
|
MAILPILE_DOMAIN_NAME=
|
|
|
|
MAILPILE_CODE=
|
|
|
|
MAILPILE_ONION_PORT=8103
|
|
|
|
MAILPILE_REPO="https://github.com/mailpile/Mailpile"
|
2017-05-13 18:32:17 +02:00
|
|
|
MAILPILE_COMMIT='6f56fe4ad736c8e385bea658454bed110d08c60d'
|
2016-11-06 15:03:51 +01:00
|
|
|
MAILPILE_PORT=33411
|
|
|
|
|
|
|
|
mailpile_variables=(MAILPILE_REPO
|
|
|
|
MAILPILE_DOMAIN_NAME
|
|
|
|
MAILPILE_CODE
|
|
|
|
ONION_ONLY
|
|
|
|
DDNS_PROVIDER
|
|
|
|
MY_USERNAME)
|
|
|
|
|
|
|
|
function remove_user_mailpile {
|
|
|
|
remove_username="$1"
|
2016-11-19 20:17:33 +01:00
|
|
|
${PROJECT_NAME}-pass -u $remove_username --rmapp mailpile
|
2016-11-06 15:03:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function add_user_mailpile {
|
2016-11-19 20:17:33 +01:00
|
|
|
${PROJECT_NAME}-pass -u $1 -a mailpile -p "$2"
|
2016-11-06 15:03:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function install_interactive_mailpile {
|
|
|
|
if [ ! $ONION_ONLY ]; then
|
|
|
|
ONION_ONLY='no'
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $ONION_ONLY != "no" ]]; then
|
|
|
|
MAILPILE_DOMAIN_NAME='mailpile.local'
|
|
|
|
write_config_param "MAILPILE_DOMAIN_NAME" "$MAILPILE_DOMAIN_NAME"
|
|
|
|
else
|
|
|
|
function_check interactive_site_details
|
|
|
|
interactive_site_details "mailpile" "MAILPILE_DOMAIN_NAME" "MAILPILE_CODE"
|
|
|
|
fi
|
|
|
|
APP_INSTALLED=1
|
|
|
|
}
|
|
|
|
|
|
|
|
function change_password_mailpile {
|
2016-11-20 13:37:13 +01:00
|
|
|
echo -n ''
|
|
|
|
#${PROJECT_NAME}-pass -u $1 -a mailpile -p "$2"
|
2016-11-06 15:03:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function reconfigure_mailpile {
|
|
|
|
echo -n ''
|
|
|
|
}
|
|
|
|
|
|
|
|
function upgrade_mailpile {
|
|
|
|
read_config_param "MAILPILE_DOMAIN_NAME"
|
|
|
|
|
2017-05-13 18:32:17 +02:00
|
|
|
CURR_COMMIT=$MAILPILE_COMMIT
|
|
|
|
if grep -q "mailpile commit" $COMPLETION_FILE; then
|
|
|
|
CURR_COMMIT=$(get_completion_param "mailpile commit")
|
|
|
|
fi
|
2017-06-12 23:59:25 +02:00
|
|
|
if [[ "$CURR_COMMIT" == "$MAILPILE_COMMIT" ]]; then
|
|
|
|
return
|
2017-05-13 18:32:17 +02:00
|
|
|
fi
|
|
|
|
|
2016-11-06 15:03:51 +01:00
|
|
|
function_check set_repo_commit
|
2016-11-06 16:07:15 +01:00
|
|
|
set_repo_commit /var/www/$MAILPILE_DOMAIN_NAME/mail "mailpile commit" "$MAILPILE_COMMIT" $MAILPILE_REPO
|
2016-12-31 15:49:36 +01:00
|
|
|
|
2017-06-12 23:59:25 +02:00
|
|
|
cd /var/www/$MAILPILE_DOMAIN_NAME/mail
|
|
|
|
pip install -r requirements.txt
|
2017-05-13 18:32:17 +02:00
|
|
|
|
2017-06-12 23:59:25 +02:00
|
|
|
chown -R mailpile:mailpile /var/www/$MAILPILE_DOMAIN_NAME/mail
|
2016-11-06 15:03:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function backup_local_mailpile {
|
2016-11-06 17:22:37 +01:00
|
|
|
if [ ! -f /etc/systemd/system/mailpile.service ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
MAILPILE_DOMAIN_NAME='mailpile.local'
|
|
|
|
if grep -q "mailpile domain" $COMPLETION_FILE; then
|
|
|
|
MAILPILE_DOMAIN_NAME=$(get_completion_param "mailpile domain")
|
|
|
|
fi
|
|
|
|
source_directory=/var/www/${MAILPILE_DOMAIN_NAME}/mail/.local
|
|
|
|
if [ -d $source_directory ]; then
|
|
|
|
systemctl stop mailpile
|
|
|
|
|
|
|
|
function_check backup_directory_to_usb
|
|
|
|
backup_directory_to_usb $source_directory mailpile
|
|
|
|
|
|
|
|
systemctl start mailpile
|
|
|
|
fi
|
2016-11-06 15:03:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function restore_local_mailpile {
|
2016-11-06 17:22:37 +01:00
|
|
|
if [ ! -f /etc/systemd/system/mailpile.service ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
MAILPILE_DOMAIN_NAME='mailpile.local'
|
|
|
|
if grep -q "mailpile domain" $COMPLETION_FILE; then
|
|
|
|
MAILPILE_DOMAIN_NAME=$(get_completion_param "mailpile domain")
|
|
|
|
fi
|
|
|
|
if [ $MAILPILE_DOMAIN_NAME ]; then
|
|
|
|
systemctl stop mailpile
|
|
|
|
|
|
|
|
temp_restore_dir=/root/tempmailpile
|
|
|
|
restore_directory_from_usb $temp_restore_dir mailpile
|
|
|
|
if [ -d /var/www/${MAILPILE_DOMAIN_NAME}/mail/.local ]; then
|
|
|
|
mv /var/www/${MAILPILE_DOMAIN_NAME}/mail/.local /var/www/${MAILPILE_DOMAIN_NAME}/mail/.previous
|
|
|
|
fi
|
|
|
|
temp_source_dir=$(find ${temp_restore_dir} -name ".local")
|
|
|
|
cp -r ${temp_source_dir} /var/www/${MAILPILE_DOMAIN_NAME}/mail/
|
|
|
|
if [ ! "$?" = "0" ]; then
|
|
|
|
if [ -d mv /var/www/${MAILPILE_DOMAIN_NAME}/mail/.previous ]; then
|
2016-11-06 17:42:24 +01:00
|
|
|
if [ -d /var/www/${MAILPILE_DOMAIN_NAME}/mail/.previous ]; then
|
|
|
|
rm -rf /var/www/${MAILPILE_DOMAIN_NAME}/mail/.previous
|
|
|
|
fi
|
2016-11-06 17:22:37 +01:00
|
|
|
mv /var/www/${MAILPILE_DOMAIN_NAME}/mail/.previous /var/www/${MAILPILE_DOMAIN_NAME}/mail/.local
|
|
|
|
fi
|
|
|
|
backup_unmount_drive
|
|
|
|
exit 3685
|
|
|
|
fi
|
|
|
|
rm -rf ${temp_restore_dir}
|
|
|
|
chown -R mailpile: /var/www/$MAILPILE_DOMAIN_NAME/mail/
|
|
|
|
|
|
|
|
if [ -d /etc/letsencrypt/live/${MAILPILE_DOMAIN_NAME} ]; then
|
|
|
|
ln -s /etc/letsencrypt/live/${MAILPILE_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${MAILPILE_DOMAIN_NAME}.key
|
|
|
|
ln -s /etc/letsencrypt/live/${MAILPILE_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${MAILPILE_DOMAIN_NAME}.pem
|
|
|
|
fi
|
|
|
|
|
|
|
|
systemctl start mailpile
|
|
|
|
fi
|
2016-11-06 15:03:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function backup_remote_mailpile {
|
2016-11-06 17:22:37 +01:00
|
|
|
if [ ! -f /etc/systemd/system/mailpile.service ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
MAILPILE_DOMAIN_NAME='mailpile.local'
|
|
|
|
if grep -q "mailpile domain" $COMPLETION_FILE; then
|
|
|
|
MAILPILE_DOMAIN_NAME=$(get_completion_param "mailpile domain")
|
|
|
|
fi
|
|
|
|
source_directory=/var/www/${MAILPILE_DOMAIN_NAME}/mail/.local
|
|
|
|
if [ -d $source_directory ]; then
|
|
|
|
systemctl stop mailpile
|
|
|
|
|
|
|
|
function_check backup_directory_to_usb
|
|
|
|
backup_directory_to_friend $source_directory mailpile
|
|
|
|
|
|
|
|
systemctl start mailpile
|
|
|
|
fi
|
2016-11-06 15:03:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function restore_remote_mailpile {
|
2016-11-06 17:22:37 +01:00
|
|
|
if [ ! -f /etc/systemd/system/mailpile.service ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
MAILPILE_DOMAIN_NAME='mailpile.local'
|
|
|
|
if grep -q "mailpile domain" $COMPLETION_FILE; then
|
|
|
|
MAILPILE_DOMAIN_NAME=$(get_completion_param "mailpile domain")
|
|
|
|
fi
|
|
|
|
if [ $MAILPILE_DOMAIN_NAME ]; then
|
|
|
|
systemctl stop mailpile
|
|
|
|
|
|
|
|
temp_restore_dir=/root/tempmailpile
|
|
|
|
restore_directory_from_friend $temp_restore_dir mailpile
|
|
|
|
if [ -d /var/www/${MAILPILE_DOMAIN_NAME}/mail/.local ]; then
|
|
|
|
mv /var/www/${MAILPILE_DOMAIN_NAME}/mail/.local /var/www/${MAILPILE_DOMAIN_NAME}/mail/.previous
|
|
|
|
fi
|
|
|
|
temp_source_dir=$(find ${temp_restore_dir} -name ".local")
|
|
|
|
cp -r ${temp_source_dir} /var/www/${MAILPILE_DOMAIN_NAME}/mail/
|
|
|
|
if [ ! "$?" = "0" ]; then
|
|
|
|
if [ -d mv /var/www/${MAILPILE_DOMAIN_NAME}/mail/.previous ]; then
|
|
|
|
mv /var/www/${MAILPILE_DOMAIN_NAME}/mail/.previous /var/www/${MAILPILE_DOMAIN_NAME}/mail/.local
|
|
|
|
fi
|
|
|
|
backup_unmount_drive
|
|
|
|
exit 36732
|
|
|
|
fi
|
|
|
|
rm -rf ${temp_restore_dir}
|
|
|
|
chown -R mailpile: /var/www/$MAILPILE_DOMAIN_NAME/mail/
|
|
|
|
|
|
|
|
if [ -d /etc/letsencrypt/live/${MAILPILE_DOMAIN_NAME} ]; then
|
|
|
|
ln -s /etc/letsencrypt/live/${MAILPILE_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${MAILPILE_DOMAIN_NAME}.key
|
|
|
|
ln -s /etc/letsencrypt/live/${MAILPILE_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${MAILPILE_DOMAIN_NAME}.pem
|
|
|
|
fi
|
|
|
|
|
|
|
|
systemctl start mailpile
|
|
|
|
fi
|
2016-11-06 15:03:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function remove_mailpile {
|
|
|
|
if [ ${#MAILPILE_DOMAIN_NAME} -eq 0 ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
systemctl stop mailpile
|
|
|
|
systemctl disable mailpile
|
|
|
|
rm /etc/systemd/system/mailpile.service
|
2017-06-10 22:37:50 +02:00
|
|
|
systemctl daemon-reload
|
2016-11-06 15:03:51 +01:00
|
|
|
|
|
|
|
read_config_param "MAILPILE_DOMAIN_NAME"
|
2016-11-06 16:05:49 +01:00
|
|
|
nginx_dissite $MAILPILE_DOMAIN_NAME
|
2016-11-14 10:55:11 +01:00
|
|
|
remove_certs ${MAILPILE_DOMAIN_NAME}
|
2016-11-06 16:05:49 +01:00
|
|
|
if [ -f /etc/nginx/sites-available/$MAILPILE_DOMAIN_NAME ]; then
|
|
|
|
rm -f /etc/nginx/sites-available/$MAILPILE_DOMAIN_NAME
|
2016-11-06 15:03:51 +01:00
|
|
|
fi
|
2016-11-06 16:05:49 +01:00
|
|
|
if [ -d /var/www/$MAILPILE_DOMAIN_NAME ]; then
|
|
|
|
rm -rf /var/www/$MAILPILE_DOMAIN_NAME
|
|
|
|
fi
|
|
|
|
function_check remove_ddns_domain
|
|
|
|
remove_ddns_domain $MAILPILE_DOMAIN_NAME
|
2017-06-12 12:19:43 +02:00
|
|
|
|
2017-06-12 12:33:54 +02:00
|
|
|
groupdel -f mailpile
|
|
|
|
userdel -r mailpile
|
2016-11-06 15:03:51 +01:00
|
|
|
|
|
|
|
remove_config_param MAILPILE_DOMAIN_NAME
|
|
|
|
remove_config_param MAILPILE_CODE
|
|
|
|
function_check remove_onion_service
|
|
|
|
remove_onion_service mailpile ${MAILPILE_ONION_PORT}
|
|
|
|
remove_completion_param "install_mailpile"
|
|
|
|
|
|
|
|
enable_email_encryption_at_rest
|
|
|
|
|
|
|
|
sed -i '/Mailpile/d' $COMPLETION_FILE
|
|
|
|
sed -i '/mailpile/d' $COMPLETION_FILE
|
|
|
|
}
|
|
|
|
|
|
|
|
function install_mailpile {
|
|
|
|
if [ ! $ONION_ONLY ]; then
|
|
|
|
ONION_ONLY='no'
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! $MAILPILE_DOMAIN_NAME ]; then
|
|
|
|
echo $'The mailpile domain name was not specified'
|
|
|
|
exit 63824
|
|
|
|
fi
|
|
|
|
|
|
|
|
apt-get -yq install python-pip python-lxml python-dev libjpeg-dev
|
|
|
|
|
|
|
|
if [ ! -d /var/www/$MAILPILE_DOMAIN_NAME ]; then
|
|
|
|
mkdir /var/www/$MAILPILE_DOMAIN_NAME
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd /var/www/$MAILPILE_DOMAIN_NAME
|
2016-11-06 16:07:15 +01:00
|
|
|
if [ -d /var/www/$MAILPILE_DOMAIN_NAME/mail ]; then
|
|
|
|
rm -rf /var/www/$MAILPILE_DOMAIN_NAME/mail
|
2016-11-06 15:26:49 +01:00
|
|
|
fi
|
2017-06-15 13:33:16 +02:00
|
|
|
|
|
|
|
if [ -d /repos/mailpile ]; then
|
|
|
|
mkdir mail
|
2017-06-17 19:37:06 +02:00
|
|
|
cp -r -p /repos/mailpile/. mail
|
2017-06-15 13:33:16 +02:00
|
|
|
cd mail
|
|
|
|
git pull
|
|
|
|
else
|
|
|
|
git_clone $MAILPILE_REPO mail
|
|
|
|
fi
|
|
|
|
|
2016-11-06 16:07:15 +01:00
|
|
|
cd mail
|
2016-11-06 15:03:51 +01:00
|
|
|
git checkout $MAILPILE_COMMIT -b $MAILPILE_COMMIT
|
|
|
|
set_completion_param "mailpile commit" "$MAILPILE_COMMIT"
|
|
|
|
|
|
|
|
if [ ! -f requirements-dev.txt ]; then
|
|
|
|
echo $'No python requirements file found'
|
|
|
|
exit 62382
|
|
|
|
fi
|
|
|
|
pip install -r requirements.txt
|
|
|
|
|
2016-11-06 16:07:15 +01:00
|
|
|
adduser --system --home=/var/www/$MAILPILE_DOMAIN_NAME/mail/ --group mailpile
|
2016-11-06 16:31:32 +01:00
|
|
|
adduser mailpile debian-tor
|
2016-11-13 12:46:02 +01:00
|
|
|
adduser mailpile www-data
|
2016-12-02 11:51:11 +01:00
|
|
|
adduser mailpile mail
|
2016-11-13 21:25:44 +01:00
|
|
|
adduser mailpile $MY_USERNAME
|
2016-11-06 16:07:15 +01:00
|
|
|
chown -R mailpile: /var/www/$MAILPILE_DOMAIN_NAME/mail/
|
2016-11-06 15:03:51 +01:00
|
|
|
|
|
|
|
# create folders and tags
|
2016-11-06 16:07:15 +01:00
|
|
|
su -c "cd /var/www/$MAILPILE_DOMAIN_NAME/mail && ./mp --setup" - mailpile
|
2016-11-06 15:03:51 +01:00
|
|
|
|
2016-11-14 10:49:01 +01:00
|
|
|
MAILPILE_ONION_HOSTNAME=$(add_onion_service mailpile 80 ${MAILPILE_ONION_PORT})
|
|
|
|
|
2016-11-06 15:03:51 +01:00
|
|
|
echo '[Unit]' > /etc/systemd/system/mailpile.service
|
|
|
|
echo 'Description=Mailpile Email Client' >> /etc/systemd/system/mailpile.service
|
|
|
|
echo 'After=syslog.target network.target nginx.target' >> /etc/systemd/system/mailpile.service
|
|
|
|
echo '' >> /etc/systemd/system/mailpile.service
|
|
|
|
echo '[Service]' >> /etc/systemd/system/mailpile.service
|
2016-11-06 15:41:53 +01:00
|
|
|
echo 'User=mailpile' >> /etc/systemd/system/mailpile.service
|
2016-12-02 19:48:04 +01:00
|
|
|
echo 'Group=mailpile' >> /etc/systemd/system/mailpile.service
|
2016-11-06 16:07:15 +01:00
|
|
|
echo "WorkingDirectory=/var/www/$MAILPILE_DOMAIN_NAME/mail" >> /etc/systemd/system/mailpile.service
|
|
|
|
echo "ExecStart=/var/www/$MAILPILE_DOMAIN_NAME/mail/mp --www=0.0.0.0:${MAILPILE_PORT} --wait" >> /etc/systemd/system/mailpile.service
|
2016-11-06 15:03:51 +01:00
|
|
|
echo 'Restart=always' >> /etc/systemd/system/mailpile.service
|
|
|
|
echo 'RestartSec=10' >> /etc/systemd/system/mailpile.service
|
|
|
|
echo '' >> /etc/systemd/system/mailpile.service
|
|
|
|
echo '[Install]' >> /etc/systemd/system/mailpile.service
|
|
|
|
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/mailpile.service
|
|
|
|
chmod +x /etc/systemd/system/mailpile.service
|
|
|
|
|
|
|
|
mailpile_nginx_site=/etc/nginx/sites-available/$MAILPILE_DOMAIN_NAME
|
2016-11-06 16:23:38 +01:00
|
|
|
if [[ $ONION_ONLY == "no" ]]; then
|
|
|
|
function_check nginx_http_redirect
|
|
|
|
nginx_http_redirect $MAILPILE_DOMAIN_NAME
|
2016-11-06 15:03:51 +01:00
|
|
|
echo 'server {' >> $mailpile_nginx_site
|
2016-11-06 16:23:38 +01:00
|
|
|
echo ' listen 443 ssl;' >> $mailpile_nginx_site
|
2016-11-17 23:45:20 +01:00
|
|
|
echo ' listen [::]:443 ssl;' >> $mailpile_nginx_site
|
2016-11-06 16:23:38 +01:00
|
|
|
echo " server_name $MAILPILE_DOMAIN_NAME;" >> $mailpile_nginx_site
|
2016-11-06 15:03:51 +01:00
|
|
|
echo '' >> $mailpile_nginx_site
|
2016-11-06 16:23:38 +01:00
|
|
|
echo ' # Security' >> $mailpile_nginx_site
|
|
|
|
function_check nginx_ssl
|
|
|
|
nginx_ssl $MAILPILE_DOMAIN_NAME
|
|
|
|
|
2016-11-06 15:03:51 +01:00
|
|
|
function_check nginx_disable_sniffing
|
|
|
|
nginx_disable_sniffing $MAILPILE_DOMAIN_NAME
|
2016-11-06 16:23:38 +01:00
|
|
|
|
|
|
|
echo ' add_header Strict-Transport-Security max-age=15768000;' >> $mailpile_nginx_site
|
2016-11-06 15:03:51 +01:00
|
|
|
echo '' >> $mailpile_nginx_site
|
|
|
|
echo ' # Logs' >> $mailpile_nginx_site
|
2016-11-10 14:26:31 +01:00
|
|
|
echo ' access_log /dev/null;' >> $mailpile_nginx_site
|
|
|
|
echo ' error_log /dev/null;' >> $mailpile_nginx_site
|
2016-11-06 15:03:51 +01:00
|
|
|
echo '' >> $mailpile_nginx_site
|
|
|
|
echo ' # Root' >> $mailpile_nginx_site
|
2016-11-06 16:07:15 +01:00
|
|
|
echo " root /var/www/$MAILPILE_DOMAIN_NAME/mail;" >> $mailpile_nginx_site
|
2016-11-06 15:03:51 +01:00
|
|
|
echo '' >> $mailpile_nginx_site
|
|
|
|
echo ' location / {' >> $mailpile_nginx_site
|
|
|
|
function_check nginx_limits
|
|
|
|
nginx_limits $MAILPILE_DOMAIN_NAME '15m'
|
2016-11-13 21:22:15 +01:00
|
|
|
echo ' rewrite /(.*) /$1 break;' >> $mailpile_nginx_site
|
|
|
|
echo ' proxy_set_header X-Real-IP $remote_addr;' >> $mailpile_nginx_site
|
2016-11-06 16:22:08 +01:00
|
|
|
echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $mailpile_nginx_site
|
2016-11-13 21:22:15 +01:00
|
|
|
echo ' proxy_set_header Host $http_host;' >> $mailpile_nginx_site
|
|
|
|
echo ' proxy_set_header X-NginX-Proxy true;' >> $mailpile_nginx_site
|
|
|
|
echo " proxy_pass http://localhost:${MAILPILE_PORT};" >> $mailpile_nginx_site
|
|
|
|
echo ' proxy_redirect off;' >> $mailpile_nginx_site
|
2016-11-06 15:03:51 +01:00
|
|
|
echo ' }' >> $mailpile_nginx_site
|
2016-11-11 17:26:54 +01:00
|
|
|
echo '' >> $mailpile_nginx_site
|
2016-11-11 18:36:30 +01:00
|
|
|
nginx_keybase ${MAILPILE_DOMAIN_NAME}
|
2016-11-06 15:03:51 +01:00
|
|
|
echo '}' >> $mailpile_nginx_site
|
2016-11-14 10:49:01 +01:00
|
|
|
echo '' >> $mailpile_nginx_site
|
2016-11-06 16:23:38 +01:00
|
|
|
else
|
|
|
|
echo -n '' > $mailpile_nginx_site
|
2016-11-06 15:03:51 +01:00
|
|
|
fi
|
2016-11-06 16:23:38 +01:00
|
|
|
echo 'server {' >> $mailpile_nginx_site
|
|
|
|
echo " listen 127.0.0.1:$MAILPILE_ONION_PORT default_server;" >> $mailpile_nginx_site
|
2016-11-14 10:49:01 +01:00
|
|
|
echo " server_name $MAILPILE_ONION_HOSTNAME;" >> $mailpile_nginx_site
|
2016-11-06 16:23:38 +01:00
|
|
|
echo '' >> $mailpile_nginx_site
|
|
|
|
function_check nginx_disable_sniffing
|
|
|
|
nginx_disable_sniffing $MAILPILE_DOMAIN_NAME
|
|
|
|
echo '' >> $mailpile_nginx_site
|
|
|
|
echo ' # Logs' >> $mailpile_nginx_site
|
2016-11-10 14:26:31 +01:00
|
|
|
echo ' access_log /dev/null;' >> $mailpile_nginx_site
|
|
|
|
echo ' error_log /dev/null;' >> $mailpile_nginx_site
|
2016-11-06 16:23:38 +01:00
|
|
|
echo '' >> $mailpile_nginx_site
|
|
|
|
echo ' # Root' >> $mailpile_nginx_site
|
|
|
|
echo " root /var/www/$MAILPILE_DOMAIN_NAME/mail;" >> $mailpile_nginx_site
|
|
|
|
echo '' >> $mailpile_nginx_site
|
|
|
|
echo ' location / {' >> $mailpile_nginx_site
|
|
|
|
function_check nginx_limits
|
|
|
|
nginx_limits $MAILPILE_DOMAIN_NAME '15m'
|
2016-11-13 21:22:15 +01:00
|
|
|
echo ' rewrite /(.*) /$1 break;' >> $mailpile_nginx_site
|
|
|
|
echo ' proxy_set_header X-Real-IP $remote_addr;' >> $mailpile_nginx_site
|
2016-11-06 16:23:38 +01:00
|
|
|
echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $mailpile_nginx_site
|
2016-11-13 21:22:15 +01:00
|
|
|
echo ' proxy_set_header Host $http_host;' >> $mailpile_nginx_site
|
|
|
|
echo ' proxy_set_header X-NginX-Proxy true;' >> $mailpile_nginx_site
|
|
|
|
echo " proxy_pass http://localhost:${MAILPILE_PORT};" >> $mailpile_nginx_site
|
|
|
|
echo ' proxy_redirect off;' >> $mailpile_nginx_site
|
2016-11-06 16:23:38 +01:00
|
|
|
echo ' }' >> $mailpile_nginx_site
|
2016-11-11 17:26:54 +01:00
|
|
|
echo '' >> $mailpile_nginx_site
|
2016-11-11 18:36:30 +01:00
|
|
|
nginx_keybase ${MAILPILE_DOMAIN_NAME}
|
2016-11-06 16:23:38 +01:00
|
|
|
echo '}' >> $mailpile_nginx_site
|
2016-11-06 15:03:51 +01:00
|
|
|
|
|
|
|
function_check create_site_certificate
|
2016-11-06 16:05:49 +01:00
|
|
|
if [ ! -f /etc/ssl/certs/${MAILPILE_DOMAIN_NAME}.pem ]; then
|
2016-11-06 15:03:51 +01:00
|
|
|
create_site_certificate $MAILPILE_DOMAIN_NAME 'yes'
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f /etc/ssl/certs/${MAILPILE_DOMAIN_NAME}.crt ]; then
|
|
|
|
mv /etc/ssl/certs/${MAILPILE_DOMAIN_NAME}.crt /etc/ssl/certs/${MAILPILE_DOMAIN_NAME}.pem
|
|
|
|
fi
|
|
|
|
if [ -f /etc/ssl/certs/${MAILPILE_DOMAIN_NAME}.pem ]; then
|
2017-03-18 13:52:11 +01:00
|
|
|
chown root:root /etc/ssl/certs/${MAILPILE_DOMAIN_NAME}.pem
|
2016-11-13 11:26:58 +01:00
|
|
|
sed -i "s|.crt|.pem|g" /etc/nginx/sites-available/${MAILPILE_DOMAIN_NAME}
|
2016-11-06 15:03:51 +01:00
|
|
|
fi
|
|
|
|
if [ -f /etc/ssl/private/${MAILPILE_DOMAIN_NAME}.key ]; then
|
2017-03-18 13:52:11 +01:00
|
|
|
chown root:root /etc/ssl/private/${MAILPILE_DOMAIN_NAME}.key
|
2016-11-06 15:03:51 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
function_check nginx_ensite
|
|
|
|
nginx_ensite $MAILPILE_DOMAIN_NAME
|
|
|
|
|
2016-11-19 20:17:33 +01:00
|
|
|
${PROJECT_NAME}-pass -u $MY_USERNAME -a mailpile -p "*"
|
2016-11-06 15:03:51 +01:00
|
|
|
|
|
|
|
function_check add_ddns_domain
|
|
|
|
add_ddns_domain $MAILPILE_DOMAIN_NAME
|
|
|
|
|
|
|
|
disable_email_encryption_at_rest
|
|
|
|
|
2016-11-13 12:46:02 +01:00
|
|
|
# if strict https is enforced then buttons don't work. This is probably a security bug
|
2016-11-13 21:29:43 +01:00
|
|
|
sed -i "/Content-Security-Policy/d" $mailpile_nginx_site
|
2016-11-13 12:46:02 +01:00
|
|
|
|
2016-11-13 21:22:15 +01:00
|
|
|
# link to the administrator's keyring
|
|
|
|
if [ -d /var/www/$MAILPILE_DOMAIN_NAME/mail/.gnupg ]; then
|
|
|
|
mv /var/www/$MAILPILE_DOMAIN_NAME/mail/.gnupg /var/www/$MAILPILE_DOMAIN_NAME/mail/.gnupg_orig
|
|
|
|
fi
|
2016-11-13 22:23:44 +01:00
|
|
|
cp -r /home/$MY_USERNAME/.gnupg /var/www/$MAILPILE_DOMAIN_NAME/mail/
|
2016-11-13 21:22:15 +01:00
|
|
|
chown -R mailpile:mailpile /var/www/$MAILPILE_DOMAIN_NAME/mail/.gnupg
|
|
|
|
chmod +x /var/www/$MAILPILE_DOMAIN_NAME/mail/.gnupg
|
|
|
|
|
2017-06-09 21:14:58 +02:00
|
|
|
pip install jinja2==2.9.6
|
|
|
|
pip install pgpdump==1.5
|
|
|
|
|
2016-11-06 15:03:51 +01:00
|
|
|
systemctl enable mailpile
|
|
|
|
systemctl daemon-reload
|
|
|
|
systemctl start mailpile
|
|
|
|
systemctl restart nginx
|
|
|
|
|
|
|
|
set_completion_param "mailpile domain" "$MAILPILE_DOMAIN_NAME"
|
|
|
|
APP_INSTALLED=1
|
|
|
|
}
|
|
|
|
|
|
|
|
# NOTE: deliberately no exit 0
|