-
Notifications
You must be signed in to change notification settings - Fork 37
/
setup.sh
executable file
·379 lines (310 loc) · 13.8 KB
/
setup.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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#!/bin/bash
set -e
fqdn_to_dn() {
printf 'dc=%s' "$1" | sed -E 's/\./,dc=/g'
}
random_string() {
LC_CTYPE=C tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c32
}
LANG_OPTIONS=("de-at" "de-ch" "de-de" "en" "en-gb" "es" "fr" "it" "nl" "pl-pl")
PLUGIN_OPTIONS=("contactfax" "desktopnotifications" "filepreviewer" "files" "filesbackend-smb" "filesbackend-owncloud" "folderwidgets" "gmaps" "intranet" "mattermost" "mdm" "pimfolder" "quickitems" "smime" "titlecounter" "webappmanual" "zdeveloper")
lang_menu() {
echo "Available options:"
for i in "${!LANG_OPTIONS[@]}"; do
printf "%3d%s) %s\n" $((i+1)) "${lang_choices[i]:- }" "${LANG_OPTIONS[i]}"
done
[[ "$msg" ]] && echo "$msg"; :
}
plugin_menu() {
echo "Available options:"
for i in "${!PLUGIN_OPTIONS[@]}"; do
printf "%3d%s) %s\n" $((i+1)) "${plugin_choices[i]:- }" "${PLUGIN_OPTIONS[i]}"
done
[[ "$msg" ]] && echo "$msg"; :
}
docker_tag_search() {
image="$1"
results=$(reg tags "$image" 2> /dev/null)
echo "$results" | xargs -n1 | sort --version-sort -ru | xargs
}
if [ ! -e /etc/machine-id ]; then
echo "This compose file uses /etc/machine-id to identify the system its running on. The file does not seem to exist on your system, please create it."
exit 1
fi
echo "Creating individual env files for containers (if they do not exist already)"
for dockerenv in ldap password-self-service mail db kopano_ssl kopano_server kopano_webapp kopano_zpush kopano_grapi kopano_kapi kopano_dagent kopano_spooler kopano_gateway kopano_ical kopano_monitor kopano_scheduler kopano_search kopano_konnect kopano_kwmbridge kopano_kwmserver kopano_meet kopano_kapps; do
touch ./"$dockerenv".env
done
if ! grep -q download.kopano.io ./apt_auth.conf 2&> /dev/null; then
echo "Adding example entry to local apt_auth.conf"
echo "machine download.kopano.io login serial password REPLACE-ME" >> ./apt_auth.conf
fi
if [ ! -e ./.env ]; then
PRINT_SETUP_SUCCESS=""
echo "Creating an .env file for you"
# if the optional https://github.com/genuinetools/reg is installed this will list available tags
if command -v reg > /dev/null; then
echo "Available tags in zokradonh/kopano_core/: $(docker_tag_search zokradonh/kopano_core)"
fi
value_default=latest
read -r -p "Which tag do you want to use for Kopano Core components? [$value_default]: " new_value
CORE_VERSION=${new_value:-$value_default}
if command -v reg > /dev/null; then
echo "Available tags in https://hub.docker.com/r/zokradonh/kopano_webapp/: $(docker_tag_search zokradonh/kopano_webapp)"
fi
value_default=latest
read -r -p "Which tag do you want to use for Kopano WebApp? [$value_default]: " new_value
WEBAPP_VERSION=${new_value:-$value_default}
if command -v reg > /dev/null; then
echo "Available tags in https://hub.docker.com/r/zokradonh/kopano_zpush/: $(docker_tag_search zokradonh/kopano_zpush)"
fi
value_default=latest
read -r -p "Which tag do you want to use for Z-Push? [$value_default]: " new_value
ZPUSH_VERSION=${new_value:-$value_default}
if command -v reg > /dev/null; then
echo "Available tags in https://hub.docker.com/r/zokradonh/kopano_konnect/: $(docker_tag_search zokradonh/kopano_konnect)"
fi
value_default=latest
read -r -p "Which tag do you want to use for Kopano Konnect? [$value_default]: " new_value
KONNECT_VERSION=${new_value:-$value_default}
value_default=latest
read -r -p "Which tag do you want to use for Kopano Kapps? [$value_default]: " new_value
KAPPS_VERSION=${new_value:-$value_default}
value_default=latest
read -r -p "Which tag do you want to use for Kopano Kwmserver? [$value_default]: " new_value
KWM_VERSION=${new_value:-$value_default}
value_default=latest
read -r -p "Which tag do you want to use for Kopano Meet? [$value_default]: " new_value
MEET_VERSION=${new_value:-$value_default}
value_default=latest
read -r -p "Which tag do you want to use for Kopano kDAV? [$value_default]: " new_value
KDAV_VERSION=${new_value:-$value_default}
value_default="Kopano Demo"
read -r -p "Name of the Organisation for LDAP [$value_default]: " new_value
LDAP_ORGANISATION=${new_value:-$value_default}
value_default="kopano.demo"
read -r -p "FQDN to be used (for reverse proxy).
Hint: use $value_default:2015 (with your actual FQDN) in case port 443 is already in use on the system (it has to be 443 or 2015, other ports will not work).
[$value_default]: " new_value
FQDN=${new_value:-$value_default}
value_default="self_signed"
read -r -p "Email address to use for Lets Encrypt.
Use 'self_signed' as your email to create self signed certificates.
Use 'off' if you want to run the service without tls encryption. Make sure to use an ssl-terminating reverse proxy in front in this case.
[$value_default]: " new_value
EMAIL=${new_value:-$value_default}
# Let Kapi accept self signed certs if required
if [ "$EMAIL" == "self_signed" ]; then
INSECURE="yes"
else
INSECURE="no"
fi
LDAP_BASE_DN=$(fqdn_to_dn "${FQDN%:*}")
value_default="$LDAP_BASE_DN"
read -r -p "Name of the BASE DN for LDAP [$value_default]: " new_value
LDAP_BASE_DN=${new_value:-$value_default}
value_default="ldap://ldap:389"
read -r -p "LDAP server to be used (defaults to the bundled OpenLDAP) [$value_default]: " new_value
LDAP_SERVER=${new_value:-$value_default}
if [ "$LDAP_SERVER" != "$value_default" ]; then
# We don't need an admin password in case we don't use the bundled LDAP server
LDAP_ADMIN_PASSWORD=""
value_default="$LDAP_BASE_DN"
read -r -p "LDAP search base [$value_default]: " new_value
LDAP_SEARCH_BASE=${new_value:-$value_default}
value_default="cn=readonly,$LDAP_BASE_DN"
read -r -p "LDAP bind user (needs read permissions) [$value_default]: " new_value
LDAP_BIND_DN=${new_value:-$value_default}
value_default="kopano123"
read -r -p "LDAP bind password to be used [$value_default]: " new_value
LDAP_BIND_PW=${new_value:-$value_default}
PRINT_SETUP_SUCCESS="$PRINT_SETUP_SUCCESS \n!! You have specified the LDAP server '${LDAP_SERVER}', don't forget to remove the bundled ldap and ldap-admin services in docker-compose.yml\n"
else
value_default="yes"
read -r -p "Use bundled LDAP with demo users? yes/no [$value_default]: " new_value
LDAP_CONTAINER_QUESTION=${new_value:-$value_default}
if [ "${LDAP_CONTAINER_QUESTION}" == "yes" ]; then
LDAP_CONTAINER="kopano_ldap_demo"
else
LDAP_CONTAINER="kopano_ldap"
fi
LDAP_ADMIN_PASSWORD=$(random_string)
LDAP_SEARCH_BASE="$LDAP_BASE_DN"
LDAP_BIND_DN="cn=readonly,$LDAP_BASE_DN"
LDAP_BIND_PW=$(random_string)
fi
# TODO get locale from system
value_default="en_US.UTF-8"
read -r -p "Language to be used for new mailboxes (needs to be available as a locale in the container) [$value_default]: " new_value
MAILBOXLANG=${new_value:-$value_default}
if [ -f /etc/timezone ]; then
value_default=$(cat /etc/timezone)
elif [ -f /etc/localtime ]; then
value_default=$(readlink /etc/localtime|sed -n 's|^.*zoneinfo/||p')
else
value_default="Europe/Berlin"
fi
read -r -p "Timezone to be used [$value_default]: " new_value
TZ=${new_value:-$value_default}
value_default="postmaster@${FQDN%:*}"
read -r -p "E-Mail Address displayed for the 'postmaster' [$value_default]: " new_value
POSTMASTER_ADDRESS=${new_value:-$value_default}
value_default="db"
read -r -p "Name/Address of Database server (defaults to the bundled one) [$value_default]: " new_value
MYSQL_HOST=${new_value:-$value_default}
if [ "$MYSQL_HOST" != "$value_default" ]; then
# We don't need an admin password in case we don't use the bundled DB server
MYSQL_ROOT_PASSWORD=""
value_default="kopanoDbUser"
read -r -p "Username to connect to the database [$value_default]: " new_value
MYSQL_USER=${new_value:-$value_default}
value_default="kopanoDbPw"
read -r -p "Password to connect to the database [$value_default]: " new_value
MYSQL_PASSWORD=${new_value:-$value_default}
value_default="kopano"
read -r -p "Database to use for Kopano [$value_default]: " new_value
MYSQL_DATABASE=${new_value:-$value_default}
PRINT_SETUP_SUCCESS="$PRINT_SETUP_SUCCESS \n!! You have specified the DB server '${MYSQL_HOST}', don't forget to remove the bundled db service in docker-compose.yml\n"
else
MYSQL_USER="kopano"
MYSQL_DATABASE="kopano"
MYSQL_ROOT_PASSWORD=$(random_string)
MYSQL_PASSWORD=$(random_string)
fi
ADDITIONAL_KOPANO_WEBAPP_PLUGINS=""
prompt="Check for additional plugins (again to uncheck, ENTER when done): "
while plugin_menu && read -rp "$prompt" num && [[ "$num" ]]; do
# shellcheck disable=SC2015
[[ "$num" != *[![:digit:]]* ]] &&
(( num > 0 && num <= ${#PLUGIN_OPTIONS[@]} )) ||
{ msg="Invalid option: $num"; continue; }
((num--)); msg="${PLUGIN_OPTIONS[num]} was ${plugin_choices[num]:+un}checked"
[[ "${plugin_choices[num]}" ]] && plugin_choices[num]="" || plugin_choices[num]="+"
done
KOPANO_WEBAPP_PLUGIN=""
for i in "${!PLUGIN_OPTIONS[@]}"; do
[[ "${plugin_choices[i]}" ]] && { KOPANO_WEBAPP_PLUGIN="${KOPANO_WEBAPP_PLUGIN} kopano-webapp-plugin-${PLUGIN_OPTIONS[i]}"; }
done
ADDITIONAL_KOPANO_WEBAPP_PLUGINS="${ADDITIONAL_KOPANO_WEBAPP_PLUGINS}${KOPANO_WEBAPP_PLUGIN}"
value_default="no"
read -r -p "Integrate WhatsApp into DeskApp yes/no [$value_default]: " new_value
WHATSAPPDESKAPP_BOOLEAN=${new_value:-$value_default}
if [ "${WHATSAPPDESKAPP_BOOLEAN}" == "yes" ]; then
ADDITIONAL_KOPANO_WEBAPP_PLUGINS="${ADDITIONAL_KOPANO_WEBAPP_PLUGINS} whatsapp4deskapp"
fi
echo "${PRINT_SETUP_SUCCESS}"
cat <<EOF > "./.env"
# please consult https://github.com/zokradonh/kopano-docker
# for possible configuration values and their impact
CORE_VERSION=$CORE_VERSION
WEBAPP_VERSION=$WEBAPP_VERSION
ZPUSH_VERSION=$ZPUSH_VERSION
KONNECT_VERSION=$KONNECT_VERSION
KWM_VERSION=$KWM_VERSION
MEET_VERSION=$MEET_VERSION
KDAV_VERSION=$KDAV_VERSION
KAPPS_VERSION=$KAPPS_VERSION
LDAP_CONTAINER=$LDAP_CONTAINER
LDAP_ORGANISATION="$LDAP_ORGANISATION"
LDAP_DOMAIN=${FQDN%:*}
LDAP_BASE_DN=$LDAP_BASE_DN
LDAP_SERVER=$LDAP_SERVER
LDAP_HOST=${LDAP_SERVER#ldap://}
LDAP_ADMIN_PASSWORD=$LDAP_ADMIN_PASSWORD
LDAP_READONLY_USER_PASSWORD=$LDAP_BIND_PW
LDAP_BIND_DN=$LDAP_BIND_DN
LDAP_BIND_PW=$LDAP_BIND_PW
LDAP_SEARCH_BASE=$LDAP_SEARCH_BASE
# LDAP query filters
LDAP_QUERY_FILTER_USER=(&(kopanoAccount=1)(mail=%s))
LDAP_QUERY_FILTER_GROUP=(&(objectclass=kopano-group)(mail=%s))
LDAP_QUERY_FILTER_ALIAS=(&(kopanoAccount=1)(kopanoAliases=%s))
LDAP_QUERY_FILTER_DOMAIN=(&(|(mail=*@%s)(kopanoAliases=*@%s)))
SASLAUTHD_LDAP_FILTER=(&(kopanoAccount=1)(uid=%s))
# LDAP user password self-service reset settings
SELF_SERVICE_SECRETEKEY=$(random_string)
SELF_SERVICE_PASSWORD_MIN_LENGTH=5
SELF_SERVICE_PASSWORD_MAX_LENGTH=0
SELF_SERVICE_PASSWORD_MIN_LOWERCASE=0
SELF_SERVICE_PASSWORD_MIN_UPPERCASE=0
SELF_SERVICE_PASSWORD_MIN_DIGIT=1
SELF_SERVICE_PASSWORD_MIN_SPECIAL=1
# switch the value of these two variables to use the activedirectory configuration
KCUNCOMMENT_LDAP_1=!include /usr/share/kopano/ldap.openldap.cfg
KCCOMMENT_LDAP_1=!include /usr/share/kopano/ldap.active-directory.cfg
MYSQL_HOST=$MYSQL_HOST
MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD
MYSQL_USER=$MYSQL_USER
MYSQL_PASSWORD=$MYSQL_PASSWORD
MYSQL_DATABASE=$MYSQL_DATABASE
KCCONF_SERVER_SERVER_NAME=Kopano
POSTMASTER_ADDRESS=$POSTMASTER_ADDRESS
MAILBOXLANG=$MAILBOXLANG
TZ=$TZ
# Defines how Kopano can be accessed from the outside world
FQDN=$FQDN
FQDNCLEANED=${FQDN%:*}
DEFAULTREDIRECT=/webapp
EMAIL=$EMAIL
CADDY=2015
HTTP=80
HTTPS=443
LDAPPORT=389
SMTPPORT=25
SMTPSPORT=465
MSAPORT=587
IMAPPORT=143
ICALPORT=8080
KOPANOPORT=236
KOPANOSPORT=237
# Settings for test environments
INSECURE=$INSECURE
# Docker and docker-compose settings
# Docker Repository to push to/pull from
docker_repo=zokradonh
COMPOSE_PROJECT_NAME=kopano
COMPOSE_FILE=docker-compose.yml:docker-compose.ports.yml:docker-compose.db.yml:docker-compose.ldap.yml:docker-compose.mail.yml
# Modify below to build a different version, than the Kopano nightly release
# credentials for repositories are handled through a file called apt_auth.conf (which will be created through setup.sh or Makefile)
#KOPANO_CORE_REPOSITORY_URL=https://download.kopano.io/supported/core:/8.7/Debian_10/
#KOPANO_KAPPS_REPOSITORY_URL=https://download.kopano.io/supported/kapps:/master/Debian_10/
#KOPANO_MEET_REPOSITORY_URL=https://download.kopano.io/supported/meet:/final/Debian_10/
#KOPANO_WEBAPP_FILES_REPOSITORY_URL=https://download.kopano.io/supported/files:/pre-final/Debian_10/
#KOPANO_WEBAPP_MDM_REPOSITORY_URL=https://download.kopano.io/supported/mdm:/final/Debian_10/
#KOPANO_WEBAPP_REPOSITORY_URL=https://download.kopano.io/supported/webapp:/final/Debian_10/
#KOPANO_WEBAPP_SMIME_REPOSITORY_URL=https://download.kopano.io/supported/smime:/final/Debian_10/
#KOPANO_ZPUSH_REPOSITORY_URL=https://download.kopano.io/zhub/z-push:/final/Debian_10/
#DOWNLOAD_COMMUNITY_PACKAGES=0
# Remove this variable to not push versioned containers with the :latest tag
PUBLISHLATEST=yes
# Additional packages to install
ADDITIONAL_KOPANO_PACKAGES=""
ADDITIONAL_KOPANO_WEBAPP_PLUGINS="$ADDITIONAL_KOPANO_WEBAPP_PLUGINS"
EOF
else
if ! grep -q COMPOSE_FILE ./.env; then
echo "Adding COMPOSE_FILE setting to .env (for docker-compose.ports.yml)"
echo "COMPOSE_FILE=docker-compose.yml:docker-compose.ports.yml" >> ./.env
fi
if ! grep -q docker-compose.db.yml ./.env; then
echo "Adding docker-compose.db.yml to COMPOSE_FILE variable in .env"
cfvalue="$(grep COMPOSE_FILE ./.env)"
sed -i "/^COMPOSE_FILE=/d" ./.env
echo "$cfvalue:docker-compose.db.yml" >> ./.env
fi
if ! grep -q docker-compose.ldap.yml ./.env; then
echo "Adding docker-compose.ldap.yml to COMPOSE_FILE variable in .env"
cfvalue="$(grep COMPOSE_FILE ./.env)"
sed -i "/^COMPOSE_FILE=/d" ./.env
echo "$cfvalue:docker-compose.ldap.yml" >> ./.env
fi
if ! grep -q docker-compose.mail.yml ./.env; then
echo "Adding docker-compose.mail.yml to COMPOSE_FILE variable in .env"
cfvalue="$(grep COMPOSE_FILE ./.env)"
sed -i "/^COMPOSE_FILE=/d" ./.env
echo "$cfvalue:docker-compose.mail.yml" >> ./.env
fi
echo ".env already exists with initial configuration"
echo "If you want to change the configuration, please edit .env directly"
exit 1
fi