summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: f64306a39a41651e4480d882bcc692bad39b2a3b (plain)
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# Maintainer: MartiMcFly <martimcfly [at] autorisation.de>
# Contributor: MartiMcFly <martimcfly [at] autorisation.de>

# Administrator Manual: https://documentation.kopano.io/kopanocore_administrator_manual/
# User Manual: http://documentation.kopano.io/user_manual_kopanocore
# Migration 7.2.1: https://documentation.kopano.io/kopano_migration_manual/KopanoMigrationManual.pdf
pkgname='kopano-core-git'
pkgver='9.0.12'
pkgrel='1'
pkgdesc='Foundation for groupware messaging enabling clients'
groups=(
    'kopano'
    )
arch=(
    'armv7h'
    'aarch64'
    'i686'
    'x86_64'
     )
url='https://www.kopano.com/'
license=(
    'AGPL3'
	)

_tagPrefix="kopanocore-"
# template start; name=base-scm; version=1;
#_tagPrefix=""
#_tagSuffix=""

_basePkgName="${pkgname//-git/}"

if [[ "${pkgname}" == *-git ]];
then
    # Version can't be set before pkgver has run
    provides+=("${pkgname//-git/}=${pkgver}")
fi

_gitLogByDay() {
    local NEXT=$(date +%F)
    local SINCE="1970-01-01"
    local UNTIL=$NEXT
    local LOG_FORMAT="* %s %an"
    git log --no-merges --since="${SINCE}" --until="${UNTIL}" --format="%cd" --date=short --follow . | sort -u | while read DATE ; do
	local GIT_PAGER=$(git log --no-merges --reverse --format="${LOG_FORMAT}" --since="${DATE} 00:00:00" --until="${DATE} 23:59:59" --author="${AUTHOR}" --follow . | uniq)
	if [ ! -z "$GIT_PAGER" ]
	then
	    echo
	    echo -e "[$DATE]"
	    echo -e "${GIT_PAGER}"
	fi
    done
}
if git rev-parse ;
then
    _gitLogByDay > changelog
    changelog="changelog"
fi

# https://wiki.archlinux.org/index.php/VCS_package_guidelines#Git
pkgver() {
    cd ${srcdir}/${pkgname}
    if [[ "${pkgname}" == *-git ]];
    then
	_lastTag=$(git tag -l "${_tagPrefix}*" --sort=v:refname | tail -n 1)
	_revision="$(git rev-list --count HEAD).$(git rev-parse --short HEAD)"
	if [ ! -z "${_lastTag}" ];
	then
	    echo "${_lastTag}" | sed "s|${_tagPrefix}\(.*\)${_tagSuffix}|\1.r${_revision}|"
	else
	    echo "${pkgver}" | sed "s|\(.*\)-git|1.r${_revision}|"
	fi
    else
        echo ${pkgver}
    fi
}

_sourceBranch=$(if [[ "${pkgname}" == *-git ]]; then echo "#branch=master"; else echo "#tag=${_tagPrefix}${pkgver}${_tagSuffix}"; fi)
# template end;
source=(
    "${pkgname}::git+https://stash.kopano.io/scm/kc/kopanocore.git${_sourceBranch}"
	)
md5sums=(
    'SKIP'
	)

makedepends=(
    # CORE: https://stash.kopano.io/projects/KC/repos/kopanocore/browse/doc/install.txt
    # Mandatory build-time dependencies
    'gcc'
    'binutils>=2.22'
    'pkgconf'
    'gsoap>=2.8.73'
    'icu>=52'
    'libxcrypt' # for:libcrypt with crypt_r
    'gettext'
    'libical>=0.9'
    'libiconv' # src:https://aur.archlinux.org/packages/libiconv/
    'openssl' # for:librcrypto/libssl
    'ncurses>=5'
    'util-linux-libs' # libuuid
    'kopano-libvmime>=0.9.2k2' # src:https://aur.archlinux.org/packages/kopano-libvmime/
    'libxml2'
    'mariadb-libs>=5.1' # for:MariaDB Connector/C 3.0 or MySQL Connector/C 5.1
    'xapian-core' # version:>=1.2.21
    'zlib' # version:>=1.2
    #
    # Optional build-time dependencies
    'gperftools>=2'
    'krb5'
    'curl>=7' # libcurl
    'pam>=1'
    'openldap>=2.4'
    'php>=7'
    'python>=3'
    'swig>=2.0'
    #
    # Optional build-time dependencies: Unmentioned
    'libhx>=1.10'
    #
    # Optional build-time dependencies: Unsupported
    # 'libs3' # src:https://aur.archlinux.org/packages/libs3-git/
    # 'rrdtool>=1.3'

    # PKGBUILD
    'git'
    'sed'
	    )
