diff --git a/build.gradle b/build.gradle index 3525805..34d003f 100644 --- a/build.gradle +++ b/build.gradle @@ -30,8 +30,12 @@ def architectures = [ 'arm64' ] +def packageTypes = [ + 'Deb', + 'Rpm' +] + ospackage { - arch = "${OSPACKAGE_ARCH}" os = LINUX packager = "https://github.com/openhab/openhab-linuxpkg" maintainer = "https://community.openhab.org" @@ -149,151 +153,176 @@ def distributions = [ ] def generate_distro_tasks = { dist, gDescription, gPackageName, gInputFile, gVersion, gRelease, gDebDist -> - task "distro-${dist}"(type: Deb, dependsOn: "download-${dist}") { - release = gRelease - packageName = gPackageName - version = gVersion - distribution = gDebDist - 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 "${debResourcesDir}dirs${path}" - user u - permissionGroup g - dirMode mode - fileMode mode - } - } - - if (dist.contains("addons")){ - requires('openhab2') - from(gInputFile) { - into 'usr/share/openhab2/addons' - } - } else { - preInstall file(resourcesDir + 'deb/control-runtime/preinst') - postInstall file(resourcesDir + 'deb/control-runtime/postinst') - preUninstall file(resourcesDir + 'deb/control-runtime/prerm') - postUninstall file(resourcesDir + 'deb/control-runtime/postrm') - - configurationFile('/etc/default/openhab2') - configurationFile('/usr/lib/systemd/system/openhab2.service') - - requires('adduser') - - FileTree tar = tarTree(gInputFile) - suckUpEmptyDirectories('/var/log/openhab2', user, permissionGroup, 0755) - suckUpEmptyDirectories('/var/lib/openhab2/persistence/db4o', user, permissionGroup, 0755) - suckUpEmptyDirectories('/var/lib/openhab2/persistence/rrd4j', user, permissionGroup, 0755) - suckUpEmptyDirectories('/var/lib/openhab2/persistence/mapdb', user, permissionGroup, 0755) - suckUpEmptyDirectories('/usr/share/openhab2/bin', user, permissionGroup, 0755) - from(debResourcesDir + 'etc/default/openhab2'){ - user 'root' - permissionGroup 'root' - fileMode 0644 - into '/etc/default' - } - from(debResourcesDir + 'bin/setpermissions.sh'){ - user 'root' - permissionGroup 'root' - fileMode 0775 - into '/usr/share/openhab2/bin' - } - from(debResourcesDir + 'systemd/openhab2.service'){ - fileMode 0644 - user 'root' - permissionGroup 'root' - into '/usr/lib/systemd/system' + packageTypes.each { pType -> + def packageType = Deb + if (pType == 'Rpm') { packageType = Rpm } + task "distro-${pType}-${dist}"(type: packageType, dependsOn: "download-${dist}") { + + if (pType == 'Deb') { arch = "${OSPACKAGE_ARCH}" } + release = gRelease + packageName = gPackageName + if (pType == 'Rpm') { + gVersion = gVersion.replaceAll('~','.') } - from(debResourcesDir + 'etc/init.d/openhab2'){ - fileMode 0775 - user 'root' - permissionGroup 'root' - into '/etc/init.d/' - } - from(tar){ - into '/usr/share/openhab2' - exclude 'conf/**' - exclude 'userdata/**' - exclude 'runtime/bin/oh2_dir_layout' - exclude 'start.bat' - exclude 'start_debug.bat' - } - from(tar){ - into '/etc/openhab2' - include 'conf/**' - eachFile { details -> - def pkgPath = details.path - 'conf' - details.path = pkgPath - configurationFile(details.path) + version = gVersion + distribution = gDebDist + 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 "${debResourcesDir}dirs${path}" + user u + permissionGroup g + dirMode mode + fileMode mode } } - from(tar){ - into '/var/lib/openhab2' - include 'userdata/**' - exclude 'userdata/etc/startup.properties' - exclude 'userdata/etc/config.properties' - exclude 'userdata/etc/distribution.info' - exclude 'userdata/etc/jre.properties' - exclude 'userdata/etc/org.apache.karaf.*' - exclude 'userdata/etc/profile.cfg' - exclude 'userdata/etc/branding.properties' - exclude 'userdata/etc/branding-ssh.properties' - exclude 'userdata/etc/custom.properties' - exclude 'userdata/etc/version.properties' - eachFile { details -> - def pkgPath = details.path - 'userdata' - details.path = pkgPath - configurationFile(details.path) - } - } - from(tar){ - into '/var/lib/openhab2' - include 'userdata/etc/startup.properties' - include 'userdata/etc/config.properties' - include 'userdata/etc/distribution.info' - include 'userdata/etc/jre.properties' - include 'userdata/etc/org.apache.karaf.*' - include 'userdata/etc/profile.cfg' - include 'userdata/etc/branding.properties' - include 'userdata/etc/branding-ssh.properties' - include 'userdata/etc/custom.properties' - include 'userdata/etc/version.properties' - eachFile { details -> - def pkgPath = details.path - 'userdata' - details.path = pkgPath + + if (dist.contains('addons')){ + requires('openhab2') + from(gInputFile) { + if (pType == 'Rpm') {addParentDirs=false} + into 'usr/share/openhab2/addons' } - } + } else { + preInstall file(resourcesDir + 'deb/control-runtime/preinst') + postInstall file(resourcesDir + 'deb/control-runtime/postinst') + preUninstall file(resourcesDir + 'deb/control-runtime/prerm') + postUninstall file(resourcesDir + 'deb/control-runtime/postrm') - from(debResourcesDir + 'bin/oh2_dir_layout'){ - fileMode 0775 - into '/usr/share/openhab2/runtime/bin' - } - } - } + configurationFile('/etc/default/openhab2') + configurationFile('/usr/lib/systemd/system/openhab2.service') - task "upload-${dist}"(type:Exec, dependsOn: "distro-${dist}") { + if (pType == 'Deb') { + requires('adduser') + } - def debArchs = "" - architectures.each {arch -> debArchs = debArchs + "deb.architecture=${arch};"} + FileTree tar = tarTree(gInputFile) + suckUpEmptyDirectories('/var/log/openhab2', user, permissionGroup, 0755) + suckUpEmptyDirectories('/var/lib/openhab2/persistence/db4o', user, permissionGroup, 0755) + suckUpEmptyDirectories('/var/lib/openhab2/persistence/rrd4j', user, permissionGroup, 0755) + suckUpEmptyDirectories('/var/lib/openhab2/persistence/mapdb', user, permissionGroup, 0755) + suckUpEmptyDirectories('/usr/share/openhab2/bin', user, permissionGroup, 0755) + from(debResourcesDir + 'etc/default/openhab2'){ + fileType CONFIG | NOREPLACE + user 'root' + permissionGroup 'root' + fileMode 0644 + into '/etc/default' + } + from(debResourcesDir + 'bin/setpermissions.sh'){ + user 'root' + permissionGroup 'root' + fileMode 0775 + into '/usr/share/openhab2/bin' + } + from(debResourcesDir + 'systemd/openhab2.service'){ + fileType CONFIG | NOREPLACE + fileMode 0644 + user 'root' + permissionGroup 'root' + into '/usr/lib/systemd/system' + } + from(debResourcesDir + 'etc/init.d/openhab2'){ + fileMode 0775 + user 'root' + permissionGroup 'root' + into '/etc/init.d/' + } + from(tar){ + into '/usr/share/openhab2' + exclude 'conf/**' + exclude 'userdata/**' + exclude 'runtime/bin/oh2_dir_layout' + exclude 'start.bat' + exclude 'start_debug.bat' + } + from(tar){ + fileType CONFIG | NOREPLACE + into '/etc/openhab2' + include 'conf/**' + eachFile { details -> + def pkgPath = details.path - 'conf' + details.path = pkgPath + configurationFile(details.path) + } + } + from(tar){ + fileType CONFIG | NOREPLACE + into '/var/lib/openhab2' + include 'userdata/**' + exclude 'userdata/etc/startup.properties' + exclude 'userdata/etc/config.properties' + exclude 'userdata/etc/distribution.info' + exclude 'userdata/etc/jre.properties' + exclude 'userdata/etc/org.apache.karaf.*' + exclude 'userdata/etc/profile.cfg' + exclude 'userdata/etc/branding.properties' + exclude 'userdata/etc/branding-ssh.properties' + exclude 'userdata/etc/custom.properties' + exclude 'userdata/etc/version.properties' + eachFile { details -> + def pkgPath = details.path - 'userdata' + details.path = pkgPath + configurationFile(details.path) + } + } + from(tar){ + into '/var/lib/openhab2' + include 'userdata/etc/startup.properties' + include 'userdata/etc/config.properties' + include 'userdata/etc/distribution.info' + include 'userdata/etc/jre.properties' + include 'userdata/etc/org.apache.karaf.*' + include 'userdata/etc/profile.cfg' + include 'userdata/etc/branding.properties' + include 'userdata/etc/branding-ssh.properties' + include 'userdata/etc/custom.properties' + include 'userdata/etc/version.properties' + eachFile { details -> + def pkgPath = details.path - 'userdata' + details.path = pkgPath + } + } - def fileName = "${gPackageName}_${gVersion}-${gRelease}_${OSPACKAGE_ARCH}.deb" - def curlURL = "https://openhab.jfrog.io/${ARTIFACTORY_ORG}/${ARTIFACTORY_REPO}/pool/main/${gVersion}/${fileName};deb.distribution=${gDebDist};deb.component=main;${debArchs};artifactory.licenses=Eclipse-1.0" + from(debResourcesDir + 'bin/oh2_dir_layout'){ + fileMode 0775 + into '/usr/share/openhab2/runtime/bin' + } + } + } - executable "curl" - args "-X", "PUT", "${curlURL}", "-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 == "https://openhab.jfrog.io/${ARTIFACTORY_ORG}/${ARTIFACTORY_REPO}/pool/main/${gVersion}/${fileName}" : false - if (! success){ - throw new GradleException("upload failed: " + object.message) + task "upload-${pType}-${dist}"(type:Exec, dependsOn: "distro-${pType}-${dist}") { + + def debArchs = '' + def curlURL = '' + def fileName = '' + def curlOptions = '' + + if (pType == 'Deb') { + architectures.each {arch -> debArchs = debArchs + "deb.architecture=${arch};"} + fileName = "${gPackageName}_${gVersion}-${gRelease}_${OSPACKAGE_ARCH}.deb" + curlURL = "https://openhab.jfrog.io/${ARTIFACTORY_ORG}/${ARTIFACTORY_REPO}/pool/main/${gVersion}/${fileName}" + curlOptions = "deb.distribution=${gDebDist};deb.component=main;${debArchs};artifactory.licenses=Eclipse-1.0" + } else if (pType == 'Rpm') { + fileName = "${gPackageName}-${gVersion}-${gRelease}.noarch.rpm" + curlURL = "https://openhab.jfrog.io/${ARTIFACTORY_ORG}/${ARTIFACTORY_REPO}-rpm/${gDebDist}/${gVersion}/${fileName}" + curlOptions = "artifactory.licenses=Eclipse-1.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) + } } } } diff --git a/resources/deb/control-runtime/postinst b/resources/deb/control-runtime/postinst index c2dc94f..f76512b 100644 --- a/resources/deb/control-runtime/postinst +++ b/resources/deb/control-runtime/postinst @@ -1,4 +1,14 @@ #!/bin/sh +# +# Executed after the installation of the new package +# +# On .deb based systems: +# $1=configure : On installation or upgrade +# $2=* : On upgrade, unset otherwise +# +# On .rpm based systems: +# $1=1 : On installation +# $1=2 : On upgrade UD_TMP=/var/lib/openhab2/tmp @@ -56,8 +66,8 @@ waitForStopFinished(){ } case "$1" in - configure) - if [ -z $2 ] ; then + configure|1|2) + if [ -z $2 ] && [ $1 -ne 2 ] ; then # this is a fresh installation if [ -x /bin/systemctl ] ; then echo "### NOT starting on installation, please execute the following statements to configure openHAB to start automatically using systemd" diff --git a/resources/deb/control-runtime/postrm b/resources/deb/control-runtime/postrm index 9dd3508..b576e2b 100644 --- a/resources/deb/control-runtime/postrm +++ b/resources/deb/control-runtime/postrm @@ -1,4 +1,13 @@ #!/bin/sh +# +# On .deb based systems: +# Executed after removal of the package +# $1=remove : On standard remove, keeps conffiles +# $1=purge : On purge, get rid of everything +# +# On .rpm based systems: +# Executed after all scripts have taken place +# $1=0 : On remove, get rid of everything set -e @@ -21,8 +30,8 @@ removeCache(){ case "$1" in remove) removeOpenHABInit - removeCache - exit 0 + removeCache + exit 0 ;; purge) removeOpenHABInit @@ -38,10 +47,29 @@ case "$1" in rm -rf /etc/openhab2 exit 0 ;; - upgrade) - removeCache - exit 0 - ;; + 0) # Indicates removal on RPM. There is no purge, so assume remove get rid of all + removeOpenHABInit + if getent passwd $OH_USER > /dev/null 2>&1; then + userdel --force $OH_USER || true + fi + if getent group $OH_GROUP > /dev/null 2>&1; then + groupdel $OH_GROUP || true + fi + rm -rf /var/log/openhab2 + rm -rf /var/lib/openhab2 + rm -rf /usr/share/openhab2 + rm -rf /etc/openhab2 + exit 0 + ;; + + upgrade) + removeCache + exit 0 + ;; + 1) # Indicates RPM upgrade. postrm is called after postinst so do nothing here + exit 0 + ;; + abort-install|abort-upgrade|disappear|failed-upgrade) ;; *) diff --git a/resources/deb/control-runtime/preinst b/resources/deb/control-runtime/preinst index b7b2d05..b85ef31 100644 --- a/resources/deb/control-runtime/preinst +++ b/resources/deb/control-runtime/preinst @@ -1,4 +1,14 @@ #!/bin/sh +# +# Executed before the installation of the new package +# +# On .deb based systems: +# $1=install : On installation +# $1=upgrade : On upgrade +# +# On .rpm based systems: +# $1=1 : On installation +# $1=2 : On upgrade set -e @@ -12,8 +22,8 @@ removeCache(){ } case "$1" in - install) - removeCache + install) # APT Install or Upgrade + removeCache OH_USER=openhab OH_GROUP=openhab if [ x"${USER_AND_GROUP}" != x ]; then @@ -29,6 +39,32 @@ case "$1" in --gecos "openhab2 runtime user" --home /var/lib/openhab2 "$OH_USER" fi ;; + 1|2) # RPM Install (1) or Upgrade (2) + if [ -x /bin/systemctl ] ; then + /bin/systemctl --no-reload stop openhab2.service > /dev/null 2>&1 || true + elif [ -x "/etc/init.d/openhab2" ]; then + if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then + invoke-rc.d openhab2 stop > /dev/null 2>&1 || true + else + /etc/init.d/openhab2 stop > /dev/null 2>&1 || true + fi + sleep 5 + fi + removeCache + OH_USER=openhab + OH_GROUP=openhab + if [ x"${USER_AND_GROUP}" != x ]; then + OH_USER=`echo ${USER_AND_GROUP} | cut -d ":" -f 1` + OH_GROUP=`echo ${USER_AND_GROUP} | cut -d ":" -f 2` + fi + if ! getent group "$OH_GROUP" > /dev/null 2>&1 ; then + groupadd --system "$OH_GROUP" + fi + if ! getent passwd "$OH_USER" > /dev/null 2>&1 ; then + useradd --system -g "$OH_GROUP" \ + --shell /bin/false \ + --home /var/lib/openhab2 "$OH_USER" + fi + ;; esac - exit 0 diff --git a/resources/deb/control-runtime/prerm b/resources/deb/control-runtime/prerm index 0e3b1f1..c9c5271 100644 --- a/resources/deb/control-runtime/prerm +++ b/resources/deb/control-runtime/prerm @@ -1,4 +1,14 @@ #!/bin/sh +# +# On .deb based systems: +# Executed on old package before all other scripts +# $1=upgrade : On upgrade +# $2=remove : On any uninstall +# +# On .rpm based systems: +# Executed on old package (after the installation of the new package on upgrade...) +# $1=0 : On removal +# $1=1 : On upgrade set -e @@ -22,11 +32,11 @@ stopOpenHAB() { case "$1" in upgrade) stopOpenHAB - exit 0 + exit 0 ;; - remove|deconfigure) + remove|deconfigure|0) # 0 Indicates removal on an RPM system stopOpenHAB - exit 0 + exit 0 ;; failed-upgrade) ;;