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
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
|
# Find this package on https://github.com/pietmacom/kopano-pkgbuilds.git
pkgname='kopano-webapp-desktopnotifications-git'
pkgver='2.0.3'
_source='git+https://stash.kopano.io/scm/kwa/desktopnotifications.git'
_tagPrefix='v'
# template start; name=kopano-webapp-plugin; version=1;
# _source=
# _tagPrefix=kopanocore-
pkgrel=1
groups=(
'kopano'
'kopano-webapp-plugins'
)
arch=(
'any'
)
manifestXml() {
_manifestXmlFile="src/${pkgname}/manifest.xml"
if [ -e "${_manifestXmlFile}" ];
then
xmllint --xpath "string(/plugin/info/$1)" ${_manifestXmlFile}
else
echo
fi
}
pkgdesc="$(manifestXml 'description')"
url="$(manifestXml 'authorURL')"
for _licenseFile in AGPL-3
do
if [ -e "src/${pkgname}/${_licenseFile}" ];
then
license+=('AGPL-3')
fi
done
# template start; name=base-scm; version=1;
#_tagPrefix=""
#_tagSuffix=""
#_remoteGit=""
if [[ "${pkgname}" == *-latest ]] && [ ! -z "${_remoteGit}" ];
then
pkgver=$(git ls-remote --refs --tags "${_remoteGit}" | sed 's|.*tags/\(.*\)$|\1|' | sort -u | grep -vE "(beta|alpha|test)" | tail -n 1)
fi
_basePkgName="${pkgname//-git/}"
if [[ "${pkgname}" == *-git ]];
then
# Version can't be set before pkgver has run
provides+=("${_basePkgName}=${pkgver}")
fi
_gitLogByDay() {
local NEXT=$(date +%F)
local SINCE="1970-01-01"
local UNTIL=$NEXT
local LOG_FORMAT="* %s"
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 [ ! -e "changelog" ] \
|| 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
# elif [[ "${pkgname}" == *-latest ]];
# then
# #_tagReleaseFormat="^[0-9]*(\.[0-9])*$"
# _lastRelease=$(git tag -l "${_tagPrefix}*" --sort=v:refname | grep -v "(alpha|beta|test)" | tail -n 1)
# echo "${_lastRelease}" | sed "s|${_tagPrefix}\(.*\)${_tagSuffix}|\1|"
else
echo "${pkgver}"
fi
}
_patchFromGit() {
_patchDir="${srcdir}/$(basename $(pwd))-patch.git"
if [ ! -e "${_patchDir}" ];
then
git clone --bare ${1} ${_patchDir}
fi
_branchName="${_sourceBranch//#*=/}"
_patchGIT="git --git-dir="${_patchDir}""
# Patch From Specific Range
if [ ! -z "${3}" ];
then
_sourceCommit=$($_patchGIT rev-parse --verify --quiet "${2}")
_targetCommit=$($_patchGIT rev-parse --verify --quiet "${3}")
if $_patchGIT format-patch "^${_sourceCommit}" "${_targetCommit}" --stdout | git apply -v ;
then
echo "Patch Applied From Commit Between ${2} to ${3}"
else
echo "Patch Failed."
exit 1
fi
# Patch From Specific Commit
elif [ ! -z "${2}" ];
then
_sourceCommit=$($_patchGIT rev-parse --verify --quiet "${2}")
if $_patchGIT format-patch -1 "${_sourceCommit}" --stdout | git apply -v ;
then
echo "Patch Applied From Commit ${2}"
else
echo "Patch Failed."
exit 1
fi
# Patch From "*-latest-patch" Branch
elif [[ "${pkgname}" != *-git ]] \
&& _sourceCommit=$($_patchGIT rev-parse --verify --quiet "${_branchName}") \
&& _targetCommit=$($_patchGIT rev-parse --verify --quiet "${_branchName}-latest-patch") ;
then
if $_patchGIT format-patch "^${_sourceCommit}" "${_targetCommit}" --stdout | git apply -v ;
then
echo "Patch Applied From Branch ${_branchName}-latest-patch"
else
echo "Patch Failed."
exit 1
fi
# Patch From "master-latest-patch" Branch
elif _sourceCommit=$($_patchGIT rev-parse --verify --quiet "master") \
&& _targetCommit=$($_patchGIT rev-parse --verify --quiet "master-latest-patch") ;
then
if $_patchGIT format-patch "^${_sourceCommit}" "${_targetCommit}" --stdout | git apply -v ;
then
echo "Patch Applied From Branch master-latest-patch"
else
echo "Patch Failed."
exit 1
fi
else
echo "No Patch Branch Found"
fi
}
_sourceBranch=$(if [[ "${pkgname}" == *-git ]]; then echo "#branch=master"; else echo "#tag=${_tagPrefix}${pkgver}${_tagSuffix}"; fi)
# template end;
source+=(
"${pkgname}::${_source}${_sourceBranch}"
)
md5sums+=(
'SKIP'
)
_phpIni="${_basePkgName}.ini"
if [ -e "${_phpIni}" ];
then
source+=(
"${_phpIni}"
)
md5sums+=(
"$(md5sum ${_phpIni})"
)
fi
makedepends+=(
# WEBAPP: https://stash.kopano.io/projects/KW/repos/kopano-webapp/browse/README.md
'apache-ant'
'libxml2'
# PKGBUILD
'git'
'gzip'
)
depends+=(
'kopano-webapp'
)
if [ -f 'install' ];
then
install='install'
fi
# template start; name=base-build-webapp; version=1;
# https://wiki.archlinux.org/index.php/Web_application_package_guidelines
_binDir=usr/share/webapps/${_basePkgName}
_confDir=etc/webapps/${_basePkgName}
# template start; name=base-build; version=1;
# https://wiki.archlinux.org/index.php/Arch_package_guidelines
#_binDir=
#_confDir=
if [ -z "${_basePkgName}" ];
then
_basePkgName="${pkgname}"
fi
_docDir=usr/share/doc/${_basePkgName}
_stateDir=var/lib/${_basePkgName}
_logDir=var/log/${_basePkgName}
_licenseDir=usr/share/licenses/${_basePkgName}
_commonPermissions='u=rwx,g=rx,o=rx u=rw,g=r,o=r'
_securePermissions='u=rwx,g=rx,o= u=rw,g=r,o='
# Strictly Formatted Installation
#
# Known system -parent- directories are created and rights are
# copied from local system.
#
### Files
#
# (1) _install user:group ${_commonPermissions} newFile destDir/
# * Create Empty File In Destination-Directory
# => destDir/newFile
#
# (2) _install user:group ${_commonPermissions} sourceFile destDir/
# * Copy Source-File Into Destination-Directory
# => destDir/sourcFileName
#
# (3) _install user:group ${_commonPermissions} sourceFile destDir/destFileName
# * Copy Source-File Into Destinatin-Directory With New Name
# => destDir/destFileName
#
### Directories
# Leaf directory are created and rights are applied.
#
# (4) _install user:group ${_commonPermissions} destDir/newDir
# * Create New Directory
# => destDir/newDir
#
# (5) _install user:group ${_commonPermissions} sourceDir destDir/
# * Copy Source-Directory Into Destination-Directory
# => destDir/sourceDirName
#
# (6) _install user:group ${_commonPermissions} sourceDir destDir
# * Copy Content of Source-Directory Into Destination-Directory
# => destDir/sourceDirContent
#
# https://www.shellbefehle.de/befehle/chmod/
_install() {
local _chown="$1"
local _chmodDir="$2"
local _chmodFile="$3"
### Directories
# (4) Create New Directory
if [ -z "$5" ];
then
local _dest="$4"
_mkParentDir "${_dest}"
if [ ! -e "${_dest}" ];
then
mkdir "${_dest}"
fi
chown ${_chown} ${_dest}
chmod "${_chmodDir}" ${_dest}
return 0
fi
local _source=$4
local _dest=$5
if [ -d "${_source}" ];
then
if [[ ${_dest} == */ ]];
then
# (5) Copy Source-Directory Into Destination-Directory
_dest="${_dest}$(basename ${_source})"
fi
_mkParentDir "${_dest}"
# (5),(6) Copy Content of Source-Directory Into Destination-Directory
if [ ! -e "${_dest}" ];
then
mkdir "${_dest}"
fi
cp -fRT ${_source} ${_dest}
find ${_dest} -exec chown "${_chown}" {} \;
find ${_dest} -type f -exec chmod "${_chmodFile}" {} \;
find ${_dest} -type d -exec chmod "${_chmodDir}" {} \;
return 0
fi
### Files
if [[ ${_dest} == */ ]];
then
# (2) Copy Source-File Into Destination-Directory
_dest=${_dest}$(basename ${_source})
fi
_mkParentDir "${_dest}"
if [ ! -f "${_source}" ];
then
# (1) Create Empty File In Destination-Directory
touch ${_dest}
else
# (1),(3) Copy Source-File Into Destinatin-Directory With New Name
cp -fL ${_source} ${_dest}
fi
chown ${_chown} ${_dest}
chmod "${_chmodFile}" ${_dest}
}
# Creates known System -parent- directories and copies
# permissions.
_mkParentDir() {
local _destParent="$(dirname $1)"
if [ -e "${_destParent}" ];
then
return 0
fi
# Check System Directory
find / -maxdepth 1 -mindepth 1 -type d -print0 | while read -d $'\0' _rootDir
do
if [[ "${_destParent}" == *${_rootDir}* ]];
then
_destSystemPath=$(echo ${_destParent} | grep -o "${_rootDir}.*")
if [ -d "${_destSystemPath}" ];
then
mkdir -p ${_destParent}
chmod --reference=${_destSystemPath} ${_destParent}
chown --reference=${_destSystemPath} ${_destParent}
break;
fi
fi
done
if [ ! -e "${_destParent}" ];
then
_knownSystemDirectories=(
'usr/share/webapps'
'etc/webapps'
)
for _knownSystemDirectory in "${_knownSystemDirectories[@]}"
do
if [[ ${_destParent} == *${_knownSystemDirectory} ]];
then
mkdir -p ${_destParent}
break;
fi
done
fi
if [ ! -e "${_destParent}" ];
then
echo "Parent not found (${_destParent}). Maybe its a not known System-Directory:"
for _systemDirectory in "${_systemDirectories[@]}"
do
echo " ${_systemDirectory}"
done
exit 1
fi
}
# template end;
# compressStatic /usr/share/webapps/xxx 'htm|css|html|js'
_compressStatic() {
_dir=$1
if [ -z "$2" ];
then
_fileExtensions='htm|css|html|js'
fi
find ${_dir} -type f -regextype posix-extended -regex '.*\.('${_fileExtensions}')' -print0 \
| while read -d $'\0' _staticFile
do
if [ -f "${_staticFile}".gz ]
then
FILE_ORIG=$(stat -c %Y "${_staticFile}")
FILE_GZIP=$(stat -c %Y "${_staticFile}".gz)
if [ $FILE_ORIG -gt $FILE_GZIP ]
then
rm "${_staticFile}".gz
gzip -k -9 "${_staticFile}"
echo "Deleted old .gz and created new one at: ${_staticFile}.gz"
else
echo "Skipping - Already up to date: ${_staticFile}.gz"
fi
else
gzip -k -9 "${_staticFile}"
echo "Created new: ${_staticFile}.gz"
fi
done
}
# template end;
if [ -f "src/${pkgname}/config.php" ];
then
backup=(
"${_confDir}/config.php"
)
fi
_pluginName=${_basePkgName//kopano-webapp-/}
build() {
# Build-Environment
_kopanoWebappDir="${srcdir}/kopano-webapp"
cp -R /usr/share/webapps/kopano-webapp \
${_kopanoWebappDir}
cp -R /usr/share/doc/kopano-webapp/tools \
${_kopanoWebappDir}/
mkdir -p ${_kopanoWebappDir}/plugins
mkdir -p ${_kopanoWebappDir}/deploy
cp -R ${srcdir}/${pkgname} \
kopano-webapp/plugins/${_pluginName}
cd kopano-webapp/plugins/${_pluginName}
if [ -f 'Makefile' ];
then
# htmleditor-quill, htmleditor-jodit, htmleditor-minimaltiny is using DESTDIR ?= deploy
# SMIME is using DEPLOY instead of standard variable DESTDIR
make deploy \
DESTDIR="../../deploy/plugins/${_pluginName}" \
DEPLOY="../../deploy/plugins/${_pluginName}"
elif [ -f "build.xml" ];
then
# Fetchmail is using different root-, target-folder
ant deploy \
-Droot-folder="$(pwd)/../../" \
-Dtarget-folder="$(pwd)/../../deploy/plugins"
else
echo "Nothing to build."
fi
}
package() {
# Override
_binDir=usr/share/webapps/kopano-webapp/plugins/${_pluginName}
# BIN
cd ${srcdir}/kopano-webapp/deploy/plugins/${_pluginName}
_install root:root ${_commonPermissions} . \
${pkgdir}/${_binDir}
_compressStatic ${pkgdir}/${_binDir}
# CONF
if [ -e "${pkgdir}/${_binDir}/config.php" ];
then
cp ${pkgdir}/${_binDir}/config.php \
${pkgdir}/${_binDir}/config.php.dist
_install http:http ${_securePermissions} ${pkgdir}/${_confDir}
_install http:http ${_securePermissions} ${pkgdir}/${_binDir}/config.php \
${pkgdir}/${_confDir}/
ln -sf ${_confDir}/config.php \
${pkgdir}/${_binDir}/config.php
fi
# DOC
if [ -e "${srcdir}/${_phpIni}" ];
then
_install root:root ${_commonPermissions} ${pkgdir}/${_docDir}
_install root:root ${_commonPermissions} ${srcdir}/${_phpIni} \
${pkgdir}/${_docDir}/
fi
# LICENSE
for _licenseFile in LICENSE.txt AGPL-3
do
if [ -e "${pkgdir}/${_binDir}/${_licenseFile}" ];
then
_install root:root ${_commonPermissions} ${pkgdir}/${_licenseDir}
_install root:root ${_commonPermissions} ${pkgdir}/${_binDir}/${_licenseFile} \
${pkgdir}/${_licenseDir}/
fi
done
# STATE
_install http:http ${_securePermissions} ${pkgdir}/${_stateDir}
# OTHER: PHP
if [ -e '${srcdir}/${_phpIni}' ];
then
_install root:root ${_commonPermissions} ${srcdir}/${_phpIni} \
${pkgdir}/etc/php/conf.d/
fi
}
# _setConfig PLUGIN_MDM_USER_DEFAULT_ENABLE_MDM true config.php
_setConfig() {
local _configAttribute="$1"
local _configValue="$2"
local _configFile="$(echo $3 | sed 's|\"|\\"|g')"
sed -i -e "s|\(${_configAttribute}', \)\(.*\)\();$\)|\1${_configValue}\3|" ${_configFile}
}
# template end;
|