Luca Prete
Committed by Gerrit Code Review

Adding rpm generation functionalities in onos-package

Change-Id: Iced5950e6f509700dcce5f419edec52a90a1ab83
......@@ -21,12 +21,15 @@ export BUILD_NUMBER=${BUILD_NUMBER:-$(id -un)~$(date +'%Y/%m/%d@%H:%M')}
export ONOS_POM_VERSION="1.3.0-SNAPSHOT"
export ONOS_VERSION=${ONOS_VERSION:-1.3.0.$BUILD_NUMBER}
# ONOS production bits (onos.tar.gz & onos.zip) staging environment
# ONOS production bits (onos.tar.gz, onos.zip, onos.deb, onos.rpm) staging environment
export ONOS_BITS=onos-${ONOS_VERSION%~*}
export ONOS_STAGE_ROOT=${ONOS_STAGE_ROOT:-/tmp}
export ONOS_STAGE=$ONOS_STAGE_ROOT/$ONOS_BITS
export ONOS_DEB_ROOT=$ONOS_STAGE_ROOT/deb
export ONOS_DEB=$ONOS_STAGE.deb
export ONOS_RPM_ROOT=$ONOS_STAGE_ROOT/rpm
export ONOS_RPM=$ONOS_STAGE.rpm
export ONOS_RPM_VERSION=${ONOS_POM_VERSION//-/.}
export ONOS_TAR=$ONOS_STAGE.tar.gz
export ONOS_ZIP=$ONOS_STAGE.zip
......
......@@ -95,12 +95,10 @@ function build_deb() {
sudo rm -fr $ONOS_DEB_ROOT
mkdir -p $ONOS_DEB_ROOT/DEBIAN
mkdir -p $ONOS_DEB_ROOT/opt/
mkdir -p $ONOS_DEB_ROOT/etc/init
mkdir -p $ONOS_DEB_ROOT/{DEBIAN,opt,etc/init}
{
echo "Package: onos"
echo "Package: ONOS"
echo "Architecture: all"
echo "Maintainer: ONOS Project"
echo "Depends: debconf (>= 0.5.00), default-jre-headless (>= 1.8) | openjdk-8-jre | oracle-java8-installer"
......@@ -121,6 +119,69 @@ function build_deb() {
sudo mv $ONOS_STAGE_ROOT/deb.deb $ONOS_DEB && ls -l $ONOS_DEB
}
# Build an RPM package
function build_rpm() {
read -r -p "WARN: rpm-build utility and root priviledges are need to build the package. Do you want to continue? [Y/n] " response
case $response in
[nN][oO])
exit 0
;;
*)
sudo rm -fr $ONOS_RPM_ROOT
sudo yum -y install rpm-build
mkdir -p $ONOS_RPM_ROOT/{BUILD,RPMS,SOURCES/ONOS-$ONOS_RPM_VERSION/{etc/init,opt},SPECS,SRPMS}
cp -r $ONOS_STAGE $ONOS_RPM_ROOT/SOURCES/ONOS-$ONOS_RPM_VERSION/opt/onos
cp $ONOS_ROOT/tools/package/debian/onos.conf $ONOS_RPM_ROOT/SOURCES/ONOS-$ONOS_RPM_VERSION/etc/init/
cd $ONOS_RPM_ROOT/SOURCES
COPYFILE_DISABLE=1 tar zcf ONOS-$ONOS_RPM_VERSION.tar.gz ONOS-$ONOS_RPM_VERSION
{
echo "Name: ONOS"
echo "Version: $ONOS_RPM_VERSION"
echo "Release: 1"
echo "Summary: Open Networking Operating System (ONOS)"
echo "Vendor: ONOS Project"
echo "Packager: ONOS Project"
echo "Group: Applications/Engineering"
echo "Requires: jre >= 1:8"
echo "License: Apache 2.0"
echo "URL: http://www.onosproject.org"
echo "Source0: ONOS-$ONOS_RPM_VERSION.tar.gz"
echo "BuildArch: noarch"
echo "BuildRoot: %{_tmppath}/%{name}-buildroot"
echo "%description"
echo "Open Network Operating System (ONOS) is an opensource SDN controller."
echo -e "\n"
echo "%prep"
echo "%setup -q"
echo -e "\n"
echo "%install"
echo "mkdir -p %{buildroot}"
echo "cp -R * %{buildroot}"
echo -e "\n"
echo "%clean"
echo "rm -rf %{buildroot}"
echo -e "\n"
echo "%files"
echo "%defattr(-,root,root,-)"
echo "/etc/init/onos.conf"
echo "/opt/onos/"
echo -e "\n"
echo "%post"
echo "echo ONOS successfully installed at /opt/onos"
} > $ONOS_RPM_ROOT/SPECS/onos.spec
rpmbuild --define "_topdir $ONOS_RPM_ROOT" -bb $ONOS_RPM_ROOT/SPECS/onos.spec
cp $ONOS_RPM_ROOT/RPMS/noarch/ONOS-$ONOS_RPM_VERSION-1.noarch.rpm $ONOS_STAGE_ROOT && ls -l $ONOS_STAGE_ROOT/ONOS-$ONOS_RPM_VERSION-1.noarch.rpm
;;
esac
}
# Script entry point
[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
. $ONOS_ROOT/tools/build/envDefaults
......@@ -133,12 +194,15 @@ rm -fr $ONOS_STAGE
# If there are parameters check if we want to build a deb - otherwise build tar.gz
case ${1:---tar} in
"--tar") build_stage_dir
"--tar" | "-T") build_stage_dir
build_compressed_package
;;
"--deb") build_stage_dir
"--deb" | "-D") build_stage_dir
build_deb
;;
*) echo "usage: $(basename $0) [--tar|--deb]" >&2 && exit 1
"--rpm" | "-R") build_stage_dir
build_rpm
;;
*) echo "usage: $(basename $0) [--tar|--deb|--rpm]" >&2 && exit 1
;;
esac
......