piler-docker/install-piler.sh

194 lines
5.9 KiB
Bash
Raw Normal View History

2022-03-08 11:02:21 +00:00
#!/bin/bash
2022-03-09 13:28:14 +00:00
# Colors
if [ -z ${BASH_SOURCE} ]; then
blue=`echo "\e[1m\e[34m"`
green=`echo "\e[1m\e[32m"`
greenBold=`echo "\e[1m\e[1;32m"`
redBold=`echo "\e[1m\e[1;31m"`
red=`echo "\e[1m\e[31m"`
purple=`echo "\e[1m\e[35m"`
bold=`echo "\e[1m"`
normal=`echo "\e[0m"`
else
blue=`echo -e "\e[1m\e[34m"`
green=`echo -e "\e[1m\e[32m"`
greenBold=`echo -e "\e[1m\e[1;32m"`
redBold=`echo -e "\e[1m\e[1;31m"`
puple=`echo -e "\e[1m\e[35m"`
bold=`echo -e "\e[1m"`
normal=`echo -en "\e[0m"`
fi
HLINE="=================================================================="
2022-03-08 11:02:21 +00:00
. ./piler.conf
2022-03-09 13:46:53 +00:00
if [ ! -f /opt/piler-docker/.env ]; then
ln -s ./piler.conf .env
fi
2022-03-08 11:02:21 +00:00
2022-03-09 13:28:14 +00:00
if [ -f /opt/piler-docker/docker-compose.yml ]; then
rm /opt/piler-docker/docker-compose.yml
fi
if [ "$USE_LETSENCRYPT" = "yes" ]; then
cp /opt/piler-docker/config/piler-ssl.yml /opt/piler-docker/docker-compose.yml
else
cp /opt/piler-docker/config/piler-default.yml /opt/piler-docker/docker-compose.yml
fi
while true; do
read -ep "Postfix must be uninstalled prior to installation. Do you want to uninstall Postfix now? (y/n): " yn
case $yn in
[Yy]* ) apt purge postfix -y; break;;
[Nn]* ) echo -e "${redBold} The installation process is aborted because Postfix has not been uninstalled.!! ${normal}"; exit;;
* ) echo -e "${red} Please confirm with y or n.";;
esac
done
2022-03-08 12:42:38 +00:00
# docker start
echo
2022-03-09 13:28:14 +00:00
echo "${greenBold}${HLINE}"
2022-03-09 13:46:53 +00:00
echo "${greenBold} start docker-compose for Piler"
2022-03-09 13:28:14 +00:00
echo "${greenBold}${HLINE}${normal}"
2022-03-08 12:42:38 +00:00
echo
2022-03-08 11:02:21 +00:00
2022-03-08 12:42:38 +00:00
cd /opt/piler-docker
2022-03-09 13:28:14 +00:00
if [ "$USE_LETSENCRYPT" = "yes" ]; then
if ! docker network ls | grep -o "nginx-proxy"; then
docker network create nginx-proxy
echo
echo "${blue}${HLINE}"
2022-03-09 14:00:10 +00:00
echo "${blue} docker network created"
2022-03-09 13:28:14 +00:00
echo "${blue}${HLINE}${normal}"
echo
fi
fi
2022-03-08 11:02:21 +00:00
docker-compose up -d
2022-03-08 12:42:38 +00:00
echo
2022-03-09 13:28:14 +00:00
echo "${blue}${HLINE}"
2022-03-09 13:46:53 +00:00
echo "${blue} backup the File config-site.php"
2022-03-09 13:28:14 +00:00
echo "${blue}${HLINE}${normal}"
2022-03-08 12:42:38 +00:00
echo
2022-03-08 11:02:21 +00:00
2022-03-08 14:12:53 +00:00
if [ ! -f /var/lib/docker/volumes/piler-docker_piler_etc/_data/config-site.php.bak ]; then
cp /var/lib/docker/volumes/piler-docker_piler_etc/_data/config-site.php /var/lib/docker/volumes/piler-docker_piler_etc/_data/config-site.php.bak
else
rm /var/lib/docker/volumes/piler-docker_piler_etc/_data/config-site.php
cp /var/lib/docker/volumes/piler-docker_piler_etc/_data/config-site.php.bak /var/lib/docker/volumes/piler-docker_piler_etc/_data/config-site.php
fi
2022-03-08 11:02:21 +00:00
2022-03-08 12:42:38 +00:00
echo
2022-03-09 13:28:14 +00:00
echo "${blue}${HLINE}"
2022-03-09 14:00:10 +00:00
echo "${blue} set User settings ..."
2022-03-09 13:28:14 +00:00
echo "${blue}${HLINE}${normal}"
2022-03-08 12:42:38 +00:00
echo
2022-03-09 13:28:14 +00:00
2022-03-08 12:42:38 +00:00
cat >> /var/lib/docker/volumes/piler-docker_piler_etc/_data/config-site.php <<EOF
2022-03-08 11:02:21 +00:00
// Smarthost
2022-03-08 12:42:38 +00:00
\$config['SMARTHOST'] = '$SMARTHOST';
\$config['SMARTHOST_PORT'] = '25';
2022-03-08 11:02:21 +00:00
// CUSTOM
\$config['PROVIDED_BY'] = '$PILER_DOMAIN';
\$config['SUPPORT_LINK'] = 'mailto:$SUPPORT_MAIL';
\$config['COMPATIBILITY'] = '';
// fancy features.
\$config['ENABLE_INSTANT_SEARCH'] = 1;
\$config['ENABLE_TABLE_RESIZE'] = 1;
\$config['ENABLE_DELETE'] = 1;
\$config['ENABLE_ON_THE_FLY_VERIFICATION'] = 1;
// general settings.
\$config['TIMEZONE'] = '$TIME_ZONE';
// authentication
// Enable authentication against an imap server
\$config['ENABLE_IMAP_AUTH'] = 1;
\$config['RESTORE_OVER_IMAP'] = 1;
\$config['IMAP_RESTORE_FOLDER_INBOX'] = 'INBOX';
\$config['IMAP_RESTORE_FOLDER_SENT'] = 'Sent';
\$config['IMAP_HOST'] = '$IMAP_SERVER';
\$config['IMAP_PORT'] = 993;
\$config['IMAP_SSL'] = true;
// authentication against an ldap directory (disabled by default)
//\$config['ENABLE_LDAP_AUTH'] = 1;
//\$config['LDAP_HOST'] = '$SMARTHOST';
//\$config['LDAP_PORT'] = 389;
//\$config['LDAP_HELPER_DN'] = 'cn=administrator,cn=users,dc=mydomain,dc=local';
//\$config['LDAP_HELPER_PASSWORD'] = 'myxxxxpasswd';
//\$config['LDAP_MAIL_ATTR'] = 'mail';
//\$config['LDAP_AUDITOR_MEMBER_DN'] = '';
//\$config['LDAP_ADMIN_MEMBER_DN'] = '';
//\$config['LDAP_BASE_DN'] = 'ou=Benutzer,dc=krs,dc=local';
// authentication against an Uninvention based ldap directory
//\$config['ENABLE_LDAP_AUTH'] = 1;
//\$config['LDAP_HOST'] = '$SMARTHOST';
//\$config['LDAP_PORT'] = 7389;
//\$config['LDAP_HELPER_DN'] = 'uid=ldap-search-user,cn=users,dc=mydomain,dc=local';
//\$config['LDAP_HELPER_PASSWORD'] = 'myxxxxpasswd';
//\$config['LDAP_AUDITOR_MEMBER_DN'] = '';
//\$config['LDAP_ADMIN_MEMBER_DN'] = '';
//\$config['LDAP_BASE_DN'] = 'cn=users,dc=mydomain,dc=local';
//\$config['LDAP_MAIL_ATTR'] = 'mailPrimaryAddress';
//\$config['LDAP_ACCOUNT_OBJECTCLASS'] = 'person';
//\$config['LDAP_DISTRIBUTIONLIST_OBJECTCLASS'] = 'person';
//\$config['LDAP_DISTRIBUTIONLIST_ATTR'] = 'mailAlternativeAddress';
EOF
2022-03-09 13:28:14 +00:00
if [ "$USE_MAILCOW" = true ]; then
2022-03-08 11:02:21 +00:00
2022-03-08 12:42:38 +00:00
echo
2022-03-09 13:28:14 +00:00
echo "${blue}${HLINE}"
2022-03-08 11:02:21 +00:00
echo "set Mailcow Api-Key config"
2022-03-09 13:28:14 +00:00
echo "${blue}${HLINE}${normal}"
2022-03-08 12:42:38 +00:00
echo
2022-03-08 11:02:21 +00:00
2022-03-08 12:42:38 +00:00
cat >> /var/lib/docker/volumes/piler-docker_piler_etc/_data/config-site.php <<EOF
2022-03-08 11:02:21 +00:00
// Mailcow API
2022-03-08 12:42:38 +00:00
\$config['MAILCOW_API_KEY'] = '$MAILCOW_APIKEY';
\$config['MAILCOW_SET_REALNAME'] = true;
\$config['CUSTOM_EMAIL_QUERY_FUNCTION'] = 'query_mailcow_for_email_access';
\$config['MAILCOW_HOST'] = '$MAILCOW_HOST'; // default $config['IMAP_HOST']
2022-03-08 11:02:21 +00:00
include('auth-mailcow.php');
EOF
2022-03-08 12:42:38 +00:00
curl -o /var/lib/docker/volumes/piler-docker_piler_etc/_data/auth-mailcow.php https://raw.githubusercontent.com/patschi/mailpiler-mailcow-integration/master/auth-mailcow.php
2022-03-08 11:02:21 +00:00
fi
2022-03-08 14:12:53 +00:00
# docker restart
2022-03-08 12:42:38 +00:00
echo
2022-03-09 13:28:14 +00:00
echo "${blue}${HLINE}"
2022-03-09 13:46:53 +00:00
echo "${blue} restart docker-compose ..."
2022-03-09 13:28:14 +00:00
echo "${blue}${HLINE}${normal}"
2022-03-08 12:42:38 +00:00
echo
2022-03-08 11:02:21 +00:00
2022-03-08 12:42:38 +00:00
cd /opt/piler-docker
2022-03-08 11:02:21 +00:00
docker-compose restart
2022-03-08 12:42:38 +00:00
echo
2022-03-09 13:28:14 +00:00
echo "${greenBold}${HLINE}"
2022-03-09 13:46:53 +00:00
echo "${greenBold} Piler install completed successfully"
echo "${greenBold}${HLINE}${normal}"
2022-03-08 12:42:38 +00:00
echo
2022-03-09 13:46:53 +00:00
echo
echo "${greenBold}${HLINE}"
2022-03-09 13:28:14 +00:00
if [ "$USE_LETSENCRYPT" = "yes" ]; then
echo "${greenBold}you can start in your Browser with https://${PILER_DOMAIN}!"
else
2022-03-09 14:00:10 +00:00
echo "${greenBold}you can start in your Browser with:"
2022-03-09 13:46:53 +00:00
echo "${greenBold}http://${PILER_DOMAIN} or http://local-ip"
2022-03-09 13:28:14 +00:00
fi
echo "${greenBold}${HLINE}${normal}"
2022-03-08 12:42:38 +00:00
echo