depends=(
    # CORE: https://stash.kopano.io/projects/KC/repos/kopanocore/browse/doc/install.txt
    'mariadb>=5.1.73'

    # SEARCH: https://stash.kopano.io/projects/KC/repos/kopanocore/browse/ECtools/search/requirements.txt
    'python-xapian'
    'python-bsddb'
    #
    # Attachment Parser
    # https://stash.kopano.io/projects/KC/repos/kopanocore/browse/ECtools/search/kopano_search/plaintext.py
    'python-magic'
    #
    # https://stash.kopano.io/projects/KC/repos/kopanocore/browse/installer/searchscripts/attachments_parser.db
    'libiconv'
    'w3m'
    'poppler' # for:pdftotext
    'catdoc' # for:catdoc,catppt,xls2csv
    'libxslt' # for:xsltproc
    'unzip'
    'gawk'


    # SPAMD: https://stash.kopano.io/projects/KC/repos/kopanocore/browse/ECtools/spamd/requirements.txt
    # Duplicate
    # 'python-bsddb'


    # BACKUP: https://stash.kopano.io/projects/KC/repos/kopanocore/browse/ECtools/backup/requirements.txt
    # Duplicate
    # 'python-bsddb'


    # SWIG: https://stash.kopano.io/projects/KC/repos/kopanocore/browse/swig/python/kopano/requirements.txt
    'python-pytz'
    'python-tzlocal'
    'python-dateutil'
    'python-pilkit'
        )
optdepends=(
    # CORE
    'gperftools' # for:libtcmalloc
    # Unsupported
    # 'libs3'
	    )

# TODO _licenseDir is supposed to be the pkgname. For unification changed here.
_confDir="etc/kopano"
_licenseDir="usr/share/licenses/kopano"
_docDir="usr/share/doc/kopano"

