forked from openhab/openhab-linuxpkg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
495 lines (443 loc) · 19.6 KB
/
build.gradle
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
import de.undercouch.gradle.tasks.download.Download
import groovy.json.JsonSlurper
buildscript {
dependencies{
classpath fileTree(dir: 'libs', include: '*jar')
classpath 'org.apache.commons:commons-lang3:3.9'
classpath 'org.vafer:jdeb:1.8'
classpath 'com.bmuschko:gradle-docker-plugin:3.2.1'
}
}
plugins {
id "de.undercouch.download" version "4.0.4"
}
apply plugin: "nebula.ospackage"
def ARTIFACTORY_ORG = project.hasProperty('artifactoryOrg') ? project.property('artifactoryOrg') : System.env.ARTIFACTORY_ORGANISATION
def ARTIFACTORY_REPO = project.hasProperty('artifactoryRepo') ? project.property('artifactoryRepo') : System.env.ARTIFACTORY_REPO
def ARTIFACTORY_KEY = project.hasProperty('artifactoryKey') ? project.property('artifactoryKey') : System.env.ARTIFACTORY_API_KEY
def ARTIFACTORY_GPG = project.hasProperty('artifactoryGpg') ? project.property('artifactoryGpg') : System.env.ARTIFACTORY_API_GPG
def ARTIFACTORY_GPG_KEY = project.hasProperty('artifactoryGpgKey') ? project.property('artifactoryGpgKey') : System.env.ARTIFACTORY_GPG_KEY
def ARTIFACTORY_GPG_KEY_ID = project.hasProperty('artifactoryGpgKeyId') ? project.property('artifactoryGpgKeyId') : System.env.ARTIFACTORY_GPG_KEY_ID
ARTIFACTORY_ORG = ARTIFACTORY_ORG ?: 'artifactory'
ARTIFACTORY_REPO = ARTIFACTORY_REPO ?: 'openhab-linuxpkg'
ARTIFACTORY_GPG_KEY_ID = ARTIFACTORY_GPG_KEY_ID ?: 'A224060A'
def OHVersion = project.hasProperty('openHABVersion') ? project.property('openHABVersion') : System.env.OPENHAB_VERSION
def OHTestingVersion = project.hasProperty('openHABTestingVersion') ? project.property('openHABTestingVersion') : System.env.OPENHAB_TESTING_VERSION
def OHSnapVersion = project.hasProperty('openHABSnapshotVersion') ? project.property('openHABSnapshotVersion') : System.env.OPENHAB_SNAPSHOT_VERSION
def OHReleaseNumber = project.hasProperty('openHABReleaseNumber') ? project.property('openHABReleaseNumber') : System.env.OPENHAB_RELEASE_NUMBER
def OHDistroBuildNumber = project.hasProperty('openHABDistroBuildNumber') ? project.property('openHABDistroBuildNumber') : System.env.DISTRO_BUILD_NUMBER
OHVersion = OHVersion ?: '3.0.0'
OHTestingVersion = OHTestingVersion ?: '3.0.0.B1'
OHSnapVersion = OHSnapVersion ?: '3.0.0'
OHReleaseNumber = OHReleaseNumber ?: '1'
def timestamp = new Date().format('yyyyMMddHHmmss')
def OHPackageSnapVersion = OHDistroBuildNumber ? "${OHSnapVersion}~S${OHDistroBuildNumber}" : "${OHSnapVersion}~" + timestamp
def OSPACKAGE_ARCH = "all"
def architectures = [
'all',
'armhf',
'armel',
'mips',
'arm64'
]
def packageTypes = [
'Deb',
'Rpm'
]
ospackage {
os = LINUX
packager = "https://github.com/openhab/openhab-linuxpkg"
maintainer = "https://community.openhab.org"
vendor = "openHAB Foundation"
url = "www.openhab.org"
conflicts('openhab2')
conflicts('openhab-runtime')
replaces('openhab2','3.0.0~', LESS)
breaks('openhab2','3.0.0~', LESS)
conflicts('openhab2-online')
conflicts('openhab2-offline')
user = 'openhab'
permissionGroup = 'openhab'
if(ARTIFACTORY_GPG_KEY != null){
signingKeyId = "${ARTIFACTORY_GPG_KEY_ID}"
signingKeyRingFile = new File("${ARTIFACTORY_GPG_KEY}")
signingKeyPassphrase = "${ARTIFACTORY_GPG}"
signingKeySignatureSize = 543
}
}
def distributions = [
[
"dist": 'openhab-release',
"description": 'Linux installation package for openHAB.',
"debDist": ['stable','testing','unstable'],
"packageName": 'openhab',
"url": "https://openhab.jfrog.io/artifactory/libs-release-local/org/openhab/distro/openhab/${OHVersion}/openhab-${OHVersion}.tar.gz",
"path": buildDir.getAbsolutePath() + '/' + "openhab-${OHVersion}.tar.gz",
"version": "${OHVersion}",
"release": "${OHReleaseNumber}"
],[
'dist': 'openhab-addons-release',
'description': 'Linux installation package for openHAB Add-ons.',
'debDist': ['stable','testing','unstable'],
'packageName': 'openhab-addons',
'url': "https://openhab.jfrog.io/artifactory/libs-release-local/org/openhab/distro/openhab-addons/${OHVersion}/openhab-addons-${OHVersion}.kar",
'path': buildDir.getAbsolutePath() + '/' + "openhab-addons-${OHVersion}.kar",
'version': "${OHVersion}",
'release': "${OHReleaseNumber}"
],[
"dist": 'openhab-testing',
"description": 'Linux installation package for openHAB.',
"debDist": ['testing'],
"packageName": 'openhab',
"url": "https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab/${OHTestingVersion}/openhab-${OHTestingVersion}.tar.gz",
"path": buildDir.getAbsolutePath() + '/' + "openhab-${OHTestingVersion}.tar.gz",
"version": "${OHTestingVersion}",
"release": "${OHReleaseNumber}"
],[
'dist': 'openhab-addons-testing',
'description': 'Linux installation package for openHAB Add-ons.',
'debDist': ['testing'],
'packageName': 'openhab-addons',
'url': "https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab-addons/${OHTestingVersion}/openhab-addons-${OHTestingVersion}.kar",
'path': buildDir.getAbsolutePath() + '/' + "openhab-addons-${OHTestingVersion}.kar",
'version': "${OHTestingVersion}",
'release': "${OHReleaseNumber}"
],[
'dist': 'openhab-snapshot',
'description': 'Linux installation package for openHAB.',
'debDist': ['unstable'],
'packageName': 'openhab',
'url': "https://ci.openhab.org/job/openHAB3-Distribution/lastSuccessfulBuild/artifact/distributions/openhab/target/openhab-${OHSnapVersion}-SNAPSHOT.tar.gz",
'path': buildDir.getAbsolutePath() + '/' + "openhab-${OHSnapVersion}-SNAPSHOT.tar.gz",
'version': "${OHPackageSnapVersion}",
'release': '1'
],[
'dist': 'openhab-addons-snapshot',
'description': 'Linux installation package for openHAB Add-ons.',
'debDist': ['unstable'],
'packageName': 'openhab-addons',
'url': "https://ci.openhab.org/job/openHAB3-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-addons/target/openhab-addons-${OHSnapVersion}-SNAPSHOT.kar",
'path': buildDir.getAbsolutePath() + '/' + "openhab-addons-${OHSnapVersion}-SNAPSHOT.kar",
'version': "${OHPackageSnapVersion}",
'release': '1'
]
]
def generate_distro_tasks = { dist, gDescription, gPackageName, gInputFile, gVersion, gRelease, gDebDist ->
def topDist = gDebDist.first()
packageTypes.each { pType ->
def packageType = Deb
if (pType == 'Rpm') { packageType = Rpm }
task "distro-${pType}-${dist}"(type: packageType, dependsOn: "download-${dist}") {
if ((topDist == 'testing') && (gVersion.count('.') > 2)) {
def lastDotIndex = gVersion.lastIndexOf('.')
def newVersion = gVersion.substring(0,lastDotIndex)+'~'+gVersion.substring(lastDotIndex+1);
gVersion=newVersion.toString()
}
if (pType == 'Deb') { arch = "${OSPACKAGE_ARCH}" }
release = gRelease
packageName = gPackageName
version = gVersion
distribution = topDist
packageDescription = gDescription
/**
* Suck up all the empty directories that we need to install into the path.
*/
Closure suckUpEmptyDirectories = { path, u, g, mode ->
into(path) {
from "resources/dirs${path}"
user u
permissionGroup g
dirMode mode
fileMode mode
}
}
if (dist.contains('addons')){
requires('openhab')
from(gInputFile) {
if (pType == 'Rpm') {addParentDirs=false}
into '/usr/share/openhab/addons'
}
} else {
if (pType == 'Rpm') {
preInstall file('resources/control-runtime/preinst')
postInstall file('resources/control-runtime/postinst')
preUninstall file('resources/control-runtime/prerm')
postUninstall file('resources/control-runtime/postrm')
postTrans file('resources/control-runtime/posttrans')
} else {
preInstallFile file('resources/control-runtime/preinst')
postInstallFile file('resources/control-runtime/postinst')
preUninstallFile file('resources/control-runtime/prerm')
postUninstallFile file('resources/control-runtime/postrm')
}
configurationFile('/etc/default/openhab')
configurationFile('/etc/profile.d/openhab.sh')
configurationFile('/etc/openhab-cli/command-overrides.sh')
if (pType == 'Deb') {
requires('adduser')
}
suggests('default-jre | java11-runtime | java11-runtime-headless')
recommends('zip')
recommends('unzip')
FileTree tar = tarTree(gInputFile)
suckUpEmptyDirectories('/var/log/openhab', user, permissionGroup, 0755)
suckUpEmptyDirectories('/var/lib/openhab/persistence/db4o', user, permissionGroup, 0755)
suckUpEmptyDirectories('/var/lib/openhab/persistence/rrd4j', user, permissionGroup, 0755)
suckUpEmptyDirectories('/var/lib/openhab/persistence/mapdb', user, permissionGroup, 0755)
suckUpEmptyDirectories('/usr/share/openhab/bin', user, permissionGroup, 0755)
from('resources/etc/default/openhab'){
fileType CONFIG | NOREPLACE
user 'root'
permissionGroup 'root'
fileMode 0644
into '/etc/default/'
}
from('resources/etc/profile.d/openhab.sh'){
fileType CONFIG | NOREPLACE
fileMode 0644
user 'root'
permissionGroup 'root'
into '/etc/profile.d/'
}
from('resources/systemd/openhab.service'){
fileMode 0644
user 'root'
permissionGroup 'root'
into '/usr/lib/systemd/system/'
}
from('resources/usr/bin/openhab-cli'){
fileMode 0755
user 'root'
permissionGroup 'root'
into '/usr/bin/'
}
if (pType == 'Deb') {
from('resources/etc/init.d/deb/openhab'){
fileMode 0775
user 'root'
permissionGroup 'root'
into '/etc/init.d/'
}
if (topDist == 'stable') {
from('resources/etc/apt/sources.list.d/openhab-linuxpkg.list'){
fileMode 0644
user 'root'
permissionGroup 'root'
into '/etc/apt/sources.list.d/'
}
}
} else {
from('resources/etc/init.d/rpm/openhab'){
fileMode 0775
user 'root'
permissionGroup 'root'
into '/etc/init.d/'
}
if (topDist == 'stable') {
from('resources/etc/yum.repos.d/openhab-linuxpkg.repo'){
fileMode 0644
user 'root'
permissionGroup 'root'
into '/etc/yum.repos.d/'
}
}
}
from ('resources/replacements/update'){
fileMode 0755
into '/usr/share/openhab/runtime/bin/'
}
from ('resources/replacements/start.sh'){
fileMode 0755
into '/usr/share/openhab/'
}
from ('resources/etc/openhab-cli'){
fileType CONFIG | NOREPLACE
fileMode 0755
user 'root'
permissionGroup 'root'
into '/etc/openhab-cli/'
}
from(tar){
into '/usr/share/openhab'
exclude 'conf/**'
exclude 'userdata/**'
exclude '**/*.bat'
exclude '**/*.ps1'
exclude 'runtime/bin/contrib/**'
exclude 'runtime/bin/update'
exclude 'start.sh'
}
from(tar){
fileType CONFIG | NOREPLACE
into '/etc/openhab'
include 'conf/**'
eachFile { details ->
def pkgPath = details.path - 'conf'
details.path = pkgPath
configurationFile('/' + details.path)
}
}
from(tar){
fileType CONFIG | NOREPLACE
into '/var/lib/openhab'
include 'userdata/**'
exclude 'userdata/etc/all.policy'
exclude 'userdata/etc/branding.properties'
exclude 'userdata/etc/branding-ssh.properties'
exclude 'userdata/etc/com.eclipsesource.jaxrs.connector.cfg'
exclude 'userdata/etc/com.eclipsesource.jaxrs.swagger.cfg'
exclude 'userdata/etc/config.properties'
exclude 'userdata/etc/custom.properties'
exclude 'userdata/etc/custom.system.properties'
exclude 'userdata/etc/distribution.info'
exclude 'userdata/etc/jmx.acl.org.apache.karaf.bundle.cfg'
exclude 'userdata/etc/jmx.acl.org.apache.karaf.config.cfg'
exclude 'userdata/etc/jre.properties'
exclude 'userdata/etc/org.apache.felix.eventadmin.impl.EventAdmin.cfg'
exclude 'userdata/etc/org.apache.felix.fileinstall-deploy.cfg'
exclude 'userdata/etc/org.apache.karaf.*'
exclude 'userdata/etc/org.jupnp.cfg'
exclude 'userdata/etc/org.ops4j.pax.url.mvn.cfg'
exclude 'userdata/etc/overrides.properties'
exclude 'userdata/etc/profile.cfg'
exclude 'userdata/etc/startup.properties'
exclude 'userdata/etc/system.properties'
exclude 'userdata/etc/version.properties'
exclude 'userdata/tmp/**'
eachFile { details ->
def pkgPath = details.path - 'userdata'
details.path = pkgPath
configurationFile('/' + details.path)
}
}
from(tar){
into '/var/lib/openhab'
include 'userdata/etc/all.policy'
include 'userdata/etc/branding.properties'
include 'userdata/etc/branding-ssh.properties'
include 'userdata/etc/com.eclipsesource.jaxrs.connector.cfg'
include 'userdata/etc/com.eclipsesource.jaxrs.swagger.cfg'
include 'userdata/etc/config.properties'
include 'userdata/etc/custom.properties'
include 'userdata/etc/custom.system.properties'
include 'userdata/etc/distribution.info'
include 'userdata/etc/jmx.acl.org.apache.karaf.bundle.cfg'
include 'userdata/etc/jmx.acl.org.apache.karaf.config.cfg'
include 'userdata/etc/jre.properties'
include 'userdata/etc/org.apache.felix.eventadmin.impl.EventAdmin.cfg'
include 'userdata/etc/org.apache.felix.fileinstall-deploy.cfg'
include 'userdata/etc/org.apache.karaf.*'
include 'userdata/etc/org.jupnp.cfg'
include 'userdata/etc/org.ops4j.pax.url.mvn.cfg'
include 'userdata/etc/overrides.properties'
include 'userdata/etc/profile.cfg'
include 'userdata/etc/startup.properties'
include 'userdata/etc/system.properties'
include 'userdata/etc/version.properties'
eachFile { details ->
def pkgPath = details.path - 'userdata'
details.path = pkgPath
}
}
}
}
task "upload-${pType}-${dist}"(type:Exec, dependsOn: "distro-${pType}-${dist}") {
def debArchs = ''
def debDists = ''
def curlURL = ''
def fileName = ''
def curlOptions = ''
if (pType == 'Deb') {
architectures.each {arch -> debArchs = debArchs + "deb.architecture=${arch};"}
gDebDist.each {singleDebDist -> debDists = debDists + "deb.distribution=${singleDebDist};"}
fileName = "${gPackageName}_${gVersion}-${gRelease}_${OSPACKAGE_ARCH}.deb"
curlURL = "https://openhab.jfrog.io/${ARTIFACTORY_ORG}/${ARTIFACTORY_REPO}/pool/main/${gVersion}/${fileName}"
curlOptions = "{$debDists};deb.component=main;${debArchs};artifactory.licenses=Eclipse-2.0"
} else if (pType == 'Rpm') {
fileName = "${gPackageName}-${gVersion}-${gRelease}.noarch.rpm"
curlURL = "https://openhab.jfrog.io/${ARTIFACTORY_ORG}/${ARTIFACTORY_REPO}-rpm/${topDist}/${gVersion}/${fileName}"
curlOptions = 'artifactory.licenses=Eclipse-2.0'
}
executable 'curl'
args '-X', 'PUT', "${curlURL};${curlOptions}", '-H', "X-JFrog-Art-Api: ${ARTIFACTORY_KEY}", '-H', "X-GPG-PASSPHRASE: ${ARTIFACTORY_GPG}", '-T', "build/distributions/${fileName}"
standardOutput = new ByteArrayOutputStream()
doLast {
println standardOutput.toString()
def jsonSlurper = new JsonSlurper()
def object = jsonSlurper.parseText(standardOutput.toString())
def success = object.uri != null ? object.uri == "${curlURL}" : false
if (! success){
throw new GradleException('upload failed: ' + object.message)
}
}
}
}
}
distributions.each { dist -> generate_distro_tasks(dist.dist, dist.description, dist.packageName,
dist.path, dist.version, dist.release, dist.debDist)}
task packageDistros(dependsOn: tasks.findAll { t -> t.name.startsWith('distro-')}) {
description = 'Builds all the packages available for the distribution.'
group = 'openHAB Package'
}
task buildSnapshot(dependsOn: tasks.findAll { t -> t.name.endsWith('-snapshot')}) {
description = 'Performs all major tasks for the snapshot repos: Download -> Build -> Upload.'
group = 'openHAB Main'
}
task buildTesting(dependsOn: tasks.findAll { t -> t.name.endsWith('-testing')}) {
description = 'Performs all major tasks for the testing repos: Download -> Build -> Upload.'
group = 'openHAB Main'
}
task buildRelease(dependsOn: tasks.findAll { t -> t.name.endsWith("-release")}){
description = 'Performs all major tasks for the Release (stable) repos: Download -> Build -> Upload.'
group = 'openHAB Main'
}
def generate_download_tasks = { dist, url, path ->
task "download-${dist}"(type: Download) {
onlyIfNewer true
src url
dest new File(path)
}
}
distributions.each { dist -> generate_download_tasks(dist.dist, dist.url, dist.path)}
task downloadDistros(dependsOn: tasks.findAll {t -> t.name.startsWith("download-")} << {})
task removeOlderVersions(type:Exec) {
def expiryDays = 3
def expiryEpoch = System.currentTimeMillis() - (86400000 * expiryDays)
description = "Deletes packages older than ${expiryDays} days from the target repo."
group = 'openHAB Cleanup'
executable 'curl'
args '-X', 'GET', '-H', "X-JFrog-Art-Api: ${ARTIFACTORY_KEY}", "https://openhab.jfrog.io/${ARTIFACTORY_ORG}/api/search/usage?notUsedSince=${expiryEpoch}&repos=${ARTIFACTORY_REPO},${ARTIFACTORY_REPO}-rpm"
standardOutput = new ByteArrayOutputStream()
errorOutput = new ByteArrayOutputStream()
doLast {
def jsonSluper = new JsonSlurper()
def jsonText = jsonSluper.parseText(standardOutput.toString())
if (jsonText.errors) {
def errortext=jsonText.errors.message.toString()
if (errortext == '[No results found.]') {
println "Cleanup found no versions older than ${expiryDays} days!"
} else {
throw new GradleException('Cleanup failed: ' + errortext)
}
} else {
def matches = jsonText.results
def foldersToDelete = []
matches.each { object ->
def matchedURL = object.uri
if ((matchedURL.contains('~') || matchedURL.contains('unstable')) && (!matchedURL.contains('~RC') && !matchedURL.contains('~M')) && (matchedURL.contains('.deb') || matchedURL.contains('.rpm'))) {
def matchedFolder = matchedURL.substring(0,matchedURL.lastIndexOf('/'))
def matchedLocation = matchedFolder - 'api/storage/'
if (! foldersToDelete.contains(matchedLocation)) {
foldersToDelete.add(matchedLocation)
}
}
}
foldersToDelete.each { folderURL ->
exec {
println folderURL + " is older than ${expiryDays} days. Set for deletion..."
commandLine 'curl', '-X', 'DELETE', '-H', "X-JFrog-Art-Api: ${ARTIFACTORY_KEY}", "${folderURL}"
}
}
}
}
}