Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added RPM package generation and upload #37

Merged
merged 8 commits into from
Feb 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 40 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -149,9 +153,17 @@ def distributions = [
]

def generate_distro_tasks = { dist, gDescription, gPackageName, gInputFile, gVersion, gRelease, gDebDist ->
task "distro-${dist}"(type: Deb, dependsOn: "download-${dist}") {
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('~','.')
}
version = gVersion
distribution = gDebDist
packageDescription = gDescription
Expand All @@ -169,9 +181,10 @@ def generate_distro_tasks = { dist, gDescription, gPackageName, gInputFile, gVer
}
}

if (dist.contains("addons")){
if (dist.contains('addons')){
requires('openhab2')
from(gInputFile) {
if (pType == 'Rpm') {addParentDirs=false}
into 'usr/share/openhab2/addons'
}
} else {
Expand All @@ -183,7 +196,9 @@ def generate_distro_tasks = { dist, gDescription, gPackageName, gInputFile, gVer
configurationFile('/etc/default/openhab2')
configurationFile('/usr/lib/systemd/system/openhab2.service')

if (pType == 'Deb') {
requires('adduser')
}

FileTree tar = tarTree(gInputFile)
suckUpEmptyDirectories('/var/log/openhab2', user, permissionGroup, 0755)
Expand All @@ -192,6 +207,7 @@ def generate_distro_tasks = { dist, gDescription, gPackageName, gInputFile, gVer
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
Expand All @@ -204,6 +220,7 @@ def generate_distro_tasks = { dist, gDescription, gPackageName, gInputFile, gVer
into '/usr/share/openhab2/bin'
}
from(debResourcesDir + 'systemd/openhab2.service'){
fileType CONFIG | NOREPLACE
fileMode 0644
user 'root'
permissionGroup 'root'
Expand All @@ -224,6 +241,7 @@ def generate_distro_tasks = { dist, gDescription, gPackageName, gInputFile, gVer
exclude 'start_debug.bat'
}
from(tar){
fileType CONFIG | NOREPLACE
into '/etc/openhab2'
include 'conf/**'
eachFile { details ->
Expand All @@ -233,6 +251,7 @@ def generate_distro_tasks = { dist, gDescription, gPackageName, gInputFile, gVer
}
}
from(tar){
fileType CONFIG | NOREPLACE
into '/var/lib/openhab2'
include 'userdata/**'
exclude 'userdata/etc/startup.properties'
Expand Down Expand Up @@ -276,28 +295,38 @@ def generate_distro_tasks = { dist, gDescription, gPackageName, gInputFile, gVer
}
}

task "upload-${dist}"(type:Exec, dependsOn: "distro-${dist}") {
task "upload-${pType}-${dist}"(type:Exec, dependsOn: "distro-${pType}-${dist}") {

def debArchs = ""
architectures.each {arch -> debArchs = debArchs + "deb.architecture=${arch};"}

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"
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}", "-H", "X-JFrog-Art-Api: ${ARTIFACTORY_KEY}", "-H", "X-GPG-PASSPHRASE: ${ARTIFACTORY_GPG}", "-T", "build/distributions/${fileName}"
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 == "https://openhab.jfrog.io/${ARTIFACTORY_ORG}/${ARTIFACTORY_REPO}/pool/main/${gVersion}/${fileName}" : false
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)}
Expand Down
14 changes: 12 additions & 2 deletions resources/deb/control-runtime/postinst
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -56,8 +66,8 @@ waitForStopFinished(){
}

case "$1" in
configure)
if [ -z $2 ] ; then
configure|1|2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment with doc about what 1|2 args mean.

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"
Expand Down
28 changes: 28 additions & 0 deletions resources/deb/control-runtime/postrm
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -38,10 +47,29 @@ case "$1" in
rm -rf /etc/openhab2
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)
;;
*)
Expand Down
40 changes: 38 additions & 2 deletions resources/deb/control-runtime/preinst
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -12,7 +22,7 @@ removeCache(){
}

case "$1" in
install)
install) # APT Install or Upgrade
removeCache
OH_USER=openhab
OH_GROUP=openhab
Expand All @@ -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
12 changes: 11 additions & 1 deletion resources/deb/control-runtime/prerm
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -24,7 +34,7 @@ case "$1" in
stopOpenHAB
exit 0
;;
remove|deconfigure)
remove|deconfigure|0) # 0 Indicates removal on an RPM system
stopOpenHAB
exit 0
;;
Expand Down