install='install'
for _configFile in src/${pkgname}/installer/linux/*.cfg; do
    backup+=("${_confDir}/$(basename ${_configFile})")
done

prepare() {
    cd ${srcdir}/${pkgname}
    ./bootstrap.sh
}

# https://stash.kopano.io/projects/KC/repos/kopanocore/browse/Dockerfile.build
build() {
    cd ${srcdir}/${pkgname}

    # When using official VMIME
    # https://stash.kopano.io/projects/KC/repos/kopanocore/browse/doc/install.txt#68
    #
    # VMIME_CFLAGS='$(pkg-config vmime --cflags)' \
    # VMIME_LIBS='$(pkg-config vmime --libs)' \

    ./configure \
`# https://stash.kopano.io/projects/KC/repos/kopanocore/browse/Jenkinsfile` \
    TCMALLOC_CFLAGS=' ' \
    TCMALLOC_LIBS='-ltcmalloc_minimal' \
    PYTHON="$(which python3)" \
    PYTHON_CFLAGS="$(pkg-config python3 --cflags)" \
    PYTHON_LIBS="$(pkg-config python3 --libs)" \
    --enable-release \
    --enable-pybind \
    \
`# https://documentation.kopano.io/kopanocore_administrator_manual/compiling_from_source.html` \
    --enable-epoll \
    --enable-unicode \
    --enable-python \
    --disable-static \
    --with-userscript-prefix='/etc/kopano/userscripts' \
    --with-quotatemplate-prefix='/etc/kopano/quotamails' \
    \
`# Arch specific` \
    --prefix='/usr' \
    --sbindir='$(prefix)/bin' \
    --localstatedir='/var' \
    --sysconfdir='/etc' \
    --with-searchscripts-prefix='/etc/kopano/searchscripts'

    make
}

package() {
    cd ${srcdir}/${pkgname}

    # BASE
    # => multithreaded build breaks everything
    export MAKEFLAGS="-j1"
    make install DESTDIR="$(realpath ${pkgdir})"

    # LICENSE
    mkdir -p ${pkgdir}/${_licenseDir}
    cp CONTRIBUTING.md AGPL-3 LICENSE.txt \
	${pkgdir}/${_licenseDir}/

    # DOC
    cp RELNOTES.txt \
	"${pkgdir}/${_docDir}"

    cp -r "${pkgdir}/${_docDir}/example-config" \
	"${pkgdir}/${_docDir}/installed-config"
    prepare_configs "${pkgdir}/${_docDir}/installed-config"

    # CONF
    for _configFile in ${pkgdir}/${_docDir}/installed-config/*.cfg; do
	_pkgConfigFile="${pkgdir}/${_confDir}/$(basename ${_configFile})"
	cp ${_configFile} ${_pkgConfigFile}
#	chown kopano:kopano ${_pkgConfigFile}
	chmod 0600 ${_pkgConfigFile}
    done
}

# User-Scripts

prepare_configs() {
    # Common
    config_path="$1"
    run_as_user="kopano"
    run_as_group="kopano"
    running_path="/var/lib/kopano"
    server_socket="/var/run/kopano/server.sock"
    server_socket_prio="/var/run/kopano/prio.sock"
    search_socket="/var/run/kopano/search.sock"
    ssl_protocols="TLSv1 TLSv1\.1 TLSv1\.2"
    ssl_ciphers="AES256\+EECDH:AES256\+EDH:\!aNULL"
    ssl_privatekey="/etc/ssl/private/kopano.key"
    ssl_certificate="/etc/ssl/private/kopano.crt"

    # => service
    # => server-connection (socket only)
    # => individual

    # https://stash.kopano.io/projects/KC/repos/kopanocore/browse/doc/kopano-server.cfg.5
    config_file="${config_path}/server.cfg"
    set_config "run_as_user" "${run_as_user}" ${config_file}
    set_config "run_as_group" "${run_as_group}" ${config_file}
    set_config "log_method" "syslog" ${config_file}  
    set_config "log_file" "-" ${config_file}
    set_config "log_level" "3" ${config_file}
    set_config "server_pipe_name" "${server_socket}" ${config_file}
    set_config "server_pipe_priority" "${server_socket_prio}" ${config_file}
    set_config "server_listen" "" ${config_file}
    set_config "server_listen_tls" "" ${config_file}
    set_config "server_ssl_prefer_server_ciphers" "yes" ${config_file}
    set_config "server_ssl_protocols" "${ssl_protocols}" ${config_file}
    set_config "server_ssl_ciphers" "${ssl_ciphers}" ${config_file}
    set_config "server_ssl_key_file" "${ssl_privatekey}" ${config_file}
    set_config "server_ssl_key_pass" "" ${config_file}
    set_config "server_ssl_ca_file" "${ssl_certificate}" ${config_file}
    set_config "server_ssl_ca_path" "/etc/ssl/certs" ${config_file}
    # => individual
    set_config "attachment_storage" "files" ${config_file} 
    set_config "attachment_compression" "0" ${config_file}
    set_config "disabled_features" "" ${config_file}
    set_config "hide_everyone" "yes" ${config_file}
    set_config "search_enabled" "yes" "${config_file}"
    set_config "search_socket" "file://${search_socket}" "${config_file}"
    set_config "mysql_socket" "/run/mysqld/mysqld.sock" ${config_file}
    set_config "mysql_user" "kopano" ${config_file}
    set_config "mysql_password" "kopano" ${config_file}

    # https://stash.kopano.io/projects/KC/repos/kopanocore/browse/doc/kopano-archiver.cfg.5
    config_file="${config_path}/archiver.cfg"
    set_config "log_method" "syslog" ${config_file}  
    set_config "log_file" "-" ${config_file}
    set_config "log_level" "3" ${config_file}
    set_config "server_socket" "file://${server_socket}" ${config_file}

    # https://stash.kopano.io/projects/KC/repos/kopanocore/browse/doc/kopano-backup.cfg.5
    config_file="${config_path}/backup.cfg"
    set_config "log_method" "syslog" ${config_file}  
    set_config "log_file" "-" ${config_file}
    set_config "log_level" "3" ${config_file}
    set_config "server_socket" "file://${server_socket}" ${config_file}

    # https://stash.kopano.io/projects/KC/repos/kopanocore/browse/doc/kopano-dagent.cfg.5
    config_file="${config_path}/dagent.cfg"
    set_config "run_as_user" "${run_as_user}" ${config_file}
    set_config "run_as_group" "${run_as_group}" ${config_file}
    set_config "log_method" "syslog" ${config_file}  
    set_config "log_file" "-" ${config_file}
    set_config "log_level" "3" ${config_file}
    set_config "server_bind" "127.0.0.1" ${config_file}
    set_config "server_socket" "file://${server_socket}" ${config_file}

    # https://stash.kopano.io/projects/KC/repos/kopanocore/browse/doc/kopano-gateway.cfg.5
    config_file="${config_path}/gateway.cfg"
    set_config "log_method" "syslog" ${config_file}  
    set_config "log_file" "-" ${config_file}
    set_config "log_level" "3" ${config_file}
    set_config "server_bind" "127.0.0.1" ${config_file}
    set_config "server_socket" "file://${server_socket}" ${config_file}
    set_config "ssl_prefer_server_ciphers" "yes" ${config_file}   
    set_config "ssl_protocols" "${ssl_protocols}" ${config_file}
    set_config "ssl_ciphers" "${ssl_ciphers}" ${config_file}
    set_config "ssl_private_key_file" "${ssl_privatekey}" ${config_file}   
    set_config "ssl_certificate_file" "${ssl_certificate}" ${config_file}   
    # => individual
    # avoid requests to be upgraded to admin privileges
    set_config "run_as_user" "nobody" ${config_file}
    set_config "run_as_group" "nobody" ${config_file}
    set_config "imap_generate_utf8" "no" "${config_file}"
    set_config "imap_public_folders" "yes" "${config_file}"
    set_config "process_model" "fork" ${config_file}

    # https://stash.kopano.io/projects/KC/repos/kopanocore/browse/doc/kopano-ical.cfg.5
    config_file="${config_path}/ical.cfg"
    set_config "log_method" "syslog" ${config_file}  
    set_config "log_file" "-" ${config_file}
    set_config "log_level" "3" ${config_file}
    set_config "server_bind" "127.0.0.1" ${config_file}
    set_config "server_socket" "file://${server_socket}" ${config_file}
    set_config "ssl_prefer_server_ciphers" "yes" ${config_file}
    set_config "ssl_protocols" "${ssl_protocols}" ${config_file}
    set_config "ssl_ciphers" "${ssl_ciphers}" ${config_file}
    set_config "ssl_private_key_file" "${ssl_privatekey}" ${config_file}
    set_config "ssl_certificate_file" "${ssl_certificate}" ${config_file}
    # => individual
    # avoid requests to be upgraded to admin privileges
    set_config "process_model" "fork" ${config_file}
    set_config "run_as_user" "nobody" ${config_file}
    set_config "run_as_group" "nobody" ${config_file}

    # https://stash.kopano.io/projects/KC/repos/kopanocore/browse/doc/kopano-monitor.cfg.5
    config_file="${config_path}/monitor.cfg"
    set_config "run_as_user" "${run_as_user}" ${config_file}
    set_config "run_as_group" "${run_as_group}" ${config_file}
    set_config "log_method" "syslog" ${config_file}
    set_config "log_file" "-" ${config_file}
    set_config "log_level" "3" ${config_file}
    set_config "server_socket" "file://${server_socket}" ${config_file}

    # https://stash.kopano.io/projects/KC/repos/kopanocore/browse/doc/kopano-unix.cfg.5

    # https://stash.kopano.io/projects/KC/repos/kopanocore/browse/doc/kopano-search.cfg.5
    config_file="${config_path}/search.cfg"
    set_config "run_as_user" "${run_as_user}" ${config_file}
    set_config "run_as_group" "${run_as_group}" ${config_file}
    set_config "log_method" "syslog" ${config_file}  
    set_config "log_file" "-" ${config_file}
    set_config "log_level" "3" ${config_file}
    set_config "server_socket" "file://${server_socket}" ${config_file}
    set_config "server_bind_name" "file://${search_socket}" "${config_file}"
    set_config "ssl_private_key_file" "${ssl_privatekey}" ${config_file}   
    set_config "ssl_certificate_file" "${ssl_certificate}" ${config_file}   
    # => individual
    set_config "index_attachements" "yes" "${config_file}"

    # https://stash.kopano.io/projects/KC/repos/kopanocore/browse/doc/kopano-spooler.cfg.5
    cfg="${config_path}/spooler.cfg" 
    set_config "run_as_user" "${run_as_user}" ${config_file}
    set_config "run_as_group" "${run_as_group}" ${config_file}
    set_config "log_method" "syslog" ${config_file}  
    set_config "log_file" "-" ${config_file}
    set_config "log_level" "3" ${config_file}
    set_config "server_socket" "file://${server_socket}" ${config_file}
    # => individual
    set_config "allow_send_to_everyone" "no" "${config_file}"
}

set_config() {
    local config_attribute="$1"
    local config_attribute_prefix=$(echo -n "${config_attribute}" | sed "s|\(_\).*|\1|")
    local config_value="$2"
    local config_file="$3"

    # Uncomment And Set Attribute
    if grep -q "${config_attribute}" ${config_file} ;
    then
	# Uncomment (Replaces Optional Comments And Spaces)
	sed -i "s|^#*\s*\(${config_attribute}.*\)|\1|" ${config_file}

	# Set ("name = value" => "name = newvalue")
	sed -i "s|^\(${config_attribute}\)\s*\=.*|\1 = ${config_value}|" ${config_file}

    # Add Attribute At Right Position
    elif [ ! -z "${config_attribute_prefix}" ] \
	&& grep -q "${config_attribute_prefix}" ${config_file} ;
    then
	# Find Last Attribut From Prefix-Group
	local config_attribute_last_from_group=$(tac ${config_file} | grep -m 1 "^#*\s*${config_attribute_prefix}" | grep -o "${config_attribute_prefix}[^ =]*")
	sed -i "s|\(${config_attribute_last_from_group}.*$\)|\1\n${config_attribute} = ${config_value}|" ${config_file}

    # Add Attribute At The End of File 
    else
	sed -i -z "s|\(.*[^\n]\)|\1\n${config_attribute} = ${config_value}|" ${config_file}

    fi
}