-
Notifications
You must be signed in to change notification settings - Fork 216
/
config_via_dialog.sh
258 lines (210 loc) · 9.78 KB
/
config_via_dialog.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/usr/bin/env bash
# Author: Zhang Huangbin (zhb _at_ iredmail.org)
#---------------------------------------------------------------------
# This file is part of iRedMail, which is an open source mail server
# solution for Red Hat(R) Enterprise Linux, CentOS, Debian and Ubuntu.
#
# iRedMail is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# iRedMail 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with iRedMail. If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------
# Note: config file will be sourced in 'conf/core', function `check_env()`.
. ${CONF_DIR}/global
. ${CONF_DIR}/core
. ${CONF_DIR}/openldap
. ${CONF_DIR}/postfix
. ${CONF_DIR}/roundcube
. ${CONF_DIR}/iredadmin
trap "exit 255" 2
# Initialize config file.
echo '' > ${IREDMAIL_CONFIG_FILE}
chown ${SYS_USER_ROOT}:${SYS_GROUP_ROOT} ${IREDMAIL_CONFIG_FILE}
chmod 0400 ${IREDMAIL_CONFIG_FILE}
DIALOG="dialog --colors --no-collapse --insecure --ok-label Next \
--no-cancel --backtitle ${PROG_NAME}:_Open_Source_Mail_Server_Solution"
# Welcome message.
${DIALOG} \
--title "Welcome" \
--yesno "\
Welcome to the iRedMail setup wizard, we will ask you some simple questions required to setup a mail server. If you encounter any trouble or issues, please report to our support forum: https://forum.iredmail.org/
---------------------------- WARNING ----------------------------
iRedMail is designed to be deployed on a __FRESH__ server, which means your server should __NOT__ have mail related components installed, e.g. Nginix / Apache, MySQL / MariaDB / PostgreSQL / OpenLDAP, Postfix, Dovecot, Amavisd, etc. iRedMail will install and configure required softwares automatically. Otherwise it may mess up your server by overriding existing config files without asking.
-----------------------------------------------------------------
NOTE: You can abort this setup wizard by pressing key Ctrl-C.
" 20 76
# Exit when user choose 'exit'.
[ X"$?" != X"0" ] && ECHO_INFO "Exit." && exit 0
# Storage base directory
while :; do
${DIALOG} \
--title "Default mail storage path" \
--inputbox "\
Please specify a directory (in lowercase) used to store user mailboxes.
Default is: ${STORAGE_BASE_DIR}
NOTES:
* Depends on the mail traffic, it may take large disk space.
* Maildir path will be converted to lowercases, so please create this
directory in lowcases.
* It cannot be /var/mail or /root.
* Mailboxes will be stored under its sub-directory: ${STORAGE_BASE_DIR}/${STORAGE_NODE}/
* Daily backup of SQL/LDAP databases will be stored under another sub-directory: /var/vmail/backup.
" 20 76 "${STORAGE_BASE_DIR}" 2>${RUNTIME_DIR}/.storage_base_dir
export STORAGE_BASE_DIR="$(cat ${RUNTIME_DIR}/.storage_base_dir | tr '[A-Z]' '[a-z]')"
# Make sure storage directory is not one of:
# - /var/mail: it's used to store mails for system accounts
# - /root: only root user can access it, mail services won't work.
if echo ${STORAGE_BASE_DIR} | grep -iE '^(/var/mail\>|/root\>)' &>/dev/null; then
:
else
break
fi
done
rm -f ${RUNTIME_DIR}/.storage_base_dir &>/dev/null
export STORAGE_BASE_DIR="${STORAGE_BASE_DIR}"
echo "export STORAGE_BASE_DIR='${STORAGE_BASE_DIR}'" >> ${IREDMAIL_CONFIG_FILE}
# --------------------------------------------------
# ------------ Default web server ------------------
# --------------------------------------------------
export DISABLE_WEB_SERVER='NO'
export WEB_SERVER=''
if [ X"${DISTRO}" == X'OPENBSD' ]; then
while : ; do
${DIALOG} \
--title "Preferred web server" \
--radiolist "Choose a web server you want to run.
TIP: Use SPACE key to select item." \
20 76 3 \
"Nginx" "The fastest web server" "on" \
"No web server" "I don't need any web applications on this server" "off" \
2>${RUNTIME_DIR}/.web_server
web_server_case_sensitive="$(cat ${RUNTIME_DIR}/.web_server)"
web_server="$(echo ${web_server_case_sensitive} | tr '[a-z]' '[A-Z]')"
[ X"${web_server}" != X"" ] && break
done
rm -f ${RUNTIME_DIR}/.web_server
else
while : ; do
${DIALOG} \
--title "Preferred web server" \
--radiolist "Choose a web server you want to run.
TIP: Use SPACE key to select item." \
20 76 3 \
"Nginx" "The fastest web server" "on" \
"No web server" "I don't need any web applications on this server" "off" \
2>${RUNTIME_DIR}/.web_server
web_server_case_sensitive="$(cat ${RUNTIME_DIR}/.web_server)"
web_server="$(echo ${web_server_case_sensitive} | tr '[a-z]' '[A-Z]')"
[ X"${web_server}" != X"" ] && break
done
rm -f ${RUNTIME_DIR}/.web_server
fi
if [ X"${web_server}" == X'NGINX' ]; then
export WEB_SERVER='NGINX'
else
export DISABLE_WEB_SERVER='YES'
echo "export DISABLE_WEB_SERVER='YES'" >>${IREDMAIL_CONFIG_FILE}
fi
echo "export WEB_SERVER='${WEB_SERVER}'" >>${IREDMAIL_CONFIG_FILE}
# --------------------------------------------------
# --------------------- Backends --------------------
# --------------------------------------------------
export DIALOG_AVAILABLE_BACKENDS=''
if [ X"${ENABLE_BACKEND_OPENLDAP}" == X'YES' ]; then
export DIALOG_AVAILABLE_BACKENDS="${DIALOG_AVAILABLE_BACKENDS} OpenLDAP An_open_source_implementation_of_LDAP_protocol off"
fi
if [ X"${ENABLE_BACKEND_MARIADB}" == X'YES' ]; then
export DIALOG_AVAILABLE_BACKENDS="${DIALOG_AVAILABLE_BACKENDS} MariaDB An_enhanced,_drop-in_replacement_for_MySQL off"
fi
if [ X"${ENABLE_BACKEND_PGSQL}" == X'YES' ]; then
export DIALOG_AVAILABLE_BACKENDS="${DIALOG_AVAILABLE_BACKENDS} PostgreSQL Powerful,_open_source_database_system off"
fi
while : ; do
${DIALOG} \
--title "Choose preferred backend used to store mail accounts" \
--radiolist "It's strongly recommended to choose the one you're familiar with for easy maintenance. They all use the same webmail (Roundcube) and admin panel (iRedAdmin), and no big feature differences between them.
TIP: Use SPACE key to select item.
" 20 76 4 ${DIALOG_AVAILABLE_BACKENDS} 2>${RUNTIME_DIR}/.backend
BACKEND_ORIG_CASE_SENSITIVE="$(cat ${RUNTIME_DIR}/.backend)"
BACKEND_ORIG="$(echo ${BACKEND_ORIG_CASE_SENSITIVE} | tr '[a-z]' '[A-Z]')"
[ X"${BACKEND_ORIG}" != X"" ] && break
done
rm -f ${RUNTIME_DIR}/.backend &>/dev/null
if [ X"${BACKEND_ORIG}" == X'OPENLDAP' ]; then
export BACKEND='OPENLDAP'
elif [ X"${BACKEND_ORIG}" == X'MARIADB' ]; then
export BACKEND='MYSQL'
elif [ X"${BACKEND_ORIG}" == X'POSTGRESQL' ]; then
export BACKEND='PGSQL'
export BACKEND_ORIG='PGSQL'
fi
echo "export BACKEND_ORIG='${BACKEND_ORIG}'" >> ${IREDMAIL_CONFIG_FILE}
echo "export BACKEND='${BACKEND}'" >> ${IREDMAIL_CONFIG_FILE}
# Read-only SQL user/role, used to query mail accounts in Postfix, Dovecot.
export VMAIL_DB_BIND_PASSWD="$(${RANDOM_STRING})"
echo "export VMAIL_DB_BIND_PASSWD='${VMAIL_DB_BIND_PASSWD}'" >> ${IREDMAIL_CONFIG_FILE}
# For database management: vmail.
export VMAIL_DB_ADMIN_PASSWD="$(${RANDOM_STRING})"
echo "export VMAIL_DB_ADMIN_PASSWD='${VMAIL_DB_ADMIN_PASSWD}'" >> ${IREDMAIL_CONFIG_FILE}
# For mlmmj mailing list manager
export MLMMJADMIN_API_AUTH_TOKEN="$(${RANDOM_STRING})"
echo "export MLMMJADMIN_API_AUTH_TOKEN='${MLMMJADMIN_API_AUTH_TOKEN}'" >> ${IREDMAIL_CONFIG_FILE}
# For database management: vmail.
export NETDATA_DB_PASSWD="$(${RANDOM_STRING})"
echo "export NETDATA_DB_PASSWD='${NETDATA_DB_PASSWD}'" >> ${IREDMAIL_CONFIG_FILE}
if [ X"${BACKEND}" == X'OPENLDAP' ]; then
. ${DIALOG_DIR}/ldap_config.sh
. ${DIALOG_DIR}/mysql_config.sh
elif [ X"${BACKEND}" == X'MYSQL' ]; then
. ${DIALOG_DIR}/mysql_config.sh
elif [ X"${BACKEND}" == X'PGSQL' ]; then
. ${DIALOG_DIR}/pgsql_config.sh
fi
# Virtual domain configuration.
. ${DIALOG_DIR}/virtual_domain_config.sh
# Optional components.
. ${DIALOG_DIR}/optional_components.sh
# Append EOF tag in config file.
echo "#EOF" >> ${IREDMAIL_CONFIG_FILE}
#
# Ending message.
#
cat <<EOF
*************************************************************************
***************************** WARNING ***********************************
*************************************************************************
* *
* Below file contains sensitive infomation (username/password), please *
* do remember to *MOVE* it to a safe place after installation. *
* *
* * ${IREDMAIL_CONFIG_FILE}
* *
*************************************************************************
********************** Review your settings *****************************
*************************************************************************
* Storage base directory: ${STORAGE_BASE_DIR}
* Mailboxes: ${STORAGE_MAILBOX_DIR}
* Daily backup of SQL/LDAP databases: ${BACKUP_DIR}
* Store mail accounts in: ${BACKEND_ORIG_CASE_SENSITIVE}
* Web server: ${web_server_case_sensitive}
* First mail domain name: ${FIRST_DOMAIN}
* Mail domain admin: ${DOMAIN_ADMIN_NAME}@${FIRST_DOMAIN}
* Additional components: ${OPTIONAL_COMPONENTS}
EOF
ECHO_QUESTION -n "Continue? [y|N]"
read_setting ${AUTO_INSTALL_WITHOUT_CONFIRM}
case ${ANSWER} in
Y|y) : ;;
N|n|*)
ECHO_INFO "Cancelled, Exit."
exit 255
;;
esac