create functions
This commit is contained in:
+61
-30
@@ -8,11 +8,11 @@ if [[ ! -f ".configured" ]]; then
|
||||
|
||||
set -x
|
||||
|
||||
: ${IPADDR:=127.0.0.1}
|
||||
: ${MYSQLIP:=127.0.0.1}
|
||||
: ${MYSQLPORT:=3306}
|
||||
: ${MYSQLUSER:=admin_iredmail}
|
||||
: ${MYSQLPASS:=admin_password}
|
||||
: ${MYSQL_SERVER_ADDRESS:=127.0.0.1}
|
||||
: ${MYSQL_SERVER_PORT:=3306}
|
||||
: ${MYSQL_ROOT_USER:=admin_iredmail}
|
||||
: ${MYSQL_ROOT_PASSWD:=admin_password}
|
||||
: ${MYSQL_GRANT_HOST:=%}
|
||||
: ${MYSQLEXIST:=NO}
|
||||
: ${SETFQDN:=test.testdomain.ru}
|
||||
: ${STORAGE_BASE_DIR:=/var/vmail}
|
||||
@@ -28,6 +28,7 @@ if [[ ! -f ".configured" ]]; then
|
||||
: ${LDAP_ADMIN_PW:=`eval </dev/urandom tr -dc A-Za-z0-9 | (head -c $1 &>/dev/null || head -c 20)`}
|
||||
: ${LDAP_ROOTPW:=`eval </dev/urandom tr -dc A-Za-z0-9 | (head -c $1 &>/dev/null || head -c 20)`}
|
||||
: ${LDAP_SEARCH_BASE:=cn=users,dc=testdomain,dc=ru}
|
||||
: ${LDAP_EXTERNAL_USE:=YES}
|
||||
: ${LDAP_EXTERNAL_SERVER:=127.0.0.1}
|
||||
: ${LDAP_EXTERNAL_BINDUSER:=vmail}
|
||||
: ${LDAP_EXTERNAL_BINDPW:=$LDAP_BINDPW}
|
||||
@@ -44,15 +45,24 @@ if [[ ! -f ".configured" ]]; then
|
||||
: ${SOGO_SIEVE_MASTER_PASSWD:=`eval </dev/urandom tr -dc A-Za-z0-9 | (head -c $1 &>/dev/null || head -c 20)`}
|
||||
: ${IREDAPD_DB_PASSWD:=`eval </dev/urandom tr -dc A-Za-z0-9 | (head -c $1 &>/dev/null || head -c 20)`}
|
||||
: ${FAIL2BAN_DB_PASSWD:=`eval </dev/urandom tr -dc A-Za-z0-9 | (head -c $1 &>/dev/null || head -c 20)`}
|
||||
: ${USE_SYSTEMD:=NO}
|
||||
|
||||
useradd -U --home-dir /home/syslog --groups adm -s /usr/sbin/nologin syslog
|
||||
|
||||
if [[ X"${MYSQLEXIST}" == X'YES' || X"${MYSQLEXIST}" == X'yes' ]]; then
|
||||
while ! mysqladmin ping -h"$MYSQLIP" --silent; do
|
||||
: ${USE_EXISTING_MYSQL:=YES}
|
||||
fi
|
||||
|
||||
|
||||
if [[ X"${MYSQLEXIST}" == X'YES' || X"${MYSQLEXIST}" == X'yes' ]]; then
|
||||
while ! mysqladmin ping -h"${MYSQL_SERVER_ADDRESS}" --silent; do
|
||||
sleep 1
|
||||
done
|
||||
fi
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
echo '>create initial config file'
|
||||
|
||||
cat <<EOF > /iredmail/config
|
||||
export STORAGE_BASE_DIR='$STORAGE_BASE_DIR'
|
||||
export WEB_SERVER='$WEB_SERVER'
|
||||
@@ -89,12 +99,14 @@ EOF
|
||||
# Install iredmail
|
||||
|
||||
if [[ X"${MYSQLEXIST}" == X'YES' || X"${MYSQLEXIST}" == X'yes' ]]; then
|
||||
USE_EXISTING_MYSQL=YES MYSQL_SERVER_ADDRESS=$MYSQLIP \
|
||||
MYSQL_SERVER_PORT=$MYSQLPORT MYSQL_ROOT_USER=$MYSQLUSER \
|
||||
MYSQL_ROOT_PASSWD=$MYSQLPASS MYSQL_GRANT_HOST=$IPADDR \
|
||||
USE_EXISTING_MYSQL=YES MYSQL_SERVER_ADDRESS=$MYSQL_SERVER_ADDRESS \
|
||||
MYSQL_SERVER_PORT=$MYSQL_SERVER_PORT MYSQL_ROOT_USER=$MYSQL_ROOT_USER \
|
||||
MYSQL_ROOT_PASSWD=$MYSQL_ROOT_PASSWD MYSQL_GRANT_HOST=$MYSQL_GRANT_HOST \
|
||||
AUTO_USE_EXISTING_CONFIG_FILE=y AUTO_INSTALL_WITHOUT_CONFIRM=y \
|
||||
AUTO_CLEANUP_REMOVE_SENDMAIL=y AUTO_CLEANUP_REPLACE_MYSQL_CONFIG=y \
|
||||
bash /iredmail/iRedMail.sh
|
||||
echo $MYSQL_SERVER_ADDRESS
|
||||
echo $MYSQL_GRANT_HOST
|
||||
else
|
||||
AUTO_USE_EXISTING_CONFIG_FILE=y AUTO_INSTALL_WITHOUT_CONFIRM=y \
|
||||
AUTO_CLEANUP_REMOVE_SENDMAIL=y AUTO_CLEANUP_REPLACE_MYSQL_CONFIG=y \
|
||||
@@ -104,20 +116,24 @@ EOF
|
||||
cp /opt/www/iredadmin/rc_scripts/uwsgi/debian.ini /etc/uwsgi/apps-enabled/iredadmin.ini
|
||||
cp /opt/mlmmjadmin/rc_scripts/uwsgi/debian.ini /etc/uwsgi/apps-enabled/mlmmjadmin.ini
|
||||
|
||||
|
||||
external_ldap_config()
|
||||
{
|
||||
|
||||
# Enable external AD authentication
|
||||
|
||||
postconf -e virtual_alias_maps=''
|
||||
postconf -e sender_bcc_maps=''
|
||||
postconf -e recipient_bcc_maps=''
|
||||
postconf -e relay_domains=''
|
||||
postconf -e relay_recipient_maps=''
|
||||
postconf -e sender_dependent_relayhost_maps=''
|
||||
postconf -e smtpd_sasl_local_domain=$FIRST_DOMAIN
|
||||
postconf -e virtual_mailbox_domains=$FIRST_DOMAIN
|
||||
postconf -e transport_maps='hash:/etc/postfix/transport'
|
||||
postconf -e smtpd_sender_login_maps='proxy:ldap:/etc/postfix/ad_sender_login_maps.cf'
|
||||
postconf -e virtual_mailbox_maps='proxy:ldap:/etc/postfix/ad_virtual_mailbox_maps.cf'
|
||||
postconf -e virtual_alias_maps='proxy:ldap:/etc/postfix/ad_virtual_group_maps.cf'
|
||||
postconf -e virtual_alias_maps=''
|
||||
postconf -e sender_bcc_maps=''
|
||||
postconf -e recipient_bcc_maps=''
|
||||
postconf -e relay_domains=''
|
||||
postconf -e relay_recipient_maps=''
|
||||
postconf -e sender_dependent_relayhost_maps=''
|
||||
postconf -e smtpd_sasl_local_domain=$FIRST_DOMAIN
|
||||
postconf -e virtual_mailbox_domains=$FIRST_DOMAIN
|
||||
postconf -e transport_maps='hash:/etc/postfix/transport'
|
||||
postconf -e smtpd_sender_login_maps='proxy:ldap:/etc/postfix/ad_sender_login_maps.cf'
|
||||
postconf -e virtual_mailbox_maps='proxy:ldap:/etc/postfix/ad_virtual_mailbox_maps.cf'
|
||||
postconf -e virtual_alias_maps='proxy:ldap:/etc/postfix/ad_virtual_group_maps.cf'
|
||||
|
||||
cat <<EOF > /etc/postfix/transport
|
||||
$FIRST_DOMAIN dovecot
|
||||
@@ -135,9 +151,8 @@ bind_dn = $LDAP_EXTERNAL_BINDUSER
|
||||
bind_pw = $LDAP_EXTERNAL_BINDPW
|
||||
search_base = $LDAP_EXTERNAL_BASE
|
||||
scope = sub
|
||||
query_filter = (&(objectclass=person)(userPrincipalName=%s))
|
||||
result_attribute= mail
|
||||
result_format = %d/%u/Maildir/
|
||||
query_filter = (&(userPrincipalName=%s)(objectClass=person)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))
|
||||
result_attribute= userPrincipalName
|
||||
debuglevel = 0
|
||||
EOF
|
||||
|
||||
@@ -151,7 +166,7 @@ bind_dn = $LDAP_EXTERNAL_BINDUSER
|
||||
bind_pw = $LDAP_EXTERNAL_BINDPW
|
||||
search_base = $LDAP_EXTERNAL_BASE
|
||||
scope = sub
|
||||
query_filter = (&(objectclass=person)(mail=%s))
|
||||
query_filter = (&(objectclass=person)(userPrincipalName=%s))
|
||||
result_attribute= userPrincipalName
|
||||
result_format = %d/%u/Maildir/
|
||||
debuglevel = 0
|
||||
@@ -169,12 +184,13 @@ search_base = $LDAP_EXTERNAL_BASE
|
||||
scope = sub
|
||||
query_filter = (&(objectClass=group)(mail=%s))
|
||||
special_result_attribute = member
|
||||
leaf_result_attribute = mail
|
||||
result_attribute= mail
|
||||
#leaf_result_attribute = mail
|
||||
result_attribute= userPrincipalName
|
||||
debuglevel = 0
|
||||
EOF
|
||||
|
||||
sed -i '/check_policy_service inet:127.0.0.1:7777/d' /etc/postfix/main.cf
|
||||
|
||||
rm -rf /etc/dovecot/dovecot-ldap.conf
|
||||
|
||||
cat <<EOF > /etc/dovecot/dovecot-ldap.conf
|
||||
@@ -274,12 +290,19 @@ cat <<EOF >> /opt/www/roundcubemail/config/config.inc.php
|
||||
// Directory setups
|
||||
);
|
||||
EOF
|
||||
}
|
||||
|
||||
|
||||
if [[ X"${EXTERNAL_LDAP_USE}" == X'YES' || X"${EXTERNAL_LDAP_USE}" == X'yes' ]]; then
|
||||
external_ldap_config
|
||||
fi
|
||||
|
||||
|
||||
touch /.configured
|
||||
|
||||
else
|
||||
|
||||
if [[ X"${MYSQLEXIST}" == X'YES' || X"${MYSQLEXIST}" == X'yes' ]]; then
|
||||
if [[ X"${MYSQLEXIST}" != X'YES' || X"${MYSQLEXIST}" != X'yes' ]]; then
|
||||
service mysql start
|
||||
fi
|
||||
service iredapd start
|
||||
@@ -289,11 +312,19 @@ else
|
||||
service nginx start
|
||||
service php7.2-fpm start
|
||||
service amavisd start
|
||||
|
||||
# Start syslog-ng
|
||||
|
||||
/usr/sbin/syslog-ng -F --no-caps &
|
||||
|
||||
service postfix start
|
||||
service mlmmjadmin_enable start
|
||||
service uwsgi start
|
||||
service slapd start
|
||||
|
||||
if [[ X"${EXTERNAL_LDAP_USE}" != X'YES' || X"${EXTERNAL_LDAP_USE}" != X'yes' ]]; then
|
||||
service slapd start
|
||||
service iredapd start
|
||||
fi
|
||||
|
||||
while true; do sleep 1; done
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user